Finite State Machines. Modify the traffic light controller FSM of Table 14.4 so that it takes an additional input, carns, that indicates when there is a car waiting in the north-south direction. Change the logic so that once the light changes to east-west, it stays with east-west green until a car is detected waiting in the north-south direction. Show a state table and state diagram for your new FSM.

The Correct Answer and Explanation is :
To modify the traffic light controller FSM as described in your request, we need to consider how the new input, carns, (indicating if a car is waiting in the north-south direction) will affect the system. The original FSM alternates between east-west and north-south traffic lights, but now, we want to keep the east-west direction green until a car is detected waiting in the north-south direction.
Modified FSM Behavior
- State Definitions:
- NS Green (S0): North-South direction has green, East-West direction has red.
- EW Green (S1): East-West direction has green, North-South direction has red.
- EW Red (S2): East-West direction is red, but the FSM will stay here unless a car is detected waiting in the north-south direction.
- Inputs:
carns: This input tells the FSM whether a car is waiting in the north-south direction. It will be a binary input, where1indicates that a car is waiting, and0means no car is waiting.
- Transition Logic:
- In state
S1(east-west green), ifcarns = 1(there’s a car waiting in the north-south direction), the FSM will switch to stateS0(north-south green). - Once the FSM is in state
S0, it will stay there untilcarnsis0, indicating there are no cars waiting in the north-south direction, at which point it can return to stateS1(east-west green).
State Table
| Current State | carns | Next State |
|---|---|---|
| S0 (NS Green) | 0 | S1 (EW Green) |
| S0 (NS Green) | 1 | S0 (NS Green) |
| S1 (EW Green) | 0 | S1 (EW Green) |
| S1 (EW Green) | 1 | S0 (NS Green) |
State Diagram
[S0] --(carns=0)--> [S1] --(carns=1)--> [S0]
^ |
|---------------------------|
Explanation:
- State S0 (NS Green): This is the state where the north-south traffic is green. The FSM stays in this state if a car is detected in the north-south direction (i.e.,
carns = 1). Once no car is waiting, it transitions toS1. - State S1 (EW Green): In this state, east-west traffic is green. The FSM remains in this state unless a car is detected waiting in the north-south direction (
carns = 1), which triggers a transition back to stateS0.
This modification ensures that once the light turns green for east-west traffic, it stays green until there is a car waiting for north-south traffic. This is more efficient because it avoids switching between states unnecessarily and gives priority to the direction with the car waiting.
The behavior is implemented by tracking the carns input, making the system adaptive to the presence of waiting vehicles in the north-south direction.