Hi,
I´m using the NRF52810 device and have an issue with the SAADC peripheral.
I basically have 2 channel where i want to do some averaging to improve noise.
The setup is as follows:
// Configure SAADC singled-ended channel, Internal reference (0.6V) and 1/2 gain. This gives input range 0-1.2V NRF_SAADC->CH[0].CONFIG = (SAADC_CH_CONFIG_GAIN_Gain1_2 << SAADC_CH_CONFIG_GAIN_Pos) | (SAADC_CH_CONFIG_MODE_SE << SAADC_CH_CONFIG_MODE_Pos) | (SAADC_CH_CONFIG_REFSEL_Internal << SAADC_CH_CONFIG_REFSEL_Pos) | (SAADC_CH_CONFIG_RESN_Bypass << SAADC_CH_CONFIG_RESN_Pos) | (SAADC_CH_CONFIG_RESP_Bypass << SAADC_CH_CONFIG_RESP_Pos) | (SAADC_CH_CONFIG_TACQ_3us << SAADC_CH_CONFIG_TACQ_Pos) | (SAADC_CH_CONFIG_BURST_Enabled << SAADC_CH_CONFIG_BURST_Pos); // Configure the SAADC channel with VDD as positive input, no negative input(single ended). NRF_SAADC->CH[0].PSELP = SAADC_CH_PSELP_PSELP_AnalogInput2 << SAADC_CH_PSELP_PSELP_Pos; NRF_SAADC->CH[0].PSELN = SAADC_CH_PSELN_PSELN_NC << SAADC_CH_PSELN_PSELN_Pos; //Channel 6 - NTC // Configure SAADC singled-ended channel, Reference (VDD/4) and 1/4 gain. This gives input range 0-VDD NRF_SAADC->CH[1].CONFIG = (SAADC_CH_CONFIG_GAIN_Gain1_4 << SAADC_CH_CONFIG_GAIN_Pos) | (SAADC_CH_CONFIG_MODE_SE << SAADC_CH_CONFIG_MODE_Pos) | (SAADC_CH_CONFIG_REFSEL_VDD1_4 << SAADC_CH_CONFIG_REFSEL_Pos) | (SAADC_CH_CONFIG_RESN_Bypass << SAADC_CH_CONFIG_RESN_Pos) | (SAADC_CH_CONFIG_RESP_Bypass << SAADC_CH_CONFIG_RESP_Pos) | (SAADC_CH_CONFIG_TACQ_3us << SAADC_CH_CONFIG_TACQ_Pos) | (SAADC_CH_CONFIG_BURST_Enabled << SAADC_CH_CONFIG_BURST_Pos); // Configure the SAADC channel with VDD as positive input, no negative input(single ended). NRF_SAADC->CH[1].PSELP = SAADC_CH_PSELP_PSELP_AnalogInput6 << SAADC_CH_PSELP_PSELP_Pos; NRF_SAADC->CH[1].PSELN = SAADC_CH_PSELN_PSELN_NC << SAADC_CH_PSELN_PSELN_Pos; // Configure the SAADC resolution. NRF_SAADC->RESOLUTION = SAADC_RESOLUTION_VAL_14bit << SAADC_RESOLUTION_VAL_Pos; // Configure result to be put in RAM at the location of "result" variable. // Average result will be sent to memory, 2 channels means 2 average values. //NRF_SAADC->RESULT.MAXCNT = 2; //NRF_SAADC->OVERSAMPLE = SAADC_OVERSAMPLE_OVERSAMPLE_Over16x << SAADC_OVERSAMPLE_OVERSAMPLE_Pos; NRF_SAADC->RESULT.MAXCNT = 2; NRF_SAADC->OVERSAMPLE = SAADC_OVERSAMPLE_OVERSAMPLE_Over256x << SAADC_OVERSAMPLE_OVERSAMPLE_Pos; //adcResult is of size 2 NRF_SAADC->RESULT.PTR = (uint32_t)&adcResult[0]; // No automatic sampling, will trigger with TASKS_SAMPLE. NRF_SAADC->SAMPLERATE = SAADC_SAMPLERATE_MODE_Task << SAADC_SAMPLERATE_MODE_Pos; // Enable SAADC (would capture analog pins if they were used in CH[0].PSELP) NRF_SAADC->ENABLE = SAADC_ENABLE_ENABLE_Enabled << SAADC_ENABLE_ENABLE_Pos; // Calibrate the SAADC (only needs to be done once in a while) NRF_SAADC->TASKS_CALIBRATEOFFSET = 1; while (NRF_SAADC->EVENTS_CALIBRATEDONE == 0); NRF_SAADC->EVENTS_CALIBRATEDONE = 0; while (NRF_SAADC->STATUS == (SAADC_STATUS_STATUS_Busy <<SAADC_STATUS_STATUS_Pos));
When the adc is started (task started), i want to collect several samples in a loop.
void StartAdcWaitForResult() { // Do a SAADC sample, will put the result in the configured RAM buffer. NRF_SAADC->TASKS_SAMPLE = 1; while (NRF_SAADC->EVENTS_END == 0); NRF_SAADC->EVENTS_END = 0; }
while(sampleCounter-- > 0) { StartAdcWaitForResult(); raw_signals[0] = adcResult[0]; raw_signals[1] = adcResult[0]; SendData(); }
It works the first time, then the StartAdcWaitForResult hangs (since the end event never happens again).
If i trigger the TASK_STOP and then TASK_START before StartAdcWaitForResult it works, not sure why.
But I assume this is not how it´s suppose to be working...?