Hello!
I'm learning how to use properly the saadc for knowing muy battery state of discharge. First of all I'm testing the saadc example which is included in the SDK, changing paramenters, understaning the functions...etc.
In this function in particular is where I have troubles:
/* setup m_timer for compare event every 400ms */
uint32_t ticks = nrf_drv_timer_ms_to_ticks(&m_timer, 400);
I understand that this function is for convert the ms which I want the timer interrupt to occur to ticks of the timer.
And in the function definition:
__STATIC_INLINE uint32_t nrf_drv_timer_ms_to_ticks(
nrf_drv_timer_t const * const p_instance,
uint32_t timer_ms)
I can see that the number of ticks is a variable uint32, so it could have a value from 0 to 4294967295.
In my aplication i would like to have a saadc conversion every 5 minutes, so, my timer_ms should be:
5min * 60sec/min * 1000ms/sec = 300000ms And this number doesn't exceed the uint32_t range.
But when I run the program, I can see a converted value (yes, only one, I changed the following define: #define SAMPLES_IN_BUFFER 1, before was 5) every 30sec aprox, not every 5min.
What is the problem? I have noticed that if my variable timer_ms is 60000:
uint32_t ticks = nrf_drv_timer_ms_to_ticks(&m_timer, 60000);
I have a value from the saadc every minute, and if it's 5*60000:
uint32_t ticks = nrf_drv_timer_ms_to_ticks(&m_timer, 5*60000);
the error still hapens...
Thank you all, here is my code (is a txt file, I can't put the code well on the web with the text editor):
main.c
And a screen capture of the values showed: