Switching states

Hi, I am new in PLC programs and I have a question. For a traffic light, I have to change from green to yellow and from yellow to red with 2 sec. delay. The problem is that when I activate the change the state is in green and after every 2 sec. is going in yellow for a very short time and then back to green again. Probably I am not using the TON timer properly. Thanks in advance:


CMD_STOP:
state := ST_GREEN;
timer(in := FALSE);
timer(in := TRUE, pt := T#2s);
IF timer.Q THEN
state := ST_YELLOW;
timer(in := FALSE);
timer(in := TRUE, pt := T#2s);
IF timer.Q THEN
timer(in := FALSE);
timer(in := TRUE, pt := T#2s);
IF timer.Q THEN
state := ST_RED;
END_IF
END_IF
END_IF
 
So you should only need one timer() call to run a TON, and that one call will be executed once on each scan cycle - that code is going to reset the timer on every scan cycle (first line after CMD STOP: ) I don't think the timer will ever expire.

Do you have programming experience in other domains, e.g C or Python or JavaScript or AWK?
 
Try running the following program by itself, where count is an integer and timer is a TON:
Code:
timer(in:=count < 10000, PT:=T#2s);

IF count < 10000 THEN
    count := count +1;
ELSE
    count := 0;
END_IF;

Watch the behavior of timer.ET and timer.Q in particular.
 
Hi, I am new in PLC programs and I have a question. For a traffic light, I have to change from green to yellow and from yellow to red with 2 sec. delay. The problem is that when I activate the change the state is in green and after every 2 sec. is going in yellow for a very short time and then back to green again. Probably I am not using the TON timer properly. Thanks in advance:

Code:
CMD_STOP:
            state := ST_GREEN;
            timer(in := FALSE);
            timer(in := TRUE, pt := T#2s);
            IF timer.Q  THEN
                state := ST_YELLOW;                   <==
                timer(in := FALSE);                   <==
                timer(in := TRUE, pt := T#2s);        <==
                   IF timer.Q THEN                    <==
                timer(in := FALSE);                   <==
                timer(in := TRUE, pt := T#2s);        <==
                    IF timer.Q THEN                   <==
                        state := ST_RED;              <==
                    END_IF;                           <==
                END_IF;                               <==
            END_IF;

To be clear, the lines of code above followed by <== will never execute
 
Par for the course. New member looking for free homework help, likely never to post again or contribute to the forum. Dr. giving his best tutorial for free, 4:1 post ratio to OP, will go unnoticed or unappreciated by OP.

Microcosm of what's wrong with the world today, and why the new generation, in general, will never succeed.

FYI, ignore my rant...I'm in a particular Randy mood ;)
 
and why the new generation, in general, will never succeed.
I'm pretty sure our parents and grandparents had similar opinions of us when we were the OP's age. Be nice them though, they're the people who'll be picking out and staffing our nursing homes.
 
I'm pretty sure our parents and grandparents had similar opinions of us when we were the OP's age. Be nice them though, they're the people who'll be picking out and staffing our nursing homes.
Yes and no....older generations have always rhoughr the younger generation lacking. But there's a fundamental laziness and entitlement today. The everyone gets a trophy generation thats never existed before. As for the nursing home, nope. Bullet before that time comes. I've seen the level of "care" in nursing homes with my parents. Those snot nosed brats can't give basic care eirher.
 
Yes and no....older generations have always rhoughr the younger generation lacking. But there's a fundamental laziness and entitlement today. The everyone gets a trophy generation thats never existed before. As for the nursing home, nope. Bullet before that time comes. I've seen the level of "care" in nursing homes with my parents. Those snot nosed brats can't give basic care eirher.
Oof. Randy indeed! ?
 
then again, the question pointed to the use of the TON, which is somewhat insightful, and useful as it should lead, eventually, to the scan cycle and a (hopefully) light bulb moment.
0abeb900a7f613f9cbb465fb2f46f434.gif
 
then again, the question pointed to the use of the TON, which is somewhat insightful, and useful as it should lead, eventually, to the scan cycle and a (hopefully) light bulb moment.
0abeb900a7f613f9cbb465fb2f46f434.gif

Won't help if his lightbulb isn't tied to the right timer, or is tied to multiple instances of the same time.
 
then again, the question pointed to the use of the TON, which is somewhat insightful, and useful as it should lead, eventually, to the scan cycle and a (hopefully) light bulb moment.
0abeb900a7f613f9cbb465fb2f46f434.gif
I'm with you. When I read this, my thought was, hey, this person at least TRIED. That gives them a leg up on most HW asks. Hopefully they never came back because they had their lightbulb moment, not because they gave up.
 

Similar Topics

Hello everyone, I have a problem with an S7-300 system and would appreciate some help. I have two S7-300 PLCs communicating via Profinet. One for...
1
Replies
211
Views
I was going through the configuration of 1734 - IB8S and OB8S modules of a GuardLogix Safety PLC. I understand the use of Safety Pulse Test in an...
22
Replies
1,880
Views
Hello, I have a question regarding switching off a 24 V DC supply. I want to use one main contactor to disconnect the 24 V DC line and isolate...
4
Replies
666
Views
Would anyone give me feedback? I have a situation where I must switch between 2 different current transformers, 8 in total. The analog module in...
15
Replies
1,615
Views
Hello all, I have a application where we are moving a servo to a position. At the position we are switching to a torque move, after the...
0
Replies
606
Views
Top