# ziyan/altera-de2-ann architecture

> Architecture diagram of the GitHub repository ziyan/altera-de2-ann, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-06-17). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/ziyan/altera-de2-ann
- Repository: https://github.com/ziyan/altera-de2-ann

## Overview

##### Project type and purpose
- This is an FPGA hardware-design project that implements an Artificial Neural Network (ANN) on the Altera DE2 development board.
- The README (“Artificial Neural Network on Altera DE2”) and the presence of VHDL files, QSF/QPF, and Quartus IP files indicate a custom hardware architecture rather than software.

##### File structure
- Top level:
- doc/ – design report
- src/ – all HDL sources and Quartus project files
- Under src/:
- ann/ – the top-level ANN VHDL entity (ann.vhd) plus project files (ann.qpf)
- / – display controller for the onboard LCD (display.vhd)
- lib/float/ – floating-point arithmetic IP (add, sub, mul, div, exp, cmp, etc.)
- lib/lcd/ – low-level LCD interface (lcd.vhd)
- lib/lfsr/ – linear-feedback shift register for random/pattern generation
- lib/sram/ – SRAM interface IP
- pr/ – pattern-recognition or pattern-generator logic (patterns.vhd, pr.vhd)
- Quartus project files (de2.qsf, de2.vhd) indicate the top-level wrapper for the DE2 board.

##### README

a. DE2 Board I/O Blocks
- On-chip SRAM interface (lib/sram)
- LCD module (lib/lcd + display.vhd)
- Clock/reset and any pushbuttons or switches (from de2.vhd)
b. Pattern Generator
- LFSR block (lib/lfsr) or PR block (src/pr) to produce ANN inputs
c. ANN Core
- Top-level ANN entity (src/ann/ann.vhd)
- Internally instantiates floating-point units (fp.vhd plus all fp_* IPs)
d. Floating-Point Arithmetic Units
- Separate IP blocks (fp_add, fp_sub, fp_mul, fp_div, fp_exp, fp_cmp)
- Connected via a shared bus or point-to-point with the ANN core
e. Controller
- .vhd invoking lcd.vhd to show results
f. Configuration/Project Files

##### Relationships and data flow
- LFSR/PR → ANN inputs
- ANN core → floating-point units (requests and results back)
- ANN outputs → display controller → LCD
- Clock and reset lines fanning out from a central clock generator module

##### Architectural patterns and design principles
- Modular IP-based design: each function packaged as a VHDL component
- Synchronous dataflow: all modules triggered on the common clock
- Separation of concerns: arithmetic (float lib), control/pattern gen (pr, lfsr), UI (LCD/display), compute (ANN)

##### Technologies and frameworks
- VHDL for all RTL
- Quartus II for synthesis, fitter, and programming (QSF/QPF)
- Altera DE2 board peripherals (SRAM, LCD)

c. Surround it with child modules: FPUs adjacent, SRAM below, pattern generator on the left, display on the right.

## Diagram (Mermaid)

```mermaid
flowchart TB
    subgraph "DE2 Board Wrapper"
        DE2["DE2 Top-Level Wrapper"]:::main
    end
    click DE2 "https://github.com/ziyan/altera-de2-ann/blob/master/src/de2.vhd"
    click DE2 "https://github.com/ziyan/altera-de2-ann/blob/master/src/de2.qsf"

    CLOCK["Clock/Reset Generator"]:::control

    subgraph "Pattern Generator" 
        LFSR["LFSR"]:::control
        PR["Pattern Recognition Logic"]:::control
    end
    click LFSR "https://github.com/ziyan/altera-de2-ann/blob/master/src/lib/lfsr/lfsr.vhd"
    click PR "https://github.com/ziyan/altera-de2-ann/blob/master/src/pr/patterns.vhd"
    click PR "https://github.com/ziyan/altera-de2-ann/blob/master/src/pr/pr.vhd"

    ANN["ANN Core"]:::compute
    click ANN "https://github.com/ziyan/altera-de2-ann/blob/master/src/ann/ann.vhd"
    click ANN "https://github.com/ziyan/altera-de2-ann/blob/master/src/ann.qpf"

    subgraph "Floating-Point Units"
        FPCommon["FP Common"]:::compute
        FPAdd["FP Add"]:::compute
        FPSub["FP Sub"]:::compute
        FPMul["FP Mul"]:::compute
        FPDiv["FP Div"]:::compute
        FPExp["FP Exp"]:::compute
        FPCmp["FP Cmp"]:::compute
    end
    click FPCommon "https://github.com/ziyan/altera-de2-ann/blob/master/src/lib/float/fp.vhd"
    click FPAdd "https://github.com/ziyan/altera-de2-ann/blob/master/src/lib/float/fp_add.vhd"
    click FPAdd "https://github.com/ziyan/altera-de2-ann/blob/master/src/lib/float/fp_add.qip"
    click FPSub "https://github.com/ziyan/altera-de2-ann/blob/master/src/lib/float/fp_sub.vhd"
    click FPSub "https://github.com/ziyan/altera-de2-ann/blob/master/src/lib/float/fp_sub.qip"
    click FPMul "https://github.com/ziyan/altera-de2-ann/blob/master/src/lib/float/fp_mul.vhd"
    click FPMul "https://github.com/ziyan/altera-de2-ann/blob/master/src/lib/float/fp_mul.qip"
    click FPDiv "https://github.com/ziyan/altera-de2-ann/blob/master/src/lib/float/fp_div.vhd"
    click FPDiv "https://github.com/ziyan/altera-de2-ann/blob/master/src/lib/float/fp_div.qip"
    click FPDiv "https://github.com/ziyan/altera-de2-ann/blob/master/src/lib/float/fp_div.hex"
    click FPExp "https://github.com/ziyan/altera-de2-ann/blob/master/src/lib/float/fp_exp.vhd"
    click FPExp "https://github.com/ziyan/altera-de2-ann/blob/master/src/lib/float/fp_exp.qip"
    click FPCmp "https://github.com/ziyan/altera-de2-ann/blob/master/src/lib/float/fp_cmp.vhd"
    click FPCmp "https://github.com/ziyan/altera-de2-ann/blob/master/src/lib/float/fp_cmp.qip"

    subgraph "Memory"
        SRAM["SRAM Interface"]:::memory
    end
    click SRAM "https://github.com/ziyan/altera-de2-ann/blob/master/src/lib/sram/sram.vhd"

    subgraph "Display"
        DisplayCtrl["Display Controller"]:::io
        LCD["LCD Interface"]:::io
    end
    click DisplayCtrl "https://github.com/ziyan/altera-de2-ann/blob/master/src/display/display.vhd"
    click LCD "https://github.com/ziyan/altera-de2-ann/blob/master/src/lib/lcd/lcd.vhd"

    %% Connections
    DE2 --> CLOCK
    CLOCK --> LFSR
    CLOCK --> PR
    CLOCK --> ANN
    CLOCK --> FPCommon
    CLOCK --> FPAdd
    CLOCK --> FPSub
    CLOCK --> FPMul
    CLOCK --> FPDiv
    CLOCK --> FPExp
    CLOCK --> FPCmp
    CLOCK --> SRAM
    CLOCK --> DisplayCtrl
    CLOCK --> LCD

    LFSR -->|data_out| ANN
    PR -->|patterns| ANN

    ANN -->|request/result| FPCommon
    ANN -->|request/result| FPAdd
    ANN -->|request/result| FPSub
    ANN -->|request/result| FPMul
    ANN -->|request/result| FPDiv
    ANN -->|request/result| FPExp
    ANN -->|request/result| FPCmp

    ANN -->|weights| SRAM
    ANN -->|output| DisplayCtrl
    DisplayCtrl -->|lcd_data| LCD

    classDef main fill:#f0f0f0,stroke:#333,stroke-width:2px
    classDef compute fill:#cce5ff,stroke:#004085
    classDef io fill:#d4edda,stroke:#155724
    classDef memory fill:#fff3cd,stroke:#856404
    classDef control fill:#f5c6cb,stroke:#721c24
```
