Have you ever wished PAC Control had a table of timers? Here’s a simple way to implement just that.
This came up because we had a customer timing a number of “move gate” events, and wanted to see if 12 seconds had elapsed since the “open” or “close” gate command had been issued for a particular each gate.
He just needed one numeric table (64-bit int table in this case) for “time since powerup” for each gate (each an element in that table). Then instead of checking the timer, he’d just get “time since powerup” now, subtract from the previously recorded “start time”, and see if 12 seconds had gone by.
The slightly tricky part is where to get that value to avoid rollover, like you’d have to worry about if you use “Get Seconds Since Midnight” (which rolls over a midnight) or certain parts of the memory map that roll over every 49.7 or 49,710 days.
MMP address F030 0228 returns a 64-bit value that’s milliseconds since powerup which only rolls over every 584,542,046 YEARS. (I’ll refrain from corny jokes here, suffice to say, I don’t think we care what happens in half a BILLION years.)
I’ll attach a chart, but here are the relevant OptoScript snippets:
// "Start" timing for index nIndex in the table nnTempReadValue = 0; nResult = ReadNumFromIoUnitMemMap( LocalMemMap, 0xF0300228, nnTempReadValue ); // Sanity check on mem map read if ( (nnTempReadValue == 0) or (nResult <> 0) ) then // something's not right if we get here, need to check IP address on LocalMemMap (should be 127.0.0.1) // or firmware version to make sure this area of the mem map is supported (like if you have really old firmware) AddMessageToQueue(16, "Something's not right. Check IP address and firmware on local I/O Unit"); else nntMillisecondsSincePowerup[nIndex] = nnTempReadValue; endif
Here’s where we check (in a loop with a delay, of course), how long it’s been since then:
// Read the current time and compare to nIndex in the table of previously recorded values nnTempReadValue = 0; nResult = ReadNumFromIoUnitMemMap( LocalMemMap, 0xF0300228, nnTempReadValue ); nnTimeElapsedMS = (nnTempReadValue - nntMillisecondsSincePowerup[nIndex]);
At this point, the customer I mentioned would compare his nnTimeElapsedMS to 12000 (milliseconds) and then do whatever he needed to do if that amount of time had passed.
Easy! Note the 64-bit values since that’s what we’re reading from the memory map (more bits means more days/years before we have to worry about rollover).
Hope that’s helpful.
TimerTableChart9_0Basic.zip (2.52 KB)