Author: Hilal Gure
Email: hilal_shide@live.com
Year: 2025
This project implements a Gamma-code encoder using Finite State Machine (FSM) logic on an FPGA.
It converts input symbols from switches into LED blink patterns representing short (dot), medium (dash), and long (bar) pulses.
The system also displays the chosen symbol on a seven-segment display and includes modular testbenches for simulation.
- Modular design: LUT → Shift Register → FSM → Display
- Accurate 0.25 s base timing from a 50 MHz input clock
- Verified through ModelSim simulation
- Tested on physical FPGA hardware (Quartus Prime)
- Complete documentation in English and Norwegian
- IEEE-style LaTeX report included under
/docs/latex
| Input/Output | Function |
|---|---|
SW[3:0] |
Select symbol to encode |
KEY1 |
Start encoding sequence |
KEY0 |
Reset (active-high) |
LEDR[0] |
Encoded blink output |
LEDR[9] |
Reset indicator |
HEX0 |
Displays selected symbol |
Pulse encoding:
00→ Dot (0.25 s)01→ Dash (0.75 s)10→ Bar (1.50 s)
The top-level entity (gamma_code_encoder.vhd) connects all modules:
- Gamma LUT – Maps selected symbol to an 8-bit Gamma code.
- Shift Register – Outputs 2-bit tokens sequentially to FSM.
- FSM – Controls LED output timing and sequencing.
- Counter – Generates a 0.25 s timing tick from 50 MHz.
- Seven-Segment Display – Shows selected character on
HEX0.
All modules were simulated and tested in ModelSim:
- Each VHDL entity has a dedicated testbench.
- The FSM and timing were validated through waveform analysis.
- Debugging LEDs visualized internal control signals (
tick_qsec,load_reg,shift_en, etc.).
Simulation ensured correctness before hardware synthesis in Quartus Prime.
Gamma-Code-Encoder/
│
├── src/ # VHDL source files
│ ├── gamma_code_encoder.vhd
│ ├── gamma_lut.vhd
│ ├── gamma_shift_reg.vhd
│ ├── fsm.vhd
│ ├── seven_seg.vhd
│ └── counter_slow.vhd
│
├── testbench/ # ModelSim testbenches
│ ├── tb_gamma_lut.vhd
│ ├── tb_gamma_shift_reg.vhd
│ ├── tb_fsm.vhd
│ ├── tb_counter_slow.vhd
│ └── tb_seven_seg.vhd
│
├── docs/ # Reports and documentation
│ ├── Gamma_Code_Encoder_Report.pdf # English report
│ ├── original_norwegian.pdf # Original report
│ └── latex/
│ ├── main.tex
│ ├── references.bib
│ └── figures/ # Images for the paper
│
├── LICENSE
├── .gitignore
└── README.md
📘 English version: docs/Gamma_Code_Encoder_Report.pdf
📗 Norwegian version: docs/original_norwegian.pdf
📄 LaTeX source: docs/latex/
- Open ModelSim and create a project.
- Add files from
src/and a testbench fromtestbench/. - Set the testbench as top-level and Run Simulation.
- Inspect waveforms for correct blink durations and FSM transitions.
- Open Quartus Prime and create a new project.
- Add all design files from
/src/. - Assign FPGA pins for:
CLOCK_50SW[3:0],KEY[1:0],LEDR[9:0],HEX0[6:0]
- Compile and program the FPGA.
- Observe the LED and display outputs.
- D. M. Harris and S. L. Harris, Digital Design and Computer Architecture: RISC-V Edition, Morgan Kaufmann, 2022.
- B. Cohen, Free Range VHDL: No Strings Attached!, VhdlCohen Publishing, 2013.
This project is licensed under the MIT License — see the LICENSE file for details.
© 2025 Hilal Gure
All block diagrams, schematics, and simulation waveforms are included in the repository under
docs/latex/figures/
| Category | File | Description |
|---|---|---|
| FSM & Control | Gamma FSM.png | Finite State Machine (FSM) architecture showing timing, signal flow, and control of led_out, shift_en, and load_reg. |
| State machine viewer.png | FSM state diagram with five states: S1_LOAD, S2_CHECK, S3_BLINK, S4_PAUSE, S5_DONE. |
|
| State table.png | State transition table listing conditions for each transition (start, empty, qsec_tick, etc.). |
|
| Modules | Gamma LUT.png | Look-Up Table (LUT) mapping the 4-bit switch input (SW[3:0]) to an 8-bit Gamma code. |
| Skiftregister.png | Shift register (gamma_shift_reg) that outputs 2-bit tokens sequentially and asserts finished when done. |
|
| Teller.png | Quarter-second counter (counter_slow) dividing the 50 MHz clock to generate tick_qsec. |
|
| Implementation Views | RTL VIEWER.png | RTL schematic of the top-level Gamma-code encoder showing module interconnections. |
| Technology map viewer post mapping.png | Technology map after synthesis showing FPGA resource mapping and logic placement. | |
| Simulation Waveforms | wavechart counter_slow.png | Testbench waveform confirming correct counter rollover and tick generation. |
| wavechart gamma LUT.png | LUT waveform showing correct 8-bit Gamma codes for each 4-bit input. | |
| wavechart gamma shift reg.png | Shift register waveform showing 2-bit token outputs and finished signal. |
|
| wavechart fsm.png | FSM waveform showing proper control of load_reg, shift_en, and led_out. |
|
| wavechart sevensegment.png | Seven-segment display waveform verifying symbol-to-segment decoding on HEX0. |
- All images are stored in:
docs/latex/figures/ - They illustrate both the design hierarchy and the simulation verification process.
- These figures correspond to the modules and results discussed in
Gamma_Code_Encoder_Report.pdfandoriginal_norwegian.pdf.