UPC EETAC Bachelor's Degree in Telecommunications Systems and Network Engineering EEL

Chapter 3 problems

- D3.14 -

Traffic light controller (µC - C)

Products

D3.13

D3.15


1. Specifications

Design a traffic light controller for the given street intersection in Fig. 1. Let us organise the project in several phases and steps to make it easy to conceive and design. 

The same project designed using hardware is stated in D2.14.

Traffic light system to be implemented

Circuit block

Fig 1. Street intersection to be controlled by our Traffic_light system.

Find information on the internet on the green/yellow/red traffic light sequence currently used in Europe. Or simply observe a real traffic light intersection and deduce its operating sequence. We can imagine the six states shown in Fig. 2. Complete your research by finding typical colour times for four-way intersections according to approach speed, vehicle length, and street width.

The night-mode NM signal may originate from a daylight sensor or, better, an auxiliary clock. When NM = '0' (daytime mode, for instance, from 5:00 to 23:00), the standard traffic light sequence operates continuously. When NM = '1' (night mode), both light poles display intermittent 1 Hz yellow lights, and the vertical pole STOP signs are activated at the intersection. Operators can also use this mode when performing maintenance off-duty. 

Night mode timer

Fig 2. Night mode signal activated from a real-time clock. We can easily model this timed digital signal using a switch.

Draw an example of a timing diagram considering only the control signal NM and a start/stop signal ST_L to switch on and off the application. At this stage, our aim is to generate the colour patterns, thus, let us make it simple considering that at every CLK rising edge detected by interrupt, the colour patter changes. 

As a second step, add car sensors CA and CB to stop the normal traffic light sequence operation when cars are not detected in a given street. The idea is that if no cars are detected in street B, there is no need to stop the cars in avenue A, they can circulate always in green.

Car sensors

Fig 3. Car detection signals from inductive sensors buried in the tarmac and conditioned by retriggerable timers (LAB11). When cars are detected on the crossing, CA or CB pulses with a minimum duration of 2 minutes are generated. We can easily model this detector behaviour by reading/polling switches.

As a third step, add PA and PB push-buttons to allow pedestrians to cross the intersection at any time when the traffic light sequence is locked in a given street because there are no cars in the other.  

Pedestrina push-buttons

Fig 4. Pedestrian push-buttons on the poles. We can model these buttons in the same way as we did for the car sensors. A retriggerable timer generates long pulses of 3 seconds duration, which are thus easily modelled by simple switches. A pedestrian may press the push-button repeatedly while waiting to cross the street, having the effect of a single digital pulse.

NOTE: The aim is to read and study various materials, books, examples, and advanced tutorials, without copying directly from them. Imagine that this project builds upon the LAB10 tutorial, where an FSM-controlled binary counter was organised using interrupts to control state transitions. The better you comprehend the laboratory tutorial, the faster you will design this application.

 

2. Planning phases  and steps

Design phase #1: An FSM to generate the traffic light sequence

Solve the circuit for the design step #1. Only when it is fully tested, working correctly and reported, solve design step #2.

Design Step #1: Implement the basic traffic light sequence, including only the night mode switch NM. and the signal ST_L to switch on and off the application.

Project location:

C:\CSD\P10\Traffic\(files)

Project source files:

"Traffic.pdsprj", "Traffic.c"

 

A) Planning hardware

Copy and adapt a circuit from a convenient tutorial project and name it "Traffic.pdsprj". Assign pins to inputs and outputs accordingly to one of the following options (your instructor will tell you which):

Pin assignment option #1:

AG --> RB7;  AY --> RB3; AR --> RA2

BG --> RC2;  BY --> RC1; BR --> RA3

CA --> RB6;  CB --> RB5

PA --> RA1;  PB --> RC6

CLK --> RB2

NM --> RC5

Pin assignment option #2:

AG --> RB6;  AY --> RB2; AR --> RA0

BG --> RC4;  BY --> RC2; BR --> RA2

CA --> RB7;  CB --> RB3

PA --> RA1;  PB --> RC3

CLK --> RB1

NM --> RC7

Pin assignment option #3:

AG --> RB3;  AY --> RB1; AR --> RA3

BG --> RC7;  BY --> RC6; BR --> RA1

CA --> RB6;  CB --> RB7

PA --> RC2;  PB --> RA2

CLK --> RB0

NM --> RC2

Draw the hardware schematic. Buttons and switches, resistors, inputs, outputs, reset circuit MCLR_L and quartz crystal oscillator of 8 MHz. Explain how to configure inputs and outputs in init_system().

 

B) Planning software

Draw the flowchart of the general program organisation.

Draw and explain the hardware-software diagram. List all the required RAM variables and explain the difference between variables to store read/poll values and flag variables for interrupts.

Infer the state diagram governing the machine.

State diagram

Fig 5. Initial state diagram to control the traffic light sequence. 

Explain how to poll (read) the NM signal and the other sensors (car and pedestrian) in read_inputs() using bitwise operations. Explain how to measure how many times per second these switches are read.

Explain how to drive output pins in write_outputs().

Explain the external interrupt mechanism for connecting the CLK that is governing the FSM. Add a start/stop control pushbutton ST_L to another interrupt pin. Explain how the ISR() is used.

Draw the state_logic() truth table and its equivalent flowchart ready for translation to C language.

Draw the output_logic() truth table and its equivalent flowchart ready for translation to C language.

 

Developing & testing (debugging)

Develop and test (debug) the project capturing the hardware circuit in Proteus and writing the C source code.

Note: Step-by-step tactical approach for developing and testing the project: Read one input at a time and run to check that the voltage value is correctly captured as a valid digital value in RAM memory. Write one output at a time and run to check that your code is correct to light the LED connected at the output pin.

 

 


Design Step #2 (optional): Add vehicle sensors (CA and CB) to interrupt the normal traffic-light sequence when no vehicles are detected on a given street. If no vehicles are detected on Street B, there is no need to stop traffic on Avenue A; therefore, traffic on Avenue A may continue to proceed under a green signal. Vehicle sensors are typically embedded beneath the pavement near the intersection.

 


Design Step #3 (optional): Add PA and PB push-buttons to allow pedestrians to cross the intersection at any time when the traffic light sequence is locked in a given street because there are no cars in the other.  

 


Design phase #2: an LCD will indicate ASCII messages and numbers.

Explain how to connect and program the LCD display to show ASCII messages such: "Street B GREEN", "Night operation", etc. on the screen. 

Project location:

C:\CSD\P11\Traffic_LCD\(files)

Project source files:

"Traffic_LCD.pdsprj", "Traffic_LCD.c"

 


Design phase #3: using internal peripheral TMR2. Real-time programmable timer to adjust red/yellow/green light times

Configure and program TMR2 to replace the external CLK oscillator. Explain whether new states are required to drive the TMR2.

To make commercial equipment, we must complete the traffic light by adjusting the time for each colour code.

Option #1: Green_B: 70 s; Yellow_B: 5 s; Red_BA or Red_AB: 1.5 s; Green_A = 80 s; Yellow_A:  6 s

Option #2: Green_B: 60 s; Yellow_B: 4 s; Red_BA or Red_AB: 1.2 s; Green_A = 70 s; Yellow_A:  5 s

Option #3: Green_B: 90 s; Yellow_B: 5.6 s; Red_BA or Red_AB: 1.4 s; Green_A = 100 s; Yellow_A:  7.5 s

 

Project location:

C:\CSD\P12\Traffic_LCD_TMR2\(files)

Project source files:

"Traffic_LCD_TMR2.pdsprj", "Traffic_LCD_TMR2.c"

 

Optional: Add a sound wave for visually impaired people when the traffic light is GREEN.

 


Optional: Other additional features:

Add a transmission system able to report the current state of the traffic light controller to a remote computer and to accept commands such start/stop or night-mode from a central system (full duplex communication).

Discuss how to add at the street intersection a car speed measurement system with speed limit indicators and numeric displays signs.

Display a number indicating the down count of the time left before RED in street B and avenue A. .