This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

LAUNCHXL-F2800157: Clarification on Setting CAN Bitrate Metadata Bytes to "C0 7A" in DCAN Flash Kernel

Part Number: LAUNCHXL-F2800157


Tool/software:

Hello,

I am working with LAUNHXL-F2800157 and following the DCAN CAN Flash Programming Guide to configure the CAN bus bitrate. The guide instructs modifying bytes 3-4 in the generated flash kernel text file to "C0 7A" to set the desired bitrate.

I understand that these bytes contain metadata for bitrate configuration, but I'm seeking a detailed explanation of the transformation process that leads to the specific values "C0 7A". Could someone please clarify how these values are derived?

For context, my CAN clock (CANCLK) is set to [e.g., 20 MHz], and I'm aiming for a bitrate of [e.g., 100 kbps].

Thank you in advance for your assistance.

Best regards,
Taif

  • Given values:

    ```
    CAN_CALC_BITRATE = 1000000U
    CAN_CALC_CANCLK = 20000000U
    CAN_CALC_BITTIME = 20U
    CAN_CALC_TSYNC = 1U
    CAN_CALC_TPROP = 2U
    ```

    1. CAN_CALC_BRP:
    ```
    CAN_CALC_BRP = CAN_CALC_CANCLK / (CAN_CALC_BITRATE * CAN_CALC_BITTIME)
    Given:
    - CAN_CALC_CANCLK = 20000000
    - CAN_CALC_BITRATE = 1000000
    - CAN_CALC_BITTIME = 20
    Calculation: 20000000 / (1000000 * 20) = 1
    ```

    2. CAN_CALC_TPHASE:
    ```
    CAN_CALC_TPHASE = CAN_CALC_BITTIME - (CAN_CALC_TSYNC + CAN_CALC_TPROP)
    Given:
    - CAN_CALC_BITTIME = 20
    - CAN_CALC_TSYNC = 1
    - CAN_CALC_TPROP = 2
    Calculation: 20 - (1 + 2) = 17
    ```

    3. CAN_CALC_PHSEG2:
    ```
    CAN_CALC_PHSEG2 = ((CAN_CALC_TPHASE / 2U) <= 8U) ? (CAN_CALC_TPHASE / 2U) : 8U
    Given:
    - CAN_CALC_TPHASE = 17 (from step 2)
    Calculation: (17/2 = 8.5) > 8, therefore = 8
    ```

    4. CAN_CALC_TSEG2:
    ```
    CAN_CALC_TSEG2 = CAN_CALC_PHSEG2 - 1U
    Given:
    - CAN_CALC_PHSEG2 = 8 (from step 3)
    Calculation: 8 - 1 = 7
    ```

    5. CAN_CALC_PHSEG1:
    ```
    CAN_CALC_PHSEG1 = CAN_CALC_TPHASE - CAN_CALC_PHSEG2
    Given:
    - CAN_CALC_TPHASE = 17 (from step 2)
    - CAN_CALC_PHSEG2 = 8 (from step 3)
    Calculation: 17 - 8 = 9
    ```

    6. CAN_CALC_TSEG1:
    ```
    CAN_CALC_TSEG1 = (CAN_CALC_PHSEG1 + CAN_CALC_TPROP) - 1U
    Given:
    - CAN_CALC_PHSEG1 = 9 (from step 5)
    - CAN_CALC_TPROP = 2
    Calculation: (9 + 2) - 1 = 10
    ```

    7. CAN_CALC_TSJW:
    ```
    CAN_CALC_TSJW = ((CAN_CALC_PHSEG2 > 4U) ? 4U : CAN_CALC_PHSEG2) - 1U
    Given:
    - CAN_CALC_PHSEG2 = 8 (from step 3)
    Calculation: (8 > 4, therefore use 4) - 1 = 3
    ```

    8. CAN_CALC_BRPEREG:
    ```
    CAN_CALC_BRPEREG = (CAN_CALC_BRP - 1U) / 64U
    Given:
    - CAN_CALC_BRP = 1 (from step 1)
    Calculation: (1 - 1) / 64 = 0
    ```

    9. CAN_CALC_BRPREG:
    ```
    CAN_CALC_BRPREG = (CAN_CALC_BRP - 1U) % 64U
    Given:
    - CAN_CALC_BRP = 1 (from step 1)
    Calculation: (1 - 1) % 64 = 0
    ```

    10. Final CAN_CALC_BTRREG:
    ```
    CAN_CALC_BTRREG = (CAN_CALC_BRPEREG<<16U) | (CAN_CALC_TSEG2<<12U) | (CAN_CALC_TSEG1<<8U) | (CAN_CALC_TSJW<<6U) | CAN_CALC_BRPREG
    Given:
    - CAN_CALC_BRPEREG = 0 (from step 8)
    - CAN_CALC_TSEG2 = 7 (from step 4)
    - CAN_CALC_TSEG1 = 10 (from step 6)
    - CAN_CALC_TSJW = 3 (from step 7)
    - CAN_CALC_BRPREG = 0 (from step 9)
    Calculation: (0<<16) | (7<<12) | (10<<8) | (3<<6) | 0 = 0x7AC0
    ```

    Final result: CAN_CALC_BTRREG = 0x7AC0