# adrofier/vending-machine-controller-using-verilog architecture

> Architecture diagram of the GitHub repository adrofier/vending-machine-controller-using-verilog, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-05-31). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/adrofier/vending-machine-controller-using-verilog
- Repository: https://github.com/adrofier/vending-machine-controller-using-verilog

## Overview

##### Project Type and Purpose
- This is a small Verilog HDL project implementing a finite-state-machine (FSM) “Vending Machine Controller” plus a basic Verilog testbench.
- Purpose: model coin handling, product selection, dispensing, and change logic in hardware, and verify its behavior via simulation.

##### Main Components
a. Vending Machine Controller Module (vending.v)
b. Testbench Module (vending_testbench.v)
c. Simulation Environment & Toolchain (Icarus Verilog & waveform viewer)
d. External Interfaces (coin inputs, select inputs, dispense outputs, change outputs, clock/reset)

##### Relationships and Data Flow
- The Testbench drives all inputs (coins, selections, clock, reset) into the Controller.
- The Controller FSM processes inputs, transitions between states, and produces outputs (dispense, change).
- Outputs loop back to the Testbench for verification and waveform capture.
- Icarus Verilog compiles both .v files and runs the simulation, generating waveforms/logs.

##### Architectural Patterns and Design Principles
- Finite State Machine (FSM) inside the Controller: clearly delineate states like IDLE, COLLECT, DISPENSE, RETURN_CHANGE.
- Separation of concerns:
– Controller = combinational + sequential logic for machine operation
– Testbench = stimulus generator and checker
- Simulation flow: source → compile → simulate → verify waveforms

##### Technologies and Tools
- Verilog HDL for both module and testbench
- Icarus Verilog 0.9.7 (compiler/simulator)
- Waveform viewer (e.g., GTKWave) for post-simulation analysis

## Diagram (Mermaid)

```mermaid
flowchart TD
    subgraph "Stimulus & Checker"
        TB["Testbench Module\n(vending_testbench.v)"]:::testbench
    end

    subgraph "DUT Layer"
        DUT["Vending Machine Controller Module\n(vending.v)\nInputs: coin_in[], select[], clk, rst\nOutputs: dispense, change"]:::dut
        subgraph "FSM"
            IDLE["IDLE"]:::fsm
            COLLECT["COLLECT"]:::fsm
            DISPENSE_ST["DISPENSE"]:::fsm
            RETURN["RETURN_CHANGE"]:::fsm
            IDLE --> COLLECT --> DISPENSE_ST --> RETURN --> IDLE
        end
    end

    subgraph "Toolchain"
        IVC["Icarus Verilog\n(iverilog & vvp)"]:::tool
        GTK["GTKWave\n(Waveform Viewer)"]:::tool
        IVC --> GTK
    end

    subgraph "Documentation & License"
        RD["Project Documentation & Simulation Instructions\n(README.md)"]:::doc
        LIC["License Information\n(LICENSE)"]:::doc
    end

    TB -->|"drives inputs"| DUT
    DUT -->|"returns outputs"| TB
    vending_v["vending.v"]:::src --> IVC
    tb_v["vending_testbench.v"]:::src --> IVC

    classDef dut fill:#cfe2ff,stroke:#000,stroke-width:1px;
    classDef testbench fill:#d4edda,stroke:#000,stroke-width:1px;
    classDef tool fill:#f0f0f0,stroke:#000,stroke-width:1px;
    classDef doc fill:#f8d7da,stroke:#000,stroke-width:1px;
    classDef fsm fill:#e2e3ff,stroke:#000,stroke-width:1px;
    classDef src fill:#fff3cd,stroke:#000,stroke-width:1px;

    click TB "https://github.com/adrofier/vending-machine-controller-using-verilog/blob/master/vending_testbench.v"
    click DUT "https://github.com/adrofier/vending-machine-controller-using-verilog/blob/master/vending.v"
    click RD "https://github.com/adrofier/vending-machine-controller-using-verilog/blob/master/README.md"
    click LIC "https://github.com/adrofier/vending-machine-controller-using-verilog/tree/master/LICENSE"
    click vending_v "https://github.com/adrofier/vending-machine-controller-using-verilog/blob/master/vending.v"
    click tb_v "https://github.com/adrofier/vending-machine-controller-using-verilog/blob/master/vending_testbench.v"
```
