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

Is this correct place to post bug for this platform?

Question relating to:

Nordic stack and drivers for the mbed BLE API

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

Nordic file: https://github.com/mbedmicro/mbed/blob/master/libraries/mbed/targets/hal/TARGET_NORDIC/TARGET_MCU_NRF51822/analogin_api.c#L60

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

Just small addition here, you can contribute to mbed in the github repository, the link above Sam's shared. Thanks for raising this issue here.

posted by Martin Kojtal 07 Jan 2015