Light Controller

jpanhalt

Joined Jan 18, 2008
11,087
The reason for not replying in thread is that I was looking for a simple example, which I can convert to state diagram. A complete example of the traffic signal was difficult for me.

I have tried my best to create a state diagram of a simple traffic light system. I am not able to create a basic state diagram for traffic light system. So creating a state diagram for a complete traffic control system will be difficult.
Come on. A simple example is on Wikipedia, "State Diagram." https://en.wikipedia.org/wiki/State_diagram

When you call it a " traffic light system" that implies more than one 3-light device. I and others have asked you to define what you mean, but have gotten no response.
 

WBahn

Joined Mar 31, 2012
30,082
You don't need a realistic example of a traffic light, you just need a well-defined problem. You have largely provided that.

Problem: Design the control logic that cycles a set of three lights in the following way:

1) Red light will be on for 60 seconds
2) Green light will be on for 40 seconds
3) Yellow light will be on for 20 seconds

Implied, but not actually stated, is that only one light will be on at a time.

One thing that is not addressed, but that you tried to deal with anyway, is initial conditions. Generally you don't have to worry about what happens when there is no power to the system because there isn't much it can do besides sit there and look stupid. But once power is applied, what should happen? That gets into issues such as power-on-reset and power-up sequencing that are a bit beyond where you are right now. Two ways to deal with it that are at your level is to have a reset signal that, when asserted, takes the system to a defined state, or to just let the machine power up in any random state and ensure that it behaves properly from that point on. Either approach is reasonable for a made up problem like this, so you just need to decide which it is.

Since it appears that working with a separate counter is a bridge too far right now, let's forget that. Your machine will be a straight-up finite state machine using a clock that has a 20 second period. As such, all the machine knows is what state it is in right now and that one piece of information has to tell you everything about the system that you need to know in order to determine what action should be taken at the next rising clock edge.

So describe the different possibilities as assign a state designation to them:

Here are some examples:

State G: The red light is currently on and has been on for at least than 20 seconds but less than 40 seconds.
State M: The yellow light is currently on and has been on for at least 0 seconds but less than 20 seconds.

Can you describe all of the necessary states in this way?
 

jpanhalt

Joined Jan 18, 2008
11,087
You don't need a realistic example of a traffic light, you just need a well-defined problem. You have largely provided that.

Problem: Design the control logic that cycles a set of three lights in the following way:

1) Red light will be on for 60 seconds
2) Green light will be on for 40 seconds
3) Yellow light will be on for 20 seconds

Implied, but not actually stated, is that only one light will be on at a time.
What is the purpose of that, if the signal is on a vacant road with no cross traffic in the middle of the Mojave? The ONLY time I have seen a traffic signal as you describe without cross traffic is when it is in parallel with a highway and used for flow control.

Is there some situation where it would make sense on a road with no cross traffic? (Excepting a prank I and two friends did in 1961. ;) )
 

jpanhalt

Joined Jan 18, 2008
11,087
Come on....
1597006228734.png

Why isn't that 3 states? I hate to say it, but this thread is exceedingly non-productive as you seem to ignore helper suggestion. What is your purpose?

Is it related to your final year project using the STM32F407 microcontroller?
 

Thread Starter

Djsarakar

Joined Jul 26, 2020
489
Why isn't that 3 states? I hate to say it, but this thread is exceedingly non-productive as you seem to ignore helper suggestion. What is your purpose?
My aim is to learn how to create a state diagram for a any problem. That I have clearly shown in the first line of my first post. I could have taken a lot of examples to create a state diagram but I thought the traffic light system would be easier to create a state diagram. So I took example

Is it related to your final year project using the STM32F407 microcontroller?
No, it has nothing to do with final year projects. Many experience people have the suggestion that a flowchart or state diagram should be used to solve the problem. They are better tools when we are designing a project.. So I was learning how to create a state diagram.

I don't want to waste peoples time I'll be back on the thread until I get enough knowledge about state diagram
 

jpanhalt

Joined Jan 18, 2008
11,087
No, it has nothing to do with final year projects. Many experience people have the suggestion that a flowchart or state diagram should be used to solve the problem. They are better tools when we are designing a project.. So I was learning how to create a state diagram.

I don't want to waste peoples time I'll be back on the thread until I get enough knowledge about state diagram
Then why not ask a question related to finishing the course? Why ask questions about how much time a PIC12F1840 takes when you won't be using anything remotely similar? Don't you want to graduate?
 

WBahn

Joined Mar 31, 2012
30,082
What is the purpose of that, if the signal is on a vacant road with no cross traffic in the middle of the Mojave? The ONLY time I have seen a traffic signal as you describe without cross traffic is when it is in parallel with a highway and used for flow control.

Is there some situation where it would make sense on a road with no cross traffic? (Excepting a prank I and two friends did in 1961. ;) )
Forget about traffic lights! The TS is merely trying to learn how to use a state diagram to solve a simple sequential design problem. He is not trying to design an actual traffic light. Notice that in the problem definition I provided I did not use the notion of a traffic light at all. I merely said that there were three lights that were to be cycled in the manner that the TS proposed in their original post.
 

Wendy

Joined Mar 24, 2008
23,429
Nope, not Rittish, IP is British. Hey, it rhymes!

To the TS, Rittish is an annoying person who was banned but keeps coming back.
 

WBahn

Joined Mar 31, 2012
30,082
My table and state diagram are as follows

View attachment 214379
What does it mean for an arrow that has "T=40" next to it?

What does it mean for an arrow that has nothing next to it?

By convention, an arrow with nothing next to it means that this path is ALWAYS taken, while an arrow with something next to it means that that path is taken ONLY when the conditions stated are TRUE.

Describe, in words, precisely what it means if you are in state "G-on-40". Remember, after entering this state, there is going to be another clock rising edge in 20 seconds. What state does the system go to when that clock happens? If it stays in "G-on-40", then what does it do at the next clock rising edge? If it is then supposed to go to "Y-on-20", how is this supposed to happen? How can it do something different, from the same state, on this clock edge than it did on the last clock edge?

Remember, the system knows ONLY what state it is currently in and what the value of any inputs happen to be at the time of the clock edge. It must make its decision about what state to go to based ONLY on that information.
 

Thread Starter

Djsarakar

Joined Jul 26, 2020
489
@WBahn @jpanhalt

There are three LED lights, Red, Green Yellow

Step 1: I want RED LED to turn on 100ms then turn off.

Step 2: After that, I want Green LED to turn on 300 ms , then turn off.

Step 3: Finally, I want Yellow to turn on 500ms then turn off.

I want to repeat steps 1 through 3 until I turn off the power.

I have created a flow diagram and state diagram for the LED controller instead of the traffic light system.

I have tested state diagram myself I hope the diagram is completely correct

IMG_20200811_171516.jpg
 
Last edited:
Top