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

nRF51 DK timers

Hi,

File "nrf_drv_config.h" defines both TIMER1_CONFIG_BIT_WIDTH and TIMER2_CONFIG_BIT_WIDTH as "TIMER_BITMODE_BITMODE_16Bit", can these timers be configured as 24 bit / 32 bit timers as well?

I am asking because after changing TIMER1_CONFIG_BIT_WIDTH to "TIMER_BITMODE_BITMODE_32Bit", it's not trigger the interrupt handler after 1 second.

Supposedly, 32 bit and 16 Mhz should be sufficient for 1 second interrupt (Timer0 works using the same settings)

Here's the code snippet that is not working: (Borrowed from timer example code from Keil pack installer)

#if (TIMER1_ENABLED == 1)
#define TIMER1_CONFIG_FREQUENCY    NRF_TIMER_FREQ_16MHz
#define TIMER1_CONFIG_MODE         TIMER_MODE_MODE_Timer
#define TIMER1_CONFIG_BIT_WIDTH    TIMER_BITMODE_BITMODE_32Bit
#define TIMER1_CONFIG_IRQ_PRIORITY APP_IRQ_PRIORITY_LOW
#define TIMER1_INSTANCE_INDEX      (TIMER0_ENABLED)
#endif

const nrf_drv_timer_t TIMER_STOP = NRF_DRV_TIMER_INSTANCE(1);
uint32_t time_stop = 1000;
err_code = nrf_drv_timer_init(&TIMER_STOP, NULL, timer_stop_event_handler);
APP_ERROR_CHECK(err_code);
time_stop_ticks = nrf_drv_timer_ms_to_ticks(&TIMER_STOP, time_stop);
nrf_drv_timer_extended_compare(
     &TIMER_STOP, NRF_TIMER_CC_CHANNEL1, time_ticks, NRF_TIMER_SHORT_COMPARE1_CLEAR_MASK, true);
nrf_drv_timer_enable(&TIMER_STOP);

Also, what is the preferable way of configuring timer? Some answers on this forum suggest to manipulate the Timer construct directly, like the following:

github.com/.../main.c

Last question: The timer construct shows each timer can have 4 CC, then I assume for each timer, I can use nrf_drv_timer_extended_compare with "NRF_TIMER_CC_CHANNEL0", "NRF_TIMER_CC_CHANNEL1", "NRF_TIMER_CC_CHANNEL2" and "NRF_TIMER_CC_CHANNEL3"?

Thanks

  • The documentation can be somewhat confusing because it is split up into a Reference Manual and a Product Specification. The Product Specification will tell you what is actually available on the specific chip. On nRF51x22, TIMER1 and TIMER2 have only bitwidth 8/16, while TIMER0 has bitwidth 8/16/24/32. All timers have 4 compare registers. This information is in the Product Specification part 4.2.

    You can decide if you want to use the driver nrf_drv_timer or if you want to manipulate the registers dircetly (like in the github example), this is a matter of taste. I will advise you to not do both (at the same time) if you dont absolutely know what you are doing.

Related