I want to turn an LED on when the Counter in a Timer peripheral is equal to 10.
#define TIMER0_BASE 0x40008000 NRF_TIMER_Type* TIMER0 = (NRF_TIMER_Type*) TIMER0_BASE; // NRF_TIMER_Type has register structure void timerinit(NRF_TIMER_Type* timer) { /* Setup timer for PWM */ timer -> MODE &= 0; // Timer mode timer -> BITMODE |= 0x1; // Overflows after 8 bits timer -> CC[0] |= 0x0A; // Set value in CC[0] to 10 timer -> PRESCALER &= 0x0; // Counts at 16 MHz } /** * @brief Function for application main entry. */ int main(void) { bsp_board_init(BSP_INIT_LEDS); bsp_board_led_off(1); timerinit(TIMER0); TIMER0 -> TASKS_START; while(true) { if (/* Event_Compare here */) { bsp_board_led_on(1); TIMER0 -> TASKS_STOP; } } }
I tried reading from EVENTS_COMPARE[0] (TIMER0 -> EVENTS_COMPARE[0]) in the if argument, but the led is not turning on. One solution I looked at was in the PPI example in SDK 15.2, but I want to do this as simply as possible.
err_code = nrf_drv_ppi_channel_assign(m_ppi_channel1, nrf_drv_timer_event_address_get(&m_timer1, NRF_TIMER_EVENT_COMPARE0), nrf_drv_timer_task_address_get(&m_timer0, NRF_TIMER_TASK_STOP));