Skip to content

Latest commit

ย 

History

3 Commits

Folders and files

NameName
Last commit message
Last commit date
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

๐Ÿ–ฅ๏ธ FPGA Multi-Mode Interactive System

๐Ÿ‡จ๐Ÿ‡ณ ็ฎ€ไฝ“ไธญๆ–‡ ย |ย  English

Platform Language Toolchain Video Memory

๐ŸŽฏ A tidy little FPGA system with three working personalities

Built on Efinix Trion T35F324, this project combines real-time camera capture, DDR3 frame buffering, HDMI display, touch interaction, UART motion control, and physical execution in a single Verilog RTL design.

โœ๏ธ Write @โ€‚ ๐ŸŽจ Draw #โ€‚ ๐ŸŽฎ Tic-Tac-Toe X

โšก Quick Peek
๐Ÿฅ‡ Best demo: physical Tic-Tac-Toe
๐Ÿ›ค๏ธ Active path: AR0135 DVP โ†’ DDR3 โ†’ HDMI
๐Ÿฆด Shared backbone: video, UART, and 3-axis motion
๐Ÿ“– Best first read: T35_Sensor_DDR3_LCD_Test.v + uart_screen.v

๐Ÿ—บ๏ธ Quick Navigation ย ยทย  ๐Ÿš€ Quick Start ย ยทย  ๐Ÿ“Š Current Status ย ยทย  ๐Ÿ”จ Build & Simulation


๐Ÿ“ธ Project Snapshot

Tip

๐Ÿ’ก Think of this repository as one FPGA backbone wearing three different hats: @ for careful writing, # for faster drawing, and X for closed-loop robotic play.

โœ๏ธ

Write
@
slower and steadier pen tracing over UART XY paths

๐ŸŽจ

Draw
#
the same coordinate pipeline, tuned for quicker sketching

๐ŸŽฎ

Tic-Tac-Toe
X
camera sensing, move planning, and physical pick-and-place

This repository exposes three interactive modes over a shared Verilog RTL backbone: camera capture, DDR3 buffering, HDMI display, UART communication, and 3-axis stepper motion.

The checked-in project is most complete in its physical Tic-Tac-Toe path, which closes the loop from live video all the way to piece manipulation. The Write and Draw modes share the same UART motion backend and are fully functional for coordinate-driven XY motion; they differ mainly in stepper speed (Write is slower for controlled pen strokes, Draw is faster for sketching).


๐Ÿ—บ๏ธ Quick Navigation

๐Ÿ’ญ If you want to... ๐Ÿ“‚ Start here
๐Ÿ” check what is already wired and demoable Current Status
๐Ÿงญ find the main RTL route into each mode Key entry points
๐Ÿ”จ rebuild synthesis, PnR, or bitstream output Build and Simulation
๐Ÿ•น๏ธ drive Write / Draw motion over UART Control Reference
๐Ÿ”ฌ peek into the closed-loop game flow System Internals

๐Ÿš€ Quick Start

๐ŸŽฏ Scenario ๐Ÿ‘ฃ First move
๐Ÿ“– Read the active design Start with Source/T35_Sensor_DDR3_LCD_Test.v, then follow uart_screen.v into the mode-specific logic
๐Ÿ–Š๏ธ Bring up pen motion Select @ or # on the touch screen, then send XY packets on the motion UART
๐Ÿค– Demo physical Tic-Tac-Toe Enter X, choose side and turn order, then start the round with S
๐Ÿ” Rebuild the FPGA image Use the scripts in Efinity/work_syn and Efinity/work_pnr after adjusting the exported paths for your machine

โœจ Highlights

๐Ÿท๏ธ Area โœ… What is included
๐Ÿ“น Video pipeline CMOS camera input, crop, DDR3 frame buffer, HDMI/LCD output
โœ๏ธ Write mode UART XY-coordinate parser, precision-speed stepper motion for pen tracing
๐ŸŽจ Draw mode Same coordinate pipeline as Write, higher stepper speed for sketching
๐Ÿง  Game logic Board sampling, move strategy, winner check, game-state control
๐Ÿ‘† Interaction Touch-screen mode selection and control commands over UART
โš™๏ธ Motion 3-axis stepper coordination (XY interpolation + Z pen lift), piece pickup/release
๐Ÿ“ฆ Build assets Efinity project, timing constraints, generated IP, archived reports

๐Ÿ“Š Current Status

๐Ÿ“‹ Item ๐Ÿšฆ Status ๐Ÿ“ Notes
๐Ÿ” Top-level build โœ… Active Source/T35_Sensor_DDR3_LCD_Test.v
๐Ÿ“ก Active sensor path โœ… Ready AR0135 DVP โ†’ crop โ†’ DDR3 โ†’ HDMI/LCD
๐ŸŽฎ Tic-Tac-Toe mode ๐Ÿ† Most complete Detection, strategy, winner check, XYZ execution
โœ๏ธ Write mode โœ… Ready Selectable via @, UART XY coordinate parser + slower precision stepper motion
๐ŸŽจ Draw mode โœ… Ready Selectable via #, same UART protocol as Write + faster stepper motion
๐Ÿ—‚๏ธ Alternate sensor LUTs ๐Ÿ“Ž Included OV5640, SC130GS, MT9M001, IMX219
๐Ÿ”Œ MIPI path ๐Ÿšง Partial scaffolding Ports and constraints remain, but DVP/AR0135 is the active path

๐Ÿ”ฉ Hardware and Tools

๐Ÿ› ๏ธ Toolchain

  • Efinix Efinity IDE 2023.2 or later

๐Ÿงฑ Hardware for the active build

  • Efinix Trion T35F324 development board
  • AR0135 camera module
  • HDMI display

๐Ÿฆพ Extra hardware for the physical Tic-Tac-Toe setup

  • touch screen using the documented UART protocol
  • 3-axis stepper mechanism
  • electromagnet or equivalent end effector for piece pickup

Tip

๐Ÿ’ก If you only want to inspect, simulate, or rebuild the video path, the motion hardware is not required.


๐ŸŽ›๏ธ Mode Summary

๐ŸŽญ Mode โŒจ๏ธ Command โšก Speed (DIV) ๐Ÿงฉ Core modules ๐Ÿ“– Description
โœ๏ธ Write @ 1000 uart_screen, uart_fsm_top, XY_motion, motor_ctrl Precision-speed XY pen tracing via UART coordinates
๐ŸŽจ Draw # 800 Same as Write Faster XY sketching via UART coordinates
๐ŸŽฎ Tic-Tac-Toe X 800 All of the above + tictactoe_game_top, Game_strategies, winner, transfer_data Vision + strategy + robotic execution

๐Ÿ”ฌ System Internals

๐Ÿ”„ System Flow

                  โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
                  โ”‚     ๐Ÿ‘† Touch Screen (UART)            โ”‚
                  โ”‚  Mode: @ / # / X    Commands: S B Wโ€ฆ  โ”‚
                  โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
                                โ”‚
        โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
        โ”‚                       โ”‚                           โ”‚
        v                       v                           v
   โœ๏ธ Write Mode (@)      ๐ŸŽจ Draw Mode (#)       ๐ŸŽฎ Tic-Tac-Toe Mode (X)
   function_mode=0         function_mode=1          function_mode=2
        โ”‚                       โ”‚                           โ”‚
        โ”‚                       โ”‚                           v
        โ”‚                       โ”‚              ๐Ÿ“ท Camera โ†’ โœ‚๏ธ Crop โ†’ ๐Ÿ’พ DDR3 โ†’ ๐Ÿ“บ HDMI
        โ”‚                       โ”‚                           โ”‚
        โ”‚                       โ”‚                           v
        โ”‚                       โ”‚                 ๐Ÿ“Š Board-State Sampling
        โ”‚                       โ”‚                   (9-cell, 18-bit)
        โ”‚                       โ”‚                           โ”‚
        โ”‚                       โ”‚                           v
        โ”‚                       โ”‚            ๐Ÿง  Game Strategy + ๐Ÿ† Winner Check
        โ”‚                       โ”‚                           โ”‚
        v                       v                           v
        โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
                                โ”‚
                                v
                   ๐Ÿ“จ UART XY Coordinate Parser
               (X<int>.<dec>Y<int>.<dec> + Z<cmd>)
                                โ”‚
                                v
                 ๐Ÿ”€ XY Interpolation + โฌ†๏ธโฌ‡๏ธ Z Lift Control
                      (3-axis stepper motors)
                                โ”‚
                                v
                       ๐Ÿค– Physical Execution
                  (pen on paper / piece pick & place)

๐Ÿงญ Mode routing in hardware

The top-level signal function_mode (2-bit) is decoded by uart_screen.v from the touch-screen UART commands @, #, and X. This single signal then gates behavior throughout the design:

  • motor_ctrl.v: selects stepper speed โ€” DIV=1000 for Write, DIV=800 for Draw/Tic-Tac-Toe
  • Uart_Stepper.v: selects the XY motion source โ€” UART FSM for Write/Draw, game logic for Tic-Tac-Toe
  • tictactoe_game_top.v: always instantiated; its AI-generated XY output is only forwarded to the motion path when function_mode == 2'd2

๐Ÿ“ Repository Layout

๐Ÿ“ฆ T35_Write_Draw_Play/
โ”œโ”€โ”€ ๐Ÿ“‚ Source/
โ”‚   โ”œโ”€โ”€ ๐Ÿ“„ T35_Sensor_DDR3_LCD_Test.v      # Active top-level RTL
โ”‚   โ”œโ”€โ”€ ๐Ÿ“„ T35_Sensor_DDR3_LCD_Test_tb.v   # Legacy top-level smoke testbench
โ”‚   โ”œโ”€โ”€ ๐Ÿ“‚ axi/                            # AXI4 control and interconnect
โ”‚   โ”œโ”€โ”€ ๐Ÿ“‚ bsp/                            # Tic-Tac-Toe, UART, motion control
โ”‚   โ”œโ”€โ”€ ๐Ÿ“‚ cmos_i2c/                       # Sensor config LUTs and capture helpers
โ”‚   โ”œโ”€โ”€ ๐Ÿ“‚ hdmi_ip/                        # HDMI wrapper IP
โ”‚   โ”œโ”€โ”€ ๐Ÿ“‚ rgb2dvi/                        # Adapted RGB2DVI IP
โ”‚   โ””โ”€โ”€ ๐Ÿ“‚ isp/                            # ISP blocks, including interpolation
โ””โ”€โ”€ ๐Ÿ“‚ Efinity/
    โ”œโ”€โ”€ ๐Ÿ“„ T35_Sensor_DDR3_LCD_Test.xml    # Project file
    โ”œโ”€โ”€ ๐Ÿ“„ T35_Sensor_DDR3_LCD_Test.sdc    # Timing constraints
    โ”œโ”€โ”€ ๐Ÿ“„ T35_Sensor_DDR3_LCD_Test.peri.xml
    โ”œโ”€โ”€ ๐Ÿ“‚ ip/                             # Vendor-generated IP
    โ”œโ”€โ”€ ๐Ÿ“‚ work_syn/                       # Synthesis scripts
    โ”œโ”€โ”€ ๐Ÿ“‚ work_pnr/                       # Place-and-route scripts
    โ””โ”€โ”€ ๐Ÿ“‚ outflow/                        # Archived reports and outputs

๐Ÿ”‘ Key entry points


๐Ÿ”จ Build and Simulation

The repository already includes an Efinity project plus archived implementation outputs. The checked-in shell scripts are export artifacts from the original Windows environment, so you should expect to adjust tool paths and workspace paths before re-running them on another machine.

๐Ÿงฑ Synthesis

cd Efinity/work_syn
./run_efx_map.sh

Note

๐Ÿ“ run_efx_map.sh currently contains absolute D:/... and E:/... paths from the original setup, so treat it as a reference command line unless your environment matches that layout.

๐Ÿ“ Place and route

cd Efinity/work_pnr
./run_efx_pnr.sh

๐Ÿ’ฟ Bitstream generation

cd Efinity/work_pnr
./run_efx_pgm.sh

๐Ÿงช Simulation

The repository includes a legacy top-level testbench at Source/T35_Sensor_DDR3_LCD_Test_tb.v. It is best treated as a smoke-test harness for clocks, DDR-side handshaking, and I2C bring-up rather than a faithful simulation of the currently active AR0135 DVP capture path.

It includes:

  • โฐ clock generation
  • ๐Ÿ“ฅ stubbed frame/input stimulus
  • ๐Ÿ”Œ I2C simulation support

For faster simulation turnaround, set SIM_I2C = 1 to shrink the I2C configuration sequence to 3 writes.


๐Ÿ•น๏ธ Control Reference

๐Ÿ‘† Touch-Screen Commands

Screen UART: 115200 bps, 8-N-1

โŒจ๏ธ Command โš™๏ธ Function
S ๐Ÿ†• Start a new game
@ โœ๏ธ Select Write mode
# ๐ŸŽจ Select Draw mode
X ๐ŸŽฎ Select Tic-Tac-Toe mode
B โšซ Set AI side to black (2'b01)
W โšช Set AI side to white (2'b10)
N ๐Ÿค– AI plays first
M ๐Ÿง‘ Human plays first
C โœ… Confirm the human move is finished
$ ๐Ÿ  Trigger zero/home
T โฌ†๏ธ Request the touch-screen Z-up helper command
D โฌ‡๏ธ Request the touch-screen Z-down helper command

๐Ÿ“จ UART Motion Protocol (Write / Draw modes)

Write and Draw modes are driven by a second UART channel (motion control UART, 115200 bps, 8-N-1) that receives raw XY coordinate strings. This path is handled by Source/bsp/uart_fsm_top.v and its sub-modules fsm_xy_decode.v / fsm_z_decode.v.

๐Ÿ“ XY coordinate format

X<int>.<dec>Y<int>.<dec>\r\n
๐Ÿท๏ธ Element ๐Ÿ’ฌ Meaning ๐Ÿ“‹ Example
X X-axis prefix X
<int> Integer part (signed, multi-digit) 10, -5
. Decimal separator .
<dec> Decimal part (1โ€“3 digits) 500 (= 0.500), 0
Y Y-axis prefix Y
<int>.<dec> Y value (same format as X) -5.200
\r\n Terminator (CR+LF) implicit

๐Ÿ“ Examples:

๐Ÿ“จ Payload ๐Ÿ’ฌ Meaning
X10.500Y-5.200\r\n Move X+10.500, Yโˆ’5.200 (relative to current position)
X0.0Y0.0\r\n No-op (zero displacement)
X-3.0Y2.15\r\n Move Xโˆ’3.000, Y+2.150

The fsm_xy_decode state machine parses each character on-the-fly:

  1. ๐Ÿ” Wait for X prefix โ†’ enter X integer parsing
  2. โšก On . โ†’ switch to X decimal parsing (counts digits for proper scaling)
  3. ๐Ÿ” On Y โ†’ switch to Y parsing
  4. โœ… On \r, \n, F, or Z โ†’ finalize, latch the parsed values as a relative displacement, and pulse out_en to the motion pipeline.

Each new XY packet computes a delta from the previously latched position, so the motion commands are inherently relative moves.

โฌ†๏ธโฌ‡๏ธ Z-axis control

The Z-axis is controlled independently via the Z command on the same UART:

๐Ÿ“จ Payload โšก Action
Z0.00\r\n or Z<any positive> โฌ†๏ธ Z up
Z-4.00\r\n โฌ‡๏ธ Z down

The fsm_z_decode module handles these: a Z followed by - sets Z down; a Z followed by a digit sets Z up.

On the touch-screen UART, T and D are convenience commands that inject these Z messages into the motion UART path. They do not directly toggle the electromagnet in RTL. In Tic-Tac-Toe mode, the electromagnet output is driven by the game-state machine.

โšก Speed difference: Write vs Draw

๐ŸŽญ Mode function_mode โš™๏ธ Stepper DIV โœจ Effect
โœ๏ธ Write 2'b00 1000 Slower, precise pen strokes for character tracing
๐ŸŽจ Draw 2'b01 800 Faster motion for sketching shapes and lines

The speed is selected in motor_ctrl.v line 21:

assign CLK_DIV = (function_mode != 2'b0) ? 16'd800 : 16'd1000;

๐Ÿ”„ Typical Write / Draw workflow

  1. โšก Power on, wait for DDR3 calibration and video output to stabilize.
  2. ๐Ÿ“ฒ Send @ (Write) or # (Draw) from the touch screen to select the mode.
  3. ๐Ÿ“จ Send XY coordinate strings over the motion UART to trace the desired path.
  4. โฌ†๏ธโฌ‡๏ธ Use Z commands to lift and lower the pen between strokes.
  5. ๐Ÿ  Send $ at any time to zero/home the mechanism.

๐ŸŽฎ Tic-Tac-Toe Workflow

  1. โšก Power on the board and wait for sensor initialization.
  2. โณ Wait until DDR3 calibration and video output are stable.
  3. ๐Ÿ“ฒ Send X to enter Tic-Tac-Toe mode.
  4. โšซโšช Send B or W to choose the AI side.
  5. ๐Ÿค–๐Ÿง‘ Send N or M to choose turn order.
  6. ๐Ÿ†• Send S to start a new game.
  7. โœ… After the human move, send C to confirm the board update.
  8. ๐Ÿ”„ The FPGA resamples the board, computes the next move, and drives the mechanism.
  9. ๐Ÿ† Winner and tie checks run after each confirmed move.

๐Ÿ“‹ Implementation Notes

๐Ÿ—๏ธ Architecture Notes

๐Ÿ“น Video path

๐ŸŽ›๏ธ Mode selection

The top-level signal function_mode (2-bit) is decoded in Source/bsp/uart_screen.v from touch-screen UART:

// function_mode: Write=0, Draw=1, Tic-Tac-Toe=2
if (po_data == "@") function_mode <= 2'd0;   // Write
if (po_data == "#") function_mode <= 2'd1;   // Draw
if (po_data == "X") function_mode <= 2'd2;   // Tic-Tac-Toe

This signal controls speed selection in motor_ctrl.v and XY source selection in Uart_Stepper.v. The Tic-Tac-Toe controller remains instantiated at the top level; in practice, function_mode gates whether its generated XY moves are forwarded into the motion pipeline.

โœ๏ธ๐ŸŽจ Write / Draw: UART coordinate pipeline

The parsed XY deltas feed into Source/bsp/XY_motion.v, which performs a Bresenham-like interpolation:

  • ๐Ÿ”€ When both X and Y need to move, it steps both motors simultaneously (diagonal, D_XIE state).
  • โžก๏ธ When one axis is within 100 units of its target, it switches to single-axis correction (straight, D_ZHI state).
  • โš™๏ธ Each motor is driven by a dedicated motor_ctrl instance that generates step/direction pulses.

๐ŸŽฎ Tic-Tac-Toe: game logic

๐Ÿ“Š Board-state detection

The top-level RTL samples fixed video coordinates for the 9 cells and stores the result in an 18-bit current_board signal:

  • 2'b01 = โšซ black piece
  • 2'b10 = โšช white piece
  • 2'b00 = โฌœ empty

Detection thresholds use 40/140, while the HDMI overlay path uses 40/120 through yan_lcd_data for visualization.


โฐ Clocking

The design spans multiple clock domains. Relevant constraints are defined in Efinity/T35_Sensor_DDR3_LCD_Test.sdc.

๐Ÿ• Clock ๐ŸŽฏ Purpose
Axi0Clk AXI4 and DDR3-side user logic
Ddr0Clk DDR3 memory interface
hdmi_clk1x_i HDMI pixel clock
hdmi_clk2x_i HDMI serialization clock
hdmi_clk5x_i HDMI TMDS bit clock
cmos_pclk Camera pixel clock
clk_cmos Camera support clock
tx_slowclk UART and game-system clock
tx_fastclk Faster control clock

MIPI-related clocks are still present for alternate sensor integration work.


๐Ÿ“Š Resource Utilization

Figures below come from the archived Efinity reports in Efinity/outflow/, generated on November 30, 2024:

๐Ÿ“ฆ Resource ๐Ÿ“Š Utilization
๐ŸŽฏ Target device Efinix Trion T35F324 (C4)
๐Ÿงฎ Logic elements 9122 / 31680 (28.79%)
๐Ÿ“ LUTs / adders 8703 / 31680 (27.47%)
๐Ÿ—‚๏ธ Registers 3642 / 30720 (11.86%)
๐Ÿ’พ Memory blocks 18 / 288 (6.25%)
โœ–๏ธ Multipliers / DSP 4 / 120 (3.33%)
๐Ÿ• PLLs used 4 (AxiPLL, DdrPLL, HdmiPLL, MipiPLL)

โš ๏ธ Known Limitations

  • ๐Ÿ“ก The active checked-in capture path is AR0135 over DVP.
  • ๐Ÿ—‚๏ธ Alternate sensor configuration files are included, but non-AR0135 paths still need top-level integration.
  • ๐Ÿ”Œ MIPI-related ports and constraints are present, but MIPI is not the active capture path.
  • โœ๏ธ๐ŸŽจ Write/Draw modes are functional for UART-driven XY motion; they do not include on-chip font rendering or G-code parsing โ€” the host side must send pre-computed coordinate sequences.
  • ๐ŸŽฎ Tic-Tac-Toe detection relies on fixed sampling coordinates and hard-coded thresholds.
  • ๐Ÿฆพ The physical robot path assumes a calibrated mechanism and coordinate map.

๐Ÿ“œ License

This repository includes third-party IP with their own licensing terms. Check file headers and bundled license files before redistribution or reuse.

  • Source/rgb2dvi/: Digilent license, see License.txt
  • LCD / I2C modules: CrazyBingo copyright notices
  • ISP modules: CrazyBird copyright notices
  • BSP game logic: project-specific competition code

๐Ÿ–ฅ๏ธ Built with Verilog HDL on Efinix Trion T35F324 ย |ย  ๐ŸŽฏ Three modes, one backbone

About

A hardware-centric interactive system that combines live vision, display, writing, drawing, game logic, and motion control on a single Trion T35 platform.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages