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

Timer1 max value

Hello,

I'm working on nrf52832-DK with SDK11 on Timer1. I can't use TIMER0 because I'm using also the softdevice.

My code source is :

//handler
void timer_led_event_handler(nrf_timer_event_t event_type, void* p_context)
{
    
    switch(event_type)
    {
        case NRF_TIMER_EVENT_COMPARE1:
                  nrf_drv_gpiote_out_set(PIN_06);
         //nrf_drv_timer_compare_int_disable(&TIMER, NRF_TIMER_CC_CHANNEL0);


            break;
        
        default:
            //Do nothing.
            break;
    }    
}


main : 

                    time_us = 5000; //Time(in us) between consecutive compare events.
                    nrf_drv_timer_clear(&TIMER);
                    time_ticks = nrf_drv_timer_us_to_ticks(&TIMER, time_us);
                    nrf_drv_timer_compare(&TIMER_LED, NRF_TIMER_CC_CHANNEL1, time_ticks, true);
                    nrf_drv_timer_enable(&TIMER);

I want to configure my Timer1 between 1us and 10000us. I have seen that Timer 0 is BIT_WIDTH 16 bits so the maximum value can be theorically 65535 ?

But my timer restart at the value of 4097. Is it normal ? How can I configure it to set the value from 0-10000 us ?

Thank you very much

Parents
  • Hi,

    The TIMER BITMODE can be set to 32Bit(= max value 4294967295). What do you mean by "But my timer restart at the value of 4097" ? 4097 µs ?

    When you set the time_us to 5000 the TIMER compare register value will be 0x00013880(=80000), and with a prescaler value of 1, the TIMER frequency will be 16MHz / 2^PRESCALER = 16MHz. You will generate event every 80000/16MHz = 0,005 s = 5000 µs

Reply
  • Hi,

    The TIMER BITMODE can be set to 32Bit(= max value 4294967295). What do you mean by "But my timer restart at the value of 4097" ? 4097 µs ?

    When you set the time_us to 5000 the TIMER compare register value will be 0x00013880(=80000), and with a prescaler value of 1, the TIMER frequency will be 16MHz / 2^PRESCALER = 16MHz. You will generate event every 80000/16MHz = 0,005 s = 5000 µs

Children
No Data
Related