• AVR Freaks

Helpful ReplyHot!Using ECAN peripheral for dsPIC using Simulink blockset

Author
f.stojanovic
New Member
  • Total Posts : 18
  • Reward points : 0
  • Joined: 2019/05/07 01:56:09
  • Location: 0
  • Status: offline
2019/07/12 06:57:20 (permalink)
0

Using ECAN peripheral for dsPIC using Simulink blockset

Hi all, hi Lubin,
 
I cannot express how grateful I am to Microchip for offering this blockset. It has aided me tremendously with multiple projects. Right now I am looking into the ECAN peripheral configuration. From what I understood, there is no official ECAN block available, as there are just too many use cases for this peripheral that it makes little sense to develop such a solution.
Going through the datasheets and application notes, I really believe that offering basic functionalities in a couple blocks can be achieved.
In any case, I cannot seem to wrap my head around the CANOpen implementation which is recommended by Lubin. What's more, there is no working example available. Manuals for the official blockset are already scarce, let alone some third-party library, so I am out of luck on that front, as well.
 
Has any of you successfully deployed this ECAN library via C functions? If so, if you guys don't mind, can you share with the rest of us how that can be achieved?
 
Having spent a couple days on this issue, I gradually started looking into other solutions. I found this interesting repository :
https://github.com/Susurrus/ECAN_dspic
The "TODO.md" file states :
Push this back up to Lubin for incorporation into his blockset.

 
I guess somebody had been disappointed some seven years ago.
 
Thank you all in advance. Any help is greatly appreciated.
~Phil
 
#1
Lubin
Moderator
  • Total Posts : 370
  • Reward points : 5
  • Joined: 2007/03/31 07:38:15
  • Location: Bayonne, France
  • Status: offline
Re: Using ECAN peripheral for dsPIC using Simulink blockset 2019/07/12 07:28:40 (permalink) ☄ Helpfulby f.stojanovic 2019/07/15 05:27:00
0
Hi Phil,
 
Maybe you might have a look at this post: https://www.microchip.com/forums/FindPost/878818
 
Lubin
#2
f.stojanovic
New Member
  • Total Posts : 18
  • Reward points : 0
  • Joined: 2019/05/07 01:56:09
  • Location: 0
  • Status: offline
Re: Using ECAN peripheral for dsPIC using Simulink blockset 2019/07/12 07:51:07 (permalink)
0
Hi Lubin,
 
Thank you very much for your quick reply. I apologize for answering in that other thread.
 
I already attempted to use all information given in that thread. I tried to make-do with the example given, however it contains virtually nothing.
This is the whole model :
https://prnt.sc/oe5n8y
 

 
That massive green subfunction contains just a single C-function call block :
 
https://prnt.sc/oe5o18
 

The generated code doesn't even initialize my ECAN peripheral, let alone do anything else. All ECAN SFR's are at their reset values.
 
Also, I had some issues with the "space(dma)" attribute. My micro doesn't have support writing to DPSRAM, according to MPLAB. I used this to initialize the ECAN SRAM buffer instead :
 

volatile unsigned int ecan1MsgBuf[NUM_OF_ECAN_BUFFERS][8]
__attribute__((aligned(NUM_OF_ECAN_BUFFERS * 16)));

 
Thank you again. I am clearly missing something. I have tested the ECAN peripheral on my DSC, the reference is dsPIC33EV256GM106. It works flawlessly.
Cheers,
~Phil
post edited by f.stojanovic - 2019/07/12 07:52:54
#3
f.stojanovic
New Member
  • Total Posts : 18
  • Reward points : 0
  • Joined: 2019/05/07 01:56:09
  • Location: 0
  • Status: offline
Re: Using ECAN peripheral for dsPIC using Simulink blockset 2019/07/15 05:26:51 (permalink)
0
Hi again Lubin, thank you again for your input.
 
I've managed to implement that Susurrus/ECAN_dspic repository in my design, the blocks included work properly. I am developing a more generic version in future that handles bit timing automatically (distributes quanta to segments based on baud rate, bus/oscillator stability coefficient and bus length only, or baud rate only, by default).
I will gladly share it with the forum once that is done.
 
Cheers,
~Phil
#4
Lubin
Moderator
  • Total Posts : 370
  • Reward points : 5
  • Joined: 2007/03/31 07:38:15
  • Location: Bayonne, France
  • Status: offline
Re: Using ECAN peripheral for dsPIC using Simulink blockset 2019/07/15 23:49:46 (permalink)
0
I Phil,
 
Thanks for your feedback. 
With theses model, A.Boehler call custom ECAN code through the custom C function call block, but there is also few calls at initialisation. Theses call are configured in the Simulink Option panel => Code Generation => Custom Code => Initialize function (see screenshoot)

Attached Image(s)

#5
dillydilly
New Member
  • Total Posts : 12
  • Reward points : 0
  • Joined: 2018/10/24 14:17:38
  • Location: 0
  • Status: offline
Re: Using ECAN peripheral for dsPIC using Simulink blockset 2019/08/08 14:33:34 (permalink)
0
I'm excited that there are developing CAN with the blockset because I'm starting a project myself and I've never worked with the PIC blockset before.  I'm using dsPIC33EV256GM102 and I had no trouble getting the PIC initialized with working digital I/O and UART to my PC terminal.  I'm unable to get the ECAN_dsPIC module to compile due to the absence of the dsPICdrivers library. 
 
I checked your website, Lubin, and dev stopped in 2012 but I'm using Matlab 2017b. I would like to be using 2019a but I can't get anything to compile due to makerfile error.
 
Phil, can you explain how you got this working?
 
Also, I see that it's for the dsPIC33f but how hard would it be to get it working with the 33EV?  I assume the registers are slightly different and pin assignments as well.  If you could point me down the right path I would appreciate it.
 
Thank you,
Dylan
post edited by dillydilly - 2019/08/08 14:41:14
#6
dillydilly
New Member
  • Total Posts : 12
  • Reward points : 0
  • Joined: 2018/10/24 14:17:38
  • Location: 0
  • Status: offline
Re: Using ECAN peripheral for dsPIC using Simulink blockset 2019/08/08 14:44:11 (permalink)
0
Now that I'm digging around the code I see this:
 

#ifndef _ECANFUNCTIONS_H_
#define _ECANFUNCTIONS_H_
//If simulating, remove the include p33Fxxxx.h Otherwise, leave it.
#include <p33fxxxx.h>
#include "ecanDefinitions.h"
#include "CircularBuffer.h"

 
Can I just change the header to p33evxxx.h and get this working?  Surely it won't be that easy.
#7
Jump to:
© 2019 APG vNext Commercial Version 4.5