I'm working on a project to convert ladder logic to run as PICAXE basic code and from the little google research I've done it appears that historically PLCs have run ladder logic code using a fixed cycle time with typical cycle times being in the 10ms to 100ms range.
The program structure I'm planning to use to is this:
The only way I can think of of detecting when this sort of period has passed is to use peeksfr to modify the settings for timer1 but my preference would be to not alter the timer1 settings from what the PICAXE firmware sets.
Can anyone recommend another technique I could use to detect elapsed times in the 10ms to 100ms range?
The program structure I'm planning to use to is this:
Code:
; Set the PLC cycle time to use here in whatever units are convenient
PLC_CYCLE_TIME = <some-value>
; Initialize the time the last PLC cycle ended as now
LAST_PLC_CYCLE_TIME = <the-current-timer-value>
main:
<read the input pins>
<execute the ladder logic program to update the values for the output pins>
<write the output pins>
; Execute this loop to delay until the PLC cycle time has elapsed
do
ELAPSED_TIME = <the-current-timer-value> - LAST_PLC_CYCLE_TIME
until ELAPSED_TIME > PLC_CYCLE_TIME
; Update the time the last PLC cycle ended
LAST_PLC_CYCLE_TIME = LAST_PLC_CYCLE_TIME + PLC_CYCLE_TIME
goto main
Can anyone recommend another technique I could use to detect elapsed times in the 10ms to 100ms range?