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

Timer for 8 hours - NRF52

I need to turn off a GPIO after 8 hours of it being triggered. I was reading about changing the prescaler to allot for 8 hours. I did the calculations and came up with a prescaler of 56 which would give me just over 8 hours max time (8.106 hrs).

I am also using BLE, app_button, and app_timer in my project. The app_timer i am using is driving a dual digit 7 segment LED display - that timing is fairly quick to switch displays so your eyes can't see it changing digits and appears to not flicker (0 prescale and timer setting of 10 in the app_timer_start settings)

Is there another way I can calculate 8 hours without changing the prescaler and affecting my other timings? Is there another timer that can do longer time?

I appreciate your help.

  • Set your timer to give some suitable "tick" interval, and just count the number of "ticks" that correspond to 8 hours.

    Just like a real clock ticks at, say, once per second.

    It counts 60 of these ticks to get minutes.

    It counts 60 minutes to get hours.

    It counts 24 hours to get days.

    etc, etc, ...

  • Well you could just create a simple variable, lets say uint32_t timer_irq_qounter; and then just increment it every time your irq happens. So if you are having lets say 25ms timer for controlling lcd, and you want to turn off gpio pin after 8 hours, you then just count until timer_irq_counter reaches the value 86060*40 = 1152000. So you will know that your timer for lcd control has fired an interrupt 1152000 times, you will know that it is about 8 hours. It probably will not be this value exactly, because timer irq can be delayed by higher priority softdevice tasks.

  • Thank you to both that answered. I added another timer that I start when I need it that triggers every 1 minute. When the timer triggers, it increments a variable. I then check to see if the variable is 480 (8*60) and then it shuts off the GPIO. I can't believe that I didn't think of doing this myself. Sometimes, I make things more complicated than they need to be. Thanks again.

Related