Final Report Phantom Chess
Final Report Phantom Chess
GARRETT HINTON
ZACHARY HYATT
PHANTOM CHESS Final Project
ECE 3710
Design Documentation Fall Semester
2015
TABLE OF CONTENTS
Table of Figures ..................................................................................................................................... 2
1 Introduction .......................................................................................................................................... 3
2 Scope ..................................................................................................................................................... 4
3 Design Overview ................................................................................................................................... 5
3.1 Requirements ................................................................................................................................ 5
3.2 Dependencies................................................................................................................................ 5
3.3 Theory of Operation...................................................................................................................... 5
4 Design Details........................................................................................................................................ 7
4.1 Hardware Design ........................................................................................................................... 7
4.2 Software Design ............................................................................................................................ 7
4.2.1 Setup ..................................................................................................................................... 8
4.2.2 Getting User’s Move ............................................................................................................. 8
4.2.3 Relaying Move Data .............................................................................................................. 8
4.2.4 Moving Piece on Phantom Board (Motors) .......................................................................... 8
4.2.5 Moving Piece on Phantom Board (Actuator) ........................................................................ 9
5 Testing ................................................................................................................................................. 10
5.1 Test 1 – Hardware ....................................................................................................................... 10
5.2 Test 2 – Input from Buttons ........................................................................................................ 10
5.3 Test 3 – Location of Move ........................................................................................................... 10
5.4 Test 4 – Navigating to Squares.................................................................................................... 10
5.5 Test 5 – De/Activating Actuator .................................................................................................. 11
6 Conclusion ........................................................................................................................................... 12
Appendix A (Hardware Schematic and Pictures) ........................................................................................ 13
Appendix B (Code) ...................................................................................................................................... 15
Phantom Board Code .............................................................................................................................. 15
Button Board Code.................................................................................................................................. 19
TABLE OF FIGURES
Figure 1 - Function Overview ........................................................................................................................ 6
Figure 2 - Main Board Software Flow Chart.................................................................................................. 6
Figure 3 - Phantom Board Software Flow Chart ........................................................................................... 6
Figure 4 - Motor H-Bridge Logic Analyzer ..................................................................................................... 9
Figure 5 - Hardware Schematic ................................................................................................................... 13
Figure 6 - Button Board ............................................................................................................................... 13
Figure 7 - Phantom Board Base Unit ........................................................................................................... 14
Figure 8 - Phantom Board Side View .......................................................................................................... 14
1 INTRODUCTION
This document describes the design for a pair of chess boards: one chess board that sends a move and
one chess board that receives and mimics the move.
Chess is a two-player board game played on a chessboard, a checkered game board with 64 squares
arranged in an eight-by-eight grid. Each player begins the game with 16 pieces (six different types of
piece that are each allowed to move differently). The objective is to 'checkmate' the opponent's king
piece by placing it under an inescapable threat of capture. To this end, a player's pieces are used to
attack and capture the opponent's pieces, while supporting their own. In addition to checkmate, the
game can be won by voluntary resignation by the opponent, which typically occurs when too much
material is lost, or if checkmate appears unavoidable. A game may also result in a draw in several ways.
Our motives are to allow a microcontroller to transfer the moves made on one board, to the moves
made on a second board. This unit is the first step in creating a set of chess boards that allow two
players to play chess without being in the same location, but still have the experience of playing on a
real board.
There are two boards described in this document. The first is the Button Board, which is the board
where the move is made by a live player. The second is the Phantom Board where the move is made
mechanically.
2 SCOPE
This document discusses, in detail, the electrical and software design for Phantom Chess. It includes the
requirements, dependencies and theory of operation. Schematics and code segments are used to give a
more thorough explanation of the design. Testing procedures and results of each requirement are
included. The complete code is located in Appendix B.
3 DESIGN OVERVIEW
3.1 REQUIREMENTS
The requirements for our project as set by Dr. Gerdes are as follows: “Have two [chess] boards
with one piece each. If the user moves the piece on one board it is automatically moved, by the
mechanism…on the other [board].”
3.2 DEPENDENCIES
The following are dependencies for Phantom Chess:
We would suggest a larger motor for the shaft rotation as we found that the motor we used had some
difficulty to rotate the shaft and move both sliders. We may also want to use a larger magnet at the end
of our actuator. We also found that communication was difficult once we had all of the buttons
attached, so in the future we will want to use a differing form of communication.
This board however is functional and allows for some fun, and the perfect starting point for a future
project.
APPENDIX A (HARDWARE SCHEMATIC AND PICTURES)
#include "TM4C123GH6PM.h"
void initPorts(void){
SYSCTL->RCGC2 = 0x1A;
__nop();
__nop();
// Unlock PB
GPIOB->LOCK = 0x4C4F434B;
// Alternate function
// PB0, PB1 alt function enabled
GPIOB->AFSEL = 0x3;
// GPIODIR
GPIOB->DIR = 0x4;
// GPIOCR
//GPIOB->CR = 0x7;
// GPIOPUR
GPIOB->PUR = 0x0;
// Digital Enable
GPIOB->DEN = 0x4;
}
void initUART(void){
//activate clock on UART1
SYSCTL->RCGCUART = 0x2;
SYSCTL->RCGC1 = 0x2;
__nop();
__nop();
//interrupt set up
//receive fifo interrupts at 1/8 full
//M4CP[0x100] = 0x40;
//UART1->IFLS = 0x00;
//UART1->ICR = 0x10;
void initMotors(void){
//SYSCTL->RCGC2 = 0x8;
//__nop();
//__nop();
// Unlock PD
GPIOD->LOCK = 0x4C4F434B;
GPIOE->LOCK = 0x4C4F434B;
// Alternate function
GPIOD->AFSEL = 0x0;
GPIOE->AFSEL = 0x0;
// GPIODIR
GPIOD->DIR = 0xF;
GPIOE->DIR = 0xF;
// Digital Enable
GPIOD->DEN = 0xF;
GPIOE->DEN = 0xF;
}
int main(void)
{
char x_old = 0x0;
char y_old = 0x0;
char x_new = 0x0;
char y_new = 0x0;
char state = 0x0;
char hasData = 0x0;
char data = 0x0;
initPorts();
initUART();
initMotors();
while(1)
{
hasData = UART1->FR & 0x10;
if(hasData == 0x0){
data = UART1->DR;
state++;
}
//Do Stuff
if(data != 0x0){
switch(state){
case 0x1:
x_old = data;
break;
case 0x2:
y_old = data;
break;
case 0x3:
x_new = data;
break;
case 0x4:
y_new = data;
move(x_old, y_old, x_new, y_new);
state = 0x0;
break;
}
data = 0x0;
}
move(1,2,3,4);
move(4,3,2,1);
}
#include "TM4C123GH6PM.h"
void initPorts(void){
SYSCTL->RCGC2 = 0x3F;
__nop();
__nop();
// Unlock PB and PF
GPIOA->LOCK = 0x4C4F434B;
GPIOB->LOCK = 0x4C4F434B;
GPIOC->LOCK = 0x4C4F434B;
GPIOD->LOCK = 0x4C4F434B;
GPIOE->LOCK = 0x4C4F434B;
GPIOF->LOCK = 0x4C4F434B;
// Alternate function
// PB0, PB1 alt function enabled
GPIOD->AFSEL = 0xC0;
// GPIODIR
GPIOD->DIR = 0x0;
// GPIOCR
PD[0x524] = 0xC0;
// GPIOPUR
GPIOD->PUR = 0xC0;
// Digital Enable
GPIOA->DEN = 0xFF;
GPIOB->DEN = 0xFF;
GPIOC->DEN = 0xFF;
GPIOD->DEN = 0xFF;
GPIOE->DEN = 0xFF;
GPIOF->DEN = 0xFF;
void initUART(void){
//activate clock on UART2
SYSCTL->RCGCUART = 0x4;
SYSCTL->RCGC1 = 0x4;
__nop();
__nop();
void initButtons(void){
int main(void)
{
char xCheck = 0;
char yCheck = 0;
//char garbageData=0;
int delay = 0x7A1200;
short x[8] = {0,0,0,0,0,0,0,0};
char i = 0;
char y = 0;
char xval = 0;
char state = 0x2;
char currx = 0;
char curry = 0;
char newx = 0;
char newy = 0;
char check = 0;
//char groupSelect = 0;
//char rowSelect = 0;
//char isFull;
initPorts();
initUART();
initButtons();
while(1){
//x[2] =((GPIOA->DATA)>>2) + ((GPIOB->DATA & 0xC)<<4);
//groupings: PA[2-7],PB[2-7],PC[4-7],PD[0-3,6-7],PE[0-5],PF[0-4]:
we wont use pd[6-7]
for(i=3;i<5;i++){ //for(i=2;i<5;i++){
xval=0;
y=0;
if(x[i]!=0x0){
xval = i;
//if(newx!=3||newx!=4){state = 2;}
/*
switch(groupSelect){
case 0x0:
y = PB[0x3fc] & 0x7;
break;
case 0x1:
y=(PB[0x3fc] & 0x38)>>3;
break;
case 0x2:
y=((PB[0x3fc] & 0xC0)>>6) + ((PD[0x3fc]& 0x1)<<2);
//PD0 is most sig bit
break;
case 0x3:
y=(PD[0x3fc] & 0xE)>>1;
break;
case 0x4:
y=(PD[0x3fc] & 0x70)>>4;
break;
case 0x5:
y=((PD[0x3fc] & 0x80)>>7) + ((PC[0x3fc] & 0x3)<<1);
//PD7 is least sig bit
break;
case 0x6:
y=(PC[0x3fc] & 0x1C)>>2;
break;
case 0x7:
y=(PC[0x3fc] & 0xE0)>>5;
break;
}
/*
x[0] = PB[0x3fc] & 0x7;
x[1] = (PB[0x3fc] & 0x38)>>3;
x[2] = ((PB[0x3fc] & 0xC0)>>6) + ((PD[0x3fc]& 0x1)<<2); //PD0 is
most sig bit
x[3] = (PD[0x3fc] & 0xE)>>1;
x[4] = (PD[0x3fc] & 0x70)>>4;
x[5] = ((PD[0x3fc] & 0x80)>>7) + ((PC[0x3fc] & 0x3)<<1); //PD7
is least sig bit
x[6] = (PC[0x3fc] & 0x1C)>>2;
x[7] = (PC[0x3fc] & 0xE0)>>5;
*/
/*
*/
*/
/*
if(state == 0 ){
currx = groupSelect;
curry = y;
//transmit current to ghost board
//if full, wait
while(check == 0){
if((UART2->FR & 0x20)==0x0){
UART2->DR = currx;
UART2->DR = curry;
check = 1; //breaks out of the while loop
}
}
state = 1; //wait, McKord's a girl??
check = 0;
}
else {
newx = groupSelect;
newy = y;
//transmit new to ghost board
//if full, wait
while(check == 0){
if((UART2->FR & 0x20)==0x0){
UART2->DR = newx;
UART2->DR = newy;
check = 1; //breaks out of the while loop
}
}
state = 0;
check = 0;
}
}
*/
/*
if(xCheck == xval && yCheck == y){
state = 0x2;
}
*/
if(state ==0x1) {
newx = xval;
newy = y;
xCheck = xval;
yCheck = y;
//transmit new to ghost board
//if full, wait
while(check == 0){
if((UART2->FR & 0x20)==0x0){
if(newx!=currx && newy!=curry){
UART2->DR = newx;
UART2->DR = newy;
}
check = 1; //breaks out of the while loop
}
}
check = 0;
if(newx!=currx && newy!=curry){
state++;
}
while(delay>0){delay--;}
delay = 0x7A1200;
}
if(state == 0x0 ){
currx = xval;
curry = y;
xCheck = xval;
yCheck = y;
//transmit current to ghost board
//if full, wait
while(check == 0){
if((UART2->FR & 0x20)==0x0){
//if(currx!=0x0){
UART2->DR = currx;
UART2->DR = curry;
// }
check = 1; //breaks out of the while loop
}
}
check = 0;
//if(newx!=0x0 && currx!=xCheck && curry!=yCheck){
state++;
//}
while(delay>0){delay--;}
delay = 0x7A1200;
}
}
}
}