This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts
This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Using timer how to make 5 sec delay in pca10040 board?

Hi,

I am using pca10040 board. i need to toggle a led in 5sec once. I tried to change the prescale value. But im not able to get that much time delay.

Can any one help me on this?

Parents Reply Children
  • Hi Ole Bauck,

    Thank you for your valuable answers. Now i can able to do time delay whatever i need.

  • Hi Ole Bauck,

    If i set prescale value 9 and bitmode is 32 means. The counting will be start in 0 to 4,294,967,296. For 5 second delay i set cc[0]=156250. For my requirement i need continuously toggle a led for 5 mins. At very first time its coming in 5 second [0 - 156250] but after that its taking more time [156270 - 4,294,967,296] I dont kw how to do that..

    can u guide me on thz.. below is my function:

    void start_timer(void)
    {
            NRF_TIMER2->MODE = TIMER_MODE_MODE_Timer;
            NRF_TIMER2->TASKS_CLEAR = 1;
            NRF_TIMER2->PRESCALER = 9;
            NRF_TIMER2->BITMODE = TIMER_BITMODE_BITMODE_32Bit;
            NRF_TIMER2->CC[0] = 156250;
            NRF_TIMER2->INTENSET = (TIMER_INTENSET_COMPARE0_Enabled << TIMER_INTENSET_COMPARE0_Pos) ;
            NVIC_EnableIRQ(TIMER2_IRQn);
            NRF_TIMER2->TASKS_START = 1;
    }
    
    void TIMER2_IRQHandler(void)
    {
            if ((NRF_TIMER2->EVENTS_COMPARE[0] != 0))
            {
                    NRF_TIMER2->EVENTS_COMPARE[0] = 0;                                      
                    NRF_TIMER2->CC[0] += 156250;
                    nrf_gpio_pin_toggle(GPIO_TOGGLE_PIN);
            }
    }
    
Related