News:

  • May 06, 2026, 01:19:46 AM

Login with username, password and session length

Author Topic: Timers in Code Blocks  (Read 6465 times)

jmracek

  • Newbie
  • *
  • Posts: 1
Timers in Code Blocks
« on: December 20, 2015, 06:02:41 PM »
I just tried adding a timer (ONDTMR) to a Program code block in my Do-More processor. It seems to function but the time counts at about 1/13th the speed of real time. The same goes for other timer instructions.  The timers do function properly in the $Main Task.
  Is there a trick or are timers just not allowed in programs?

Controls Guy

  • Internal Dev
  • Hero Member
  • ****
  • Posts: 3607
  • Darth Ladder
Re: Timers in Code Blocks
« Reply #1 on: December 20, 2015, 06:16:48 PM »
Do-More timers aren't RTC-based, they integrate scan-time, so if the rung with the timer isn't scanned every actual scan, they'll fall behind.  Your timer is probably in a code block that due to its execution or time-slice is only executed about every 13th real scan.

To make them work right, you'll either need to make sure they're in code that executes every scan, at least while you're timing, or build an RTC-based one yourself (which still might expire late by up to one scan-time of the code in which it resides).
I retract my earlier statement that half of all politicians are crooks.  Half of all politicians are NOT crooks.  There.

BobO

  • Host Moderator
  • Hero Member
  • *****
  • Posts: 6154
  • Yes Pinky, Do-more will control the world!
Re: Timers in Code Blocks
« Reply #2 on: December 20, 2015, 06:17:51 PM »
Timers accumulate time when the code is being executed. If they are located code that isn't executing every scan, they will drop time. There are a bunch of reasons why a timer might not be executing every scan, but I'll need more info about the program to offer an opinion.
"It has recently come to our attention that users spend 95% of their time using 5% of the available features. That might be relevant." -BobO