Hi everyone,
I try to understand when the SAADC events are generated and received by the IRQ based on the documentation. To my understanding:
NRF_SAADC_EVENT_END: is generated when the buffer is full (all the samples have been written to the memory). For example, if the buffer size is 0, the NRF_SAADC_EVENT_END event will be generated at the same rate as NRF_SAADC_EVENT_DONE events? However, when for instance the buffer size is 5, the NRF_SAADC_EVENT_END event will be generated after 5 x NRF_SAADC_EVENT_DONE events?
So the NRF_SAADC_EVENT_END (HAL layer) and the NRFX_SAADC_EVT_DONE (NRFX layer) serve the same purpose?
NRF_SAADC_EVENT_DONE: is generated for every input sample taken (completed conversion). This is event is generated before the sampling value been copied to the RAM right?
I tried the saadc example of SDK16 to verify that events are generated as intended:
I have included the DONE event into the IRQ handler just to monitor when this event is received and I've enabled the debug logging.
void nrfx_saadc_irq_handler(void) {
if (nrf_saadc_event_check(NRF_SAADC_EVENT_DONE)) {
NRFX_LOG_DEBUG("Event: %s.", EVT_TO_STR(NRF_SAADC_EVENT_DONE));
}
if (nrf_saadc_event_check(NRF_SAADC_EVENT_END)) {
nrf_saadc_event_clear(NRF_SAADC_EVENT_END);
NRFX_LOG_DEBUG("Event: %s.", EVT_TO_STR(NRF_SAADC_EVENT_END));
.......
.....
...
..
}
I didn't modify the example. I've just set the buffer size to 5 and the timer compare event every 1s. My problem is that I receive the NRF_SAADC_EVENT_DONE twice and the NRF_SAADC_EVENT_END after each sampling (as you can see from the logs below). So in total before the buffer gets full I receive 10 x DONE events and 5 x END events. I expected to receive the 5 x DONE events and 1 x END event.
<info> SAADC: Function: nrfx_saadc_init, error code: NRF_SUCCESS.
<info> SAADC: Channel initialized: 0.
<info> SAADC: Function: nrfx_saadc_channel_init, error code: NRF_SUCCESS.
<info> SAADC: Function: nrfx_saadc_buffer_convert, buffer length: 5, active channels: 1.
<info> SAADC: Function: nrfx_saadc_buffer_convert, error code: NRF_SUCCESS.
<warning> SAADC: Function: nrfx_saadc_buffer_convert, error code: NRF_SUCCESS.
<info> app: SAADC HAL simple example started.
<debug> SAADC: Event: NRF_SAADC_EVENT_DONE.
<debug> SAADC: Event: NRF_SAADC_EVENT_END.
<debug> SAADC: Event: NRF_SAADC_EVENT_DONE.
<debug> SAADC: Event: NRF_SAADC_EVENT_DONE.
<debug> SAADC: Event: NRF_SAADC_EVENT_END.
<debug> SAADC: Event: NRF_SAADC_EVENT_DONE.
<debug> SAADC: Event: NRF_SAADC_EVENT_DONE.
<debug> SAADC: Event: NRF_SAADC_EVENT_END.
<debug> SAADC: Event: NRF_SAADC_EVENT_DONE.
<debug> SAADC: Event: NRF_SAADC_EVENT_DONE.
<debug> SAADC: Event: NRF_SAADC_EVENT_END.
<debug> SAADC: Event: NRF_SAADC_EVENT_DONE.
<debug> SAADC: Event: NRF_SAADC_EVENT_DONE.
<debug> SAADC: Event: NRF_SAADC_EVENT_END.
<warning> SAADC: Function: nrfx_saadc_buffer_convert, error code: NRF_SUCCESS.
<info> app: ADC event number: 0
<info> app: 4
<info> app: 3
<info> app: 3
<info> app: 4
<info> app: 3
<debug> SAADC: Event: NRF_SAADC_EVENT_DONE.
<debug> SAADC: Event: NRF_SAADC_EVENT_DONE.
<debug> SAADC: Event: NRF_SAADC_EVENT_END.
<debug> SAADC: Event: NRF_SAADC_EVENT_DONE.
<debug> SAADC: Event: NRF_SAADC_EVENT_DONE.
<debug> SAADC: Event: NRF_SAADC_EVENT_END.
<debug> SAADC: Event: NRF_SAADC_EVENT_DONE.
<debug> SAADC: Event: NRF_SAADC_EVENT_DONE.
<debug> SAADC: Event: NRF_SAADC_EVENT_END.
<debug> SAADC: Event: NRF_SAADC_EVENT_DONE.
<debug> SAADC: Event: NRF_SAADC_EVENT_DONE.
<debug> SAADC: Event: NRF_SAADC_EVENT_END.
<debug> SAADC: Event: NRF_SAADC_EVENT_DONE.
<debug> SAADC: Event: NRF_SAADC_EVENT_DONE.
<debug> SAADC: Event: NRF_SAADC_EVENT_END.
<warning> SAADC: Function: nrfx_saadc_buffer_convert, error code: NRF_SUCCESS.
<info> app: ADC event number: 1
<info> app: 3
<info> app: 3
<info> app: 3
<info> app: 4
<info> app: 4
<debug> SAADC: Event: NRF_SAADC_EVENT_DONE.
<debug> SAADC: Event: NRF_SAADC_EVENT_DONE.
<debug> SAADC: Event: NRF_SAADC_EVENT_END.
<debug> SAADC: Event: NRF_SAADC_EVENT_DONE.
<debug> SAADC: Event: NRF_SAADC_EVENT_DONE.
<debug> SAADC: Event: NRF_SAADC_EVENT_END.
<debug> SAADC: Event: NRF_SAADC_EVENT_DONE.
<debug> SAADC: Event: NRF_SAADC_EVENT_DONE.
<debug> SAADC: Event: NRF_SAADC_EVENT_END.
<debug> SAADC: Event: NRF_SAADC_EVENT_DONE.
<debug> SAADC: Event: NRF_SAADC_EVENT_DONE.
<debug> SAADC: Event: NRF_SAADC_EVENT_END.
<debug> SAADC: Event: NRF_SAADC_EVENT_DONE.
<debug> SAADC: Event: NRF_SAADC_EVENT_DONE.
<debug> SAADC: Event: NRF_SAADC_EVENT_END.
<warning> SAADC: Function: nrfx_saadc_buffer_convert, error code: NRF_SUCCESS.
<info> app: ADC event number: 2
<info> app: 3
<info> app: 3
<info> app: 4
<info> app: 4
<info> app: 3
<debug> SAADC: Event: NRF_SAADC_EVENT_DONE.
<debug> SAADC: Event: NRF_SAADC_EVENT_DONE.
<debug> SAADC: Event: NRF_SAADC_EVENT_END.
<debug> SAADC: Event: NRF_SAADC_EVENT_DONE.
<debug> SAADC: Event: NRF_SAADC_EVENT_DONE.
<debug> SAADC: Event: NRF_SAADC_EVENT_END.
<debug> SAADC: Event: NRF_SAADC_EVENT_DONE.
<debug> SAADC: Event: NRF_SAADC_EVENT_DONE.
<debug> SAADC: Event: NRF_SAADC_EVENT_END.
<debug> SAADC: Event: NRF_SAADC_EVENT_DONE.
<debug> SAADC: Event: NRF_SAADC_EVENT_DONE.
<debug> SAADC: Event: NRF_SAADC_EVENT_END.
<debug> SAADC: Event: NRF_SAADC_EVENT_DONE.
<debug> SAADC: Event: NRF_SAADC_EVENT_DONE.
<debug> SAADC: Event: NRF_SAADC_EVENT_END.
<warning> SAADC: Function: nrfx_saadc_buffer_convert, error code: NRF_SUCCESS.
<info> app: ADC event number: 3
<info> app: 3
<info> app: 3
<info> app: 4
<info> app: 3
<info> app: 3
<debug> SAADC: Event: NRF_SAADC_EVENT_DONE.
<debug> SAADC: Event: NRF_SAADC_EVENT_DONE.
<debug> SAADC: Event: NRF_SAADC_EVENT_END.
<debug> SAADC: Event: NRF_SAADC_EVENT_DONE.
<debug> SAADC: Event: NRF_SAADC_EVENT_DONE.
<debug> SAADC: Event: NRF_SAADC_EVENT_END.
<debug> SAADC: Event: NRF_SAADC_EVENT_DONE.
<debug> SAADC: Event: NRF_SAADC_EVENT_DONE.
<debug> SAADC: Event: NRF_SAADC_EVENT_END.
<debug> SAADC: Event: NRF_SAADC_EVENT_DONE.
<debug> SAADC: Event: NRF_SAADC_EVENT_DONE.
<debug> SAADC: Event: NRF_SAADC_EVENT_END.
<debug> SAADC: Event: NRF_SAADC_EVENT_DONE.
<debug> SAADC: Event: NRF_SAADC_EVENT_DONE.
<debug> SAADC: Event: NRF_SAADC_EVENT_END.
<warning> SAADC: Function: nrfx_saadc_buffer_convert, error code: NRF_SUCCESS.
<info> app: ADC event number: 4
<info> app: 4
<info> app: 3
<info> app: 4
<info> app: 4
<info> app: 3
The other problem is that after enabling oversampling I've got the same behavior (10 x DONE events and 5 x END events), while the documentation says that if the oversampling is enabled "END event is generated every 2OVERSAMPLE time the DONE event is generated"
Last but not least, the NRF_SAADC_INT_DONE interrupt isn't enable. How is possible that the IRQ interrupts on NRF_SAADC_EVENT_DONE event??
Could you confirm the following and guide me based on the saadc example of SDK16?
Thanks
Nick