Because of the Thanksgiving holiday in the U.S., TI E2E™ design support forum responses may be delayed the week of November 23.

TIDA-010955: TIDA-010955 Arc Fault truncating value

Part Number: TIDA-010955

In the example software for TIDA-10955 in global.c/h the bias is declared as int32_t rather than float when the array of bias data is of type float. What is the reason for casting it to int immediately?

extern int32_t tvmgen_default_bias_data_0;
extern int32_t tvmgen_default_scale_data_0;
extern int32_t tvmgen_default_shift_data_0;

Additionally, in feature_extraction.c, why is max_val stored as int8_t instead of int32_t?

int8_t max_val = shift > 127 ? 127 : shift;
int8_t min_val = max_val < -128 ? -128 : max_val;
  • For more clarification on my first question:

    In run_feature_extraction:

    //load the data into RAM first to reduce the reading time from Flash memory
    tvmgen_default_bias_data_0 = tvmgen_default_bias_data[0];
    tvmgen_default_scale_data_0 = tvmgen_default_scale_data[0];
    tvmgen_default_shift_data_0 = tvmgen_default_shift_data[0];

    tvmgen_default_bias_data_0 is an int while tvmgen_default_bias_data[] is an array of floats. Then in model_input_conversion:

    float temp_add_bias;
    // biasing, scaling and shifting to convert floating model input to fixed point model input
    temp_add_bias = model_input_float + tvmgen_default_bias_data_0;
    int32_t scale = (int32_t)floorf(temp_add_bias * tvmgen_default_scale_data_0);

    The value is added to a float and stored to a float, and the eventual final answer is cast to int anyways, so I'm a bit confused on what is the purpose of immediately casting tvmgen_default_bias_data[0] to an int rather than keeping as a float?

  • Hi Elena,

    I think you are using older version of DPSDK.
    In latest version (26.01.00.00), 

    tvmgen_default_bias_data_0
    tvmgen_default_scale_data_0
    are float 



    Additionally, in feature_extraction.c, why is max_val stored as int8_t instead of int32_t?
    max_val doesn't need to be 8-bit. On the F28P55x (C28x), int8_t is stored in 16 bits, so the clamp to [-128, 127] works correctly. Real inputs can't overflow it.
    If you want it to be portable, clamp in int32_t and cast once at the end:

    int32_t v = scale >> tvmgen_default_shift_data_0;
    v = v > 127 ? 127 : (v < -128 ? -128 : v);
    return (int8_t)v;

  • I see, thank you for the response Slight smile