Hello.
I'm using a TM320F28027 controlstick.
I have a problem with a float calculation on this device.
I have a variable float32 AVG_PWMControl_buf
I add to this buffer the result of ADC conversion in adc_isr:
AVG_PWMControl_buf += AdcResult.ADCRESULT4;
After first result is added to buffer I get the results in watch window as followed:
AdcResult.ADCRESULT4 = 3482
AVG_PWMControl_buf = 4.87932125e-42 (DEN) - strange result, especially "e-42"
Measured_Times = 1
After the second measurement:
AdcResult.ADCRESULT4 = 3536
AVG_PWMControl_buf = 9.83431262e-42 (DEN) - strange value
Measured_Times = 2
After 11 interrupts I get results as followed:
AdcResult.ADCRESULT4 = 3517
AVG_PWMControl_buf = 5.41685934e-41 (DEN)
Measured_Times = 11
And I want calculate the variable unsigned int AVG_PWMControl as:
AVG_PWMControl = AVG_PWMControl_buf / Measured_Times;
And I got the result AVG_PWMControl = 63093, which is incorrect.
What is the reason of wrong calculation of float in my project?
P.S.:
1. Code Composer Studio Version: 6.2.0.00050
2. Compiler TI v15.12.3.LTS
I've also detected, that if I decrease an amplitude of analog signal for ADC to value lower than 3000 - calculation goes correctly.
E.g. for AdcResult.ADCRESULT4 = ~2942
After 11 measurements I got:
AVG_PWMControl_buf = 4.54216884e-41 (DEN) - the value is still strange
Measured_Times = 11
AVG_PWMControl = 2946
I suspect, that there is some problem with overflow.
But how an overflow can happen with a variable of float type?
UPDATE:
If I look into memory, I can see, that variable is located only in two bytes, but type float32 is declarated.


