Home AW-SYS Support Demo

 

Previous
Next

Example 20
Counting the amount of time an input is closed (in hours, minutes and seconds)

Determine the number of hours, minutes and seconds input E0.5 remains closed and use input E0.6 to set the timer to zero.

Symbols have been used to program the solution to this problem. Their correspondence to the absolute operands has been defined in the following table.

The proposed program includes the construction of a pulse train using the CLOCK timer that functions as a time base with a period of 1 second (see Example 16). The first three statements at the beginning of the program advance the SEC counter whenever an pulse from the CLOCK is detected while INPUT is closed. SEC, or rather Z5, is therefore the seconds counter.
The second group of statements loads the value for the seconds in ACCU2 and the constant 60 in ACCU1. The two values are compared for equality and if the result is true, the MIN counter is increased by one unit and the SEC counter is reset to zero. This means that the MIN counter increases every 60 seconds and counts the minutes.
The third group of statements loads the value for the minutes in ACCU2 and the constant 60 in ACCU1. The two values are then compared for equality and if the result is true, the HOURS counter is increased by one unit and the MIN counter is reset to zero. This means that the HOURS counter increases every 60 minutes and so counts the hours.
In summary, the software timer that we have created enables us to count up to 999 hours, 59 minutes and 59 seconds (exactly!). Of course this value cannot really be considered so precise over such a long period of time especially considering the inevitable errors inherent in the internal clock of the PLC itself and the PC on which the simulation is based.
As an additional exercise, modify the program to include a counter for DAYS which increases by 1 unit every 24 hours.
The program can be checked without having to wait extensive periods of time by either reducing the time constant loaded into CLOCK to increase the frequency of the pulse train, or manually enter counter values close to the comparison limits.

More examples: 1 ] 2 ] 3 ] 4 ] 5 ] 6 ] 7 ] 8 ] 9 ] 10 ] 11 ] 12 ] 13 ] 14 ] 15 ] 16 ] 17 ] 18 ] 19 ] [ 20 ] 21 ] 22 ] 23 ] 24 ] 25 ] 26 ] 27 ] 28 ] 29 ] [ List ]
More PLCs examples: Not still available