# renzel/clockvga architecture

> Architecture diagram of the GitHub repository renzel/clockvga, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-04-20). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/renzel/clockvga
- Repository: https://github.com/renzel/clockvga

## Overview

##### Project Type and Purpose
- This is an FPGA‐based VGA‐display clock.
- It generates a time display on a VGA monitor, using button/keyboard inputs and BCD/ASCII conversion.

##### File Structure
- TopClock.vhd: top‑level entity that instantiates all submodules.
- ClockNBtn.vhd: clock generator + button (or keyboard) interface.
- Bcd.vhd: binary‑to‑BCD converter for time digits.
- (Missing but implied) ASCII/binary converter: maps BCD digits to pixel patterns.
- vga_sync.vhd: VGA timing generator (HSYNC/VSYNC, blanking, pixel clock).

##### Core Components
a. Input Interfaces
– External 50 MHz (or board) clock input
– Push‑button or PS/2 keyboard lines
b. Clock & Debounce Module (ClockNBtn)
– Divides the board clock to a 1 Hz tick
– Debounces button or decodes keyboard scan codes
c. Time Encoding Module (Bcd)
– Converts binary time counter to four BCD digits (HH:MM)
d. Character Generator / ASCII Module
– Takes BCD digits, maps each “character” to an 8×8 pixel pattern in a ROM or lookup table
e. Video Buffer / Pixel Streamer (optional)
– Assembles pixel patterns into a raster‐scanable stream
f. VGA Synchronization Module (vga_sync)
– Generates HSYNC / VSYNC, blanking signals, pixel‐clock enable
g. TopClock (top‑level)
– Wires everything together, assigns FPGA pins for VGA analog outputs (R,G,B,HS,VS) and inputs

##### Architectural Patterns
- Pipeline flow from time base → digit encoding → video pipeline → VGA adapter.
- Modular VHDL hierarchy: TopClock sits at root, each submodule is a leaf node.
- Synchronous domains (pixel clock vs. system clock).

##### Technologies and Interfaces
- VHDL modules mapped to FPGA fabric.
- VGA analog interface (R,G,B DACs + HS/VS).
- PS/2 keyboard or GPIO push‑button interface.

##### Final Checklist
[ ] All major modules from the file tree are represented.
[ ] Connections between modules are complete and labeled.
[ ] Input pins (clock, button/keyboard) and output pins (VGA) are shown.
[ ] Data flows (time data and video data) are clearly distinguished.
[ ] Boundaries of clock domains are marked (50 MHz vs. pixel clock).

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Input layer
    ClockIn["50MHz Clock Input<br/>(FPGA pin)"]:::input
    ButtonPS2["Push-button / PS2 Keyboard"]:::input

    %% Top-level container
    subgraph "TopClock"
        direction TB
        CCN["Clock & Debounce Module<br/>(ClockNBtn.vhd)"]:::processing
        BCD["Time Encoding Module<br/>(Bcd.vhd)"]:::processing
        ASCII["ASCII ROM / Char Gen"]:::processing
        PS["Pixel Streamer"]:::processing
        SYN["VGA Sync Module<br/>(vga_sync.vhd)"]:::sync
    end

    %% Output
    VGAout["VGA Port<br/>(R,G,B,HS,VS)"]:::output

    %% Connections
    ClockIn -->|"sys_clk 50MHz"| CCN
    ButtonPS2 -->|"btn/key"| CCN
    CCN -->|"1Hz tick"| BCD
    BCD -->|"digit[3:0] (HH:MM)"| ASCII
    ASCII -->|"pixel_data[7:0]"| PS
    SYN -->|"pixel_clk_en"| PS
    PS -->|"pixel_clk"| SYN
    PS -->|"RGB data"| VGAout
    SYN -->|"HSYNC/VSYNC"| VGAout

    %% Click events
    click TopClock "https://github.com/renzel/clockvga/blob/master/TopClock.vhd"
    click CCN "https://github.com/renzel/clockvga/blob/master/ClockNBtn.vhd"
    click BCD "https://github.com/renzel/clockvga/blob/master/Bcd.vhd"
    click SYN "https://github.com/renzel/clockvga/blob/master/vga_sync.vhd"

    %% Styles
    classDef input fill:#ccffcc,stroke:#333,stroke-width:1px
    classDef processing fill:#cce5ff,stroke:#333,stroke-width:1px
    classDef sync fill:#ffe0b3,stroke:#333,stroke-width:1px
    classDef output fill:#ffcccc,stroke:#333,stroke-width:1px
```
