Midweek PLC Musings

Back To The Simple Toggle

You would think that a simple toggle bit instruction would be one of the simplest items to implement in a PLC. Turns out it is not! In the early days of PLCs, I’m talking the early eighties here, this deceptively simple challenge was often used in PLC training courses. What could be simpler: Push a button and turn something on, a light maybe. Then push it again and turn it off. To solve this challenge without resorting to one-shots, counters or timers stumps most who think they know how to work with a PLC. There are some HMI systems where their designers have jumped in, and provided an on-screen button that can be set up as a toggle. But that is just a bad idea, because it is created by sending first a “set bit” instruction, and then with the next button click, later on, send a “reset bit”. Now you have an external to the PLC entity control how the PLC behaves, not recommended. One of the hard won principles of PLC control is to having the PLC be responsible for all its control functionality. And what if you need a toggle function based on a hardwired pushbutton?

So lets face the toggle function requirement like the knowledgeable programmers we are. It is easy to get trapped into an experimenting rabbit hole when addressing a seemingly simple program requirement like this. But that’s why I am writing this, to urge you away from the sort of “seat of the pants” programming approach that gets you labeled with all sorts of interesting names (usually by people who know precious little about the subject, you know how it goes).

Lets try a more structured approach: We know that we have to use the scan sequence to create kind of a one-shot functionality. Without actually resorting to one-shot instructions though, because that is another programming habit to be discouraged. I’m writing a programming standard that addresses this subject in case you are interested. Ok, the next thing we should separate is the actual bit that we want to toggle, from the logic that steers the direction of the input bit (the pushbutton or the HMI clicked button influenced bit).

The first objective then, is to make a kind of one-shot logic, taking advantage of the timing that is part of the program execution scan, that then can be used the turn on the toggle. By placing a Pushbutton Examine On instruction in series with a PrePress Examine On instruction, and a Toggle Examine Off instruction controlling the StobeOn Output Energize instruction. The key here is that the PrePress Output Energize bit is controlled by a Pushbutton Examine Off instruction, in a rung placed further down in the scan sequence. In this manner, while the Pushbutton Examine On instruction is true for a long time (as long as the button is pressed, possibly for many scans), the PrePress Examine On that was on as long as the Pushbutton was not pressed, is only on for the first scan on which the Pushbutton is pressed. That is making the one-shot functionality happen. We are purposely using something any programming standard worth its salt will recommend against, because normally you want to set up any selection or program steering logic before executing it. So we are purposely building scan sensitive logic. Isn’t it great how we can figure out and predict how the PLC will execute our logic? Ok, so now over to you. Can you complete the toggle logic? Don’t burn up too much time on it though - these days no-one will pay you for that. These days we just use a counter, when a toggle is required, because memory is so much cheaper than our time.

要查看或添加评论,请登录

Hugo Ahrens的更多文章

  • Midweek PLC Musings

    Midweek PLC Musings

    There was some commentary about function block programming and its suitability for the application at hand. It might be…

  • Midweek PLC Musings

    Midweek PLC Musings

    Last week I regaled you with the ever lasting impact of ladder logic. Turns out I’m not done with that topic, because…

  • Midweek PLC Musings

    Midweek PLC Musings

    In Support of Ladder Logic Not that ladder logic needs my support specifically to keep it alive. It’s doing quite well…

    4 条评论
  • Midweek PLC Musings

    Midweek PLC Musings

    Last week I developed some general thoughts about what you would include in a typical single speed motor control…

  • Midweek PLC Musings

    Midweek PLC Musings

    Thinking about a General Motor Logic Block. So last week we looked at abstraction, and I thought it might be helpful to…

  • Midweek PLC Musings

    Midweek PLC Musings

    Abstraction in Art and the Art of PLC Programming What is it about abstract art that gets so many people unsure…

  • Midweek PLC Musings

    Midweek PLC Musings

    Alternating Logic What are we talking about when confronted with the requirement to discuss something that requires…

  • Midweek PLC Musings

    Midweek PLC Musings

    Truth And Fake News Those of us still using Ladder Logic during some part of our day have a great advantage over the…

    2 条评论
  • Midweek PLC Musings

    Midweek PLC Musings

    Calling a Spade a Shovel In the technical world we live in there is no faster way to discount your trade value - than…

  • Midweek PLC Musings

    Midweek PLC Musings

    Programmers Notebooks, what are they for? No they are not a design tool. They are a memory aid and progress reference.

社区洞察

其他会员也浏览了