ADC data to float conversion

Tip / Sign in to post questions, reply, level up, and achieve exciting badges. Know more

cross mob
User8734
Level 4
Level 4
Good day,

Please advise how convert data from ADC to float format?

I get data from ADC result register in uint16_t variable and see reasonable data at debugging (Like 16363).

What shall I do next to convert it to float32_t format?

BR
K
0 Likes
3 Replies
Travis
Employee
Employee
First solution authored Welcome! 500 replies posted
For 10 bit ADC and Vref at 3.3V, then the total step is 1024. Please note that only the first 16bit of the result register shows the conversion result.

Example:
uint32_t ADC_value;
float result;

ADC_value = Read_AD(); // only the first 16bit is the AD result

result = (ADC_value/1024) * 3.3;
0 Likes
Not applicable
Hi,

You can just declare another float variable and put the result from uint16_t into it.


uint16_t var_A;
float var_F;

var_F = (float)var_A;

0 Likes
User8734
Level 4
Level 4
Good day Jackson,

Thanks, it's working!:)

BR
K
0 Likes