Traffic Light Help PLEASE!!!!!!!

Thread Starter

sexycircuit

Joined Nov 29, 2009
5


We need to design a traffic controller for a 4-way intersection, managed by stop lights.
- The main road traffic is east – west

-The minor road traffic is north – south

-The main road traffic will flow continuously until any car appears at the intersection on the minor road.

-When a car comes to the intersection on the minor road, a switch is closed, and the minor road traffic is allowed to pass through the intersection for some time before the main road traffic is again allowed to flow.

-The green light for the minor road must be on for at least 20 seconds to allow one car to pass through the intersection.

-For safety, the yellow light (in for both directions) must be on for a minimum of 10 seconds

How would we create a state table with the requirements above? Once we can get started on this part then we can do the rest of the project with ease. Please help us on getting a truth table started with present state and next state incorporating flip flops as well.

Thank you
 

hgmjr

Joined Jan 28, 2005
9,027
Have you made a stab at setting something up?

I am going to move this to the Homework Section where it belongs.

hgmjr
 

Thread Starter

sexycircuit

Joined Nov 29, 2009
5
That's the thing. We were setting up the state table, but we cant figure out how to. We know that when the traffic light is red it will be a 1 and the yellow and green should be 0's, but then we get confused on how to incorporate the other traffic lights on N and S side to go opposite it.
Like when one traffic light is on red the other light should be green so both being 1.
It just got real messy and now we are lost. :(
 
Why should it be messy at all! This is a pet peeve of mine, when sitting at a traffic signal, and you can see the is no other traffic in any direction, and you still have to sit and wait for a stupid timer to time out. ENOUGH! We need smart traffic controls in this day and age, nothing less! These ridiculous signals are the cause of many traffic deaths across the nation, such that city councilmen are thinking about replacing the signals with 1890's roundabouts. Imagine, roundabouts! Were going backwards with technology, not forwards! When you are sitting at a light, you can see what needs to be done! Why not do it! Here is a rare opportunity for all you college people to start a new industry, smart traffic controls! Better yet, let the traffic control learn the traffic patterns so that the control programs itself! With human moderation and cheap mega-memories, this is no dream, its time has come!

Regards, DPW [ Spent years making heaters out of op-amps.]
 

Audioguru

Joined Dec 20, 2007
11,248
Traffic lights have a red light for a long time so that the traffic does not go faster and faster and faster and faster and faster and faster and faster and faster and faster and faster and ... kill somebody.

Wouldn't it be nice if a traffic signal can sense you coming and sense that nobody is in the 90 degree direction and keep the light green for you?
 

ke5nnt

Joined Mar 1, 2009
384
Why should it be messy at all! This is a pet peeve of mine, when sitting at a traffic signal, and you can see the is no other traffic in any direction, and you still have to sit and wait for a stupid timer to time out. ENOUGH! We need smart traffic controls in this day and age, nothing less! These ridiculous signals are the cause of many traffic deaths across the nation, such that city councilmen are thinking about replacing the signals with 1890's roundabouts. Imagine, roundabouts! Were going backwards with technology, not forwards! When you are sitting at a light, you can see what needs to be done! Why not do it! Here is a rare opportunity for all you college people to start a new industry, smart traffic controls! Better yet, let the traffic control learn the traffic patterns so that the control programs itself! With human moderation and cheap mega-memories, this is no dream, its time has come!

Regards, DPW [ Spent years making heaters out of op-amps.]
Regarding "smart" traffic control technology, I believe Minneapolis has a system like that, which follows traffic patterns and adjusts light timing based on traffic volume and speed. In fact, this system placed Minneapolis at the top of the list of "most technologically advanced cities in the U.S." a few years back.


Now, regarding the question at hand, I'm not really sure how you mean about "state tables" as I'm not a student and have never used any before, but, I did write this code for a similar traffic light in assembly, which might help you.

The code probably isn't done, because I didn't spend much time on it, and it doesn't operate on any sensors, strictly a timer (don't worry dwayne, I'm not going to stick this light in your neighborhood :D ). The code has a description at the top.

It would be relatively easy to adjust the code to incorporate sensors, where tripping the sensor would induce a state change on one of the pins, which triggers an interrupt to change your secondary road signals to green after a yellow cycle on the main lanes, counts a timer, and then throws yellow on secondaries before going back to Red secondary/green main.

Again, it's late for me, I work midnights, so I didn't double check this before posting it, but I think it's complete so there shouldn't be any errors:

Rich (BB code):
;************************************************************************
;TRAFFIC CONTROL SIGNAL                                                    *
;THIS SIGNAL IS INTENDED TO CONTROL TRAFFIC AT A 4-WAY INTERSECTION        *
;WITH THE "MAIN" ROAD HAVING A GREEN ARROW AND INDEPENDENT YELLOW        *
;CONTROL FOR STOPPING TURN TRAFFIC.  SECONDARY ROAD IS STANARD R-Y-G    *
;LIGHTS.  THIS PROGRAM ALSO HAS 2 "NIGHT MODE" OPERATIONS WHERE            *
;MAIN LANES FLASH YELLOW WHILE SECONDARY ROAD FLASHES RED, OR            *
;4-WAY FLASHING RED DEPENDING ON POSITION OF A PERIPHERAL SWITCH        *
;                                                                        *
;CREATED BY RYAN GOFF FOR THE PIC16F628A                                *
;************************************************************************
;CONFIGURATION
    LIST        P=PIC16F628A
    #INCLUDE    P16F628A.INC
    __CONFIG B'10000100100000'
    ERRORLEVEL    -302
;
    ORG        01
    GOTO    INIT
;
    ORG        04
    GOTO    INIT
;
    COUNT1    EQU    22
    COUNT2    EQU    23
;*************************************************************************
;SUBROUTINES
SBNCE    MOVLW    0x51
        MOVWF    COUNT1
SBNCE1    DECFSZ    COUNT1        ;20MS DELAY TO COMBAT SWITCH BOUNCE
        GOTO    SBNCE1
        RETURN
;
T500MS    MOVLW    0x32
        MOVWF    COUNT1
        MOVLW    0x04
        MOVWF    COUNT2
T500MS1    DECFSZ    COUNT1        ;500MS DELAY FOR NIGHT MODE FLASHING
        GOTO    $+2
        DECFSZ    COUNT2
        GOTO    T500MS1
        RETURN
;
T3SEC    MOVLW    0x32
        MOVWF    COUNT1
        MOVLW    0x14
        MOVWF    COUNT2
T3SEC1    DECFSZ    COUNT1        ;3 SECOND DELAY
        GOTO    $+2
        DECFSZ    COUNT2
        GOTO    T3SEC1
        RETURN
;
T10SEC    MOVLW    0xFF
        MOVWF    COUNT1
        MOVLW    0x40
        MOVWF    COUNT2
T10SEC1    DECFSZ    COUNT1        ;10 SECOND DELAY FOR GREEN TURN ARROW
        GOTO    $+2
        DECFSZ    COUNT2
        GOTO    T10SEC1
        RETURN
;
T20SEC    MOVLW    0xFF
        MOVWF    COUNT1
        MOVLW    0x80
        MOVWF    COUNT2
T20SEC1    DECFSZ    COUNT1        ;20 SECOND DELAY FOR GREEN LIGHT
        GOTO    $+2
        DECFSZ    COUNT2
        GOTO    T20SEC1
        RETURN
;************************************************************************
;PROGRAM INITIALIZATION
INIT    BSF        STATUS,5    ;BANK 1
        MOVLW    00
        MOVWF    TRISB        ;ALL PORT B ARE OUTPUT
        MOVLW    B'00000011'
        MOVWF    TRISA        ;RA0 AND RA1 INPUT, OTHERS OUTPUT
        BCF        STATUS,5    ;BANK 0
        BTFSC    PORTA,0        ;NIGHT MODE DESIRED?
        GOTO    NMRY        ;FLASH RED/YELLOW
        BTFSC    PORTA,1        ;OTHER NIGHT MODE DESIRED?
        GOTO    NMRR        ;FLASH RED/RED
;*************************************************************************
;NORMAL SIGNAL OPERATION
NORM    MOVLW    B'00001001'
        MOVWF    PORTB        ;ALL TRAFFIC LANES RED
        CALL    T3SEC        ;FOR 3 SECONDS
        MOVLW    B'01001001'
        MOVWF    PORTB        ;MAIN LANE TURN ARROW GREEN, ALL OTHERS RED
        CALL    T10SEC        ;FOR 10 SECONDS
        MOVLW    B'00101001'
        MOVWF    PORTB        ;MAIN LANE TURN ARROW YELLOW, ALL OTHERS RED
        CALL    T3SEC        ;FOR 3 SECONDS
        MOVLW    B'00001001'
        MOVWF    PORTB        ;ALL TRAFFIC LANES RED
        CALL    T3SEC        ;FOR 3 SECONDS
        BTFSC    PORTA,0        ;R/Y NIGHT MODE DESIRED?
        GOTO    NMRY        ;GO TO R/Y NIGHT MODE
        BTFSC    PORTA,1        ;R/R NIGHT MODE DESIRED?
        GOTO    NMRR        ;GO TO R/R NIGHT MODE
        MOVLW    B'10000001'
        MOVWF    PORTB        ;MAIN TRAFFIC LANES GREEN, TURN ARROWS OFF, SECONDARY RED
        CALL    T20SEC        ;FOR 20 SECONDS
        MOVLW    B'00110001'
        MOVWF    PORTB        ;MAIN TRAFFIC LANES YELLOW + TURN YELLOW + SECONDARY RED
        CALL    T3SEC        ;FOR 3 SECONDS
        MOVLW    B'00001001'
        MOVWF    PORTB        ;ALL TRAFFIC LANES RED
        CALL    T3SEC        ;FOR 3 SECONDS
        BTFSC    PORTA,0        ;R/Y NIGHT MODE DESIRED?
        GOTO    NMRY        ;GO TO R/Y NIGHT MODE
        BTFSC    PORTA,1        ;R/R NIGHT MODE DESIRED?
        GOTO    NMRR        ;GO TO R/R NIGHT MODE
        MOVLW    B'00001100'
        MOVWF    PORTB        ;SECONDARY GREEN, MAIN LANES RED
        CALL    T20SEC        ;FOR 20 SECONDS
        MOVLW    B'00001010'
        MOVWF    PORTB        ;SECONDARY YELLOW, MAIN LANES RED
        CALL    T3SEC        ;FOR 3 SECONDS
        MOVLW    B'00001001'
        MOVWF    PORTB        ;ALL TRAFFIC LANES RED
        CALL    T3SEC        ;FOR 3 SECONDS
        BTFSC    PORTA,0        ;R/Y NIGHT MODE DESIRED?
        GOTO    NMRY        ;GO TO R/Y NIGHT MODE
        BTFSC    PORTA,1        ;R/R NIGHT MODE DESIRED?
        GOTO    NMRR        ;GO TO R/R NIGHT MODE
        GOTO    NORM        ;OR REMAIN IN NORMAL CYCLE OPERATION
;**************************************************************************
;R/Y NIGHT MODE OPERATION.  PORTA 0
NMRY    CALL    SBNCE        ;SWITCH BOUNCE COMBATANT
NMRY1    MOVLW    B'00110000'
        MOVWF    PORTB        ;MAIN LANES ALL YELLOW, ALL OTHERS OFF
        CALL    T500MS        ;FOR 1/2 SECOND
        MOVLW    B'00000001'
        MOVWF    PORTB        ;SECONDARY RED, ALL OTHERS OFF
        CALL    T500MS        ;FOR 1/2 SECOND
        BTFSS    PORTA,0        ;STILL WANT R/Y NIGHT MODE?
        GOTO    TRANS        ;IF NO, TRANSITION TO NORMAL CYCLE MODE
        BTFSC    PORTA,1        ;SWITCH TO R/R NIGHT MODE?
        GOTO    NMRR        ;THEN GO TO R/R NIGHT MODE
        GOTO    NMRY1        ;OR STAY IN THIS NIGHT MODE
;**************************************************************************
;R/R NIGHT MODE OPERATION.  PORTA 1
NMRR    CALL    SBNCE        ;SWITCH BOUNCE COMBATANT
NMRR1    MOVLW    B'00001000'
        MOVWF    PORTB        ;MAIN LANES RED, ALL OTHERS OFF
        CALL    T500MS        ;FOR 1/2 SECOND
        MOVLW    B'00000001'
        MOVWF    PORTB        ;SECONDARY RED, ALL OTHERS OFF
        CALL    T500MS        ;FOR 1/2 SECOND
        BTFSC    PORTA,0        ;R/Y NIGHT MODE DESIRED?
        GOTO    NMRY        ;THEN GO TO R/Y NIGHT MODE
        BTFSS    PORTA,1        ;R/R NIGHT MODE STILL DESIRED?
        GOTO    TRANS        ;NO, TRANSITION TO NORMAL CYCLE MODE
        GOTO    NMRR1        ;YES, STAY IN R/R NIGHT MODE
;**************************************************************************
;TRANSITION FROM NIGHT MODE TO NORMAL
TRANS    CALL    SBNCE        ;SWITCH BOUNCE COMBATANT
        MOVLW    B'10000001'
        MOVWF    PORTB        ;MAIN TRAFFIC LANES GREEN, SECONDARY RED
        CALL    T10SEC        ;FOR 10 SECONDS
        MOVLW    B'00110001'
        MOVWF    PORTB        ;MAIN TRAFFIC LANES YELLOW + ARROW YELLOW. SECONDARY RED
        GOTO    NORM        ;GO TO NORMAL CYCLE OPERATION
;**************************************************************************
        END
OK, I couldn't help myself, I skimmed it briefly and noticed just a couple things. First, probably need to increase the time delay for switch bounce just a bit if using a switch at all. Second, you can adjust timing any way you please for individual light durations. I also made sure that when switching to night mode during normal operation, that the light would continue to cycle normally until all lanes were red, before beginning to flash, rather than go straight from green to flashing red on any particular side. Much safer.
 
Last edited:

Thread Starter

sexycircuit

Joined Nov 29, 2009
5
Thank you for the coding but we're actually coding it in Verilog. Also, the trouble we're having is getting a truth table started using present and next states.
 
Thank you for the coding but we're actually coding it in Verilog. Also, the trouble we're having is getting a truth table started using present and next states.
I hope you are using tri-state logic; on, off & other. Maybe that will resolve your truth table troubles.

Regards, DPW [ Spent years making heaters out of op-amps.]
 
Top