Skip to the content
4 layers76.2 × 63.5 mmPet on a chip, the printed circuit board in 3D

Senior Design

Size
76.2 × 63.5 mm
Copper layers
4
Thickness
1.6 mm
Parts
69
Nets
159
Pads
417
Tracks, vias
1,058, 91
Pours
2
Routed
Yes
KiCad
KiCad 8.0 (file 20240108)
Created
14 Apr 2021
Updated
31 Oct 2026

Overview

Pet on a chip is an open-source printed circuit board by ept221, from the ept221/pet-on-a-chip repository on GitHub, published under the MIT licence. It is a 4-layer board of 76.2 × 63.5 mm with 69 parts on 159 nets, routed with 1,058 tracks and 91 vias.

It is built around the ICE40HX8K-BG121, N25Q032A13ESC40F and FT2232HL, with the L77HDE15SD1CH4F, LDL1117S33R and TLV70012DDCR among its other parts. Its parts include 28 capacitors, 21 resistors, 7 ICs, 4 connectors and 3 diodes. It belongs with the robots and motor control and fPGA and programmable logic boards and the FPGA and CPLD boards of this library.

Main components

6

README

README.md

Pet On A Chip

Pet on a chip is a project which condenses the control logic the robot described in Frank DaCosta's book "How to Build Your Own Working Robot Pet" onto a single FPGA. More details, pictures, and videos can be found on this blog post.

tinySoC

tinySoC is a small system on a chip responsible for controlling the robot. It consists of an 8-bit CPU, an 80 column VGA graphics controller, a programmable interrupt controller, GPIO, counter/timer peripherals, dual closed loop motor controllers, a servo controller, a sonar controller, and a UART, all implemented on an iCE40 FPGA. It also comes with an assembler and utilities for loading programs into the chip's internal block memory without having to rerun synthesis and place-and-route.

The CPU

datapath The CPU is an 8-bit RISC core, with a Harvard architecture. It has a 16-bit wide instruction memory, an 8-bit wide data memory, and both have a 16-bit address. The CPU has 16 general purpose 8-bit registers along with a 4-bit status register. The processor is not fully pipelined, but does fetch the next instruction while executing the current one. Most instructions execute in a single clock cycle, but a few take two or three.

The GPU

gpu The GPU operates in a monochrome 80 column text mode, and outputs a VGA signal at a resolution of 640 by 480 at 60 frames per second. The GPU contains an ASCII buffer which the user can write to in order to display messages on the screen. A control register allows the user to set the text to one of 7 colors, and to enable an interrupt to the CPU which fires every time a frame finishes and enters the blanking period. Not shown in the diagram is control logic that allows the screen to be scrolled upwards by writing to the control register.

The Instruction Set

instruction set part 1 instruction set part 2

The PCBs

The main board: Delux Pet on a Chip The expantion board: Daughter Board

The Assembler

The assembler is case insensitive.

Comments

Comments begin with semicolons.

assembly
        .code
        ldi r0, 1 ; This is a comment

Constants

Constants are in decimal by default, but hexadecimal and binary are also supported. Constants can also be negative and are stored in two's complement form when assembled. Chars can also be entered as constants.

assembly
        .code
        ldi r0, 10     ; Decimal constant
        ldi r0, 0x0A   ; Hexadecimal constant
        ldi r0, 0b1010 ; Binary constant
        ldi r0, -10    ; A negative constant
        ldi r0, 'a'    ; A char constant
        ldi r0, '\n'   ; An escaped char constant

Label Definitions

Label definitions may be any string ending with a colon, as long as the string is not in the form of a constant or is one of the reserved keywords

assembly
        .code
        ldi r0, 10
loop:   adi r0, -1
        bnz loop
        hlt

Directives

.code

Specifies that the following lines are code to be assembled and placed in instruction memory.

.data

Specifies that the following lines are data to be placed in data memory.

.org

Sets the origin to the given address. Only forward movement of the origin is permitted.

assembly
        .code
        ldi r0, 1
        out r0, 0
        br foo
        
        .org 0x0B
foo:    out r0, 1
        hlt

;*************************************************************************
; Assembles to the following:
; Address        Label          Code                     Source
; ------------------------------------------------------------------------
; 0x0000                        0b0000000000010001       LDI R0, 1        
; 0x0001                        0b0000000000001001       OUT R0, 0        
; 0x0002                        0b0000000010011110       BR FOO           
; 0x000B         FOO:           0b0000000000011001       OUT R0, 1        
; 0x000C                        0b1111111111111111       HLT 
.db

Writes one or more data bytes sequentially into data memory.

assembly
        .data
        .db 0x01, 0x44, 0x73

;*************************************************************************
; Assembles to the following:
; Address        Label          Data
; ------------------------------------------
; 0x0000                        0x01
; 0x0001                        0x44
; 0x0002                        0x73
.ds

Defines a block of space in the data memory. This is useful for allocating room for a buffer.

assembly
        .data
        .db 5
        .ds 3
        .db 7

;*************************************************************************
; Assembles to the following:
; Address        Label          Data
; ------------------------------------------
; 0x0000                        0x05                                         
; 0x0004                        0x07 
.string

Writes a null terminated ASCII string into data memory. Double quotes and backslashes must be escaped with a backslash.

assembly
        .data
        .string "The robot says \"Hi!\""
        
;*************************************************************************
; Assembles to the following:
; Address        Label          Data
; ------------------------------------------
; 0x0000                        0x54
; 0x0001                        0x68
; 0x0002                        0x65
; 0x0003                        0x20
; 0x0004                        0x72
; 0x0005                        0x6F
; 0x0006                        0x62
; 0x0007                        0x6F
; 0x0008                        0x74
; 0x0009                        0x20
; 0x000A                        0x73
; 0x000B                        0x61
; 0x000C                        0x79
; 0x000D                        0x73
; 0x000E                        0x20
; 0x000F                        0x22
; 0x0010                        0x48
.ostring

Write a ASCII string into data memory. The string is open, which means that it is not null terminated. This is useful if you have a long string that you want to split up into multiple lines in the assembly source file.

assembly
        .data
        .ostring "Hi! "
        .string  "Bye!"

;*************************************************************************
; Assembles to the following:
; Address        Label          Data
; ------------------------------------------
; 0x0000                        0x48
; 0x0001                        0x69
; 0x0002                        0x21
; 0x0003                        0x20
; 0x0004                        0x42
; 0x0005                        0x79
; 0x0006                        0x65
; 0x0007                        0x21
; 0x0008                        0x00
.define

Equates a symbol with a number.

assembly
        .code
        .define foo, 5
        ldi r0, foo
        hlt
        
;*************************************************************************
; Assembles to the following:        
; Address        Label          Code                     Source
; ------------------------------------------------------------------------
; 0x0000                        0b0000000001010001       LDI R0, FOO     
; 0x0001                        0b0000000011110000       HLT  

Expressions

Any time an instruction or directive requires a numerical argument, an expression can be used. Supported operations inside expressions include addition and subtraction. The location counter $ is also made available. If an instruction is two bytes long then $ refers to the address of the second byte. Expressions may contain symbols, but must resolve within two passes of the assembler, and if used for directive arguments, must resolve in a single pass.

assembly
; Example resolution in one pass
        .code
        .define foo, 5
        ldi r0, foo + 7
        hlt

;*************************************************************************
; Assembles to the following:
; Address        Label          Code                     Source
; ------------------------------------------------------------------------
; 0x0000                        0b0000000011000001       LDI R0, FOO + 7
; 0x0001                        0b0000000011110000       HLT
assembly
; Example resolution in two passes
        .code
        ldi r0, foo + 7
        hlt
        .define foo, 5

;*************************************************************************
; Assembles to the following:
; Address        Label          Code                     Source
; ------------------------------------------------------------------------
; 0x0000                        0b0000000011000001       LDI R0, FOO + 7
; 0x0001                        0b0000000011110000       HLT
assembly
; Example resolution in two passes with $
        .code
        ldi r0, $
        jmp $ + foo
        .define foo, 2
        nop
        nop
        nop
        hlt

;*************************************************************************
; Assembles to the following:
; Address        Label          Code                     Source
; ------------------------------------------------------------------------
; 0x0000                        0b0000000000000001       LDI R0, $
; 0x0001                        0b0000000010111000       JMP $ + FOO
; 0x0002                        0b0000000000000100
; 0x0003                        0b0000000000000000       NOP
; 0x0004                        0b0000000000000000       NOP
; 0x0005                        0b0000000000000000       NOP
; 0x0006                        0b0000000011110000       HLT

The Development Process

To perform synthesis and place-and-route, run:

bash
make synth
make pnr

To assemble a demo program, run:

bash
./assemble programs/shell.asm shell

To upload the configuration bitstream for the previously assembled program, run:

bash
./upload shell

You will now be able to interact with a basic shell over the UART at 115200 baud. Additionally, the output will also be sent over the VGA interface.

Requirements

  • Yosys for synthisis
  • nextpnr for place and route
  • icestorm tools for icebram and iceprog

Peripherals

There are a variety of memory mapped peripherals included in the system. The memory map is configured in soc/src/d_ram_and_io/d_ram_and_io.v. Currently addresses 0x0000 to 0x07FF are mapped to data ram. The peripherals are mapped from 0x1000 to 0x10FF. The instructions in and out are designed to allow for quickly and easily reading and writing to peripherals within this address range. For example, out r1, 5 writes the value in r1 to address 0x1005. In contrast, when reading and writing to data memory, or writing to the graphics buffer which is from 0x2000 to 0x2960, in and out cannot be used, and the other load and store instructions must be used instead, which require setting up a pointer in a register pair to the memory location you want to operate on.

GPIO

AddressRegisterr/wDescription
0x1000Directionr/wSets GPIO pins to input or output
0x1001Portr/wWrite values to be outputed
0x1002PinrRead values on pins

Counter Timer

AddressRegisterr/wDescription
0x1003Scale LSBr/w
0x1004Scale MSBr/w
0x1005Controlr/w
0x1006CMPR0r/w
0x1007CMPR1r/w
0x1008Counterr

UART

AddressRegisterr/wDescription
0x1009Baudr/wConfigures the baudrate
0x100AStatusrSignals empty tx buffer and or full rx buffer
0x100BBufferr/wWrite to tx buffer, read from rx buffer

Motor Controller

AddressRegisterr/wDescription
0x100CControlr/wSets the motors' directions
0x100DEnabler/wEnables the motor driver
0x100ESpeed 0r/wTarget speed of motor 0
0x100FSpeed 1r/wTarget speed of motor 1
0x1010RPM 0rActual speed of motor 0
0x1011RPM 1rActual speed of motor 1

Servo Controller

AddressRegisterr/wDescription
0x1012Positionr/wSets the position of the servo

Sonar Controller

AddressRegisterr/wDescription
0x1013StatusrSignals new reading in range register
0x1014RangerHolds the measured distance

Programmable Interrupt Controller

AddressRegisterr/wDescription
0x1015Vect 0 Lowr/wLSBs of interrupt vector 0
0x1016Vect 0 Highr/wMSBs of interrupt vector 0
0x1017Vect 1 Lowr/wLSBs of interrupt vector 1
0x1018Vect 1 Highr/wMSBs of interrupt vector 1
0x1019Vect 2 Lowr/wLSBs of interrupt vector 2
0x101AVect 2 Highr/wMSBs of interrupt vector 2
0x101BVect 3 Lowr/wLSBs of interrupt vector 3
0x101CVect 3 Highr/wMSBs of interrupt vector 3

Parts

69
QtyValueFootprintReferences
160.1µFCapacitor_SMD:C_0603_1608MetricC1, C3, C4, C5, C6, C7, C8, C9, C11, C13, C18, C19, C24, C25, C26, C27
510KResistor_SMD:R_0603_1608MetricR10, R11, R12, R15, R16
410kResistor_SMD:R_0603_1608MetricR1, R4, R5, R21
41kResistor_SMD:R_0603_1608MetricR6, R7, R8, R9
31µFCapacitor_SMD:C_0603_1608MetricC14, C15, C17
3270Resistor_SMD:R_0603_1608MetricR17, R18, R19
34.7µFCapacitor_SMD:C_0603_1608MetricC10, C12, C16
3LEDResistor_SMD:R_0603_1608MetricD1, RX1, TX1
2100Resistor_SMD:R_0603_1608MetricR13, R14
2100nFCapacitor_SMD:C_0603_1608MetricC22, C23
210µFCapacitor_SMD:C_0603_1608MetricC20, C21
2ASTX-H11Oscillator:Oscillator_SMD_Abracon_ASE-4Pin_3.2x2.5mmX1, X2
2Conn_02x15_Odd_EvenConnector_PinHeader_2.54mm:PinHeader_2x15_P2.54mm_VerticalJ3, J4
2SW_PushButton_Switch_THT:SW_PUSH_6mmSW1, SW2
112kResistor_SMD:R_0603_1608MetricR3
12.2kResistor_SMD:R_0603_1608MetricR2
13.3µFCapacitor_SMD:C_0603_1608MetricC2
14.7kResistor_SMD:R_0603_1608MetricR20
1470µFCapacitor_SMD:CP_Elec_6.3x7.7C28
193LCxxCPackage_SO:SOIC-8_3.9x4.9mm_P1.27mmU1
1FT2232HLPackage_QFP:LQFP-64_10x10mm_P0.5mmU2
1ICE40HX8K-BG121Package_BGA:BGA-121_9.0x9.0mm_Layout11x11_P0.8mm_Ball0.4mm_Pad0.35mm_NSMDU6
1L77HDE15SD1CH4Fpet on a chip:AMPHENOL_L77HDE15SD1CH4FU7
1LDL1117S33RPackage_TO_SOT_SMD:SOT-223-3_TabPin2U3
1N25Q032A13ESC40FPackage_SO:SOP-8_3.9x4.9mm_P1.27mmU5
1Screw_Terminal_01x02TerminalBlock_4Ucon:TerminalBlock_4Ucon_1x02_P3.50mm_HorizontalJ2
1TLV70012DDCRPackage_TO_SOT_SMD:SOT-23-5U4
1USB_BConnector_USB:USB_B_OST_USB-B1HSxx_HorizontalJ1

The 67 most common of 69 parts.

More from ept221/pet-on-a-chip

1
  • 2 layers76.2 × 38.1 mmDaughter, the printed circuit board in 3D

    Daughter

    ept221/pet-on-a-chip

    Senior Design

    42 parts13MIT

Similar boards

  • 4 layers97.8 × 69.8 mmICE40UPDevBoard, the printed circuit board in 3D

    ICE40UPDevBoard

    aslak3/ICE40UPDevBoard

    A development board for iCE40UP5K FPGAs

    96 parts10GPL-2.0
  • 2 layers85 × 55 mmBizcard, the printed circuit board in 3D

    Bizcard

    wsaudio/Bizcard

    Drum machine business card

    54 parts
  • 4 layers85 × 56 mmPico vga sd aud, the printed circuit board in 3D

    Pico vga sd aud

    kuninet/KZ80-USBKBD

    KZ80 MSX USB Keyboard Adapter

    71 parts5MIT
  • 4 layers74 × 52 mmPicow vga sd aud, the printed circuit board in 3D

    Picow vga sd aud

    cwillforeal/cwill_keyboard

    Test Repo For messing around with keyboard things and the pico

    52 partsMIT
  • 2 layers180 × 190 mmM2-io emulator board, the printed circuit board in 3D

    M2-io emulator board

    Maillouski/Model-2-IO-Board-for-m2m3

    Drop-in replacement for the Sega 837-10539 I/O board (Daytona USA twin, Model 2), built around an Arduino Mega 2560. KiCad 10, CC BY-NC-SA 4.0.

    163 parts
  • 2 layers37.1 × 63.8 mmGd vga pico proto pcb, the printed circuit board in 3D

    Gd vga pico proto pcb

    baldengineer/Mega-IIe

    Using the Mega II from a IIgs to make a Apple IIe compatible computer: The Mega IIe!

    74 parts33MIT
  • 4 layers113 × 117.8 mmFPGA DevBoard, the printed circuit board in 3D

    FPGA DevBoard

    Benny-Chippers/Enchanted_Rocks

    The dev board PCB for the MacroController project

    197 partsMIT
  • 4 layers45 × 75 mmYui, the printed circuit board in 3D

    Yui

    hasenbanck/yui

    YUI is a USB/SPDIF to I2S interface using a STM32 and a iCE40 FPGA

    77 parts10

Questions

How big is the Pet on a chip PCB?

It measures 76.2 × 63.5 mm and has 4 copper layers, 1.6 mm thick.

What parts does the Pet on a chip use?

69 parts, built around the ICE40HX8K-BG121, N25Q032A13ESC40F, FT2232HL and L77HDE15SD1CH4F. The full list of its parts is on this page, with links to each part's symbol and footprint where PCBKit's library has them.

Where can I download the Pet on a chip KiCad files?

From the ept221/pet-on-a-chip repository on GitHub, at the commit this page was made from: the board is pcb/pet on a chip/pet on a chip.kicad_pcb and its schematic pcb/daughter/daughter.kicad_sch. PCBKit opens the board in the browser, with nothing to install.

Can I use the Pet on a chip design in my own project?

Its repository publishes it under the MIT licence: you may reuse it on that licence's terms (keep the author's notice, and for a copyleft licence share your changes alike).