I am using the nRF51-DK and have Timer1 setup as follows:
void start_timer(void)
{
NRF_TIMER1->MODE = TIMER_MODE_MODE_Timer;
NRF_TIMER1->TASKS_CLEAR = 1;
NRF_TIMER1->PRESCALER = 4;
NRF_TIMER1->BITMODE = TIMER_BITMODE_BITMODE_16Bit;
NRF_TIMER1->CC[1] = 1000;
// Enable interrupt on Timer 2, both for CC[0] and CC[1] compare match events
NRF_TIMER1->INTENSET = (TIMER_INTENSET_COMPARE1_Enabled << TIMER_INTENSET_COMPARE1_Pos);
NVIC_EnableIRQ(TIMER1_IRQn);
NRF_TIMER1->TASKS_START = 1; // Start TIMER1
}
void TIMER1_IRQHandler(void)
{
if (NRF_TIMER1->EVENTS_COMPARE[1] &&
NRF_TIMER1->INTENSET & TIMER_INTENSET_COMPARE1_Msk) {
//Clear compare register event
NRF_TIMER1->EVENTS_COMPARE[1] = 0;
if(nrf_gpio_pin_read(21)) {
nrf_gpio_pin_clear(21);
}
else {
nrf_gpio_pin_set(21);
}
}
}
I have an oscilloscope connected to pin 21, and am finding that no matter what I set to NRF_TIMER1->CC[1]
, the pulse width remains the same.
I am also finding that for NRF_TIMER1->PRESCALER
set to 0, I am getting a pulse of period ~8 ms. That seems incorrect. Again, NRF_TIMER1->CC[1]
has no effect.
Overall I think I am not setting up the timer correctly. I'd appreciate any help with this.
I am using this code with SoftDevice S110.
(Please note that I don't want to use the nrf_drv_timer
methods as I find them to be confusing, and would rather use the registers so I can understand the feature consistent with the data sheet.)
Thanks