Question

In: Electrical Engineering

Design an automatic traffic light control signal for a road square using 1MHz internal oscillator of...

Design an automatic traffic light control signal for a road square using 1MHz internal oscillator of PIC16F887. Each traffic light must consist of three (Red, Yellow, Green) lights. Use proteus for implementation. Your code must use four light signals installed on each road connecting to square.

in word program form.(text and diagram )

Solutions

Expert Solution

Peripheral Interface Controllers (PIC) is one of the most sophisticated microcontrollers produced by microchip technology. Such microcontrollers are commonly used in modern computer applications. The PIC controller integrates all types of advanced interface ports and memory modules. Like a normal microcontroller, the PIC chip also combines a microprocessor called a CPU and is integrated with various types of memory modules (RAM, ROM, EEPROM, etc), I/ O ports, timers / counters, communication ports.  

The entire PIC family of microcontrollers uses the Harvard architecture. This system has a program and data retrieved from separate memory and the computer has a program memory bus and a data memory bus (more than 8 lines in a typical bus). This enhances the bandwidth (data throughput) over the traditional von Neumann architecture where the program and data are retrieved from the same memory (access via the same bus). Separating program and code memory also enables instructions to be shaped differently from an 8-bit long text phrase.

PIC 16F877 is one of Microchip's most popular microcontrollers. This controller is commonly used for advanced and mainstream applications due to its low price, wide variety of features, high efficiency and ease of availability. It is ideal for applications such as motion control applications, measuring devices, research purposes, and so on. The PIC 16F877 contains all the modules that modern microcontrollers usually have.

Features

  1. Just 35 simple instructions.
  2. Both single-cycle instructions except for two-cycle program branches.
  3. High-performance RISC Processor.
  4. Operation speed: clock input (200MHz), instruction loop (200nS).
  5. Up to 368×8bit RAM (data memory), 256×8 EEPROM (data memory), 8k×14 of flash memory.
  6. Various addressing modes (direct, Indirect, relative addressing modes).
  7. Power on Reset (POR).
  8. 14 internal interrupts
  9. Power-Up Timer (PWRT) and oscillator start-up timer
  10. Operating voltage range (2.0 – 5.56)volts
  11. Low power consumption (<0.6mA typical @3v-4MHz, 20µA typical @3v-32MHz and <1 A typical standby)
  12. 3 timer/counter modules - Timer 0 (8 bit), Timer 1 (16 bit) and Timer 2 (8 bit) with prescalar
  13. 10 bit ADC(Analog to Digital Converter)
  14. Synchronous Serial Port (SSP) with SPI (master code) and I2C (master/slave).
  15. Universal Synchronous Asynchronous Receiver Transmitter (USART) with 9 bit address detection.
  16. Parallel Slave Port (PSP) 8 bit wide with external RD, WR and CS controls
  17. 5 input/output ports.  

I/O Ports

PIC16F877 has five essential input / output ports. These are generally referred to as PORT A (R A), PORT B (RB), PORT C (RC), PORT D (RD) and PORT E (RE). These ports are used to interface input / output. In this controller, "PORT A" is only 6 bit wide (RA-0 to RA-7), "PORT B" is only 8 bit wide (RB-0 to RB-7,RC-0 to RC-7,RD-0 to RD-7), "PORT E" is only 3 bit wide (RE-0 to RE-7).

Each of these ports are bi-directional. The port direction is handled by the use of TRIS(X) registers (TRIS D used to set the direction of PORT D , TRIS E used to set the direction for PORT E ). Setting the TRIS(X) bit '1' would assign the corresponding PORT(X) bit to the input.  Writing   the TRIS(X) bit '0' would set the equivalent PORT(X) bit as output.


Timer 0 module

  1. Timer-0 Module is built in 8 bit timer / counter
  2. It can be readable / writable easily.
  3. Built in a pre-scalar programmable 8-bit software.
  4. Select internal / external clock pulses conveniently.
  5. Interrupt the overflow from FFh to 00h.
  6. Edge selection of the external clock pulse

Normally, timer mode is selected by emptying the T0CS bit in the option register. In Timer mode, when the Timer 0 Module increases with each instruction cycle, the TMR0 registry is written, the increment is impeded for the following two instruction cycles. The user will get through this by adding an modified value to the TMR0 register. Counter mode is chosen by setting the T0CS bit in Counter mode. Timer 0 will increase on each rising or dropping edge of the RA4 / T0CKI plate. The incremental edge is calculated by the Timer 0 Source Edge Select bit, T0SE. The T0SE bit clearing selects the rising edge. The pre-scaler is shared between the Timer0 module and the Watchdog Timer.

OPTION REGISTER

RBPU INTEDG T0CS T0SE PSA PS2 PS1 PS0

TMR0 interrupt is triggered only when the TMR0 register is overflowing from FFh to 00h. This overflow sets the TMR0IF bit. The interrupt can be obscured by removing the TMR0IE bit. Bit TMR0IF must be cleared by the Timer 0 Module Interrupt Service Routine before re-enabling this interrupt.

Interrupt control register (INTCON)

GIE PIE TMROIE INTE RBIE TMR0IF INTF RBIF

So PIC 16F877 is interfaced with LEDs which represents the traffic lights in a 4 way junction. Low-power LEDs are used for all lights of different colors, namely red , yellow and green. The red LED indicates "stop running," the yellow LED indicates "start slow down" and the green LED indicates "drive." Twelve LEDs are used; three to each light. So we must connect the LEDs to the I/O port of the PIC controller. Let the 12 LEDsbe connected in PORT B and PORT D. So these ports must be output ports. Here the algorithm to implement the system is,  

Turn on the Green LED in signal 1 & Red signals to other roads to give time to the vehicles at signal 1 to pass. After 10 seconds, the yellow light at signal 1 will light up to give an indication that the red light at signal 1 is about to come up and also to give an indication to the vehicles at signal 2 that the green light is about to light up.

So after 5 seconds, red light at signal 1 will come up and green light at signal will come up meaning vehicles at signal 1 must stop and vehicles at signal 2 can move.

Similarly the traffic light controller will work for the signal 3, signal 4 and the system will keep looping.

Signal 1 - LEDs in RB1,RB2 and RB3

Signal 2 - LEDs in RB4, RB5 and RB6

Signal 3 - LEDs in RD5, RD6 and RD7

Signal 4 LEDs in RD2. RD3 and RD4

Delay generation using TIMER 0

Here we use internal clock oscillator of 1 MHz , so the equation of output frequency is given by,  

Here required delay is 10 seconds and 5 seconds. So we must add a variable so that we can change to get the different required delay. So now the equation becomes,

Where count is the variable.  

So when delay is 10 seconds, the output frequency will be,  

So the count value will be,

Let TMR0 = 0 and prescaler = 256.  

So ,

  

So to get 10 seconds delay use count = 38 and to get 5 seconds delay use count = 19 .

#include<pic.h>


int count = 0 
void main()
{
TRISB= 0  // Make PORT B as output port 
TRISD=0    // Make PORT D as output port 
PORTB=0    // Initialize port b, so all leds are off 
PORTD=0    // Initialize port d, so all leds are off 
TMR0 =0    // According to the delay calculation 
T0CS=0     // Choose the internal clock source 
TOSE=0     // Increments on low to high edge of the clock 
PS0 = 1 
PS1 = 1
PS2 = 1    // To select prescalar as 256   
while (1)    // Infinite loop  
{
PORTB = 0x18 // Make RB3 = 1 and RB4=1 in port B so Green light of signal 1 will be on and red light of signal 2 will be on
PORTD= 0x90  // make RD7 = 1 and RD4= 1 so that red signals in 3 and 4 will be on 
while(!TOIF)// Untill Timer overflows stay here 
TOIF=0      //Resetting the flag 
count++     // Increment count 
if(count==38) // Generate 10 second delay
{
count=0 // Reset count 
}

PORTB = 0x04   // Making Green LED at signal 1 LOW and making yellow LED at signal 1 HIGH for 5 seconds
while(!TOIF)// Untill Timer overflows stay here 
TOIF=0      //Resetting the flag 
count++     // Increment count 
if(count==19) // Generate 5 second delay
{
count=0 // Reset count 
}
 
PORTB = 0x48 
PORTD = 0x30 //  Making Green  LED at signal 2 and red LED's at other signal HIGH 
while(!TOIF)// Untill Timer overflows stay here 
TOIF=0      //Resetting the flag 
count++     // Increment count 
if(count==38) // Generate 10 second delay
{
count=0 // Reset count 
} 
PORTB= 0x20 // Making Green LED at signal 2 LOW and making yellow LED at signal 2 HIGH for 5 seconds
while(!TOIF)// Untill Timer overflows stay here 
TOIF=0      //Resetting the flag 
count++     // Increment count 
if(count==19) // Generate 5 second delay
{
count=0 // Reset count 
} 
PORTB= 0x18
PORTD = 0x90  // Making Green  LED at signal 3 and red LED's at other signal HIGH 
while(!TOIF)// Untill Timer overflows stay here 
TOIF=0      //Resetting the flag 
count++     // Increment count 
if(count==38) // Generate 10 second delay
{
count=0 // Reset count 
}  
PORTD= 0x50   // Making Green LED at signal 3 LOW and making yellow LED at signal 3 HIGH for 5 seconds 
while(!TOIF)// Untill Timer overflows stay here 
TOIF=0      //Resetting the flag 
count++     // Increment count 
if(count==19) // Generate 5 second delay
{
count=0 // Reset count 
}  
PORTD=0x24 
PORTB= 0x18  // Making Green  LED at signal 4 and red LED's at other signal HIGH
while(!TOIF)// Untill Timer overflows stay here 
TOIF=0      //Resetting the flag 
count++     // Increment count 
if(count==38) // Generate 10 second delay
{
count=0 // Reset count 
} 
PORTD=0x28   // Making Green LED at signal 4 LOW and making yellow LED at signal 4 HIGH for 5 seconds
while(!TOIF)// Untill Timer overflows stay here 
TOIF=0      //Resetting the flag 
count++     // Increment count 
if(count==19) // Generate 5 second delay
{
count=0 // Reset count 
}   
}

Related Solutions

Design an embedded system using MSP430 to control a traffic light system. It is included a...
Design an embedded system using MSP430 to control a traffic light system. It is included a complete design description of a traffic light system to help you in your design. Show the hardware schematics and the software needed to complete your design.
IRC procedure for design pedestarin and traffic signal in about 200words Design traffic signal by Webster...
IRC procedure for design pedestarin and traffic signal in about 200words Design traffic signal by Webster method For average flow of traffic are 400 and 250 pcu/hr. Saturation flows are 1250 and 1000 pcu/hr.. Calc all red for pedestrians in 12 sec
design 4 bit four way traffic light signal by using j k flip flop and 555...
design 4 bit four way traffic light signal by using j k flip flop and 555 timer ic state equation and k map and also schematic diagram.
Traffic counts and signal timing data were collected for the intersection of Sand Creek Road and...
Traffic counts and signal timing data were collected for the intersection of Sand Creek Road and Wolf Road. The intersection is signalized. The collected data show that, for a particular cycle, vehicles on the through lane of the SB of Sand Creek Road had the following arrival headway pattern (counted from the start of the red time of the cycle): – 2.5 seconds for the first 10 seconds – 2 seconds for the time period of 44 ‐ 50 seconds,...
A car is going at 11.2 m/s on a horizontal straight road. When the traffic light...
A car is going at 11.2 m/s on a horizontal straight road. When the traffic light is 30 m away, it turns red. The reaction time of the driver is 0.3 s. The car stops just before the traffic light with constant deceleration when the break is applied. Find the time it takes for the car to stop, from the moment the light becomes red. Plot speed of the car on y-axis and the time on the x-axis, taking t=0...
For design, the daily car, pickup truck, and light van traffic is 20,000; and the daily...
For design, the daily car, pickup truck, and light van traffic is 20,000; and the daily truck traffic consists of 200 passes of single-unit trucks with single and tandem axles, and 410 passes of tractor semi-trailer trucks with single, tandem, and triple axles. The axle weights are :cars, pickups, light vans = two 2000-lb single axles;single-unit trucks = 10,000-lb steering, single axle= 22,000-lb drive, tandem axle and: tractor semi-trailer trucks = 12,000-lb steering, single axle,= 18,000-lb drive, tandem axle,= 50,000-lb...
Design a sequential traffic light controller for the intersection of street A and street B. Each...
Design a sequential traffic light controller for the intersection of street A and street B. Each street has traffic sensors which detect the presence of vehicles approaching or stopped at intersection. Sa=1 means a vehicle is approaching on street A. Sb=1 means a vehicle is approaching on street B. There are 3 outputs of each streets RedA, YellowA and GreenA, RedB, YellowB, and GreenB. Condition: “StreetA” is a main street and has a green light for at least 50s, after...
answer following questions from the Traffic Signal Systems Operations and Design Book 1. What is the...
answer following questions from the Traffic Signal Systems Operations and Design Book 1. What is the purpose of the ring barrier diagram? 2. How is timing represented in a ring barrier diagram? 3. Why use a ring barrier diagram instead of a conflict matrix to describe the sequencing of phases? 4. What is the difference between a movement and a phase ?
1. A scientist is interested in whether the design of an air traffic control display affects...
1. A scientist is interested in whether the design of an air traffic control display affects how many airplanes an air traffic controller can manage at once. The scientist evaluates 2 different displays: A low information display (airplanes shown as uniform blips) and a high information display (airplanes shown as different blips depending on aircraft model, and color coded according to speed). The scientist recruits 20 air traffic controllers and randomly assigns 10 to each display condition. The researcher asks,...
Design a Traffic Light that upon reset, turns Red for 10 seconds, then Green for 10...
Design a Traffic Light that upon reset, turns Red for 10 seconds, then Green for 10 seconds, then Yellow for 5 seconds. Assume a CLK period of 5 seconds. Draw the State Transition Diagram, State Transition Table and Output Table, find the Boolean Equations for Next State and Output and draw the logic circuit.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT