Important changes to forums and questions
All forums and questions are now archived. To start a new conversation or read the latest updates go to forums.mbed.com.
9 years, 3 months ago.
Bug? AnalogIn with nRF51822 not returning normalized 16bit
For nRF51822-mkit the mbed AnalogIn is returning raw instead of expected platform independent normalized 16bit value.
- example:
- AnalogIn adcA(p1); nRF51822p0.01==pin05==AIN2
- :
- value = adcA.read(); Correctly returning float 0.01.0 for input of GndVcc)
- value = adcA.read_u16(); Returning raw 10bit 0x0000x3FF, not the expected normalized 0x00000xFFFF
- Reference: https://developer.mbed.org/handbook/AnalogIn
- Related to: https://developer.mbed.org/questions/4239/AnalogInread_u16-function-returns-04095-/
Is this correct place to post bug for this platform?
Question relating to:
1 Answer
9 years, 3 months ago.
This is a bug and has been raised as an issue here. https://github.com/mbedmicro/mbed/issues/786
Should be a simple fix so it may be worth creating a new issue since this one is a bit more open ended. You could also create the patch... This change should be all that's needed.
// current return (uint16_t)NRF_ADC->RESULT; // 10 bit // should be uint16_t value = NRF_ADC->RESULT; return (value << 6) | ((value >> 4) & 0x003F); // 10 bit
Example of 10bit to 16bit normalization: https://github.com/mbedmicro/mbed/blob/master/libraries/mbed/targets/hal/TARGET_NXP/TARGET_LPC13XX/analogin_api.c#L116