Skip to content

samvaadi/Smart-Traffic-Controller

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Smart Traffic Controller with DPI-C Analytics

A professional hardware-software co-design project featuring a 6-state Moore Finite State Machine (FSM) implemented in SystemVerilog. This system integrates a C-based Analytics Engine via the Direct Programming Interface (DPI-C) to dynamically adjust traffic timings based on real-time data from external configuration files.


🏗️ FSM Architecture

The controller is designed as a Moore Machine, where the traffic light outputs are determined strictly by the current state. The FSM manages three distinct road components: the Main Road (M1/M2), the Protected Main Turn (MT), and the Side Street (S).

State Table (Normal Mode)

The following table describes the standard traffic cycle when the system is operating under baseline conditions.

State Phase Description Light Status (M1, M2, MT, S) Duration (Clock Cycles)
S0 Main Road Straight M1: GREEN, M2: GREEN, Others: RED 7 (Standard)
S1 Main Transition M1: YELLOW, M2: YELLOW, Others: RED 2
S2 Main Protected Turn MT: GREEN, Others: RED 5
S3 Turn Transition MT: YELLOW, Others: RED 2
S4 Side Street Flow S: GREEN, Others: RED 5
S5 Side Transition S: YELLOW, Others: RED 2

🚦 Smart Logic: The Rush Hour Mechanism

The "Smart" aspect of this controller is handled by an integrated C-function that monitors simulation time via a "backdoor" link.

  1. External Input: A separate input.txt file defines the start and end times (e.g., 20 150).
  2. Software Processing: The C-logger reads these values and compares them against the current simulation time ($time).
  3. Hardware Reaction: If the time falls within the window, a is_rush_hour bit is passed back to the FSM, extending the S0 (Main Green) duration by 300% (from 7 cycles to 21 cycles).

🧪 Verification & Test Cases

The system was verified using a 20ns reset offset to ensure the hardware initializes correctly before software-driven parameters are applied.

Test Case 1: Baseline Verification

  • Setup: input.txt set to a window outside the simulation run (e.g., 500 600).
  • Observation: The system successfully cycled through all 6 states with base timings. MT and S lights functioned correctly in their respective phases.

Test Case 2: Dynamic Rush Hour Injection

  • Setup: input.txt set to 20 150.
  • Observation: After the initial 20ns reset period, the next occurrence of S0 (Main Green) was observed to be exactly 3x longer in both the waveform and the generated log, confirming the DPI-C bridge is functioning correctly.

Test Case 3: Protected Turn Priority

  • Observation: Verified via waveform that light_MT only transitions to Green when M1, M2, and S are explicitly Red, preventing simulated collisions.

🛠️ How to Run

  1. Upload design.sv, testbench.sv, logger.c, and input.txt to EDA Playground.
  2. Select Siemens Questa or Mentor Questa as the simulator.
  3. Ensure the DPI-C compilation option is active.
  4. Run the simulation.
  5. Check the Console Output for real-time logs and open traffic_results.txt for the final analytics report.

📂 Project Structure

  • design.sv: The 6-state Moore FSM and output logic.
  • testbench.sv: Stimulus generation and DPI-C function calls.
  • logger.c: C-code for file I/O and simulation analytics.
  • input.txt: Configuration file for user-defined Rush Hour windows.

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors