# Traffic light controller and delay timer

#### spudda123

Joined Apr 19, 2021
15
I'm firstly struggling on how to draw a moore machine for a 2-way traffic light system which goes red-amber-green on both the main street and side street. I think I need 8 states and 3 inputs for this? It is for a uni project so I can attach the brief or lab sheets if more detail is needed

#### AnalogKid

Joined Aug 1, 2013
10,553
More detail is needed.

ak

#### Irving

Joined Jan 30, 2016
3,496
A Moore machine is a finite state automaton whose next state is determined entirely by the current state without external input.

So that begs the question firstly why you consider you need three inputs**?

Secondly, each street goes through a fixed light sequence. In the UK that would be:
RED
RED-AMBER
GREEN
AMBER
then back to RED - so 4 states, but your sequence might differ.

Now, what's your thinking so far?

**Edit: it seems a Moore machine can have 'internal' inputs, transitional triggers such as time delays.

Last edited:

#### spudda123

Joined Apr 19, 2021
15
More detail is needed.

ak
This is a photo of the brief and a lab we got given to do relating to the work

#### Attachments

• 143.7 KB Views: 12
• 692 KB Views: 12

#### spudda123

Joined Apr 19, 2021
15
A Moore machine is a finite state automaton whose next state is determined entirely by the current state without external input.

So that begs the question firstly why you consider you need three inputs**?

Secondly, each street goes through a fixed light sequence. In the UK that would be:
RED
RED-AMBER
GREEN
AMBER
then back to RED - so 4 states, but your sequence might differ.

Now, what's your thinking so far?

**Edit: it seems a Moore machine can have 'internal' inputs, transitional triggers such as time delays.
This is a photo of the brief I was given, it shows the 8 states they’re looking for I assume as it’s a 2-way system. I’m just not sure what the input(s) would be and where to go after drawing the 8 circles and linking them Together

#### Attachments

• 692 KB Views: 6

#### Irving

Joined Jan 30, 2016
3,496
So show your state diagram so far, and what you think the 3 inputs are..

The clues are in the brief, remembering 'inputs'are triggers for state transitions.

#### spudda123

Joined Apr 19, 2021
15
So show your state diagram so far, and what you think the 3 inputs are..

The clues are in the brief, remembering 'inputs'are triggers for state transitions.
So this is what I’ve come up with so far, I’ve taken it down to 2 inputs

#### Attachments

• 1.6 MB Views: 10

#### Irving

Joined Jan 30, 2016
3,496
OK, that's one approach. Can you think of an alternative map?

In either case, how will you handle the other key inputs in the brief? Can you see what they are?

#### spudda123

Joined Apr 19, 2021
15
OK, that's one approach. Can you think of an alternative map?

In either case, how will you handle the other key inputs in the brief? Can you see what they are?
The only other way I can think is input 1- E-W on for 4s, input 2- button pressed E-W (N-S on for 8+s)

#### spudda123

Joined Apr 19, 2021
15
The only other way I can think is input 1- E-W on for 4s, input 2- button pressed E-W (N-S on for 8+s)
And input3- no cars E-W

#### spudda123

Joined Apr 19, 2021
15
And input3- no cars E-W
This is how I would change the diagram for those inputs

#### Attachments

• 1.3 MB Views: 10

#### Irving

Joined Jan 30, 2016
3,496
OK, I see in the brief they've forced you to follow 8 sequential states. An alternative approach would be to consider the state machine for each street in isolation, and then cross-linking the two state machines. that would be more flexible (eg if, later, you wanted to add a pedestrian crossing button on each street corner as well).

As I read it, the priority on the main street implies it sits on state 0 (G-R) until triggered by the arrival of a car on the side street(s) but the state doesn't change until main street has been in the G-R for at least 8 seconds. So you need to add the timing transitions. Apart from the state machine have you created a state transition chart?

Have you read the bit about timing of state transitions and the Mealy machine (which isn't in the notes you've shown us)? How does that integrate with your state machine?

#### spudda123

Joined Apr 19, 2021
15
OK, I see in the brief they've forced you to follow 8 sequential states. An alternative approach would be to consider the state machine for each street in isolation, and then cross-linking the two state machines. that would be more flexible (eg if, later, you wanted to add a pedestrian crossing button on each street corner as well).

As I read it, the priority on the main street implies it sits on state 0 (G-R) until triggered by the arrival of a car on the side street(s) but the state doesn't change until main street has been in the G-R for at least 8 seconds. So you need to add the timing transitions. Apart from the state machine have you created a state transition chart?

Have you read the bit about timing of state transitions and the Mealy machine (which isn't in the notes you've shown us)? How does that integrate with your state machine?
I'm currently just working on the traffic light controller then moving on to the mealey machine for the delay-timer. I have done a state transition table which I will attach.

#### Attachments

• 12.3 KB Views: 8

#### Irving

Joined Jan 30, 2016
3,496
I think you're pretty much there. Your state transition input Y and Z, what do they represent and does that match the brief? Also, while not considering the Mealey machine completely you do need to factor its ouputs as inputs alongside Y and Z, rather than hanging them on the end.

#### spudda123

Joined Apr 19, 2021
15
I think you're pretty much there. Your state transition input Y and Z, what do they represent and does that match the brief? Also, while not considering the Mealey machine completely you do need to factor its ouputs as inputs alongside Y and Z, rather than hanging them on the end.
For that I just did Y- cars waiting and Z- cars through. And as for the timings, shall I just transfer the columns next to Y and Z then so they’re together? Thanks for your help btw it’s cleared a few things up for me

#### Irving

Joined Jan 30, 2016
3,496
Ok, I get where you're coming from with Y and Z though I'm not yet 100% convinced that meets the brief, but if you're comfortable with it...

Finish the table and integrate the Mealey machine and let's review that

BTW I do a very similar exercise with my Arduino programming tutorial for my MSc students, though we do a simplified approach to state machines (they don't do the math just the hi-level concept). We include pedestrians crossing with red/green man and visual/audio countdown as an add-on requirement... Its a nice example of how a state machine can simplify what otherwise is a daunting bit of programming.

Last edited:

#### spudda123

Joined Apr 19, 2021
15
Ok, I get where you're coming from with Y and Z though I'm not yet 100% convinced that meets the brief, but if you're comfortable with it...

Finish the table and integrate the Mealey machine and let's review that

BTW I do a very similar exercise with my Arduino programming tutorial for my MSc students, though we do a simplified approach to state machines (they don't do the math just the hi-level concept). We include pedestrians crossing with red/green man and visual/audio countdown as an add-on requirement... Its a nice example of how a state machine can simplify what otherwise is a daunting bit of programming.
I'm currently working on the Moore machine for the TLC rather than a Mealey which it asks for for the delay-timer in the next part. Not sure if that changes things regarding moving the timing columns? Also, I've moved the reset to the S0 rather than S4. (I made the table a while ago, hence why I'm confused now I've come back to it as I've kinda forgotten what I did). I've attached an updated Moore machine (I wasn't sure if adding the X's instead of having multiple transition lines was correct so I just underlined them alongside rather than change the whole thing for it to be wrong to use the X's).

#### Attachments

• 819.9 KB Views: 4

#### Irving

Joined Jan 30, 2016
3,496
They are only 'don't care' because you don't have the timing detail in there.

#### cg5939

Joined Apr 29, 2021
6
spudda I have a very similar project, where did you get up to in the end with your moore machine state diagram and state table?