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.

MSP432P401R: Conversion from float to unsigned interger-16

Other Parts Discussed in Thread: DAC161S055

Tool/software: Code Composer Studio

As, I am working CCS V_8 version and deveolping code for MSP432P401R. I am facing a strange problem regarding overflow. As I have my project chain (ADC-DSP-DAC) in my complete project, I am working to implement a digital bandpass filter on MSP432 of the order of 46th by using floating point feature of controller. ADC input range is (0-2.5V) and I am expecting output range same for DAC but the problem is that when I increased input value more than 2.38V Then it leads to an overflow issue. By changing offset vale on signal generator, this issue can be tackeld up to some limit but it is not a professional solution. By googling, i read some articles regarding data type conversions and followed the given procedure (i.e. int (float+0.5)) but it is not helping me. As, my question is more about c programming but I think It has relation with CCS also.

Overflow is occuring due to last values of output when some values are becoming less than zero.Can you please help me to eliminate this overflow issue ??

Note: I have attached the pictures of output  with overflow and without overflow alongside the specific part of code too. Every possible suggestion is highly appreciated.

This two picture are taking at the input of step response to the filter.

AdcInputVoltage = AdcValueDigits*2.5f/16384.0f;
     filteredf_output = SincFilter(AdcInputVoltage);
    /* if (filteredf_output<0){ DacValueDigits = (uint16_t)(( filteredf_output* 65536.0f/4.096f)+0.5);
     }
     else {DacValueDigits= (uint16_t)(( filteredf_output* 65536.0f/4.096f));
    } */
     DacValueDigits = (uint16_t)(( filteredf_output* 65536.0f/4.096f)+.5);
     //DacValueDigits = ((uint16_t)(( filteredf_output* 65536.0f/4.096f)+32678.5))-32677;

Regards,

Hasan Nawaz

  • Hasan,
    What are the values of the variables that resulted in the incorrect result? AdcValueDigits, filteredf_output, DacValueDigits ?

    Chris
  • Good morning Chris,

    As I am using floating point feature of MSP432P401R, I am using following values for above defined parameters:

    filteredf_output are float  values which are coming from the multiplication of filter coefficients and input.

    AdcValueDigits : these values are integer values coming from the digital values coming from output of ADC.

    DacValueDigits : In my project, I am using DAC161S055 as a DAC and it does not have floating point feature , therefore I need to convert that float values to unsigned interger-16 bits. I can use only unsigned integer-16 for DAC because DAC is 16 bits. 

    According to my understanding that because of conversion of data from float (32-bits) to unsigned integer (16-bits) , data loss is occuring and it is leading to this overflow issue.

    Note: Please check the data type of defined variables

    float AdcInputVoltage
    float filteredf_output
    uint16_t AdcValueDigits

    uint16_t DacValueDigits

  • Hello,
    So if the ADC result is 0x0003, then what do the other values result in? What values cause the overflow? In the code snippet you shared above certain portions are commented out. What code produced the overflow, and which code prevented it?

    Thank you,
    Chris
  • Hi chris,
    I have solved this issue. It happened due to conversion from float to integer. When filter output has negative values then due to conversion rules, every negative values has an addition of maximum value from float data type. I have trimmed that negative values and it is enough for my project.

**Attention** This is a public forum