TMS320F28P650DK: The program for TMS320F28P650DK

Part Number: TMS320F28P650DK

Hi,

We use the TMS320F28P650DK for our project, and now, We recently encountered an issue during

code debugging where variables did not behave as expected during the assignment process. #define

CURRENT_SAMPLE_DEFAULT_OFFSET_MAX 39321 // 32768 * 1.2 volatile int32_t temp2;

temp2 = CURRENT_SAMPLE_DEFAULT_OFFSET_MAX;
 
The running result is temp2 = 2457. Could you please help me find out the reason?
  • Hi Zhang,

    The root cause is that the C28x compiler treats int as 16-bit, so your constant 39321 is being interpreted as a 16-bit value, causing overflow and truncation.

    On the TMS320F28P650DK (C28x CPU), int is only 16 bits wide [1]. When the compiler encounters the literal 39321 without a type suffix, it treats it as a 16-bit integer. Since 39321 exceeds the maximum signed 16-bit value (32767), overflow occurs, producing the unexpected result of 2457.

    The Fix

    Append an L or UL suffix to force 32-bit interpretation:

    #define CURRENT_SAMPLE_DEFAULT_OFFSET_MAX 39321L
    or
    #define CURRENT_SAMPLE_DEFAULT_OFFSET_MAX ((int32_t)39321)
    This ensures the constant is treated as a long (32-bit) value before assignment to your int32_t variable [2].

    Why This Happens

    Type
    C28x CPU Size
    int
    16-bit
    long
    32-bit
    long long
    64-bit

    This is a well-known C2000 pitfall. The C/C++ language standards govern how the compiler determines constant types, and there is no compiler option to change this default behavior — you must explicitly specify the type at the source [2].

    Review your codebase for other macros with large numeric constants (above 32767 for signed, or 65535 for unsigned). Any constant exceeding 16-bit range without an L/UL suffix will exhibit the same truncation behavior on C2000 devices.


    To help refine this further, it would be useful to know:

    • Whether similar large constants exist elsewhere in your codebase that may need the same fix
    • Your compiler version and optimization settings (though this issue occurs regardless of optimization level)

    1. C2000 Academy - Data Type Sizes
    2. TMS320F28P650DK: How to make the constant default to 32 bits

    Best Regards,

    Zackary Fleenor