Alaric said:
You can skip the subtraction by using the MEQ instruction.
MEQ S:4 3FFFh 10000 OTE B3/0
My puny tired old brain is at a complete loss trying to understand how this can work.
The odds of getting the clock equal to 10000 at any scan is quite low, so it will pass without ever being true. I don't see how masking with 3FFFh can fix this.
By doing the subtraction, whatever is left over in S:4 is the accumulated error from the scan time. So the scan time is taken into account next time S:4 is greater than 10000.
Also, without the subtraction, S:4 will return to zero upon overflow, which will throw the time out. Using the mask 3FFFh, it will still overflow at 16383.
Using
GEQ S:4 10000 BST OTE B3/0 NXB SUB S:4 10000 S:4 BND is perfectly accurate on average (+- 100us), for use within the program, as it will vary only by the time within the scan, but you can be sure that the next scan after a second has passed, your output (B3/0) will be true for only one scan without the need for a one shot.
Of course if you want exacly one second action, use an interupt routine, but that is not good for using within the program, as a one shot is no good in an interupt routine.
I have been using this code for many years since the introduction of Micrologix 1000, for accurate timing. With Micrologix 1000, S:4 only has 100 counts per second.