Traffic Light

jbigger

Member
Join Date
Jun 2013
Location
Nebraska
Posts
5
While using structured text to simulate a traffic light intersection, i have used a lot of if, elsif, else statements with variables for NorthSouth-Green, NorthSouth-Yellow, NorthSouth-Red, EastWest-Green, EastWest-Yellow, EastWest-Red, LeftTurn-Green, LeftTurn-Yellow, and LeftTurn-Red. I made all of these boolean values and made them inputs (AT %I*). I'm wondering if I incorporate these with TON timers, will this work? Or is there a simpler way?
 
Well, you can do it with one timer and 7 ladder logic rungs, or when using a SQO sequencer instruction, one timer and 3 rungs.

In structured text, it will be a big jumbled mess!

Traffic LIght 1 Timer 6 rungs.jpg
 
Last edited:
In structured text, it will be a big jumbled mess!
I agree. Structured Text is not intended for this kind of relatively simple sequential logic but more for complex calculations or data handling problems. I always have found grafcet (or SFC if you like) much more adapted to this kind of problems. I guess the problem nowadays is that too much programming people are getting involved in PLC and too few electrical guys.

Kind regards,
 
jbig just give us the program, and we will comment on it.
oke lancie you gave the solution.

he jean you sound a little frustrated today.
SFC is easier, however it is more difficult to learn.
 
I've tried this program two ways thus far. One was just a simple light and the other is a lot more extensive. Let me know what's up. Thanks.

PROGRAM MAIN
VAR
green AT %I* : BOOL;
yellow AT %I* : BOOL;
red AT %I* : BOOL;
green_ton: TON;
yellow_ton: TON;
red_ton: TON;
END_VAR

green_ton(IN:= yellow_ton.Q XOR TRUE , PT:= T#30S , Q=> green, ET=> );
yellow_ton(IN:= green_ton.Q , PT:= T#4S , Q=> , ET=> );

IF green_ton.Q = TRUE THEN
yellow := FALSE;
red := FALSE;
ELSIF yellow = TRUE THEN
green := FALSE;
red := FALSE;
ELSE
red := TRUE;
END_IF










PROGRAM MAIN
VAR
ns_green AT %I* : BOOL;
ns_yellow AT %I* : BOOL;
ns_red AT %I* : BOOL;
ew_green AT %I* : BOOL;
ew_yellow AT %I* : BOOL;
ew_red AT %I* : BOOL;
lt_green AT %I* : BOOL;
lt_yellow AT %I* : BOOL;
lt_red AT %I* : BOOL;
END_VAR

IF ns_green = TRUE THEN
ns_yellow := FALSE;
ns_red := FALSE;
ew_green := FALSE;
ew_yellow := FALSE;
ew_red := TRUE;
lt_green := FALSE;
lt_yellow := FALSE;
lt_red := TRUE;
ELSIF ns_yellow = TRUE THEN
ns_green := FALSE;
ns_red := FALSE;
ew_green := FALSE;
ew_yellow := FALSE;
ew_red := TRUE;
lt_green := FALSE;
lt_yellow := FALSE;
lt_red := TRUE;
ELSIF lt_green = TRUE THEN
lt_yellow := FALSE;
lt_red := FALSE;
ns_green := FALSE;
ns_yellow := FALSE;
ns_red := TRUE;
ew_green := FALSE;
ew_yellow := FALSE;
ew_red := TRUE;
ELSIF lt_yellow = TRUE THEN
lt_green := FALSE;
lt_red := FALSE;
ns_green := FALSE;
ns_yellow := FALSE;
ns_red := TRUE;
ew_green := FALSE;
ew_yellow := FALSE;
ew_red := TRUE;
ELSIF ew_green = TRUE THEN
ew_yellow := FALSE;
ew_red := FALSE;
ns_green := FALSE;
ns_yellow := FALSE;
ns_red := TRUE;
lt_green := FALSE;
lt_yellow := FALSE;
lt_red := TRUE;
ELSIF ew_yellow = TRUE THEN
ew_green := FALSE;
ew_red := FALSE;
ns_green := FALSE;
ns_yellow := FALSE;
ns_red := TRUE;
lt_green := FALSE;
lt_yellow := FALSE;
lt_red := TRUE;
END_IF
 
Ton??

Well, you can do it with one timer and 7 ladder logic rungs, or when using a SQO sequencer instruction, one timer and 3 rungs.

In structured text, it will be a big jumbled mess!



how did you get the TON to look like this? typically it has a clock in the box with it.
 
he jean you sound a little frustrated today.
No. It's only that nowadays programmers seem no longer able to use simple ladder logic, even if it is more efficient.
SFC is easier, however it is more difficult to learn.
I beg to differ. It's fairly easy, even to implement if you don' have SFC available as a programming language. All you need are logic and memory functions. I don't have any problem translating an SFC to relay logic, pneumatics or electronics.
 
how did you get the TON to look like this? typically it has a clock in the box with it.
In RSLogix500 and many other brands of ladder logic software, a timer is always a box symbol instruction. You don't have to do anything special to get it to look that way. TON = Timer On Delay.
 
Last edited:

Similar Topics

I am a complete newbie to this stuff and wanted to try this out and was looking for any information on how I can complete this by Wednesday...
Replies
19
Views
12,817
Hey Folks I've done some browsing along the forum for some help in a matter. It would seem the question has been asked many times but it just...
Replies
41
Views
16,935
I'm looking for a simple, cost-effective way to control traffic lights from a central location. The lights are actually mounted on signs next to...
Replies
2
Views
1,884
Hey guys, I'm fairly new to PLC and RSLogix5000, as I am currently a student. I am doing a traffic light project, which is only running off of...
Replies
8
Views
1,983
Hi all, I am having a problem programming a single traffic light, one red, one green, and one yellow light. I am not a student needing home work...
Replies
12
Views
3,440
Back
Top Bottom