Hello,
I want to use multiple timer interrupts, want to fetch values from 3 analog pins on every 20secs and then average three collected values at every 60 sec. so i would like to generate two timer interrupts. One at every 20secs, to collect the values and other at every 60sec to average that values. I am using nrf sdk 15.0.0 .
Also, i want to know what is exactly happening in the timer example: Can you explain the use nrf_drv_timer_extended_compare API.
I tried to modify the timer example but it did not work, it is giving some timer instance id error.
Obviously i did not understand the example and hence can not debug my code.
Can you please help me understand the timer interrupts concept.
Thanks and Regards!
#include <stdbool.h> #include <stdint.h> #include "nrf.h" #include "nrf_drv_timer.h" #include "bsp.h" #include "app_error.h" const nrf_drv_timer_t TIMER_LED = NRF_DRV_TIMER_INSTANCE(0); const nrf_drv_timer_t TIMER_LED1 = NRF_DRV_TIMER_INSTANCE(1); static volatile uint32_t m_counter; /** * @brief Handler for timer events. */ void timer_led_event_handler(nrf_timer_event_t event_type, void* p_context) { static uint32_t i; uint32_t led_to_invert = ((i++) % LEDS_NUMBER); switch (event_type) { case NRF_TIMER_EVENT_COMPARE0: bsp_board_led_invert(1); break; default: //Do nothing. break; } } void timer_led_event_handler1(nrf_timer_event_t event_type, void* p_context) { static uint32_t i; uint32_t led_to_invert = ((i++) % LEDS_NUMBER); switch (event_type) { case NRF_TIMER_EVENT_COMPARE0: bsp_board_led_invert(2); break; default: //Do nothing. break; } } /** * @brief Function for main application entry. */ int main(void) { uint32_t time_ms = 100; //Time(in miliseconds) between consecutive compare events. uint32_t time_ms1 = 200; uint32_t time_ticks; uint32_t time_ticks1; uint32_t err_code = NRF_SUCCESS; //Configure all leds on board. bsp_board_init(BSP_INIT_LEDS); //Configure TIMER_LED for generating simple light effect - leds on board will invert his state one after the other. nrf_drv_timer_config_t timer_cfg = NRF_DRV_TIMER_DEFAULT_CONFIG; nrf_drv_timer_config_t timer_cfg1 = NRF_DRV_TIMER_DEFAULT_CONFIG; err_code = nrf_drv_timer_init(&TIMER_LED, &timer_cfg, timer_led_event_handler); APP_ERROR_CHECK(err_code); err_code = nrf_drv_timer_init(&TIMER_LED1, &timer_cfg1, timer_led_event_handler1); APP_ERROR_CHECK(err_code); time_ticks = nrf_drv_timer_ms_to_ticks(&TIMER_LED, time_ms); time_ticks1 = nrf_drv_timer_ms_to_ticks(&TIMER_LED1, time_ms1); nrf_drv_timer_extended_compare( &TIMER_LED, NRF_TIMER_CC_CHANNEL0, time_ticks, NRF_TIMER_SHORT_COMPARE0_CLEAR_MASK, true); nrf_drv_timer_extended_compare( &TIMER_LED1, NRF_TIMER_CC_CHANNEL0, time_ticks1, NRF_TIMER_SHORT_COMPARE0_CLEAR_MASK, true); nrf_drv_timer_enable(&TIMER_LED); nrf_drv_timer_enable(&TIMER_LED1); while (1) { __WFI(); } }