This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

Question about using timer counter mode

Hi,

I am going to implement a PPI to connect GPIOTE event in with TIMER COUNT TASK, and then read the count from CC[0]. But the count in CC[0] never updated. 

Basically for the GPIOTE:

nrf_drv_gpiote_init();
nrf_drv_gpiote_in_config_t pls0 = GPIOTE_CONFIG_IN_SENSE_HITOLO(true);
nrf_drv_gpiote_in_init(4, &pls0, NULL);    //gpiote pin is D04
nrf_drv_gpiote_in_event_enable(4, true);   //enable the event in

For the timer (using timer 0):

const nrf_drv_timer_t timer0 = NRF_DRV_TIMER_INSTANCE(0); //use TIMER0
nrf_drv_timer_config_t timer_cfg0 = NRF_DRV_TIMER_DEFAULT_CONFIG;
timer_cfg0.mode = 1; //TIMER mode is counter

nrf_drv_timer_init(&timer0, &timer_cfg0, NULL);

time_tick0 = nrf_drv_timer_ms_to_ticks(&timer0, 20);
nrf_drv_timer_extended_compare(&timer0, NRF_TIMER_CC_CHANNEL0, time_tick0, 
        NRF_TIMER_SHORT_COMPARE0_CLEAR_MASK, true);  //set cc
        
nrf_drv_timer_enable(&timer0);    //start counter

And for the PPI:

nrf_drv_ppi_init();
nrf_drv_ppi_channel_alloc(&ppi1);
nrf_drv_ppi_channel_assign(ppi1, 
            nrf_drv_gpiote_in_event_addr_get(4),   //gpiote in event 
            nrf_drv_timer_task_address_get(&timer0, NRF_TIMER_TASK_COUNT));
nrf_drv_ppi_channel_enable(ppi1);

Finally, get the CC[0]

nrf_timer_task_trigger(NRF_TIMER0, NRF_TIMER_TASK_CAPTURE0);
c0 = nrf_timer_cc_read(NRF_TIMER0, NRF_TIMER_CC_CHANNEL0);

Could you please have a look at these codes. The PPI config should be correct because the EEP is 40006100 and the TEP is 40008008 which are two addresses I want. Do you think my program process is right? Please let me know if further information is needed. Thanks a lot

Parents Reply Children
No Data
Related