Hello,
I am using the SAADC of a nRF52832 with a sample-rate of 1ms (1kHz).
The following code shows, how my SAADC is intialized:
#define SAADC_SAMPLE_RATE 1
void saadc_sampling_event_init(void)
{
ret_code_t err_code;
err_code = nrf_drv_ppi_init();
APP_ERROR_CHECK(err_code);
nrf_drv_timer_config_t timer_config = NRF_DRV_TIMER_DEFAULT_CONFIG;
timer_config.frequency = NRF_TIMER_FREQ_31250Hz;
err_code = nrf_drv_timer_init(&m_timer, &timer_config, timer_handler);
APP_ERROR_CHECK(err_code);
/* setup m_timer for compare event */
uint32_t ticks = nrf_drv_timer_ms_to_ticks(&m_timer,SAADC_SAMPLE_RATE);
nrf_drv_timer_extended_compare(&m_timer, NRF_TIMER_CC_CHANNEL0, ticks, NRF_TIMER_SHORT_COMPARE0_CLEAR_MASK, false);
nrf_drv_timer_enable(&m_timer);
uint32_t timer_compare_event_addr = nrf_drv_timer_compare_event_address_get(&m_timer, NRF_TIMER_CC_CHANNEL0);
uint32_t saadc_sample_event_addr = nrf_drv_saadc_sample_task_get();
/* setup ppi channel so that timer compare event is triggering sample task in SAADC */
err_code = nrf_drv_ppi_channel_alloc(&m_ppi_channel);
APP_ERROR_CHECK(err_code);
err_code = nrf_drv_ppi_channel_assign(m_ppi_channel, timer_compare_event_addr, saadc_sample_event_addr);
APP_ERROR_CHECK(err_code);
}
void saadc_sampling_event_enable(void)
{
ret_code_t err_code = nrf_drv_ppi_channel_enable(m_ppi_channel);
APP_ERROR_CHECK(err_code);
}
void saadc_init(void)
{
ret_code_t err_code;
nrf_drv_saadc_config_t saadc_config = NRF_DRV_SAADC_DEFAULT_CONFIG;
saadc_config.resolution = NRF_SAADC_RESOLUTION_8BIT;
nrf_saadc_channel_config_t channel_0_config =
NRF_DRV_SAADC_DEFAULT_CHANNEL_CONFIG_SE(NRF_SAADC_INPUT_AIN4);
channel_0_config.gain = NRF_SAADC_GAIN1_4;
channel_0_config.reference = NRF_SAADC_REFERENCE_VDD4;
err_code = nrf_drv_saadc_init(&saadc_config, saadc_callback);
APP_ERROR_CHECK(err_code);
err_code = nrf_drv_saadc_channel_init(0, &channel_0_config);
APP_ERROR_CHECK(err_code);
err_code = nrf_drv_saadc_buffer_convert(m_buffer_pool[0],SAADC_SAMPLES_IN_BUFFER);
APP_ERROR_CHECK(err_code);
...
}
My problem is, that it looks like, that the readings of the SAADC are frequency-dependent.
I applied the following 5Hz sinus-signal to the analog input:

I receive the following readings from my SAADC:

This looks fine.
But if I apply a 50Hz sinus-signal with the same amplitude and offset to the analog input, which is shown in the following picture:

I receive the following saadc readings:

The amplitude of the SAADC readings is significantly lower.
So here are my questions:
1. Why do the SAADC readings values decrease with a higher frequency?
2. Do you know what the problem is?
3. Do you have any suggestions, how to solve this issue?
Thank you very much in advance.