Hot!dsPic33CH CAN questions

Author
BLmicro
Starting Member
  • Total Posts : 39
  • Reward points : 0
  • Joined: 2011/03/22 08:20:17
  • Location: 0
  • Status: offline
2018/10/16 08:53:34 (permalink)
0

dsPic33CH CAN questions

In doc dsPIC33-PIC24-FRM-CAN-Flexible-Data-Rate-FD-Protocol-Module-70005340a sec 5 (Configuration) it states
"SYSCLK of 80 MHz, 40 MHz, 20 MHz or 10 MHz is recommended". Is that referring to the derived CAN clock or is that referring to Fosc or is that referring to Fcy/Fsysclk/Fsys which is Fosc/2? Obviously the overall device speed is not constrained by the CAN module so I'm leaning towards SYSCLK in that context as being derived CAN clock derived by the settings in the
CANCLKCON reg.  Just need to verify, clock acronyms abound!
 
So then my bit timing calculations would use that frequency (C1NBTCFGH/C1DBTCFGH <BRP> where TQ = n/Fsys) Fsys is that "SYSCLK". Correct?
 
-BL
#1

13 Replies Related Threads

    BLmicro
    Starting Member
    • Total Posts : 39
    • Reward points : 0
    • Joined: 2011/03/22 08:20:17
    • Location: 0
    • Status: offline
    Re: dsPic33CH CAN questions 2018/10/16 12:29:19 (permalink)
    0
    Also in Table 5-3, the NTq appears to have been computed with an Fsysclk of 80MHz when just above that line in the table the Fsysclk = 40Mhz. From other examples I'm seeing the Tq is computed from Fosc as well. So which is it? And to my earlier question, does enabling the CAN clock cause that clock to be used as the Fsysclk?
     
    i.e.  Tq = BRP/Fsysclk  so is the Fsysclk the Fosc or Fosc/2? The calculations appear to have used Fosc (80MHz) in that example.
     
    Also, maybe a typo but the Seg1 value below in Table 5-5 fails to add in the propagation delay from table 5-3.
     
    -BL
    #2
    purdyd
    Senior Member
    • Total Posts : 116
    • Reward points : 0
    • Joined: 2004/03/22 21:02:01
    • Status: offline
    Re: dsPic33CH CAN questions 2018/10/17 20:39:48 (permalink)
    0
    you have to setup the CANCLKCON register to select the source for the CAN clock.  Also the divider and enable.
     
    You also need to setup the input and output pins to associate with the CAN controller.
    #3
    BLmicro
    Starting Member
    • Total Posts : 39
    • Reward points : 0
    • Joined: 2011/03/22 08:20:17
    • Location: 0
    • Status: offline
    Re: dsPic33CH CAN questions 2018/10/19 08:43:22 (permalink)
    0
    My dsPic33CH is on a old Exploer16 board. So far everything has worked awesome. MSI, ADC, Interrupts, Timers etc. The slave is crunching the core algorithm with true parallel processing power. You gotta love
    pure uninterrupted concurrency! Its a beautiful thing. I have the Master core setup to handle all the messaging
    via CAN. I'm using the MCP2515 Monitor demo board to flush out the baud rate settings in the CAN interface using Listen mode.
     
    Most of the CAN module appears to be setup correctly as it sees the message from the MCP2515 but the
    Invalid Message Interrupt Flag (C1NTL.IVMIF) is set indicating to me that my NBT is not matching the settings
    on the MCP2515. I'm taking the signal after the transceiver as well with leads about 6" long to the 33CH/Exploer16.
    This signal looks very good at the 33CH, clean 5v, very sharp.
     
    I downloaded the MCP monitor code that the 18F on that board is using in order to setup my interface exactly.
     
    So I have set this on the 33CH as of now, I've actually tried several settings and none seem to work, this
    is the latest, the numbers have been juggled quite a bit so its possible there's a typo;
     
    //
    // Based on the fact that the MCP2515 on the sending board uses 10TQs for each Nominal Bit Time period (NBT)
    // @ 125KBps with a sys clock of 20MHz and a Baud Rate Prescaler (BRP) of 8 resulting in a Tq of 800ns
    // ( i.e. Tq = (2 * BRP) / 20MHz = 800ns), we will set our Tq and segments accordingly to match the NBT of
    // the sender.
    //
    // Set the clock to 100MHz CPU freq (50MIPs) from XT+PLL (ex: ((8MHz * 75) / 3) / 2 = 100MHz)
    //
    PLLFBDbits.PLLFBDIV = 75;  // M = 75 (ex: FVCO = 600MHz = 8MHz * 75)
    PLLDIVbits.POST1DIV = 3;    // N2=3 (600MHz / 3, followed by fixed / 2 = 100MHz Fosc, 50MHz Fcy)
     
    CANCLKCONbits.CANCLKSEL = 3;  // CAN Clock Source = VCO/2 = 600/2 = 300MHz
    CANCLKCONbits.CANCLKDIV = 14; // divide by 15 i.e. 300/15  = 20MHz
    CANCLKCONbits.CANCLKEN = 1;   // enabled

    /* Enable the CANFD module */
    C1CONLbits.CON = 1;
    /* Make sure the CAN module is in configuration mode, should be upon reset but make sure */
    C1CONHbits.REQOP = 4;
    while(C1CONHbits.OPMOD != 4); // if not wait here
    /* Initialize the C1FIFOBA with the start address of the CAN FIFO message buffer area. */
    C1FIFOBAL = (unsigned int) &CanRxBuffer;
    /* Set up the CANFD module for 125Kbps of Nominal bit rate speed and same fordata.. */
    C1NBTCFGH = 0x0F06; // BRP<15:8> =  15 (Tq  = 16/20MHz = 800ns), TSeg1<7:0> =  PropDelay 3Tq + Seg1 3Tq =6Tq
    C1NBTCFGL = 0x0301; // TSeg2<15:8> = 3Tq, SJW<7:0> = 1
    C1DBTCFGH = 0x0F06; // same for DBT
    C1DBTCFGL = 0x0301;
    C1TDCH = 0x0002; //TDCMOD is Auto
    C1TDCL = 0x1F00;
    /* Configure CANFD module to enable BRS */
    C1CONLbits.BRSDIS = 0x0;
    C1CONHbits.STEF = 0x0; //Don't save transmitted messages in TEF
    C1CONHbits.TXQEN = 0x0; // No TXQ
    /* Configure FIFO1 to Receive 2 messages*/
    C1FIFOCON1Hbits.FSIZE = 0x1; //2 messages
    C1FIFOCON1Hbits.PLSIZE = 0x7; //64 bytes of data
    C1FIFOCON1Lbits.TXEN = 0x0; //Receive fifo     
       
    /* Configure filter 0 and MASK 0 to accept extended id messages with id = 2 and 3 */
    C1FLTCON0Lbits.F0BP = 1; // message stored in FIFO1
    //C1FLTOBJ0L = 0x1000; // EID = 0x00002
    //C1FLTOBJ0H = 0x4000; // Match messages with extended identifier address
    //C1MASK0L = 0xF7FF; // MEID = 0x1FFFE - Last it is 0
    //C1MASK0H = 0xFFFF; // Match message types
    //C1FLTCON0Lbits.FLTEN0 = 1; // Enable the filter 0
    /* Turn the module on for operation by switching to Listen mode. */
    C1CONHbits.REQOP = 3;
    while(C1CONHbits.OPMOD != 3) // wait for transition
    {
       printf("\f Waiting.. %2d\r\n", C1CONHbits.OPMOD );
       __delay_ms(40);
       C1CONHbits.REQOP = 3;
    }
    /* Get the address of the message buffer to read the received messages.*/
    /* set UINC bit to update the FIFO tail */
    CANFD_RX_MSGOBJ *rxObj;
    rxObj = (CANFD_RX_MSGOBJ *)C1FIFOUA1L;
    C1INTHbits.RXIE = 1;

    while(C1FIFOSTA1bits.TFNRFNIF == 0)
    {
        printf("\f%04X %04X\r\n", C1VECLbits.ICODE, C1INTL);
        __delay_ms(40);
    }
     
    Once again there may be some errors in the above settings as I have juggled these numbers quite a bit.
    One was setting the CAN clock to use PLLDIV but that gave the same error.
     
    At this point I intend to get the 33CH to do a transmit and then compare the waveform
    to the MCP2515 and adjust accordingly.
     
    One question, in PLLDIV mode is the CAN clock using Fosc or Fcy? By the Oscillator
    datasheet it appears to be Fosc (Fpllo in fig 1-2 p.4).
     
    Thank you for your response and a great little device!
     
    -BL
     
     
    #4
    du00000001
    Just Some Member
    • Total Posts : 2551
    • Reward points : 0
    • Joined: 2016/05/03 13:52:42
    • Location: Germany
    • Status: offline
    Re: dsPic33CH CAN questions 2018/10/19 09:07:04 (permalink)
    0
    2 (3) things:
    1. Really make the CH transmit to see the result of your bit time settings.
    2. I didn't dig through all your settings, but you have to make sure that the "FD" feature is disabled when communicating vs. the MCP2515 (resp. non-FD nodes). Unfortunately compatibility between FD and non-FD nodes is quite limited.
    3. And one more: make sure the 11 vs. 29 bit configuration is correct: although this shouldn't really matter (one more backward compatibility issue), some silicon implementations require a correct setting of this.

    PEBKAC / EBKAC / POBCAK / PICNIC (eventually see en.wikipedia.org)
    #5
    BLmicro
    Starting Member
    • Total Posts : 39
    • Reward points : 0
    • Joined: 2011/03/22 08:20:17
    • Location: 0
    • Status: offline
    Re: dsPic33CH CAN questions 2018/10/19 10:31:04 (permalink)
    0
    Good one! That was in my notes;
     
    //Try Normal 2.0 mode
    REQOP<2:0> = 110.
     
    But I may not have had the ID set correctly coming from Listen mode where the ID doesn't matter.
     
    I don't understand that 11 vs. 29 point.
     
    -BL
    #6
    du00000001
    Just Some Member
    • Total Posts : 2551
    • Reward points : 0
    • Joined: 2016/05/03 13:52:42
    • Location: Germany
    • Status: offline
    Re: dsPic33CH CAN questions 2018/10/19 11:23:00 (permalink)
    0
    CAN meesages may come with "standard" (11-Bit) or "extended" (29-Bit) identifiers.
    Depending on silicon implementation, 29-Bit identifiers may or may not pass an 11-Bit message filter. Not sure about the other way round (11-Bit passing a 29-Bit filter).

    PEBKAC / EBKAC / POBCAK / PICNIC (eventually see en.wikipedia.org)
    #7
    crosland
    Super Member
    • Total Posts : 1561
    • Reward points : 0
    • Joined: 2005/05/10 10:55:05
    • Location: Bucks, UK
    • Status: offline
    Re: dsPic33CH CAN questions 2018/10/19 11:25:09 (permalink)
    0
    BLmicro
    I don't understand that 11 vs. 29 point.
     



    The length of the identifier.
    #8
    BLmicro
    Starting Member
    • Total Posts : 39
    • Reward points : 0
    • Joined: 2011/03/22 08:20:17
    • Location: 0
    • Status: offline
    Re: dsPic33CH CAN questions 2018/10/19 12:23:38 (permalink)
    0
    Yes I tried switching Extended ID on and off. I saw the msg go much shorter on the scope but didn't seem to help the 33CH interpret it. I'm staring to wonder if what is loaded on the MCP2515 is what I got off the Microchip web site, can't guarantee it is the exact source.
     
    If I capture the Tx from the 33CH and its way off, that will be a big clue.
     
    -BL
    #9
    purdyd
    Senior Member
    • Total Posts : 116
    • Reward points : 0
    • Joined: 2004/03/22 21:02:01
    • Status: offline
    Re: dsPic33CH CAN questions 2018/10/19 20:20:53 (permalink)
    0
    if you can see the output wave form on a scope, you can measure the bit width and determine the baud rate.
     
    send something like an address of 0x55, and data 0x55 repeating so you can get single bits
     
     
    #10
    BLmicro
    Starting Member
    • Total Posts : 39
    • Reward points : 0
    • Joined: 2011/03/22 08:20:17
    • Location: 0
    • Status: offline
    Re: dsPic33CH CAN questions 2018/10/24 12:59:29 (permalink)
    0
    I managed to capture the Tx data frame from the 33CH. I had to connect the Tx and Rx leads together on the 33CH (with a 200ohm resistor just to smooth it a bit) in order to get through arbitration. I couldn't just probe the Tx and expect to get a full data frame because the board is not connected to a bus and the Rx monitors every bit from the bus via Rx that goes out Tx. So if you just leave Rx disconnected you fail arbitration and won't get a full frame. It pays to read the Bosch spec! :-)  Then when connected together the CAN module repeated the Tx over and over bc the ack bit was not getting written over by any active listeners! Just like the spec says.
     
    I used the Tx waveform to compare to the MCP2515 and adjusted the CAN clock and the Baud Rate Pre Scaler and presto! The Invalid Message Bit cleared. ( C1INTL.IVMIF )
     
    Problem solved, onward.
     
    -BL
     
    #11
    du00000001
    Just Some Member
    • Total Posts : 2551
    • Reward points : 0
    • Joined: 2016/05/03 13:52:42
    • Location: Germany
    • Status: offline
    Re: dsPic33CH CAN questions 2018/10/24 14:51:13 (permalink)
    0
    When fiddling with any comms interface more complex than a UART, it always pays to read the pec or some basic introduction  wink
    And when it comes to data (baud) rates, it pays as well to go to some lengths to get the TX going as this is the only way to make your settings measurable.

    PEBKAC / EBKAC / POBCAK / PICNIC (eventually see en.wikipedia.org)
    #12
    purdyd
    Senior Member
    • Total Posts : 116
    • Reward points : 0
    • Joined: 2004/03/22 21:02:01
    • Status: offline
    Re: dsPic33CH CAN questions 2018/10/25 08:53:27 (permalink)
    0
    If you have a functioning CAN bus wiring, with a terminator between CANHi and CANLo, you can easily see the bit timing on the CAN bus lines.
     
    With only one CAN node on the bus, if it tries to transmit a message, it will, as you pointed out, keep trying to send the same message over and over since there is no acknowledge from another CAN node.
     
    Clock setup can often be a little bit of a mystery so I find I do this quite often.  
     
    Unfortunately, as of this date, the code configurator for the dspic33H does not support the CAN peripheral 
     
     
    #13
    BLmicro
    Starting Member
    • Total Posts : 39
    • Reward points : 0
    • Joined: 2011/03/22 08:20:17
    • Location: 0
    • Status: offline
    Re: dsPic33CH CAN questions 2018/10/29 11:40:50 (permalink)
    0
    Yes my clock setting are a bit diff from my math computations but its working like a champ now. Thanks for all the good advice!
     
    Now if Microchip would just provide the libs or source for that PC MCP2515 Monitor demo app. :-) No biggy though, we will purchase an API.
     
    -BL
    #14
    Jump to:
    © 2019 APG vNext Commercial Version 4.5