Description
Description of defect
AnalogIn::read returns a value is not correct.
■Expected behavior
AnalogIn::read should return a value from 0.0 to 1.0
■Actual behavior
AnalogIn::read returns a value from 0.0 to 0x0FFF/0XFFFF = 0.0624856946669718
■Cause:
analogin_read_u16 returns a value in the range 0x0000 - 0x0FFF since the resolution of the ADC is 12 bits.However, in analogin_read this value gets divided by 0xFFFF assuming the range is 0x0000-0xFFFF.
This causes a small error in the value returned by AnalogIn::read for the IMXRT1050 target.
■Fix proposal
Shift the value returned by analogin_read_u16 by 4 bits to make 16bit ADC
Target(s) affected by this defect ?
IMXRT1050
Toolchain(s) (name and version) displaying this defect ?
ARMC6
What version of Mbed-os are you using (tag or sha) ?
mbed-os-6.3.0
What version(s) of tools are you using. List all that apply (E.g. mbed-cli)
Mbed Studio 1.3.1
How is this defect reproduced ?
■Reproduce
With Vdd = 3.3V
In case of 3.3V ADC, iMX1050 ADC Data Register value 4096
float analogin_read (analogin_t * obj)
{
uint16_t value = analogin_read_u16 (obj); // value = 4096 Originally, 4096*16(need to 4 bit left shift)
return (float) value * (1.0f / (float) 0xFFFF); // value = 0.0625 Originally, 1.0
}