Traffic Light Help PLEASE!!!!!!!

Discussion in 'Homework Help' started by sexycircuit, Nov 29, 2009.

  1. sexycircuit

    Thread Starter New Member

    Nov 29, 2009
    5
    0


    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
     
  2. hgmjr

    Moderator

    Jan 28, 2005
    9,030
    214
    Is this a class assignment?

    hgmjr
     
  3. blueroomelectronics

    AAC Fanatic!

    Jul 22, 2007
    1,758
    98
    I sure hope it's not the transportation ministry. :)
     
  4. sexycircuit

    Thread Starter New Member

    Nov 29, 2009
    5
    0
    Yes, its for a class. Any ideas?
     
  5. hgmjr

    Moderator

    Jan 28, 2005
    9,030
    214
    Have you made a stab at setting something up?

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

    hgmjr
     
  6. sexycircuit

    Thread Starter New Member

    Nov 29, 2009
    5
    0
    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. :(
     
  7. Duane P Wetick

    Active Member

    Apr 23, 2009
    408
    19
    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.]
     
  8. Audioguru

    New Member

    Dec 20, 2007
    9,411
    896
    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?
     
  9. ke5nnt

    Active Member

    Mar 1, 2009
    384
    15
    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:

    Code ( (Unknown Language)):
    1. ;************************************************************************
    2. ;TRAFFIC CONTROL SIGNAL                                                    *
    3. ;THIS SIGNAL IS INTENDED TO CONTROL TRAFFIC AT A 4-WAY INTERSECTION        *
    4. ;WITH THE "MAIN" ROAD HAVING A GREEN ARROW AND INDEPENDENT YELLOW        *
    5. ;CONTROL FOR STOPPING TURN TRAFFIC.  SECONDARY ROAD IS STANARD R-Y-G    *
    6. ;LIGHTS.  THIS PROGRAM ALSO HAS 2 "NIGHT MODE" OPERATIONS WHERE            *
    7. ;MAIN LANES FLASH YELLOW WHILE SECONDARY ROAD FLASHES RED, OR            *
    8. ;4-WAY FLASHING RED DEPENDING ON POSITION OF A PERIPHERAL SWITCH        *
    9. ;                                                                        *
    10. ;CREATED BY RYAN GOFF FOR THE PIC16F628A                                *
    11. ;************************************************************************
    12. ;CONFIGURATION
    13.     LIST        P=PIC16F628A
    14.     #INCLUDE    P16F628A.INC
    15.     __CONFIG B'10000100100000'
    16.     ERRORLEVEL    -302
    17. ;
    18.     ORG        01
    19.     GOTO    INIT
    20. ;
    21.     ORG        04
    22.     GOTO    INIT
    23. ;
    24.     COUNT1    EQU    22
    25.     COUNT2    EQU    23
    26. ;*************************************************************************
    27. ;SUBROUTINES
    28. SBNCE    MOVLW    0x51
    29.         MOVWF    COUNT1
    30. SBNCE1    DECFSZ    COUNT1        ;20MS DELAY TO COMBAT SWITCH BOUNCE
    31.         GOTO    SBNCE1
    32.         RETURN
    33. ;
    34. T500MS    MOVLW    0x32
    35.         MOVWF    COUNT1
    36.         MOVLW    0x04
    37.         MOVWF    COUNT2
    38. T500MS1    DECFSZ    COUNT1        ;500MS DELAY FOR NIGHT MODE FLASHING
    39.         GOTO    $+2
    40.         DECFSZ    COUNT2
    41.         GOTO    T500MS1
    42.         RETURN
    43. ;
    44. T3SEC    MOVLW    0x32
    45.         MOVWF    COUNT1
    46.         MOVLW    0x14
    47.         MOVWF    COUNT2
    48. T3SEC1    DECFSZ    COUNT1        ;3 SECOND DELAY
    49.         GOTO    $+2
    50.         DECFSZ    COUNT2
    51.         GOTO    T3SEC1
    52.         RETURN
    53. ;
    54. T10SEC    MOVLW    0xFF
    55.         MOVWF    COUNT1
    56.         MOVLW    0x40
    57.         MOVWF    COUNT2
    58. T10SEC1    DECFSZ    COUNT1        ;10 SECOND DELAY FOR GREEN TURN ARROW
    59.         GOTO    $+2
    60.         DECFSZ    COUNT2
    61.         GOTO    T10SEC1
    62.         RETURN
    63. ;
    64. T20SEC    MOVLW    0xFF
    65.         MOVWF    COUNT1
    66.         MOVLW    0x80
    67.         MOVWF    COUNT2
    68. T20SEC1    DECFSZ    COUNT1        ;20 SECOND DELAY FOR GREEN LIGHT
    69.         GOTO    $+2
    70.         DECFSZ    COUNT2
    71.         GOTO    T20SEC1
    72.         RETURN
    73. ;************************************************************************
    74. ;PROGRAM INITIALIZATION
    75. INIT    BSF        STATUS,5    ;BANK 1
    76.         MOVLW    00
    77.         MOVWF    TRISB        ;ALL PORT B ARE OUTPUT
    78.         MOVLW    B'00000011'
    79.         MOVWF    TRISA        ;RA0 AND RA1 INPUT, OTHERS OUTPUT
    80.         BCF        STATUS,5    ;BANK 0
    81.         BTFSC    PORTA,0        ;NIGHT MODE DESIRED?
    82.         GOTO    NMRY        ;FLASH RED/YELLOW
    83.         BTFSC    PORTA,1        ;OTHER NIGHT MODE DESIRED?
    84.         GOTO    NMRR        ;FLASH RED/RED
    85. ;*************************************************************************
    86. ;NORMAL SIGNAL OPERATION
    87. NORM    MOVLW    B'00001001'
    88.         MOVWF    PORTB        ;ALL TRAFFIC LANES RED
    89.         CALL    T3SEC        ;FOR 3 SECONDS
    90.         MOVLW    B'01001001'
    91.         MOVWF    PORTB        ;MAIN LANE TURN ARROW GREEN, ALL OTHERS RED
    92.         CALL    T10SEC        ;FOR 10 SECONDS
    93.         MOVLW    B'00101001'
    94.         MOVWF    PORTB        ;MAIN LANE TURN ARROW YELLOW, ALL OTHERS RED
    95.         CALL    T3SEC        ;FOR 3 SECONDS
    96.         MOVLW    B'00001001'
    97.         MOVWF    PORTB        ;ALL TRAFFIC LANES RED
    98.         CALL    T3SEC        ;FOR 3 SECONDS
    99.         BTFSC    PORTA,0        ;R/Y NIGHT MODE DESIRED?
    100.         GOTO    NMRY        ;GO TO R/Y NIGHT MODE
    101.         BTFSC    PORTA,1        ;R/R NIGHT MODE DESIRED?
    102.         GOTO    NMRR        ;GO TO R/R NIGHT MODE
    103.         MOVLW    B'10000001'
    104.         MOVWF    PORTB        ;MAIN TRAFFIC LANES GREEN, TURN ARROWS OFF, SECONDARY RED
    105.         CALL    T20SEC        ;FOR 20 SECONDS
    106.         MOVLW    B'00110001'
    107.         MOVWF    PORTB        ;MAIN TRAFFIC LANES YELLOW + TURN YELLOW + SECONDARY RED
    108.         CALL    T3SEC        ;FOR 3 SECONDS
    109.         MOVLW    B'00001001'
    110.         MOVWF    PORTB        ;ALL TRAFFIC LANES RED
    111.         CALL    T3SEC        ;FOR 3 SECONDS
    112.         BTFSC    PORTA,0        ;R/Y NIGHT MODE DESIRED?
    113.         GOTO    NMRY        ;GO TO R/Y NIGHT MODE
    114.         BTFSC    PORTA,1        ;R/R NIGHT MODE DESIRED?
    115.         GOTO    NMRR        ;GO TO R/R NIGHT MODE
    116.         MOVLW    B'00001100'
    117.         MOVWF    PORTB        ;SECONDARY GREEN, MAIN LANES RED
    118.         CALL    T20SEC        ;FOR 20 SECONDS
    119.         MOVLW    B'00001010'
    120.         MOVWF    PORTB        ;SECONDARY YELLOW, MAIN LANES RED
    121.         CALL    T3SEC        ;FOR 3 SECONDS
    122.         MOVLW    B'00001001'
    123.         MOVWF    PORTB        ;ALL TRAFFIC LANES RED
    124.         CALL    T3SEC        ;FOR 3 SECONDS
    125.         BTFSC    PORTA,0        ;R/Y NIGHT MODE DESIRED?
    126.         GOTO    NMRY        ;GO TO R/Y NIGHT MODE
    127.         BTFSC    PORTA,1        ;R/R NIGHT MODE DESIRED?
    128.         GOTO    NMRR        ;GO TO R/R NIGHT MODE
    129.         GOTO    NORM        ;OR REMAIN IN NORMAL CYCLE OPERATION
    130. ;**************************************************************************
    131. ;R/Y NIGHT MODE OPERATION.  PORTA 0
    132. NMRY    CALL    SBNCE        ;SWITCH BOUNCE COMBATANT
    133. NMRY1    MOVLW    B'00110000'
    134.         MOVWF    PORTB        ;MAIN LANES ALL YELLOW, ALL OTHERS OFF
    135.         CALL    T500MS        ;FOR 1/2 SECOND
    136.         MOVLW    B'00000001'
    137.         MOVWF    PORTB        ;SECONDARY RED, ALL OTHERS OFF
    138.         CALL    T500MS        ;FOR 1/2 SECOND
    139.         BTFSS    PORTA,0        ;STILL WANT R/Y NIGHT MODE?
    140.         GOTO    TRANS        ;IF NO, TRANSITION TO NORMAL CYCLE MODE
    141.         BTFSC    PORTA,1        ;SWITCH TO R/R NIGHT MODE?
    142.         GOTO    NMRR        ;THEN GO TO R/R NIGHT MODE
    143.         GOTO    NMRY1        ;OR STAY IN THIS NIGHT MODE
    144. ;**************************************************************************
    145. ;R/R NIGHT MODE OPERATION.  PORTA 1
    146. NMRR    CALL    SBNCE        ;SWITCH BOUNCE COMBATANT
    147. NMRR1    MOVLW    B'00001000'
    148.         MOVWF    PORTB        ;MAIN LANES RED, ALL OTHERS OFF
    149.         CALL    T500MS        ;FOR 1/2 SECOND
    150.         MOVLW    B'00000001'
    151.         MOVWF    PORTB        ;SECONDARY RED, ALL OTHERS OFF
    152.         CALL    T500MS        ;FOR 1/2 SECOND
    153.         BTFSC    PORTA,0        ;R/Y NIGHT MODE DESIRED?
    154.         GOTO    NMRY        ;THEN GO TO R/Y NIGHT MODE
    155.         BTFSS    PORTA,1        ;R/R NIGHT MODE STILL DESIRED?
    156.         GOTO    TRANS        ;NO, TRANSITION TO NORMAL CYCLE MODE
    157.         GOTO    NMRR1        ;YES, STAY IN R/R NIGHT MODE
    158. ;**************************************************************************
    159. ;TRANSITION FROM NIGHT MODE TO NORMAL
    160. TRANS    CALL    SBNCE        ;SWITCH BOUNCE COMBATANT
    161.         MOVLW    B'10000001'
    162.         MOVWF    PORTB        ;MAIN TRAFFIC LANES GREEN, SECONDARY RED
    163.         CALL    T10SEC        ;FOR 10 SECONDS
    164.         MOVLW    B'00110001'
    165.         MOVWF    PORTB        ;MAIN TRAFFIC LANES YELLOW + ARROW YELLOW. SECONDARY RED
    166.         GOTO    NORM        ;GO TO NORMAL CYCLE OPERATION
    167. ;**************************************************************************
    168.         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: Nov 30, 2009
  10. ][ Shocked ][

    Member

    Apr 13, 2009
    22
    0
  11. sexycircuit

    Thread Starter New Member

    Nov 29, 2009
    5
    0
    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.
     
  12. sexycircuit

    Thread Starter New Member

    Nov 29, 2009
    5
    0
  13. Duane P Wetick

    Active Member

    Apr 23, 2009
    408
    19
    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.]
     
Loading...