Hi all,
I am currently developing audio sampling on a custom board using the nrf52832. I'd like to sample at 20khz and am using the nrfxlib driver for this (https://github.com/zephyrproject-rtos/hal_nordic/blob/master/nrfx/drivers/include/nrfx_saadc.h).
I am running the ADC at approx. 20khz now and using the internal ADC timer and am now trying to do oversampling however I could not find any example code on how to do this.
Regular results are around 4000 (raw adc values) but when I add oversampling I get strange outliers (some around 7000 and some around 16000) that do not make any sense to me. Is my implementation correct or do you have any advice on what to do here?
static volatile nrf_saadc_value_t acoustic_buffer[1];
static volatile u32_t sample_counter = 0;
static volatile u32_t interrupts_triggered = 0;
void acoustic_interrupt(nrfx_saadc_evt_t const * p_event)
{
/* Helper variables */
static s32_t acoustic_window_ptp_prev = 0;
static s32_t acoustic_window_ptp_diff = 0;
s16_t acoustic_sample = 0;
nrfx_err_t err;
nrfx_saadc_evt_t saadc_event = *p_event;
interrupts_triggered++;
switch (saadc_event.type) {
case NRFX_SAADC_EVT_DONE: {
acoustic_sample = (s16_t) *(saadc_event.data.done.p_buffer);
err = nrfx_saadc_buffer_set((nrf_saadc_value_t*) acoustic_buffer, sizeof(acoustic_buffer));
if (NRFX_SUCCESS != err) {
LOG_ERR("IRQ: %x", err);
}
/* Throw away garbage values */
if (acoustic_sample > 5000) {
return;
}
sample_counter++;
break;
}
case NRFX_SAADC_EVT_BUF_REQ:
return;
case NRFX_SAADC_EVT_CALIBRATEDONE:
LOG_INF("SAADC calibrated");
return;
case NRFX_SAADC_EVT_LIMIT:
case NRFX_SAADC_EVT_READY:
case NRFX_SAADC_EVT_FINISHED:
default:
LOG_WRN("Unexpected event received: %x", saadc_event.type);
return;
}
if (acoustic_sample > 4000) {
LOG_WRN("%i: %i / %i",sample_counter % acoustic_oversample_count, acoustic_sample, acoustic_sample_ac);
}
}