• AVR Freaks

Hot![SOLVED] dsPIC33EP conflict between USB and ECAN clock signal

Author
pablo_GH
New Member
  • Total Posts : 13
  • Reward points : 0
  • Joined: 2021/02/26 13:48:51
  • Location: 0
  • Status: offline
2021/02/27 03:52:34 (permalink)
4 (1)

[SOLVED] dsPIC33EP conflict between USB and ECAN clock signal

Hello all,
 
I'm using a dsPIC33EP256MU806 with a 20Mhz crystal attached as Primary Oscillator with PLL to get 60Mhz after PLL (FOSC), so ECAN frequency is Fp (FOSC/2) on my system. I'm also using Primary Oscillator(POSCCLK) as input in APLL to get 48Mhz for USB.
ECAN is working properly until I set APLL correctly to get 48Mhz. With 48Mhz after APLL USB is working properly, so basically if I have 48Mhz after APLL ECAN stop working and I can't have both protocols working.
 
Please see image attached, on the left APLL is set wrong so the ECAN works fine but USB don't. On the rigth side APLL is now correct to provide 48Mhz so USB works fine with this but ECAN don't. How is this possible?? APLL must not affect on PLL...
post edited by pablo_GH - 2021/03/04 12:40:19

Attached Image(s)

#1

18 Replies Related Threads

    pablo_GH
    New Member
    • Total Posts : 13
    • Reward points : 0
    • Joined: 2021/02/26 13:48:51
    • Location: 0
    • Status: offline
    Re: dsPIC33EP conflict between USB and ECAN clock signal 2021/03/01 23:12:09 (permalink)
    5 (1)
    Now I found that ECAN is working after power up, but once I connect the USB (wich is detected by PC) ECAN stop working.  So ECAN is working with APLL applied, the problem is when I connect the USB from dsPIC33E to my PC and even after disconnecting it from PC, ECAN issue remains until I reset microcontroller again. 
     
    How USB (CDC) connection to host is affecting ECAN wich is using FP after Primary Oscillator with PLL?
    #2
    RISC
    Super Member
    • Total Posts : 6067
    • Reward points : 0
    • Status: offline
    Re: dsPIC33EP conflict between USB and ECAN clock signal 2021/03/02 07:09:59 (permalink)
    4 (1)
    Hi,
    Can you give the details how you selected the different clocks in your system ?
    Do you use MCC plugin ?
    The mandatory frequency is 48MHz for USB
    Are you ready to change the external XTAL frequency ? 
    From my calculations maybe 20MHz is not a good choice if you want to have both 48MHz USB clock and max MIPS frequency (60 MIPS).
    I guess 24MHz would probably be better
    With 20 MHz XTAL :
    prescaler = 1:5, feedback = 1:48, postscaler = 1:2 
    and
    auxiliary clock = prescaler = 1:4 you get 48MHz USB clock
    then Fosc=96MHz (48 MIPS)
    regards

    For support make sure to check first here : http://microchipdeveloper.com
    There are hundreds of PIC, AVR, SAM...which one do YOU use ?
    #3
    pablo_GH
    New Member
    • Total Posts : 13
    • Reward points : 0
    • Joined: 2021/02/26 13:48:51
    • Location: 0
    • Status: offline
    Re: dsPIC33EP conflict between USB and ECAN clock signal 2021/03/02 08:41:05 (permalink)
    0
    Thank you for your reply,
     
    This is my PLL configuration;
    prescaler = 1:5, feedback = 1:28, postscaler = 1:2
    Fin= 20MHz
    N1= 4
    M= 28
    N2= 2
    Registers bits (DEC)
    PLLPRE= 2
    PLLDIV= 26
    PLLPOST= 0
    So the frequency I get is;
    Fref= 5MHz
    Fvco= 140MHz
    Fosc= 70MHz
    Fp= 35MHz
     
    This is my APLL configuration;
     prescaler = 1:5, feedback = 1:24 postcaler = 1:2
    Fain= 20MHz
    N1= 5
    M= 24
    N2= 2
    Registers bits (DEC)
    APLLPRE= 5
    APLLDIV= 24
    APLLPOST= 2
    So the frequency I get is;
    Faref= 4MHz
    Favco= 96MHz
    ACLK(USB)= 48MHz
     
    Let me try your settings proposal.
    post edited by pablo_GH - 2021/03/02 08:44:40
    #4
    pablo_GH
    New Member
    • Total Posts : 13
    • Reward points : 0
    • Joined: 2021/02/26 13:48:51
    • Location: 0
    • Status: offline
    Re: dsPIC33EP conflict between USB and ECAN clock signal 2021/03/02 08:59:46 (permalink)
    3 (1)
    With this suggested PLL
    prescaler = 1:5, feedback = 1:48, postscaler = 1:2 
    Fosc=96MHz 
    I need to change configuration bits for ECAN wich doesn't allow FCAN to be higher than 40Mhz, I can use Fosc or Fp for FCAN, but Fp in this case is 48Mhz and Fosc 96Mhz.
    #5
    pablo_GH
    New Member
    • Total Posts : 13
    • Reward points : 0
    • Joined: 2021/02/26 13:48:51
    • Location: 0
    • Status: offline
    Re: dsPIC33EP conflict between USB and ECAN clock signal 2021/03/02 09:34:42 (permalink)
    0
    I forgot your first questions, yes I used MCC only at the beginning, you can see on the original post an image attached from clock.c file genereted by MCC, this file was modified manually by me. I only changed CLKDIV, PLLFBD, ACLKCON3 and ACLKDIV3 registers.
     
    Yes, I can change xtal if necessary.
    #6
    RISC
    Super Member
    • Total Posts : 6067
    • Reward points : 0
    • Status: offline
    Re: dsPIC33EP conflict between USB and ECAN clock signal 2021/03/02 10:02:16 (permalink)
    4 (1)
    Hi,
    Regarding USB I have a different setup :
     prescaler = 1:5, feedback = 1:24 postcaler = 1:1
    Fain= 20MHz
    N1= 5
    M= 24
    N2= 1
    Registers bits (DEC)
    APLLPRE= 5
    APLLDIV= 24
    APLLPOST= 1
    So the frequency I get is;
    Faref= 4MHz
    Favco= 96MHz
    ACLK(USB)= 48MHz
     
    According to Clock reference manual : N2 = APLLPOST + 1
    Regards

    For support make sure to check first here : http://microchipdeveloper.com
    There are hundreds of PIC, AVR, SAM...which one do YOU use ?
    #7
    pablo_GH
    New Member
    • Total Posts : 13
    • Reward points : 0
    • Joined: 2021/02/26 13:48:51
    • Location: 0
    • Status: offline
    Re: dsPIC33EP conflict between USB and ECAN clock signal 2021/03/02 10:38:01 (permalink)
    0
    Yes you are rigth, on datasheet I didn't find that, I found it on a reference manual with the next values;
    N1 = APLLPRE + 1
    N2 = APLLPOST + 1
    M = APLLDIV + 15
     
    Do you see this values for N1 and M too on the document you get N2?
    #8
    pablo_GH
    New Member
    • Total Posts : 13
    • Reward points : 0
    • Joined: 2021/02/26 13:48:51
    • Location: 0
    • Status: offline
    Re: dsPIC33EP conflict between USB and ECAN clock signal 2021/03/02 10:56:49 (permalink)
    0
    I tried changing only APLLPOST = 1, then when I connect the USB my PC doesn't recongnize the device. 
    #9
    pablo_GH
    New Member
    • Total Posts : 13
    • Reward points : 0
    • Joined: 2021/02/26 13:48:51
    • Location: 0
    • Status: offline
    Re: dsPIC33EP conflict between USB and ECAN clock signal 2021/03/02 11:51:56 (permalink)
    0
    I don't find many references to APLL for dsPIC33E but according to datasheet APLLPOST mut be set to b111 to divide VCO by 1, with this setting PC doesn't recognize USB.
     
    My PC does reconize my device using b110 (divided by 2) or even b001 (divided by 64) on APLLPOST, anyway with b111, b110 and b001 everytime I connect USB, ECAN stop working.
     
    I send message thru CAN and see the feedback, when I connect the USB I see that my device send 0x00 0x00 twice thru CAN then stop sending data until I reset the device.
    post edited by pablo_GH - 2021/03/02 12:14:03
    #10
    pablo_GH
    New Member
    • Total Posts : 13
    • Reward points : 0
    • Joined: 2021/02/26 13:48:51
    • Location: 0
    • Status: offline
    Re: dsPIC33EP conflict between USB and ECAN clock signal 2021/03/03 09:40:04 (permalink)
    0
    I confirm that even disabling the Auxillary Clock, when I connect USB to my PC issue remains.
     
    Maybe this issue is not related to oscillator system...
    #11
    RISC
    Super Member
    • Total Posts : 6067
    • Reward points : 0
    • Status: offline
    Re: dsPIC33EP conflict between USB and ECAN clock signal 2021/03/03 12:32:01 (permalink)
    0
    Hi,
    For 16bits devices you need to refer tp the Family Reference Manuals for detailed operation.
    For oscillators look at this document : 
    https://ww1.microchip.com/downloads/en/DeviceDoc/70005131a.pdf
     
    For proper USB operation 2 things are essential :
    48MHz clock and USB protocole must be executed maximum every 1 ms (for Full Speed protocole)
    So, either you have a non blocking main loop, an interrupt driven USB task execution every ms or an RTOS launching this USB task
     
    How is your current software serving CAN and USB ?
    Can you manage to have CAN working fine alone and having USB working fine alone ?
    Is your issue integrating them together ?
    Regards 

    For support make sure to check first here : http://microchipdeveloper.com
    There are hundreds of PIC, AVR, SAM...which one do YOU use ?
    #12
    pablo_GH
    New Member
    • Total Posts : 13
    • Reward points : 0
    • Joined: 2021/02/26 13:48:51
    • Location: 0
    • Status: offline
    Re: dsPIC33EP conflict between USB and ECAN clock signal 2021/03/03 13:51:26 (permalink)
    0
    Thanks for the document.
     
    The 48MHz are provide just the way we saw on previous replies (using PRI+APLL), and USB is working fine with this configuration, I can send-transmit data thru USB without a problem, USB is on polling mode (not event).
     
    For ECAN I'm using Primary Oscillator with PLL to have 30MHz on CAN clock (Fp) and is working too, I send and transmit data thru CAN bus (interrupt pins for ECAN are disabled), but stops working after USB is connected, USB works always fine no matter if I have ECAN connected to CAN bus.
     
    So far I'm only tested both modules, so I don't have a main code developed, I'm only creating stubs to test and yes, both are working fine alone.
     
    I'm using MLA for USB stack and I know that in CDC when Vbus is powered by host, my device starts a routine so the host can enumerate it. When I remove Vbus my device isn't detected by my PC and ECAN still working.
     
    This makes me think that there's an interruption on Vbus pin that could create a conflict on DMA, where I set the ECAN buffers.
    #13
    RISC
    Super Member
    • Total Posts : 6067
    • Reward points : 0
    • Status: offline
    Re: dsPIC33EP conflict between USB and ECAN clock signal 2021/03/03 15:06:30 (permalink)
    0
    Hi,
    Is your system always powered from USB or from an external power supply ?
    Does the USB stack detect the state where you remove the USB connector ?
    Put a breakpoint to see if this is properly detected...
    Which hardware debugger do you use (pickit3/4, ICD3/4)
    Regards

    For support make sure to check first here : http://microchipdeveloper.com
    There are hundreds of PIC, AVR, SAM...which one do YOU use ?
    #14
    pablo_GH
    New Member
    • Total Posts : 13
    • Reward points : 0
    • Joined: 2021/02/26 13:48:51
    • Location: 0
    • Status: offline
    Re: dsPIC33EP conflict between USB and ECAN clock signal 2021/03/03 15:27:53 (permalink)
    0
    My system is self-powered so it's powered by an external supply not by USB.
     
    I'm using pickit3, thank you I will identify where is this routine so I can set the breakpoint and see what happens when USB is connected/disconnected.
    #15
    pablo_GH
    New Member
    • Total Posts : 13
    • Reward points : 0
    • Joined: 2021/02/26 13:48:51
    • Location: 0
    • Status: offline
    Re: dsPIC33EP conflict between USB and ECAN clock signal 2021/03/03 17:38:16 (permalink)
    0
    In the meantime, I confirmed this issue is not HW related, as I test CAN without USB stack, I connected the USB and there were no problems.
     
    So this issue only occurs when there is USB stack, is SW related. I'll try to see into the code as you suggested.
    Thank you.
    #16
    ric
    Super Member
    • Total Posts : 30244
    • Reward points : 0
    • Joined: 2003/11/07 12:41:26
    • Location: Australia, Melbourne
    • Status: offline
    Re: dsPIC33EP conflict between USB and ECAN clock signal 2021/03/03 18:14:44 (permalink)
    4 (1)
    pablo_GH
    ... USB is on polling mode (not event).

    It sounds like you are not polling the USB fast enough (once per millisecond) when the CAN software is running.
     

    I also post at: PicForum
    Links to useful PIC information: http://picforum.ric323.co...opic.php?f=59&t=15
    NEW USERS: Posting images, links and code - workaround for restrictions.
    To get a useful answer, always state which PIC you are using!
    #17
    Murton Pike Systems
    Super Member
    • Total Posts : 247
    • Reward points : 0
    • Joined: 2020/09/10 02:13:01
    • Location: 0
    • Status: offline
    Re: dsPIC33EP conflict between USB and ECAN clock signal 2021/03/03 19:26:26 (permalink)
    0
    ric
    pablo_GH
    ... USB is on polling mode (not event).

    It sounds like you are not polling the USB fast enough (once per millisecond) when the CAN software is running.

    I design usb scopes and data capture can take up to 20 seconds and in that time USB is not polled.
    All interrupts are stopped until scope data buffer is full.
     
     
    #18
    pablo_GH
    New Member
    • Total Posts : 13
    • Reward points : 0
    • Joined: 2021/02/26 13:48:51
    • Location: 0
    • Status: offline
    Re: dsPIC33EP conflict between USB and ECAN clock signal 2021/03/04 12:35:17 (permalink)
    0
    Thank you all for your answers.
     
    I can finally got both modules work together without issues, this was done by removing USBSuspend(); line from a function called USBDeviceTasks() (inside MLA USB stack), it wasn't really necessary for my application and was making ECAN to fail.
     
    Any further detail regarding this I will let you know, so far I really appreciate your answers.
    #19
    Jump to:
    © 2021 APG vNext Commercial Version 4.5