Timer that counts down to zero, then up, with pause function?

blazindave

Member
Join Date
Dec 2012
Location
Stone Mountain
Posts
2
Longtime lurker, first time poster... I'm no expert when it comes to PLC programming, I tend to just kind of fumble along until I come up with something that works, but this has been stumping me:

I'm using Turck hardware (programmable BL-20) which uses Codesys programming environment.

I need to build a function block that has the following inputs/outputs:
Inputs:
  • MinutesIn - this can be either a WORD or a TIME variable (I can give it either)
  • TimingOn bit - this will be a maintained signal, but I could make it momentary if necessary
  • Pause bit - this one will be maintained
Outputs:
  • Minutes (WORD)
  • Seconds (WORD)
  • Counting Up bit (see below for description)

Overview:
I'm building a system to track the time it takes to build various assemblies - the worker will scan a barcode, which will feed the allotted number of minutes into this FB (this will always be a whole number, no seconds associated with it). Worker hits start and the clock starts counting down. (e.g. if they have 200 minutes allotted, as soon as they hit start, it begins counting down from 200:00, 199:59, 199:58, etc). When it hits 0:00, it then starts counting up: 0:01, 0:02, 0:03, etc.

I need to have a pause function in there so if they take a break or run out of parts, etc, it holds the time until they resume work.

I am having a lot of trouble with the pause function, as I don't seem to have a retentive timer available to me - I've seen using a TON with an EN and that almost works, except that even when the EN input is turned off, it still keeps timing -- when I re-enable it, the time has still continued to increase. I need it to hold the value and stop increasing during that "pause" time.

I want to display the "clock" for the operator to see, so he can know if he is on pace with what's allocated, or working fast or slow. Ultimately, when TimingOn ends, I will take the values from the output Words and store them, as well as the status of the Counting Up bit (so I know if he had 10 minutes remaining or took 10 minutes too long, for example).

This seems like something that someone's probably already done at least most of, or maybe has some suggestions, ideas, etc... Any advice or libraries or FBs that are already written are greatly greatly appreciated.

Thanks, I look forward to the responses!
 
If you don't have retentive timers, can you just use a free-running 1 second clock to increment or decrement a register, based on conditions (enabled, paused, etc.)?... :confused:

🍻

-ERic
 
I need to have a pause function in there so if they take a break or run out of parts, etc, it holds the time until they resume work.

I am having a lot of trouble with the pause function, as I don't seem to have a retentive timer available to me - I've seen using a TON with an EN and that almost works, except that even when the EN input is turned off, it still keeps timing -- when I re-enable it, the time has still continued to increase. I need it to hold the value and stop increasing during that "pause" time.

Just quickly wrote up a code in Ladder to create the "Pause" functionality in Codesys Timer.

Operation of code:

"Set TIME"
is used to initially load Preset Time(PT) before pressing "Start"
(I used T#60s as an example,in your case the PT will be read from barcode)

"Start" has to be continuously on.
If "Start" is switched of Timer resets to 0.

"Pause" has to be kept on while the work is halted
"Pause" is turned off when work resumes.

Explanation:
What the code does is subtracts the time elapsed from the PT on pressing "Pause" and loads this new value(ie. remaining time) to the PT.This enables the timer to adjust for the Time already elapsed before the Pause was pressed.Releasing "Pause" causes the timer to start counting down the remaining time.

If you need further explanation feel free to ask.

Note:
This was written in a hurry and it has been a long time since I last used Codesys and so there might be others who might be able to write the code in a more compact way.
Also, there will be slight inaccuracy in the calculated "remaining time" because of the way the way the rungs are scanned/executed.

Here is Part 1:

Pause Timer 1.jpg
 
Last edited:
Thanks! I will give that a shot (won't have much time to mess with it today though).

One of those things where I've looked at enough and added code and convoluted it so much that stepping away from it, being willing to scrap all the time I've spent futzing with it so far, and using your suggestions, will undoubtedly help tremendously. Thanks again!
 
Additional details and Logic Compression

Additional Detail:
I forgot to mention that "Set TIME" also functions as reset that is, any time it is pressed it will reset the PT to what you loaded into it initially.I mention this because maybe you would require a reset functionality as well.

Logic Compression:
The logic that I shared can be compressed into 4 rungs by making the modifications shown in the attached images.

Part 1:

P_Timer 1.jpg
 
Last edited:
have a look at www.oscat.de

an easy one is run a task every second(see resources tab).
if pause then do not subtract one from timer, otherwise subtract t#1s from a runtimer VAR.

if runtimer <=0 then overtime add 1
 

Similar Topics

I have some logic that I have written within a 5380 series controller that tracks the time an event is started, while the event is running an RTO...
Replies
2
Views
91
Hi all, I have a simple question that I have overcomplicated and gotten stuck on. I have a variable, we can call it "light" that I need to stay...
Replies
4
Views
308
Question to anyone with ideas about my thoughts on upgrading a very vintage timer, which is being used to switch between 2 5hp domestic water...
Replies
14
Views
434
why my timer only executes once here? After first time i use it, ET stays at 0ms all the time. It is in FB
Replies
5
Views
311
Good morning guys, I'm searching for a Timer relay which accomplishes the "flasher" condition in the photo attached, however, I need the ability...
Replies
2
Views
556
Back
Top Bottom