Skip to content

Commit 81cc5a4

Browse files
author
Seppe Stas
committed
Fix analogin scaling for EFM32 target
Fixes #5115. `analogin_read_u16` returns a value in the range `0x0000 - 0xFFF0` 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 EFM32 target.
1 parent bb61b42 commit 81cc5a4

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

targets/TARGET_Silicon_Labs/TARGET_EFM32/analogin_api.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,8 +99,8 @@ uint16_t analogin_read_u16(analogin_t *obj)
9999

100100
float analogin_read(analogin_t *obj)
101101
{
102-
/* Convert from a uint16 to a float between 0 and 1 by division by 0xFFFF */
103-
return analogin_read_u16(obj) / (float) 0xFFFF;
102+
/* Convert from a uint16 to a float between 0 and 1 by division by 0xFFF0 */
103+
return analogin_read_u16(obj) / (float) 0xFFF0;
104104
}
105105

106106
#endif

0 commit comments

Comments
 (0)