My Function Block Diagram isn't... functioning

I've watched some tutorials and am trying to gradually write some FBD that can handle a model of an intersection (traffic lights in 4 directions, pedestrian walk signs + crossing buttons).

Before I get deep into it, I'm playing around with a few functions and seeing if things work the way I expect.

The below FBD is supposed to alternately light Green1 and Red1 but it gets stuck on Green1. Any idea where I went wrong?

1771669294387.png

Also, am I right in thinking Function Block Diagram is the best language for programming a traffic light PLC? It seems easy to read and follow.
 
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.
 

Attachments

  • Traffic Lights Seq.pdf
    82.8 KB · Views: 13
but perhaps the best way is a sequencer i.e. a word variable where it goes from 0 through to say 10
This is a new concept for me. I'm trying to understand how light timings for multiple streets at the intersection could be combined (and the most elegant way to do that), and other details like flashing pedestrian lights running at the same time (and with different patterns triggered by buttons).

I agree on using steps of 10 so there's room to add more in between, and it sounds like a great idea to keep outputs separate from controlling logic. I just saw it done this way in a YouTube video I was learning from.

How come your sequence is labelled "Structured Ladder/FBD"? Can the same sequence be used in both PLC languages?
 
The Structured part means different programs seperated i.e. create different programs for different operations & use of function blocks i.e. create a standard function like perhaps a motor control block, these function blocks pass parameters to the function manipulates them & pass parameters back to the calling program, so you only write the function once but call it many times once for each motor PLC's have ready built functions like timers for example that is a function block you pass parameters like enable, time, & it outputs things like elapsed time & a Q output. also it is possible in the IDE I use to be able to use ladder type logic.
You will notice that the traffic light code I showed it returns the sequence variable back to 0 so effectively it loops round
As shown below the two rungs are identical just one is in FBD & the other in ladder.
1771675734872.png
And yes it can be used in both ladder & FBD but in ladder certain functions like MOVE are effectively output instructions in ladder where you move say variable 1 to variable 2 but using FBD they can be linked
like this
1771675919922.png
However, in ladder old form it has to be like this it is actually the same as above but as the move function is effectively an output instruction the result has to be put in a variable then again put into the multiply function
1771676384399.png
 
The below FBD is supposed to alternately light Green1 and Red1 but it gets stuck on Green1. Any idea where I went wrong?

View attachment 81857
Assume both Red1 and Green1 values are initially 0. Assume the upper FB chain is evaluated first.

The upper NOT inverts its input (Red1 value of 0) to 1 at the upper NOT output.

The upper TOF takes its input (upper NOT output of 1) and sets its output to 1, and waits for that 1 to become 0 to start timing.

The Green1 output takes its input (upper TOF output of 1) and sets Green1 value to 1.

The lower NOT inverts its input (Green1 value of 1) to 0 at the lower NOT output.

The lower TOF takes its input (lower NOT output of 0) and leaves its output to 0, as it was never timing in the first place.

The Red1 output takes it input (lower TOF output of 0) and sets Red1 value to 0.

That completes the first scan cycle: Green1 value is now 1; Red1 value is now 0.

On the next, and all following scan cycles, since it starts with Red1 and that value is 0, everything repeats. Specifically, the upper TOF never starts timing because it's input (NOT Red1) is still 1.
 
Also, with De Morgan's Laws, that initial section can be simplified a bit (or perhaps there is a NOR block):
 

Attachments

  • 1771680045628.png
    1771680045628.png
    51 KB · Views: 9
Also, with De Morgan's Laws, that initial section can be simplified a bit (or perhaps there is a NOR block):
I'm gonna have to step in and say #TeamKarnaugh (K-maps). Sadly the quick google makes k-map sound like its for people that try and put the cube in the circle slot.
 
LOGO! FBD with TONs, using the canonical Flasher pattern; seems much simpler to me, but maybe not.

[edit: refactor to remove flag]
 

Attachments

  • 1771688984962.png
    1771688984962.png
    4.8 KB · Views: 5
That open plc is useless unless you create many FB's the move function is unconditional therefore seems you cannot use bool logic to move data as an enable
I'll try to write something better after watching some more tutorials.

Do you think traffic light controllers in the real world have variations in their scan times due to overhead caused by their longer ladder logic? Should I be concerned about timing issues (i.e. hundreds of milliseconds) once my program becomes more complex?


1772403658945.png
 
It is possible that timings could vary in an actual traffic application, but I doubt any traffic lights are controlled by general purpose PLCs or ladder logic, and nobody is going to care about the accuracy of your exercise.

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.

That said, there are aspects of some PLC applications that rely on precise timings. I did a little exercise with this issue a write back; see here: GitHub - drbitboy/PLC_2s_lamp_flash: Testing the timing of different methods of flashing a limp
 
In the uk most traffic light control is done by dedicated systems this is because the hardware is specifically designed for ruggedness and the strict requirements of government plus the integration of communications to higher level systems and control etc. There is no requirement for timing accuracy to ms it would make no difference visibly or funtional even a second or two would not make that much difference and plcs now have scan rates just as fast as those dedicated systems i have no doubt that these systems are certainly based on plc technologies in many ways a friend of mine was an engineer on those systems but not on the software code and some systems were pretty basic so there would be no issue with speed but getting approval for use of standard plcs would be difficult my friend always believed it was more to do with commercial sales rather than anything else.
 

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