techmore.in

IceStudio - Traffic Light

Creating a Traffic Light Controller using IceStudio involves designing a system that simulates the behavior of traffic lights for a typical intersection. This project will use FPGA to control traffic light signals, including red, yellow, and green lights for two directions (e.g., North-South and East-West).

Here’s a very detailed walkthrough, including the design and code steps:

1. Setup IceStudio

  1. Download and Install IceStudio:

    • Visit the IceStudio GitHub page or the official website.
    • Download the installer for your operating system (Windows, macOS, or Linux) and follow the installation instructions.
  2. Connect Your FPGA Board:

    • Connect your FPGA development board (e.g., Lattice iCE40) to your computer via USB.
  3. Open IceStudio:

    • Launch IceStudio from your desktop or applications folder.

2. Create a New Project

  1. Start a New Design:

    • Open IceStudio and select “File” > “New” to start a new project.
  2. Set Up Project Parameters:

    • Choose the appropriate FPGA device for your development board (e.g., iCE40-HX8K).
    • Save the project with a descriptive name like “TrafficLightController”.

3. Design the Traffic Light Controller Logic

  1. Add a Clock Source:

    • Drag a Clock block from the components library to the canvas.
    • Configure the clock block to use the FPGA board’s clock frequency (e.g., 12 MHz).
  2. Create Counters for Timing:

    • Drag three Counter blocks to the canvas for managing the duration of red, yellow, and green lights.
    • Configure each counter to count up to a specific value based on the desired time duration (e.g., 10,000,000 counts for 1-second duration).
  3. Design Traffic Light Timing Logic:

    • Create State Machine:
      • Drag a State Machine block to the canvas. This will control the transitions between the different traffic light states (Red, Yellow, Green).
      • Define states for North-South and East-West traffic lights.
      • Implement state transitions based on the counter outputs.
  4. Define Traffic Light Outputs:

    • Add Output Blocks:
      • Drag output blocks to represent the traffic light signals for each direction (e.g., NS_Red, NS_Yellow, NS_Green, EW_Red, EW_Yellow, EW_Green).
      • Connect these outputs to the corresponding states in your state machine.
  5. Configure Traffic Light Logic:

    • Set up State Transitions:
      • Configure the state machine to cycle through Red → Green → Yellow for each direction.
      • Define the time each light stays on by connecting the counters to control the state transitions.

4. Configure Pin Mapping

  1. Assign FPGA Pins:

    • Go to the Pin Configuration section in IceStudio.
    • Map the output pins of the traffic light signals to the correct physical pins on your FPGA board.
    • For instance, assign pins for LEDs representing the traffic lights (e.g., NS_Red to pin 1, NS_Green to pin 2, etc.).
  2. Create a Pin Constraint File (if needed):

    • You may need to manually create or modify a pin constraint file to specify exact pin locations on your FPGA board.

5. Generate and Synthesize the Design

  1. Run Synthesis:

    • Click on the Synthesize button in IceStudio. This step converts your graphical design into a netlist for the FPGA.
  2. Place and Route:

    • IceStudio will automatically handle the placement and routing of your design.
  3. Generate Bitstream:

    • Click on Generate Bitstream to create the bitstream file required to program your FPGA.

6. Program the FPGA

  1. Connect Programmer Tool:

    • Ensure that your FPGA board is connected to your computer.
  2. Load the Bitstream:

    • Use the iceprog tool or the integrated programming feature in IceStudio to upload the bitstream to your FPGA.
  3. Verify the Traffic Light Controller:

    • Once programmed, your FPGA should simulate the traffic light sequence, with LEDs turning on and off according to the designed timing logic.

7. Example Code

Below is a simplified example of the logic you might implement for the traffic light controller. This example assumes the use of Verilog for detailed logic implementation.

verilog
module TrafficLightController( input clk, // System clock input rst, // Reset output reg [1:0] NS_Lights, // North-South Lights output reg [1:0] EW_Lights // East-West Lights ); // State definitions typedef enum reg [2:0] { NS_RED = 3'b001, NS_GREEN = 3'b010, NS_YELLOW = 3'b100, EW_RED = 3'b001, EW_GREEN = 3'b010, EW_YELLOW = 3'b100 } state_t; // Counter for timing reg [31:0] counter; reg [2:0] state, next_state; // Initialize counters and states initial begin counter = 0; state = NS_RED; end // State transition logic always @(posedge clk or posedge rst) begin if (rst) begin state <= NS_RED; counter <= 0; end else begin if (counter == 10000000) begin state <= next_state; counter <= 0; end else begin counter <= counter + 1; end end end // Next state logic always @(*) begin case (state) NS_RED: next_state = (counter == 10000000) ? NS_GREEN : NS_RED; NS_GREEN: next_state = (counter == 10000000) ? NS_YELLOW : NS_GREEN; NS_YELLOW: next_state = (counter == 10000000) ? EW_RED : NS_YELLOW; EW_RED: next_state = (counter == 10000000) ? EW_GREEN : EW_RED; EW_GREEN: next_state = (counter == 10000000) ? EW_YELLOW : EW_GREEN; EW_YELLOW: next_state = (counter == 10000000) ? NS_RED : EW_YELLOW; default: next_state = NS_RED; endcase end // Output logic always @(*) begin case (state) NS_RED: begin NS_Lights = 2'b01; // Red EW_Lights = 2'b10; // Green end NS_GREEN: begin NS_Lights = 2'b10; // Green EW_Lights = 2'b01; // Red end NS_YELLOW: begin NS_Lights = 2'b01; // Yellow EW_Lights = 2'b10; // Red end EW_RED: begin NS_Lights = 2'b10; // Red EW_Lights = 2'b01; // Green end EW_GREEN: begin NS_Lights = 2'b01; // Red EW_Lights = 2'b10; // Green end EW_YELLOW: begin NS_Lights = 2'b01; // Red EW_Lights = 2'b01; // Yellow end default: begin NS_Lights = 2'b01; // Red EW_Lights = 2'b01; // Red end endcase end endmodule

8. Save and Document Your Work

  • Save the Project: Save your IceStudio project and any associated files.
  • Document Configuration: Note down the pin assignments, timing configurations, and other relevant details.

Summary

Creating a traffic light controller in IceStudio involves setting up the project, designing the timing and state machine logic for traffic lights, configuring pin mappings, synthesizing and generating the bitstream, and programming the FPGA. The detailed steps and example Verilog code provided should guide you through creating a functional traffic light controller that simulates real-world traffic light operations.

For visual aids and additional examples, consult IceStudio’s documentation or look for community tutorials that may include screenshots and more specific details.