Hidden Links



This page outlines the Tic-Tac-Jello project. This was a group assignment with Katie Earls and I, in completion of our assembly language programing lab (CPE-269). The project interface a Nexys 2 board with two external input devices and a VGA monitor output. The input consisted of a 3x3 button matrix, and a small bowl of Jello. We did this because jello is tasty and otherwise quite awesome. The Nexys 2 FPGA board, runs the PicoBlaze microcontroller described in VHDL. The majority of the code was written in the PicoBlaze assembly language. VHDL Code modification was also done to the PicoBlaze warper to integrate our external devices. The VGA driver was given in the last project and will not be discussed here.




Make sure your local installer has the following:

-       A standard computer monitor to display the game

-       A Nexys2 Board that will be used to download the required code that will implement the game

-       A Qt110 touch sensor integrated Circuit


Game input uses 9 buttons to indicate which square to select.


-       A small metal container to place the Jell-O on and with this metal container some premade JELLO

-       Last but not least the required VHDL and Pico blaze code that will implement the game.

How to Play:

The game requires two players.  One player will play using the red blocks, the other player will play using the blue blocks.  The red player goes first, using the buttons the player can select any of 9 locations to place his/her block on.  Once the red player has placed his/her block. It is now the Blue Players turn.  Each player takes turns until one of the two has connected three of their colored blocks in a row (horizontal, vertical, or diagonal) before the other player gets three in a row.  The grid will turn the color of the winners Block and the game will be over.  To reset the game and play again either of the players must touch the JELL-O.    


Technical Details:



The TicTacToe has two user inputs: a 3x3 button matrix and a touch sensitive Jello. These inputs feeds data into the Nexys2 board running a picoblaze VHDL simulation. The board will then output the TicTacToe results to a LCD display.




Button input:

Basic Setup


The buttons input device consists of 9 total buttons, all purchased from RadioShack. The outer casing was drilled from a SimplyAsia Teriyaki noodle bowl. All of these buttons are momentary-on buttons, three were incorrectly purchased momentary-off buttons. To compensate for the momentary off buttons a Hex inverter (DM74LS04), was used to flip the inconsistent bits. The corrected inputs then go into a priority encoder (SN74LS147) that will encode the 9 parallel inputs into 4 bit binary number. Voltage dividers are used to lower the 5 Volt output to match he 3.3V used by the Nexys2 Board.



Each Chip requires a 5V power supply. A USB power adapter was made to supply this power. This adapter consisted of a USB hub plugged into a computer and the rendered USB male end of a broken thumb drive.

Reset Button:

Chip details


The reset button consisted of the Jello, the metal contact to the QT110 Touch sensor, to the Nexys2 board. The chip’s output connects to the j12 connector of the Nexys2 board.



The QT110 chip will test the capacitance of Cs. When a change in capacitance is detected, a 70ms pulse is sent, this will momentarily drop the voltage value of pin 2 to ground. This pulse is mapped to BTN0 of the nexys2 board.


Note: the schematic below, pin 3 should go to ground to select pulse mode, and Re is the natural resistance fo the Jello.



Any conductor can act as a sensor. The initial touch sensor was a bowl of chocolate pudding. Because of the high resistance value of pudding (2MΩ at 4cm depth) salt was added to increase the conductivity. The pudding also proved to be very messy, leaving a chocolate finger each button press. With the increase salt content, and sanitary concerns finger licking was not an option. A container of left over pudding was a the only nice outcome from that attempt. Luckily my partner was able to steal some Jello from her roommate at the last minute.  

The Jello with a total resistance value of 2.5k at (4cm depth) didn’t require any additional salt, and could operate with out leaving a messy finger on contact.




The QT110 chip is also connected to USB power and ground. To accomplish this a old iPod cable was cut and solid core wire was soldered onto the power wires. To verify wire placement a multimeter was used to determine the correct wire cut.




VHDL code:

Modification to the wrapper


The PicoBlaze wrapper was modified to include a component called INPUT_BUTTONS. This component received all the original switch inputs, and button inputs, and passed these values unchanged as new signals: SWITCH_TO_PB, and INPUT_TO_PB. This component also connects to the interrupt lines of PicoBlaze. This connections will set when INPUT_BUTTONS receives switches in a certain combination, or when BTN0 is pressed. Remember the input buttons signals are priority encoded into a 4 bit binary number, that is only sent (active low) when a button is pressed. These 4 signals wil be recived by the Nexys 2 board as switch setting.

-- Company: Cal Poly
-- Engineer: Roeurn Tourn, Katie Earls
-- Create Date:    20:57:29 12/02/2009
-- Design Name:
-- Module Name:    Input_buttons - Behavioral
-- Project Name:
-- Target Devices:
-- Tool versions:
-- Description:
-- Dependencies:
-- Revision:
-- Revision 0.01 - File Created
-- Additional Comments:
library IEEE;

---- Uncomment the following library declaration if instantiating
---- any Xilinx primitives in this code.
--library UNISIM;
--use UNISIM.VComponents.all;

entity Input_buttons is
    Port ( clk          : in std_logic;
            Switch_in    : in  STD_LOGIC_VECTOR (7 downto 0);
           Switch_to_pb : out  STD_LOGIC_VECTOR (7 downto 0);
           button_in    : in  STD_LOGIC_vector (2 downto 0);              
           button_to_pb : out  STD_LOGIC_vector (2 downto 0);
              interupt     : out std_logic);
end Input_buttons;

architecture Behavioral of Input_buttons is

signal interupt_flag : std_logic;


interupt <= interupt_flag;
--switch_to_pb(7 downto 4) <= "0000";
Switch_to_pb(3 downto 0) <= Switch_in(3 downto 0); --passes the switch signals to pico_blaze
button_to_pb(2 downto 0) <= button_in (2 downto 0);--passes the button signals to pico_blaze

process (clk, switch_in)

    case (Switch_in(3 downto 0)) is --Sense input from the prioity encoder and then trips inturupts
            when"1110" => interupt_flag <= '1';
            when"1101" => interupt_flag <= '1';
            when"1100" => interupt_flag <= '1';
            when"1011" => interupt_flag <= '1';
            when"1010" => interupt_flag <= '1';
            when"1001" => interupt_flag <= '1';
            when"1000" => interupt_flag <= '1';
            when"0111" => interupt_flag <= '1';
            when"0110" => interupt_flag <= '1';
            when others => interupt_flag <= '0';
    end case;
    if (button_in(0)='0') then  --senses input from the reset button
    interupt_flag <= '1';
        end if;

end process;

end Behavioral;




Modification to the constraints file


The switches were mapped to the JB1 inputs, while the Reset button was mapped to the JC2 input. This is made the connection to use the external input ports of the Nexys 2 board.



PicoBlaze code:

Because the Tic-Tac-Toe game with out winner check and over write protection is currently a CPE-269 lab, I will not include the source code here.


Flowchart main

 Flowchart ISR (Interrupt Service Routine)

I do realize there is a lot of redundancies in this code. Its there simply because I was too tired after debugging to work on it any further. 




Database structure Turn information Register sC stores the current color, this also stores the current turn. The Board information Each TicTacToe board is identified by box is indicated by the diagram below.


Player location

Player Red is stored in Scratch Pad Memory 00. The least significant bit location represent box 1. A ‘1’ in the (LSB) location means that the box is occupied by Red.  The MSB location represents box 8.


If a red square is occupying box 1, 2, 3 and 5, then the value in SPM_00 is “00010111”.


The ninth block is represented by SPM_01’s MSB. If Red is occupying box 9 then SPM location then the value in SPM_01 is “10000000”.


The Blue player’s location is encoded in SPM_02. If box 1, 6, 7, and 8 were occupied by blue then the value in SPM_2 would be “11100001”.


Box 9 location for blue is encoded in SPM_01’s second most significant bit.  If Blue occupied Box 9, then  the value in SPM_01 is “01000000”.



Winner Check

To check for a red winner in the row of boxes 1,2,3, then we only need to mask SPM_00, with value “00000111” (07HEX), and the compare to value “00000111” (07HEX).