Fixed wrong conversion in GDx ADC driver
This commit is contained in:
parent
4d3eacc144
commit
d329e141ed
|
|
@ -64,13 +64,11 @@ uint16_t adc0_getRawSample(uint8_t ch)
|
||||||
uint16_t adc0_getMeasurement(uint8_t ch)
|
uint16_t adc0_getMeasurement(uint8_t ch)
|
||||||
{
|
{
|
||||||
/*
|
/*
|
||||||
* To avoid using floats, we convert the raw ADC sample to mV using 16.16
|
* ADC data width is 16 bit: to convert from ADC samples to voltage in mV,
|
||||||
* fixed point math. The equation for conversion is (sample * 3300)/4096 but,
|
* first multiply by 3300 and then divide the result by 65536 by right
|
||||||
* since converting the raw ADC sample to 16.16 notation requires a left
|
* shifting it of 16 positions.
|
||||||
* shift by 16 and dividing by 4096 is equivalent to shifting right by 12,
|
|
||||||
* we just shift left by four and then multiply by 3300.
|
|
||||||
* With respect to using floats, maximum error is -1mV.
|
* With respect to using floats, maximum error is -1mV.
|
||||||
*/
|
*/
|
||||||
uint32_t sample = (adc0_getRawSample(ch) << 4) * 3300;
|
uint32_t sample = adc0_getRawSample(ch) * 3300;
|
||||||
return ((uint16_t) (sample >> 16));
|
return ((uint16_t) (sample >> 16));
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue