My Function Block Diagram isn't... functioning

Traffic lights are a sequence of operations, it can be done with boolean logic but perhaps the best way is a sequencer i.e. a word variable where it goes from 0 through to say 10 (although a good idea to use steps of 10 that leaves plenty of steps for enhancements. it also means you can force to jump steps, go back or hold. here is a 4 way junction but programmed for two way traffic i.e. no left (or right if in the US etc.) filters. best to keep the outputs seperate from the controlling logic that way it is easy to add or disable certain lights or add pedestrian crossings.
You're so right!

In general the use of sequences are severely underrated - and the use of logic severely overrated.

Most of my programs are mostly sequences that talk to each other. There is logic as well but wherever it is, it's always simple. It's because the logic only has to apply to one simple scenario - one step in a sequence.

If you try to logically define when a particulary light should be lit, say green on traffic light no 1, you will end up with extremely complicated logic. If you however have a sequence for each traffic light, that's has a number of steps, the logic for the green light will be very simple. For example it's green when the sequence is in step 4 or 5.

In computer science a sequencer used like this is called a finite state machine.

A sequence can be implemented in a PLC using ladder or any other type of language. You don't need anything special.
 
Don't just start coding set your stall out.
Imagine a set of traffic lights north/south & east/west. so you have practically 6 actual outputs for a simple system but think about perhaps future expansion so perhaps filters in this case right hand filters (I live in the UK the correct side of the road to drive on lol).
So first allocate your I/O for example for a simple system no inputs are required, however, it might be that you wish to introduce some pedestrian crossings that require inputs for pedestrian activation or perhaps road sensors to detect traffic flow.
but at least put your filter lights on outputs.
So we have 4 red, 4 amber & 4 green (although simple would only require 2 red 2 amber & 2 green if at a later date filter was required then there is a need to split these two way common to allow for the filter.
Then write down your sequence
step 1 All RED
Step 2 NS RED/AMBER EW RED
Step 3 NS GREEN EW RED
STEP 4 time delay
STEP 5 NS AMBER EW RED
STEP 6 NS RED EW RED
Step 7 EW RED AMBER
STEP 8 EW GREEN
If you see what the pattern is a simple 4 way 2 sequence light junction.
Allocate numbers to these perhaps in steps of 20 to allow expansion in the sequence.
So Step 1 is SEQ 0
Step 2 20
Step 3 40 & so on.
Write your logic does not matter in what language what ever is comfortable.
Use the sequence values in compares to actuate the relevant outputs. (could use latched bits i.e. bool logic but can become messy.).
Then you can enhance it to perhaps add filters for each way or add pedestrian crossings, perhaps alter the timings based on a type of recipe selected depending on time of day
 
It's a niche market, with a fixed number of behaviors, so they are probably run by special-purpose devices that can be configured by the user for for the specific application, e.g. crosswalk or not, left turn signals or not, variable timings based on day of week and time of day, car sensors, communication with other intersections for coordination, etc.
Makes sense. I've seen videos showing inside traffic control cabinets and the techs aren't messing with ladder logic, now that I think about it.
but getting approval for use of standard plcs would be difficult
Well yeah, maybe they're not allowed to use standard PLCs if dedicated traffic control hardware is available/mandated.
 
In general the use of sequences are severely underrated - and the use of logic severely overrated.
I'm new to this but already felt that even for my alternating green -> red light example, the logic was pretty convoluted considering how simple the intended result was.

If you try to logically define when a particular light should be lit, say green on traffic light no 1, you will end up with extremely complicated logic. If you however have a sequence for each traffic light, that's has a number of steps, the logic for the green light will be very simple. For example it's green when the sequence is in step 4 or 5.
Interesting. So I could create a sequence using Function Block Diagram for red/green (20 seconds on each) and not need logic, just a sequence? Sounds like I could get the same result with less effort, and a less complicated diagram.

Sounds like I need to rethink my approach!
 
Ironically, Siemens used to do traffic management systems like Sitraffic sX and m60 series ATC (Advanced Traffic Controllers) for traffic lights and detectors. but I believe they sold it in about 2021
 
And when you have 6 lights in two groups of three, green+yellow+red, times two directions, N/S and E/W, note that you only need to write sequence/state logic for turning on four of thosr lights, e.g. the greens and yellows only need to "know" the current state. The reds can be inferred from only those four i.e. the N/S red light is on whenever both the N/S green and yellow are off, and similar logic applies for the E/W red light
 
Don't just start coding set your stall out.
That's what I'm doing. Definitely planning this before starting.

If you try to logically define when a particular light should be lit, say green on traffic light no 1, you will end up with extremely complicated logic. If you however have a sequence for each traffic light, that's has a number of steps, the logic for the green light will be very simple. For example it's green when the sequence is in step 4 or 5.

In computer science a sequencer used like this is called a finite state machine.
Thanks. I'm going to try to write a basic sequence for this.

Then write down your sequence
step 1 All RED
Step 2 NS RED/AMBER EW RED
Step 3 NS GREEN EW RED
Step 4 time delay
Step 5 NS AMBER EW RED
Step 6 NS RED EW RED
Step 7 EW RED/AMBER
Step 8 EW GREEN
Interestingly, I'm in Canada and we don't have the red/amber "get ready" light before green. (Doesn't exist in N. America.) Grew up in the UK though, so I'm used to the other way!

So my sequence for Canada could skip two steps and would look like this:

Step 1 All RED
Step 2 NS GREEN EW RED
Step 3 time delay
Step 4 NS AMBER EW RED
Step 5 NS RED EW RED
Step 6 EW GREEN

I'm going to try this later. It'll be my first time writing a sequence.

1772501915696.png

And when you have 6 lights in two groups of three, green+yellow+red, times two directions, N/S and E/W, note that you only need to write sequence/state logic for turning on four of those lights, e.g. the greens and yellows only need to "know" the current state. The reds can be inferred from only those four i.e. the N/S red light is on whenever both the N/S green and yellow are off, and similar logic applies for the E/W red light
I get the idea in principle but need to play around with it in OpenPLC Editor to fully get it I think.
 

Attachments

  • 1772502077354.png
    1772502077354.png
    113.2 KB · Views: 1
I'm new to this but already felt that even for my alternating green -> red light example, the logic was pretty convoluted considering how simple the intended result was.


Interesting. So I could create a sequence using Function Block Diagram for red/green (20 seconds on each) and not need logic, just a sequence? Sounds like I could get the same result with less effort, and a less complicated diagram.

Sounds like I need to rethink my approach!
Yes, do what @Pete.S. write, and don't bother with the lights at all initially; that is Business Logic (current sequence state determines light states).

Focus instead on the Sequence Logic, which writes a Step Number value (1,2,3,...,6 above) to a Sequence State variable, and manages the transitions from one Stemp Number value in that variable to the next.

All that is involved there is a series of rungs (or groups of rungs), each implementing logic like this:
  • if Step Number value is N,
    • then e.g. run timer Xn,
      • so timer Xn is only running when Step Number is N
    • AND
    • when some condition(s) is(are) met (e.g. timer Xn is expired),
      • then transition Step Number value to M
  • If Step Number value is M,
    • then ...
    • AND
    • when ...
      • the transition Step Number value to ...
  • If Step Number value is ...
    • ...
  • ...
So now you have a Sequence State variable that always has a Step Number value assigned to it, and that also transitions from one Step Number value to another according to some condition (e.g. timer expiry events).

You can run that program of Sequence Logic only, and see if it transitions as you expect. Again, don't bother with lights as that is easy.

Once you have the Sequence Logic working, you can write the Business Logic:
  • NS Green light is on if Step Number value is 2 (transition to NS Green) or 3 (timer for NS Green), and off otherwise i.e. is off for all other Step Number values
  • NS Amber light is on if Step Number value is 4, and off otherwise
  • EW Green light is on if Step Number is 6, and off otherwise
  • NS Red is on if both NS Green and NS Amber are off, and off otherwise
  • EW Red is on if both EW Green and EW Amber are otf, and off othewise
So six rungs of business logic, one for each output (light).

The main point to what @Pete.S. wrote is to isolate the Business Logic from the Sequence logic. That way the Sequence Logic can be as complicated as you want (e.g. crosswalk button inputs; car sensor inputs; emergency vehicle infrared triggers; ...), without having to keep track of the lights' states. And the Business Logic will always be at most one rung per output.

If you try to mix Sequence Logic (sequence state and transitions) and Business Logic (output states), then you have to use Set and Reset instructions, so at least two instructions per output, possibly more, which leave lights in on or off states hanging around like stale farts, and you have to clean up the Set/Reset maintained states at each transition.
 
A lot of good advice already.

One thing I may have missed, but I suggest you look into is grafcet . I was taught about this in school, it’s basically a methodology for analyzing/creating sequences, and/or analyzing a process.

That’s how I’d describe it anyway. When you google it, it says something about SFC, but I learned about grafcet way before I heard about SFC. I had been using grafcet to develop my ladder logic sequencers much before I knew of SFC.
 
A lot of good advice already.

One thing I may have missed, but I suggest you look into is grafcet . I was taught about this in school, it’s basically a methodology for analyzing/creating sequences, and/or analyzing a process.

That’s how I’d describe it anyway. When you google it, it says something about SFC, but I learned about grafcet way before I heard about SFC. I had been using grafcet to develop my ladder logic sequencers much before I knew of SFC.
Grafcet could make sense, especially if you use SFC in your PLC. I'm personally not a fan of grafcet though.

I like flow charts as they have been around much longer and can do the same thing. Flow charts are also understood by almost anyone and you can edit them in programs that most people have access to, like powerpoint (not everyone knows that though). So they're good for long term documentation of how things work.

To keep it simple I only these shapes:
1772541761610.png


But if I don't need to deliver any documentation I often resort to plain text.

Like this:
Code:
Step 0:   Stop Conveyor 1 & 2.
          Do nothing.
Step 1:   Wait for product
Step 2:   Start Conveyor 2
Step 3:   Wait 10 seconds.
          If product is still there go to Step 10
Step 4:   Stop Conveyor 2.
          Go to Step 1.
etc
 
I got sidetracked for a while but now I'm trying to pick up where I left off!
Yes, do what @Pete.S. write, and don't bother with the lights at all initially; that is Business Logic (current sequence state determines light states).

Focus instead on the Sequence Logic, which writes a Step Number value (1,2,3,...,6 above) to a Sequence State variable, and manages the transitions from one Step Number value in that variable to the next.
Okay, so if I focus on the sequence logic to start with I guess I won't need Wokwi yet as I'm still a long way from doing anything with my Arduino or the LEDs.

What program should I use to write the sequence state variable? OpenPLC Editor or could I just write the steps as a list in a text editor for now?
 
Ironically, Siemens used to do traffic management systems like Sitraffic sX and m60 series ATC (Advanced Traffic Controllers) for traffic lights and detectors. but I believe they sold it in about 2021
Knowing Siemens, their traffic solutions were probably programmed with an S7-1200... /s

Being sarcastic as I was once looking for an HVAC controller from Siemens, managed to get to the department in charge of those things and they proceed to tell me they don't use that and just use an S7-1200 for all applications.

This being said, I do remember a post maybe a couple of years ago, from someone that worked with traffic lights and the functions that existed on those controllers. If I remember correctly, it had current monitors set up to detect faulty lamps, etc...
 
Being sarcastic as I was once looking for an HVAC controller from Siemens, managed to get to the department in charge of those things and they proceed to tell me they don't use that and just use an S7-1200 for all applications.
The left hand of Siemens hardly ever knows what the right hand is doing, and there are often 3 depts in different divisions that do the same thing. Joys of working with multinational corporations....
 
The left hand of Siemens hardly ever knows what the right hand is doing, and there are often 3 depts in different divisions that do the same thing. Joys of working with multinational corporations....
Fair point... my siemens rep used to say that if electrons are moving within it, then Siemens will have a version of said device. There's a lot of history too within certain industries that they may have divested that still have an impression on people.
 
Yes many traffic lights did have current monitors for detecting blown lamps, however, a friend of mine who worked on traffic systems was adamant that in the days where S5 was the plc system they were never used on highway traffic systems in the UK, not to say temprary systems didn't use them though. the traffic controllers apparently looked very similar to the S5 135/155 racks not surprising really as 19" rack double height systems were the norm for industrial computer systems, probably the RTOS was just a modified runtime based on the standard plc system. I believe also PLC's did not have the correct certification in the 80's/90's however, the core control now I believe is often plc based but need to be certified. Temporary systems may now use standard plc controllers. Certainly in the last century the S7 was still a twinkle in the developers eye so would have been based on the older S5 for siemens & more so in the US based on AB.
 

Similar Topics

Hey all! I am working in the following: Logix Designer: 36.11 Studio 5k Emulator: V36 I have my main program (ladder and JST) calling a FBD that...
5
Replies
1,526
Views
Hi we imported a working function block diagram from one program into another. It verifies. However, we cannot select the function block diagram...
3
Replies
1,145
Views
Hi, I have attached herewith one image which our programmer has been used in S7 1500 PLC. Now we need to use the same instructions in S7 1200 PLC...
4
Replies
918
Views
I've been using RSLogix 5000 for some time and have always used the "BNOT" block to inverse a digital signal in FBDs. This can take up a lot of...
0
Replies
3,080
Views
Ironically, I have never done any function block programming in Logix5000 itself, but I have to draw out a program for it. My question is, what...
4
Replies
2,526
Views
Top