The CALC/CALCA block TIM statement

From Cassandra

Jump to: navigation, search

The TIM statement in CALC/CALCA blocks returns the number of seconds elapsed since last midnight. This can be useful in triggering events once a day, for example. However, the value returned by TIM can exhibit some jitter; for example, in a CALC/CALCA block scanning at one second, a TIM value saved to memory on one scan may not necessarily be less than a TIM value returned on the next scan, as one would expect it to be. This could be due to clock resyncing in the CP to the system master, roundoff errors in the memory registers and stack of the CALC/CALCA block (all values are converted to reals before storage), too many gamma rays, excessive sunspot or quasar activity.... Who knows?

In my case, I was trying to reset a counter every midnight. It was, unfortunately, also being reset occasionally at random times during the day. I was saving the TIM value each scan, and looking for a decrease in the TIM value from that scan to the next. Because of the jitter, it didn't work.

The best workarounds appear to be:

1. Subtract a constant value from that returned by TIM, and look for a negative-to-positive or positive-to-negative transition. I can use a small number and deal with consecutive-scan retriggering as a result, but if your application cannot, use OSP 1 to filter it.

2. Bring STATION.HOUR and STATION.MINUTE into the CALC block and use them.


Corey Clingo
BASF Corp.

Personal tools