• AVR Freaks

Helpful ReplyUsing ECAN peripheral for dsPIC using Simulink blockset

Author
f.stojanovic
New Member
  • Total Posts : 17
  • Reward points : 0
  • Joined: 2019/05/07 01:56:09
  • Location: 0
  • Status: online
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 : 359
  • 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 : 17
  • Reward points : 0
  • Joined: 2019/05/07 01:56:09
  • Location: 0
  • Status: online
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 : 17
  • Reward points : 0
  • Joined: 2019/05/07 01:56:09
  • Location: 0
  • Status: online
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 : 359
  • 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
Jump to:
© 2019 APG vNext Commercial Version 4.5