Author Topic: Self Starting Timer  (Read 9138 times)

Fladiver64

  • Newbie
  • Posts: 1
    • View Profile
Self Starting Timer
« on: June 05, 2017, 06:55:40 PM »
Ok I am very new to the PLC ladder logic world so forgive me if this is too easy for most of you. I have an application where I need to trigger an output every 30 min to keep a system from going to sleep. What I need is a timer that will start on the first pass of the ladder, run for a specified period of time, then automatically reset and run again. This loop needs to be continuous as long as the plc is powered. Any help is appreciated.

Thanks

Mike

support

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 3170
    • View Profile
    • Internet Programmable PLCs
Re:Self Starting Timer
« Reply #1 on: June 06, 2017, 12:34:34 PM »
How long do you need to keep the output? If the output stays on for 1 second every 30 minutes does it work for you?

If so you can try the attached program. The 1 second clock pulse drive an up-counter that counts to 1799 and roll over to 0 (total 1800 seconds = 30 minutes). When the counter rolls over to zero the output is turned on by the ladder program. One second later the counter is incremented to 1 again and the counter contact is open and the output is turned OFF.

You can simulate the program easily by running simulator. If you don't want to wait 30 minutes to see the result you can speed up the simulation: click "View" and click "Edit" button and then enter the following expression:

CTRPV[1] = 1790

This will set the counter #1 value to 1790 and it will continue to increment until 1799 and roll over to 0. You will observe the output #1 being turned ON for 1 second when counter present value = 0.
« Last Edit: June 07, 2017, 06:07:02 PM by support »
Email: support@triplc.com
Tel: 1-877-TRI-PLCS

support

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 3170
    • View Profile
    • Internet Programmable PLCs
Re:Self Starting Timer
« Reply #2 on: June 06, 2017, 12:35:47 PM »
Here is the .PC6 program
Email: support@triplc.com
Tel: 1-877-TRI-PLCS

garysdickinson

  • Hero Member
  • Posts: 502
  • Old PLC Coder
    • View Profile
Re:Self Starting Timer
« Reply #3 on: June 08, 2017, 01:13:04 PM »
Please be aware that the time to the first output will be 1799 seconds and the time between each subsequent output will be 1800 seconds.

This has to do with the behavior of the COUNTER when used as an up counter.  If you need the first output and all subsequent outputs to be 1800 seconds apart then you must force the Present Value of the COUNTER to 0.

This initialization can be done with a custom function that contains the following code:

CtrPV[Count30Min]=0

You need a bit of ladder logic before the rung with the COUNTER that calls your custom function on the first scan of the ladder logic file.  The "1st.Scan" contact will get the jobs done.

Best regards,

Gary D*ckinson
« Last Edit: June 08, 2017, 01:13:30 PM by garysdickinson »

dushyantbangal

  • Newbie
  • *
  • Posts: 3
  • I'm a llama!
    • View Profile
Re:Self Starting Timer
« Reply #4 on: September 11, 2017, 03:44:40 AM »
I have a similar problem, but I cannot use CLK for that.

I tried using it, but when the other code is running and the PLC is busy, the CLK circuit does not get hit and I keep on missing few milliseconds everytime.

But in case of timer, it keeps on counting even when the PLC is busy.

So, is there any way to just restart the timer instead of going through all of this?

dushyantbangal

  • Newbie
  • *
  • Posts: 3
  • I'm a llama!
    • View Profile
Re:Self Starting Timer
« Reply #5 on: September 11, 2017, 03:58:56 AM »
Refer the screenshot for connection.
The normally closed input should start your timer.

Then to reset the timer, just write a custom function and execute it when the timer hits:

CLRIO timerName
TIMERPV[1]=100 'new time

garysdickinson

  • Hero Member
  • Posts: 502
  • Old PLC Coder
    • View Profile
Re:Self Starting Timer
« Reply #6 on: September 11, 2017, 12:01:16 PM »
You can shorten your Self Starting Timer down to a single line of code that does not require a custom function to restart.  The trick is to use the inverted version of the TIMER contact to control the timer.

Please be aware that any ladder logic that uses the TIMER contact must be positioned before the rung of logic that controls the TIMER.

I'd suggest that you place the TIMER on the last rung in your program.

Please be aware that the width of the pulse created by the use of the TIMER is only a single scan of the ladder logic.  I like big fat 50% duty cycle outputs so that I can easily observe them with the flashing LEDs on the PLC OUTPUTs.  This is why I added the flip flop logic in the lines before the TIMER.

Best regards,

Gary D*ckinson
« Last Edit: September 11, 2017, 12:03:19 PM by garysdickinson »

garysdickinson

  • Hero Member
  • Posts: 502
  • Old PLC Coder
    • View Profile
Re:Self Starting Timer
« Reply #7 on: September 12, 2017, 10:45:41 AM »
This is a simpler version that gets a big fat visible output pulse and is based on 2 TIMERs.  The SV for the TIMERs determine how long the OUTPUT is on and off.

I use this setup when I need a very slow (low frequency) PWM output that the PLC PWM hardware cannot support.  I just change the SV on the fly to adjust the frequency and duty cycle.

Gary D*ckinson
« Last Edit: September 12, 2017, 10:47:40 AM by garysdickinson »