๐จ๐ณ ็ฎไฝไธญๆ ย |ย English
|
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.
|
โก Quick Peek |
๐บ๏ธ Quick Navigation ย ยทย ๐ Quick Start ย ยทย ๐ Current Status ย ยทย ๐จ Build & Simulation
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-ToeXcamera 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).
| ๐ญ 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 |
| ๐ฏ 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 |
Note
๐ Best first-read files:
Source/T35_Sensor_DDR3_LCD_Test.v,
Source/bsp/uart_screen.v,
Source/bsp/tictactoe_game_top.v
| ๐ท๏ธ 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 |
| ๐ 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 |
- Efinix Efinity IDE 2023.2 or later
- Efinix Trion T35F324 development board
- AR0135 camera module
- HDMI display
- 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 | โจ๏ธ 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
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ ๐ 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)
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-ToeUart_Stepper.v: selects the XY motion source โ UART FSM for Write/Draw, game logic for Tic-Tac-Toetictactoe_game_top.v: always instantiated; its AI-generated XY output is only forwarded to the motion path whenfunction_mode == 2'd2
๐ฆ 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
- ๐งฌ Top-level RTL:
Source/T35_Sensor_DDR3_LCD_Test.v - ๐งช Testbench:
Source/T35_Sensor_DDR3_LCD_Test_tb.v - ๐ฅ๏ธ Screen command parser:
Source/bsp/uart_screen.v - โ๏ธ๐จ Write/Draw โ UART motion FSM:
Source/bsp/uart_fsm_top.v - โ๏ธ๐จ Write/Draw โ XY coordinate parser:
Source/bsp/fsm_xy_decode.v - โ๏ธ๐จ Write/Draw โ Z-axis parser:
Source/bsp/fsm_z_decode.v - โ๏ธ๐จ Write/Draw โ XY interpolation:
Source/bsp/XY_motion.v - โ๏ธ Motion backend:
Source/bsp/Uart_Stepper.v - ๐ฉ Motor controller:
Source/bsp/motor_ctrl.v - ๐ฎ Tic-Tac-Toe โ Game controller:
Source/bsp/tictactoe_game_top.v - ๐ฎ Tic-Tac-Toe โ Move strategy:
Source/bsp/Game_strategies.v - ๐ฎ Tic-Tac-Toe โ Winner detection:
Source/bsp/winner.v - ๐ฎ Tic-Tac-Toe โ Coordinate mapping:
Source/bsp/transfer_data.v
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.
cd Efinity/work_syn
./run_efx_map.shNote
๐ 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.
cd Efinity/work_pnr
./run_efx_pnr.shcd Efinity/work_pnr
./run_efx_pgm.shThe 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
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 |
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.
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:
- ๐ Wait for
Xprefix โ enter X integer parsing - โก On
.โ switch to X decimal parsing (counts digits for proper scaling) - ๐ On
Yโ switch to Y parsing - โ
On
\r,\n,F, orZโ finalize, latch the parsed values as a relative displacement, and pulseout_ento the motion pipeline.
Each new XY packet computes a delta from the previously latched position, so the motion commands are inherently relative moves.
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.
| ๐ญ 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;- โก Power on, wait for DDR3 calibration and video output to stabilize.
- ๐ฒ Send
@(Write) or#(Draw) from the touch screen to select the mode. - ๐จ Send XY coordinate strings over the motion UART to trace the desired path.
- โฌ๏ธโฌ๏ธ Use
Zcommands to lift and lower the pen between strokes. - ๐ Send
$at any time to zero/home the mechanism.
- โก Power on the board and wait for sensor initialization.
- โณ Wait until DDR3 calibration and video output are stable.
- ๐ฒ Send
Xto enter Tic-Tac-Toe mode. - โซโช Send
BorWto choose the AI side. - ๐ค๐ง Send
NorMto choose turn order. - ๐ Send
Sto start a new game. - โ
After the human move, send
Cto confirm the board update. - ๐ The FPGA resamples the board, computes the next move, and drives the mechanism.
- ๐ Winner and tie checks run after each confirmed move.
๐ Implementation Notes
- ๐ท camera input is cropped by
Source/Sensor_Image_XYCrop.v - ๐พ frames are buffered through DDR3 by
Source/axi/axi4_ctrl.v - ๐บ display output is generated by
Source/lcd_driver.vplus HDMI logic
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-ToeThis 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.
- ๐ก
Source/bsp/uart_fsm_top.v: top-level UART motion FSM - ๐
Source/bsp/fsm_xy_decode.v: XY coordinate string parser, outputs signed 20-bit integer + decimal pairs - โฌ๏ธโฌ๏ธ
Source/bsp/fsm_z_decode.v: Z-axis command parser (Z-= down,Z<digit>= up) - โ
Source/bsp/add_inte_deci.v: signed fixed-point adder, computes relative displacement between consecutive packets - ๐๏ธ
Source/bsp/sync_fifo_cnt.v: FIFO buffer decoupling the UART receive rate from the motion execution rate
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_XIEstate). - โก๏ธ When one axis is within 100 units of its target, it switches to single-axis correction (straight,
D_ZHIstate). - โ๏ธ Each motor is driven by a dedicated
motor_ctrlinstance that generates step/direction pulses.
- ๐ฅ๏ธ
Source/bsp/uart_screen.v: touch-screen command decode - ๐๏ธ
Source/bsp/tictactoe_game_top.v: top-level game sequencing - ๐ง
Source/bsp/Game_strategies.v: move selection with prioritywin > block > first empty - ๐
Source/bsp/winner.v: winner and tie evaluation
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 piece2'b10= โช white piece2'b00= โฌ empty
Detection thresholds use 40/140, while the HDMI overlay path uses 40/120
through yan_lcd_data for visualization.
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.
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) |
- ๐ก 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.
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