# How to wire up a street light to change lights in specific states (digital circuit)

This is the final project for the only electronics course in my career. I have never taken any other electronics course and I'm seriously at a lost here. I need to score 100 here to pass the course.

I need to create a synchronous counter that will control a streetlight with 4 sides. The South-North side has 4 lights (an extra green one to steer left) while every other has 3.

The cycle lasts 14 seconds.

I have the counter made, but I have no idea how to actually make it turn on/off the lights at the specified times.

Problem instructions are as follow:

"The first green light of S-N and the one from N-S must light up for 5 seconds,
meanwhile, the red lights from E-W and W-E must be on as well.

After these 5 seconds, the yellow lights for both S-N and N-S turn on for 2 seconds.

After this, the red lights for S-N and N-S turn on
and the 2nd green light of S-N will turn on for 2 seconds to allow traffic coming from the south to steer to the west.
This is the only instance where 2 lights of the same side are lit up simultaneously.

While the 2nd green light from S-N is on, every other Red light must be on as well.

After the 2nd green light from S-N turns down, the red light of S-N and N-S will stay on, and the green lights of W-E and E-W will turn on for 3 seconds.

After these 3 seconds, the yellow lights will turn on (while the green ones will turn off) for 2 seconds

and then the red ones will turn on, starting the cycle anew.

Total duration is 14 seconds". This is SERIOUSLY driving me crazy because I see no way in which I could say "From 1 to 5 stay ON and then turn OFF", I cannot think of a single way of setting up logic gates so that they're only outputting 1 to the lights when they're 0001, 0010, 0011, 0100 and 0101. Because if I make logic to output 1 when you have that, then literally every other binary code except from 0 and 15 will output one. I.e the lights will never turn off.

Note that this is entirely digital, using Digital Works. The solution cannot have any component that is not included in the program and should, in fact, only include Flip flops, LEDs, logic gates and of course the wires.

EDIT: Thank you for your help and tips. I managed to do it. For reference, here is the completed and working circuit: • are you talking about a street light which is used for illumination, or are you taking about a traffic light which is used to regulate the flow of vehicles and pedestrians? Nov 29, 2019 at 3:07
• Start with an accurate spec for the state diagram and use FF's as shift register values with Gates to match those states to consider running your sequence. Here is a crude E-W scenario tinyurl.com/vc8evvn Nov 29, 2019 at 3:12
• do not think From 1 to 5 stay ON and then turn OFF ... instead think at 1 turn ON ... at 6 turn OFF and use J-K FF to latch the outputs Nov 29, 2019 at 3:13
• Drawing a state diagram is also a good start.
– user103380
Nov 29, 2019 at 3:28
• @jsotola Traffic light. And the problem I have with that method is that I don't have a way of combining multiple lights. If I set up gates for the W-E red and S- N green lights so that its output is 1 at every state except 5, they will turn on again at 6 and that shouldn't happen, at 6 all of those should be off and only the yellows should be on. Nov 29, 2019 at 3:42

There are lots of ways to take this. You could go asynchronous or synchronous, for example. But I'll suggest a start using a synchronous counter. You need a modulo 14 counter. For that, I might suggest a modulo 7 LFSR (not the only way to go) with a separate FF that toggles to make a total of 14 states: simulate this circuit – Schematic created using CircuitLab

The codes, in sequence, are: 0000, 0111, 0100, 1101, 1000, 0011, 1110, 0001, 0110, 0101, 1100, 1001, 0010, and 1111. (The missing codes are 1010 and 1011.) This provides 14 distinct states. You can then use these, with added logic, to generate your light controls. (Note that in the above diagram, not only do you have access to each bit but also access to the inverted state of each bit. Also, if these DFFs have both Q and /Q, then the above diagram can be simplified a bit.)

By the way, you only have 7 distinct light control wires. You need three for the east-west and west-east directions (all of which use the same controls for red, yellow, and green lights), plus three more for the shared north-south and south-north directions (again, all of which use the same controls for the red, yellow, and green lights), and one more control line for the special south-north special-green light.

This is not necessarily the best way to handle it. It may require some combinatorial logic that you may wish were smaller. But it certainly can work.

(Note that the CLK input should be driven with a $$\1\:\text{s}\$$ clock rate.)

Do you know how to lay out the combinatorial logic needed for your control lines to the lights? Is that the problem?

I've quickly laid out what I think may work, regarding K-maps for the above states. However, be aware that I may make mistakes. So check the following work for yourself. (In what follows, 0 means off and 1 means on.)

East-West and West-East K-maps:

$$\begin{array}{rl} \begin{smallmatrix}\begin{array}{r|cccc} Red&\overline{Q_B}\:\overline{Q_A}&\overline{Q_B}\: Q_A&Q_B \:Q_A&Q_B \:\overline{Q_A}\\ \hline \overline{Q_D}\:\overline{Q_C}&1&1&1&0\\ \overline{Q_D}\:Q_C&1&0&1&1\\ Q_D\: Q_C&0&1&0&1\\ Q_D\:\overline{Q_C}&1&0&x&x \end{array}\end{smallmatrix} & \begin{smallmatrix}\begin{array}{r|cccc} Yellow&\overline{Q_B}\:\overline{Q_A}&\overline{Q_B}\: Q_A&Q_B \:Q_A&Q_B \:\overline{Q_A}\\ \hline \overline{Q_D}\:\overline{Q_C}&0&0&0&1\\ \overline{Q_D}\:Q_C&0&0&0&0\\ Q_D\: Q_C&0&0&1&0\\ Q_D\:\overline{Q_C}&0&0&x&x \end{array}\end{smallmatrix}\\\\ \begin{smallmatrix}\begin{array}{r|cccc} Green&\overline{Q_B}\:\overline{Q_A}&\overline{Q_B}\: Q_A&Q_B \:Q_A&Q_B \:\overline{Q_A}\\ \hline \overline{Q_D}\:\overline{Q_C}&0&0&0&0\\ \overline{Q_D}\:Q_C&0&1&0&0\\ Q_D\: Q_C&1&0&0&0\\ Q_D\:\overline{Q_C}&0&1&x&x \end{array}\end{smallmatrix} \end{array}$$

North-South and South-North K-maps:

$$\begin{array}{rl} \begin{smallmatrix}\begin{array}{r|cccc} Red&\overline{Q_B}\:\overline{Q_A}&\overline{Q_B}\: Q_A&Q_B \:Q_A&Q_B \:\overline{Q_A}\\ \hline \overline{Q_D}\:\overline{Q_C}&0&1&0&1\\ \overline{Q_D}\:Q_C&0&1&0&1\\ Q_D\: Q_C&1&0&1&0\\ Q_D\:\overline{Q_C}&0&1&x&x \end{array}\end{smallmatrix} & \begin{smallmatrix}\begin{array}{r|cccc} Yellow&\overline{Q_B}\:\overline{Q_A}&\overline{Q_B}\: Q_A&Q_B \:Q_A&Q_B \:\overline{Q_A}\\ \hline \overline{Q_D}\:\overline{Q_C}&0&0&1&0\\ \overline{Q_D}\:Q_C&0&0&0&0\\ Q_D\: Q_C&0&0&0&1\\ Q_D\:\overline{Q_C}&0&0&x&x \end{array}\end{smallmatrix}\\\\ \begin{smallmatrix}\begin{array}{r|cccc} Green&\overline{Q_B}\:\overline{Q_A}&\overline{Q_B}\: Q_A&Q_B \:Q_A&Q_B \:\overline{Q_A}\\ \hline \overline{Q_D}\:\overline{Q_C}&1&0&0&0\\ \overline{Q_D}\:Q_C&1&0&1&0\\ Q_D\: Q_C&0&1&0&0\\ Q_D\:\overline{Q_C}&1&0&x&x \end{array}\end{smallmatrix} \end{array}$$

Special-Green South-North K-map:

$$\begin{array}{rl} \begin{smallmatrix}\begin{array}{r|cccc} Green&\overline{Q_B}\:\overline{Q_A}&\overline{Q_B}\: Q_A&Q_B \:Q_A&Q_B \:\overline{Q_A}\\ \hline \overline{Q_D}\:\overline{Q_C}&0&1&0&0\\ \overline{Q_D}\:Q_C&0&0&0&1\\ Q_D\: Q_C&0&0&0&0\\ Q_D\:\overline{Q_C}&0&0&x&x \end{array}\end{smallmatrix} \end{array}$$

I've included a possible solution below. It's validated, so it works. The point isn't to provide you with a direct answer, but is instead intended merely to let you know what one possible solution might look like.

You appeared to complain about the ability to hold the lights for given times (5 seconds, or 3 seconds, etc.) This shows exactly how that can be achieved.

I didn't attempt to optimize the design (I'm sure that more could be done.) But I simply took the above K-maps and developed what amounts to a CPLD or (AND-OR) matrix solution for the combinatorial logic. The clock is intended to have a one second cycle time. Here is the lighting results from the above schematic: Everything prefixed with NS applies to both the north-to-south direction as well as the south-to-north direction. The light prefixed with SN only applies to the south-to-north direction. The rest, prefixed with EW applies to both the east-to-west as well as the west-to-east directions.

• Which software was used to create k-map ? Nov 29, 2019 at 10:57
• @Mitu Just mathjax which is available standard when creating an answer here. Nothing else. Notepad was used to list the conditions and states and I hand-sorted them in Gray coded format before filling out the tables.
– jonk
Nov 29, 2019 at 11:01
• I'm not having much luck simulating that circuit. is this only achievable with D flip flops? Is my whole setup with JK wrong? Also, you say that I only have 7 distinct light control wires, but then proceed to count 7 distinct wires as well (3 for each normal light in SN/NS, 3 for WE/EW and 1 for the 4th light in SN = 7 distinct light controls.) so that part confused me a bit. Nov 29, 2019 at 17:28
• And yeah, the problem was about how to setup the logic. I knew that I could decode binary signals with my counter, but my problem is, for example. I set up a NAND gate to decode 6, so that the Green and red lights turn off when the counter hits 6 (so they stay for 1-5), but then, I need them to stay OFF, instead, they light up again until it hits 6 once more. Nov 29, 2019 at 17:28
• @Dasphillipbrau Well, first off I decided to use a different counter (an LFSR with mod-7 with an added FF to double the cycle period.) But it doesn't matter how you get the period. So there are a number of other choices there. Just whatever suits at the time, I think. Regarding the distinct light control wires, it's my understanding (and I can be wrong) that you only have 7 different functions. When the east-west red is on, so is the west-east red. So although that's two lights, it's only one control wire. That's how I was thinking about this.
– jonk
Nov 29, 2019 at 19:49