Skip to main content
Visitor II
June 9, 2006
Question

CAN Timing

  • June 9, 2006
  • 5 replies
  • 1414 views
Posted on June 09, 2006 at 09:20

CAN Timing

    This topic has been closed for replies.

    5 replies

    tj2Author
    Visitor II
    June 7, 2006
    Posted on June 07, 2006 at 12:50

    I have to re-calculate the CAN bit timing which is implemented in the CAN library, as I switch the APB frequency between 48MHz and 2MHz (PLL off).

    I've changed the baudrate prescaler as the library assumed 8MHz APB. In 48MHz all bitrates works 100k->1M bit. I test with a RS232->CAN dongle.

    When I change to 2MHz, I re-initialize with the same rates except the prescaler and 250K and 125K bit works correct, but I cannot get 100K bit to receive anything. I studied the reference manual and I cannot find a register that contains the Tprop segment. Does anybody know how to set this segment?

    Visitor II
    June 7, 2006
    Posted on June 07, 2006 at 13:42

    What are the Tseg paramaters that you are using?

    tj2Author
    Visitor II
    June 8, 2006
    Posted on June 08, 2006 at 05:13

    at 48MHz:

    u16 CanTimings[] = { // value bitrate NTQ TSEG1 TSEG2 SJW BRP

    CAN_TIMING(11, 4, 4, 30), //100kBit

    CAN_TIMING(11, 4, 4, 24), //125kBit

    CAN_TIMING( 4, 3, 3, 24),//250kBit

    CAN_TIMING(13, 2, 1, 6), //500kBit

    CAN_TIMING( 4, 3, 1, 6)} //1MBit

    At 2MHz:

    u16 CanTimings2M[] = { // value bitrate NTQ TSEG1 TSEG2 SJW BRP

    CAN_TIMING( 8, 3, 1, 1), //100kBit

    CAN_TIMING(11, 4, 4, 1), //125kBit

    CAN_TIMING( 4, 3, 3, 1), //250kBit

    The RS232->CAN dongle I use is setup with these values:

    t_prop=8

    t_seg1=8

    t_seg3=3

    t_sjw =1

    And then adjusted with the TQ-Scaler for the appropiate bitrate.

    Visitor II
    June 8, 2006
    Posted on June 08, 2006 at 06:49

    Calculate the required BRP(baud rate prescaler) for the clock frequency

    BRP = (Clock frequency / number of Time quanter) / Required Baud rate

    so for a 4 meg clock with 10 times PLL (40M), using 16 time quanter

    if a baud rate of 250K is required

    PBR = ( 40000000 / 16 ) / 250000 = 10

    the total number of time quanter is Tseg1 + Tseg2 + 1

    for your 20M clock at 100kbit, i calculate your BPR to be 1.6666

    you need to change the size of your time segments to get this to be a whole number, maybe try CAN_TIMING( 5, 4, 3, 2) or something, like that

    tj2Author
    Visitor II
    June 9, 2006
    Posted on June 09, 2006 at 09:20

    great CAN_TIMING( 5, 4, 3, 2) seems to work!

    My problem was that I made a mistake when calculating the total number of TQ.

    Thank you very much for your help!