lancaster-university / codal-nrf52

MIT License
3 stars 15 forks source link

Explicitly set SAADC channel config mode to single ended. #50

Closed microbit-carlos closed 1 year ago

microbit-carlos commented 1 year ago

The ADC SE (single ended) mode is set with value 0 at bit 20 in the CONFIG register for each channel.

image image

Before this PR the bit was left as zero, which does set the SE mode. This is the desired mode, as we want the differential mode to be GND. So, this addition does not actually change the value set to CH[n].CONFIG, but it's better to be explicit about the configuration.

The values for the macros can be found in: https://github.com/NordicSemiconductor/nrfx/blob/master/mdk/nrf52833_bitfields.h#L11953-L11957

/* Bit 20 : Enable differential mode */
#define SAADC_CH_CONFIG_MODE_Pos (20UL) /*!< Position of MODE field. */
#define SAADC_CH_CONFIG_MODE_Msk (0x1UL << SAADC_CH_CONFIG_MODE_Pos) /*!< Bit mask of MODE field. */
#define SAADC_CH_CONFIG_MODE_SE (0UL) /*!< Single-ended, PSELN will be ignored, negative input to SAADC shorted to GND */
#define SAADC_CH_CONFIG_MODE_Diff (1UL) /*!< Differential */
JohnVidler commented 1 year ago

Looks like a simple fix here - has this been tested with the mic to verify we have the same behaviour with and without this patch?

microbit-carlos commented 1 year ago

Not tested anything on the device, but built with and without the patch and the hex file produced was identical.

JohnVidler commented 1 year ago

Ok, lets put it in then, and I'll test again with the audio edits I'm working on.