Idiomatic pattern for double-click

Is there a simpler way to express a double click pattern in ladder-logic?

Goals are:

1. One input X1 should trigger either output Y1 or output Y2 based on whether X1 has been active within the past five seconds (e.g.: Y1 = first press, Y2 = second press within five seconds).
2. Activated output should not change during button press (e.g.: holding X1 should not result in Y1 then Y2 activating)
3. Activation of the selected output should match length of input

I came to the solution below which seems to meet the requirements, but seems overcomplicated somehow.

CfEUr.png


Is there a better way to do this? Perhaps one that eliminates that extra bit of latching memory?

The screenshot above is from AutomationDirect CLICK series - but I'm if other solutions exist in other systems (especially TwinCat or RSLogix)
 
Is there a simpler way to express a double click pattern in ladder-logic?


I'm not sure, but I think a TOF might simplify this:

  • The falling edge of the input starts the TOF timing
  • The falling edge of the TOF output when the TOF completes is a single click.
  • The rising edge of the input before the TOF completes is a double-click.
    • before the TOF completes => TOF output will be 1
    • The rising edge of the input does reset the timer current value, but it also leaves it ready to start counting again, so there may need to be an explicit, separate reset.
Also, I would buffer the input [Button X001] first, in case physical I/O is asynchronous with program scan: it might cause a problem if NO or NC contacts received different values for X001 during any one scan.
 
Simplify is a subjective term.

I wrote a TOF-based implementation that works and has one less instruction, so if that is the definition of simpler then it answers OP's query with a yes; the absence of any Set/Reset instructions is what most recommends it to me, although it has seal-ins which are almost the same thing.

I'll post it if OP confirms this is not a homework assignment (whoops, accidentally posted it for a bit).

Ignore my previous post; I didn't understand the problem at first.

Welcome to the forum!
 
Thanks for the TOF thought. I had an inkling it would come up, but the two variations I had with a off-delay were not making things any easier. I was trying to do an off-delay of an NC contact on X1 - not using an off-delay on the one-shot falling, though.

I agree that "Simpler" is a subjective term, but five-ish rungs and a latching bit of memory seemed too complex for a conceptually simple task. I think what kept complicating my solutions was the requirement for the state not to change in the activated state.

Not a homework problem, this problem comes from a live system. I removed the names and rebuilt it in a simulator to verify I couldn't come up with a better version.

Thanks for the welcome :)
 
Yeah, TOF is a mindbender, at least for this bear of little brain.
xxx.png
That is tested and seems to work. The first rung is the input buffer* so it doesn't count as part of the complexity. It was three rungs, but they all started with [XIC/NO input], so it was changed to one rung with three branches.

* It turns out the buffering is not needed because this branched arrangement tests the input in only one place; it's also not needed in this particular case because it is MicroLogix 1100.

I think it could also be implemented with two rungs and about five branches by using rising and falling edges of the input, plus Set/Reset/Latch/Unlatch:

  • the rising edge Sets/Latches either single-click output if TOF.DN is 0 or double-click output if TOF.DN is 1
  • the falling edge Resets/Unlatches both outputs, and triggers the TOF to start timing
  • This would still be about a dozen instructions in MicroLogix, basically trading the seal-ins above for the edge detection.
  • Naybe nine instruction for the ClickPLC since the edge instructions are more compact; cf. the untested approach below.
Code:
   X001      tof.Q   Y001
---]^[----+---]/[----(SET)--+---
          |                 |
          |  tof.Q   Y002   |
          +---] [----(SET)--+

  X001               Y001
---]v[----+----------(RST)--+---
          |                 |
          |          Y002   |
          +----------(RST)--+
          |                 |
          +--------[tof]Q---+
So it's more or less the same as the OP version, but eliminating the five instructions needed for the bypassed [In Doubleclick Window] bit.

It's amazing how much easier things are to read and model in my head when there are fewer instructions.
 
Thanks for posting that - exactly the sort of simpler I was thinking might exist, but couldn’t come to. Using the seal in solves the “changing during activation” problem nicely.

I agree that the version using only one shot and latching is easier to read, too.
 
Ny first attempt with the TOF was a disaster, and then I thought your OP ladder was wrong, but then I realized I misread the spec, and that actually made it easy.



I thought of something else: the latter one-shot-plus-latching may not behave as desired after a PLC power cycle. Specifically, a rising or falling edge could be missed; that is an incentive to add some first-pass/first-scan logic, at which point it gets messy again.
 
I will go to great lengths and add multiple branches and whole rungs if necessary to avoid using the TOF timer. It is always always hard on my brain monitoring them and they can always be replaced with a TON sometimes just by inverting a condition or two.

The OP original code is pretty straightforward. You might be able to avoid the SET/RESET pair and just use branches to seal in the rung holding C1 true to make it slightly "better" but it probably won't end up more concise. "better" is very subjective. A guy told me once, "There is no wrong way to write a PLC program as long as the machine works." I disagree with that premise, but the point is, if it works, it works, and optimization has limited payback. I want to end up with clean code that is easy to modify, but sometimes that may mean more code rather than less.

SET/RESET pairs are typically used in real world controllers to retain a condition through a machine power cycle. With certain makes of PLC, you may also need to mark the affected memory areas as retentive.

If this is homework from a student, I would give you an A+. Good job on the code and especially the fact that every address has a comment.
 
I will go to great lengths and add multiple branches and whole rungs if necessary to avoid using the TOF timer. It is always always hard on my brain monitoring them and they can always be replaced with a TON sometimes just by inverting a condition or two. ...

I) TOF made for this question?

I certainly understand that sentiment, but also can't help noticing that this particular application asks exactly the question the TOF answers: has the input pushbutton been off less or more than 5s?

II) Cleaner TON approach?

But I also was on a flight last night with pen and paper and, although it's untested, I got down to 12 instructions with a TON, and no explicit one-shots or Sets/Resets, so it's still a cleaner version in my mind. It is A-B-dependent as it uses the .TT bit of the timer, and although I say it has no explicit one-shots the IN_last bit is essentially the storage bit of a falling-edge/one-shot detector.
Code:
   IN    IN_last     t
--]/[--+--] [--+--[TON]--
       |       |
       | t.TT  |
       +--] [--+

  IN       [COLOR=Blue][B]t.TT  DOUBLE[/B][/COLOR]  SINGLE
--] [--+---[B][COLOR=blue]-]/[----]/[-[/COLOR][/B]----( )--+--
       |                        |
       [COLOR=Red][B]|[/B][/COLOR]   [COLOR=Red][B]t.TT[/B][/COLOR]          DOUBLE |
       [COLOR=red][B]+----] [---+-[/B][/COLOR]-------( )--+
       [B][COLOR=red]|          |[/COLOR][/B]             |
      [COLOR=red][B] |  DOUBLE  |    [/B][/COLOR]         |
       [COLOR=red][B]+----] [---+[/B][/COLOR]             |
       |                        |
       |                IN_last |
       +-------------------( )--+
I had the [OTE IN_last] branch on the first rung, and that does keep all the "this is a falling edge" logic together if the [XIC IN_last] is change to [XIO IN_last], but I found the TON logic easier to gr0k wih less clutter.

III) DeMorgan too?


One thing I noticed about this is the [XIO t.TT] AND [XIO DOUBLE] on the first output branch of the second rung followed by the [XIC t.TT] OR [XIC DOUBLE] on the second output branch, specifically that that combination is an expression of DeMorgan's Theorem(s).

IV) Pedagogy


Given those three aspects of this particular problem, I wonder if this "double-click" problem is a good teaching exercise, after the canonical seal-in and start-stop circuits; it even has the essence of patterns. The dearth of well-written homework exercises is regularly expressed on in this forum, so maybe this could be useful.
 

Similar Topics

Hello. I am working in FTVSE v8. I have many trends set up some of them work others do not. The ones that don't work show the foot print of the...
10
Replies
1,067
Views
New here so not sure if this is allowed, but this is something I developed for a work project to enable the usage of USB barcode scanners with...
1
Replies
1,762
Views
I have a general question on the theory of a vfd. I understand that when set to V/hz, the drive will bring the volts and hz up together when...
15
Replies
6,979
Views
Hi guys, I am facing problem on layer palleatizer machine.my problem is I can not change the pattern. it is running by present pattern.There is...
1
Replies
1,873
Views
Hi guys, I am facing problem on layer palleatizer machine.my problem is I can not change the pattern. it is running by present pattern.There is...
0
Replies
1,837
Views
Top