Вы находитесь на странице: 1из 7

MCO556

Traffic Lights Project Requirements


General
The project consists of creating code to control a set of traffic lights. The basic light function has the
normal red, green, yellow sequences with the addition of 4-way red and a left turn sequences. There
also is a pedestrian walk signal.
The lights also can be configured remotely via the SCI serial port. The green duration can be modified.
Associated with the traffic lights are traffic counters for each direction, a temperature sensor and left
turn sensors. The temperature sensor is used to control the duration flashing pedestrian walk signal.
The traffic counts are sent to the remote site 15 seconds. The left turn sensors control the operation of
the left turn sequence.
The project may be completed singly or in teams of two students. If a student has NOT achieved more
than 45 out of a possible 70 marks by the end of study week, the student will NOT be given the opportunity
to partner with another student. During the demonstration, you will be individually asked questions
regarding your code. If you are unable to explain the function of the code, marks will be deducted.
Submission requirements
demonstration of software operation
project archive submitted via the Traffic Lights Assignments in MySeneca
completed and signed Project Honesty Declaration form.
Projects without the completed and signed Project Honesty Declaration form will NOT be accepted.
Evaluation
This project will be worth 40% of your final grade.
You will receive marks for:
Proper functionality according to the following specifications
a programmers block in the source files
The code must be fully documented
o every significant line must have a comment
o meaningful variable and function names
o short function descriptions
Proper indenting and program structure
You will lose marks if the amount of aid required from the instructor is unreasonable. Unreasonable
means that obvious actions to determine the problem were not implemented before asking for aid.
Think of this as if it were a job situation where you wanted to avoid calling in an expensive consultant to
troubleshoot your problem.
You will lose marks, if you are unable to explain the function of the code.
Co-operation
You can help another student, but you MAY NOT directly or indirectly give your code to a fellow student
you are helping. You may discuss the concepts, but you MAY NOT write or dictate verbally the code to
another student - if it is apparent that a student (or team) has copied from another student (or
team) then both students (or teams) will receive a mark of 0.

-1
Seneca College School of Information and Communications Technology

G VandeBelt 151

MCO556
Traffic Lights Project Requirements
Intelligent Traffic Light Control Using Micro controller
North/South
Traffic Light
LEDG0
LEDG1

Walk Request Keypad

1 2 3 A
4 5 6 B
7 8 9 C
0 # D

LEDG2

G
LEDG3

L
Left Turn
Sensor to
SW0

East/West
Traffic Light

Traffic Sensor
to PORTD 0
(TP15)

LEDG7
LEDG6

LEDG5

Traffic Sensor
to PORTD 1
(TP16)

Walk Signals on LCD

-5oC

N-S
Walk
E-W

Analog Input 0 (TP8)


= Ambient Temperature

Dont Walk

-2
Seneca College School of Information and Communications Technology

G VandeBelt 151

MCO556
Traffic Lights Project Requirements
Shown above is a traffic light intersection. Write a program for the DE1 board that will control the above traffic
lights. The Input and Output connections are shown above. Specifications are as follows:
1. Time between North/South Green Light or Left Turn to Yellow Light transitions will initially be 15 seconds
but can be changed by a value sent from the PC (running a Visual C# program provided to you). The
value sent from the PC will be between 15 and 25 seconds.
2. Time between East/West Green Light to Yellow Light transitions will initially be 10 seconds but can be
changed by a second value sent from the PC. The value sent from the PC will be between 10 and 20
seconds.
3. The time between all Yellow Light to Red Light transitions is 3.
4. There is a 4-way Red condition after all Yellow Light to Red Light transitions. The 4-way Red condition is
always 2 seconds.
5. The traffic lights also have a left turn sequence for the North/South direction which occurs between the
red to green transition. The left turn sequence can be controlled for the North/South direction. There is
no left turn for the East/West Direction. The left turn duration is 4 seconds. In the left turn sequence, both
the red and left turn signals are illuminated.
6. The left turn sequence occurs whenever a car is detected in the left hand turn lane. The left turn car
sensor is connected SW0 (slide switches) for the North/South direction. The slide switch set to ON
indicates a car is present. The left turn signal will reduce the North/South green duration by 4 seconds.
If no car is present, the left turn sequence is skipped and the North/South green duration is unchanged.
7. The keypad will be used for pedestrian requests for a Walk signal in the East/West direction. Pressing
keys 5 8 will represent a Walk request in the East/West direction. If a Walk request has been detected,
the Walk signal for the pedestrian walk will be ON for first part of the Green Light. For the last part of the
Green Light, the Dont Walk signal will flash at 1 Hz (0.5 sec ON, 0.5 sec OFF). The duration of flashing
is 3 or 5 seconds depending on the ambient temperature. Any Walk requests for a specific direction will
be ignored while the Walk is illuminated for that direction.
8. No walk request is required for the North/South direction (ie. a walk request is always assumed to be
present). The left turn sequence is a Dont Walk condition.
9. The Walk signals will be displayed on the LCD display. Lines 1 and 2 of the display will be used for the
North/South direction and lines 3 and 4 will be used for the East/West direction. For the Walk condition,
the word WALK will be display. During flashing Walk condition, Dont Walk will flash on for 0.5 sec
and blank for 0.5 sec. The duration of flashing is 3 or 5 seconds depending on the ambient temperature.
For all other conditions, the words Dont Walk must be displayed.
10. Analog input 1 (TP8) measures ambient temperature. If the temperature is below 0 degrees C then the
flashing Dont Walk signal duration is increased from 3 to 5 seconds when the temperature is below 0
degrees C. The +/- 5 VDC input to the interface board corresponds to -30 to + 45 degrees C. Remember
that the interface board converts +/- 5 VDC to 0 to 2.5 VDC which is read by the microcontroller as 0 to
4095 counts. Therefore -5VDC = 0 counts = -30 DEG and +5VDC = 4096 counts = +45 DEG. The ADC
should be read once per second. In addition, the temperature must be displayed in the upper right corner
o
o
of the LCD display. The format of the display must be dd C for positive temperature and -dd C for
negative temperatures. The ASCII value for the degree symbol is 0xDF.
11. Traffic sensors are buried in the pavement to count traffic. One pulse is generated for each vehicle as it
passes. Every 15 seconds the accumulated count for each direction must be transmitted to the PC.
These sensors are connected to the PORT D inputs and should generate an interrupt for each vehicle
(i.e. on each pulse)
-3
Seneca College School of Information and Communications Technology

G VandeBelt 151

MCO556
Traffic Lights Project Requirements
Light Cycles
The following diagram shows one cycle of the traffic signals. The cycle has no left turn but includes an East/West
walk. The duration of the cycle is:
Cycle Time = 4 Red + NS green + Yellow + 4 Red + EW green + Yellow
The duration of the Walk signal is the Green time minus the Dont Walk flashing time.
Light Cycle with No left turn and E/W walk

The next diagram shows one cycle of the traffic signals with a left turn and East/West walk. The duration of the
cycle is unchanged by the Left turn, but the actual NS green time is reduce by the left turn duration. Similarly the
NS Walk duration is reduced. The actual NS green time is:
NSL green = NS green - Left
Light Cycle with Left turn and E/W walk

The duration of the North/South Walk time is controlled by the NS green time, Left turn time, and the Dont Walk
flashing time and is given by:
NS walk = NS green - Left - flash
Note:
The East/West direction is always Red when the North/south direction is Left, Green, or Yellow and the
North/South direction is always Red when the East/West direction is Green or Yellow

-4
Seneca College School of Information and Communications Technology

G VandeBelt 151

MCO556
Traffic Lights Project Requirements
Serial Communications Protocol
Communication will be 2400 b/s, 8 data bits, no parity, 1 stop bit.
Message Sent from PC to Microcontroller
STX
North/South Delay (sec)
2
MS Digit
LS Digit

East/West Delay (sec)


MS Digit
LS Digit

ETX
3

Protocol Requirements
1. The serial receive interrupt must be used to detect data sent from the PC.
2. The microcontroller must respond to the above message (if it is valid) by sending the ACK character
(ASCII code 6) to the PC. If the message is valid update both delay times.
3. To determine if the message is valid check:
that 6 characters have been received
that the first character is STX and the last character is ETX.
the N/S time is 15 to 25 s and the E/W time is 10 to 20 s
4. If the message is not valid then reply with the NAK character (ASCII code 21) and ignore the values
received.
ASCII to Integer Conversion
The data will be sent as ASCII characters and you will have to convert these characters to integers to use them in
your program. The library function atoi (in stdlib.h) will convert a NULL terminated string to an integer. For
example:
int value;
// The array below might represent the data sent from the PC
unsigned char buffer[6] = {2, 1, 4, 2, 2, 3};
unsigned char temp[3];
// Copy one of the ASCII numbers and NULL terminate
temp[0] = buffer[1];
temp[1] = buffer[2];
temp[3] = 0;
// Convert to an integer value will be equal to 14
value = atoi(temp);
Message Sent from Microcontroller to PC
STX
North/South Count
East/West Count
2
MS Digit
LS Digit
MS Digit
LS Digit

ETX
3

Protocol Requirements
1. The two accumulated counts must be sent once every 15 seconds and then reset to zero
2. The PC will not acknowledge the message
Integer to ASCII Conversion
The data will be sent as ASCII characters and you will have to convert the integer counts to ASCII characters to
transmit them. The function below will convert an integer to a NULL terminated ASCII string.
//The following function will convert n to a 2 byte ASCII string in buf[]
void btoa (unsigned char n, char buf[])
{
char idx;
for (idx = 1; idx >= 0; idx--) {
buf[idx] = (n % 10) + 0;
n = n/10;
}
buf[2] = \0;
}
-5
Seneca College School of Information and Communications Technology

G VandeBelt 151

MCO556
Traffic Lights Project Requirements
Temperature Display
The ADC code is an unsigned integer with a range of 0 to 4096. This must be converted to a signed char or
o
integer with a range of -30 to 45 C. This can be done in multiple steps:
1) convert the code to unsigned integer with a range of 0 to 75 making sure to handle rounding.
2) convert the unsigned integer to a signed integer
3) convert the signed integer to a range of -30 to 45.
4) convert result to an ASCII string using _itoa.

Interrupts
1. Use a timer interrupt(s) to generate the timing required for changing states, flashing, sending data to the
PC, and reading the ADC
2. Use a timer interrupt for the keypad driver
3. Use a timer interrupt for the LCD driver
4. Use the serial receive interrupt to receive data from the PC
5. Use the input capture interrupts to count traffic
6. SCI transmission must NOT be done in the ISR (dont call the SCI function from an ISR).
7. Do NOT call LCD functions from both ISR and non-ISR functions.

State Machines
The traffic light controller must be implemented as a state machine i.e. the controller is always in one of several
defined states. For the traffic light controller these states are:

NORTH/SOUTH LIGHTS
State
North/South
Left
North/South
Walk
North/South
Flash
North/South
Yellow
Four Way
Red N
East/West
Green
East/West
Walk
East/West
Flash
East/West
Yellow
Four Way
Red E

Red

Yellow

Green

Left

ON

OFF

OFF

ON

OFF

OFF

ON

OFF

OFF

OFF

ON

OFF

OFF

ON

OFF

OFF

ON

OFF

OFF

OFF

ON

OFF

OFF

OFF

ON

OFF

OFF

OFF

ON

OFF

OFF

OFF

ON

OFF

OFF

OFF

ON

OFF

OFF

OFF

EAST/WEST LIGHTS
Walk
Dont
Walk

Red

Yellow

Green

ON

OFF

OFF

WALK

ON

OFF

OFF

ON

OFF

OFF

ON

OFF

OFF

ON

OFF

OFF

OFF

OFF

ON

OFF

OFF

ON

OFF

OFF

ON

OFF

ON

OFF

ON

OFF

OFF

Flashing
Dont Walk
Dont
Walk
Dont
Walk
Dont
Walk
Dont
Walk
Dont
Walk
Dont
Walk
Dont
Walk

Walk
Dont
Walk
Dont
Walk
Dont
Walk
Dont
Walk
Dont
Walk
Dont
Walk
WALK
Flashing
Dont Walk
Dont
Walk
Dont
Walk

-6
Seneca College School of Information and Communications Technology

G VandeBelt 151

MCO556
Traffic Lights Project Requirements
Transitions between states occur because either an input has changed or a period of time has elapsed. Therefore
for each state, your code should set the outputs to the appropriate values and then check if the state should be
changed. This is easily done in C programming by using a switch statement as shown below:
// Give each state a value
#define EW4Red
1
// State Four Way Red after East/West Yellow
#define NSLeft
2
// State North/South left turn
...
#define EWyellow
N
// State East/West Yellow
unsigned char state = EW4Red;
// Set the state variable to the initial state.
while (1)
{
switch (state)
{
case EW4Red:
// Four Way Red after East/West Yellow
// Insert EW4Reds actions:
//
- North/South and East/West red lights ON
//
- Other lights OFF
// Check if state should changed:
//
if enough time has elapsed then
//
if left turn then
//
set initial conditions for North/South left turn state
//
else change state to steady green North/South Walk State
break;
case NSLeft:
// etc
break;

// State North/South left turn

}
}

Suggestions
Develop the program in stages. After each stage save the code as a new file.
1. Make a simple state machine which just controls a basic traffic light (no walk, no left turn, no
communication with the PC, no traffic counting)
2. Add the left turn states
3. Add walk states without flashing walk lights and without walk requests
4. Add flashing walk states with flashing walk lights
5. Add walk requests
6. Add PC communication feature for variable time for green light
7. Add traffic count upload to PC
8. Add ADC read for ambient temperature with variable flashing walk duration

-7
Seneca College School of Information and Communications Technology

G VandeBelt 151

Вам также может понравиться