Different ways to implement a timer, and its CONs and PROs

We already got 256 timers (T0-T255) that we can use to do something after a certain time has past, which include 100ms-based T0-T199, 10ms-based T200-T245, 1ms-based T246-T249 and retainable 100ms-based T250-T255.

For how to use T0-T255, please refer to other articles in this section or download sample projects from our “DOWNLOAD” page.

Today, I would like to introduce two other ways to implement a timer on our PLC.

The first one is to use the command “HOUR” . For detailed explanation of this command, please refer to the help file.

Basically, HOUR takes three parameters, a sample is like this:

IF X0 THEN HOUR k100 D0 M0

Once X0 is energised, HOUR is executed. The first parameter, K100, is the time it has accumulated in hours when X0 is on. The second takes up two WORDs D0 and D1. The hours X0 has stayed on is stored in D0. Time that has past but less than 1 hour is stored in D1 in the unit of seconds. Once X0 has been on for 100 hours continually or intermittently, as the first parameter indicates, M0 would be energised.

Admittedly, this command is meant to memorise how long a signal has been on, then do something when the set amount time is reached. But because the exact time it’s past can be accessed, there’s nothing wrong to use it as a 1second-based timer.

The benefit of this command as a timer is: 1. X0’s on state doesn’t have to be continuous. That’s to say, D0 and D1 won’t be reset if X0 turns off for a while and it can pick up from where it left once X0 comes back on. 2. Using retainable memory for D0 and D1, the accumulation of time won’t get lost in case of a reboot.

To restart the accumulation, you just need to set D0 and D1 to 0 using MOV command.

The second way is to use a oscillator combined with a counter.

Low speed counters are C0 to C234, with some 16bits, others 32bits, some retainable, others not.

For oscillator, we have M8011 for 10ms, M8012 for 100ms, M8013 for 1 second and M8014 for 1 minute.

Put a oscillator on the left side of the ladder, and a counter on the right side. You got a timer going. The time past is stored in the counter.

The good thing to use this for a timer is that you can add a switch after the oscillator, and use it as a “PAUSE and RESUME” switch of the timer.