News:

  • June 28, 2026, 05:08:20 PM

Login with username, password and session length

Author Topic: Fixed Scan Rate?  (Read 9574 times)

davidbgtx

  • Hero Member
  • *****
  • Posts: 215
  • Host be the Most
Fixed Scan Rate?
« on: November 19, 2014, 09:45:29 AM »
Maybe I'm missing it, is it not possible to have a fixed scan rate as you can in the WinPLC?

franji1

  • Bit Weenie
  • Host Moderator
  • Hero Member
  • *****
  • Posts: 3827
    • Host Engineering
Re: Fixed Scan Rate?
« Reply #1 on: November 19, 2014, 11:10:19 AM »
In Do-more, no.

But you could easily implement it via logic by sticking some code in $tBottomOfScan task (assuming its time slice was 65535, or "do NOT yield".  I will utilize MATH's TICKus() function (micro second resolution), but you could just as easily use TICKms() for just millisecond resolution

D99 contains the last scan's "count"
D98 contains the current scan's duration (calculated on the fly)
D100 will contain the desired "scan time" in micro seconds (e.g. 2000 would be 2ms)
C99 will be ON once the scan time reaches D100
REPEAT
MATH D98 "TICKus() - D99"
STRGE D98 D100
OUT C99
UNTIL C99
MATH D99 "D99 + D98"  // this will be slightly more accurate than calling TICKus() again

You will want to stick this rung in $tFirstScan to initialize D99
MATH D99 "TICKus()"

Basically, the ladder scan will "hang" while the REPEAT/UNTIL executes.  If the scan time exceeds the desired max, it will fall out immediately.

davidbgtx

  • Hero Member
  • *****
  • Posts: 215
  • Host be the Most
Re: Fixed Scan Rate?
« Reply #2 on: November 19, 2014, 12:45:47 PM »
Thanks, I'll give it a try.

BobO

  • Host Moderator
  • Hero Member
  • *****
  • Posts: 6164
  • Yes Pinky, Do-more will control the world!
Re: Fixed Scan Rate?
« Reply #3 on: November 19, 2014, 03:35:54 PM »
Thanks, I'll give it a try.

Just curious, but what problem does the fixed scan time resolve?
"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

Mike Nash

  • Hero Member
  • *****
  • Posts: 652
Re: Fixed Scan Rate?
« Reply #4 on: November 19, 2014, 04:51:01 PM »
Not my problem anymore, but I once did a pretty nice MOP (Ramp) using the fixed scan time. For later projects I decided to use the last scan actual time to calculate the amount to add or subtract.

DLTimmons

  • Hero Member
  • *****
  • Posts: 232
Re: Fixed Scan Rate?
« Reply #5 on: November 19, 2014, 05:29:10 PM »
Look at the Ramp command I us it for thing like jogging motors