0% found this document useful (0 votes)
152 views

Final Report Phantom Chess

This document describes the design of a phantom chess system with two boards - a button board where a player makes moves, and a phantom board where moves are replicated mechanically. The button board has buttons under each square connected to a microcontroller. When a button is pressed, the corresponding move is sent via UART to the phantom board. The phantom board uses two motors to position an actuator with a magnet under the correct squares to pick up and move the pieces, guided by its microcontroller receiving move signals from the button board. Testing was performed to validate hardware, button inputs, move locations, and motor navigation to squares. The complete hardware schematics and software code are included in the appendices.

Uploaded by

Jon Snow
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
152 views

Final Report Phantom Chess

This document describes the design of a phantom chess system with two boards - a button board where a player makes moves, and a phantom board where moves are replicated mechanically. The button board has buttons under each square connected to a microcontroller. When a button is pressed, the corresponding move is sent via UART to the phantom board. The phantom board uses two motors to position an actuator with a magnet under the correct squares to pick up and move the pieces, guided by its microcontroller receiving move signals from the button board. Testing was performed to validate hardware, button inputs, move locations, and motor navigation to squares. The complete hardware schematics and software code are included in the appendices.

Uploaded by

Jon Snow
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 26

MCKORD HARRIS

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:

 2 – 12 VDC source for the motors


 2 – 3.3 VDC sources for the microcontrollers
 1 – 5 VDC source to power the buttons

3.3 THEORY OF OPERATION


When powered on or reset, the Phantom Board will sit, waiting with its stationary pieces to
receive a signal indicating a move has been made on the Button Board. The Button Board is
located with the user and is a fully setup chess board with buttons underneath each piece.
When a user makes a move, he/she pushes a piece down to indicate which space he/she is
moving from. The user will then push the piece down upon the space the piece is moving to in
order to indicate where that piece should end up.
Those signals are then transmitted to the Phantom Board where a microcontroller has been
waiting to receive a signal. Two motors then work in tandem to move an actuator to a spot
under the space the user moved the piece from. A signal is then sent via a relay to engage the
actuator that has a magnet attached to its tip. That connects—through the board—to the piece
located above it. The motors then work together again to position the actuator to the space
the piece was moved to. The signal activating the actuator is then stopped and the actuator
shrinks back down and thereby releasing the piece it was attached to. The phantom board then
sits and waits for the next move it’s told to execute.
Below are schematics to describe the functions of overview, the button board, and the
phantom board.
Figure 1 - Function Overview

Figure 2 - Main Board Software Flow Chart

Figure 3 - Phantom Board Software Flow Chart


4 DESIGN DETAILS

4.1 HARDWARE DESIGN


Phantom Chess consists of two custom made chess boards: one board has buttons under each
space (Button Board) and one board has motors under it (Phantom Board) that are connected
to movable arms and to an actuator with a magnet on its end. The Pieces on top of the
Phantom Board have a piece of magnetic metal glued to their bottoms.
The Button Board is made of cardboard and has a 64-space checkered pattern drawn on it. In
the middle of each space a hole has been drilled and a button has been glued in to fill the hole.
Underneath the board, each button is connected to a common power and also to a pin on the
microcontroller. The microcontroller for the Button Board then communicates with the
microcontroller for the Phantom Board via UART.
For the Phantom Board we assembled four planks of wood, connected in a square shape, to
form the base for the chess board. On each side arm of the base, we fitted a rubber track to
two pulleys bolted to the ends of the boards. The two tracks are connected by a metal shaft
that runs across the top of the board. A motor is attached to one of the pulleys. When the
motor is powered on the pulley turns. This results in the shaft also turning therefore turning
the pulley on the other side of the board as well. As both pulleys turn, the tracks that are
connected to the pulleys also turn. A plank is connected to the tracks as well, and on this plank
is another pair of pulleys and a track, but these are connected to a different motor.
Connected to this cross-track is an actuator with a magnet attached to its end. When this
motor is powered on, the actuator can move the length of its track. The actuator is connected
to three 9-volt batteries that are connected in series to produce a 27 VDC voltage for the
actuator. The 27 VDC voltage supply is connected to a relay that is connected to a solid-state
relay on the microcontroller that determines whether the 27 VDC voltage is applied to the
actuator or not. When it is applied then the actuator arm is engaged and sticks out about a half
inch. When the voltage is not applied then the arm pulls back inside of the actuator.
See Appendix A for a detailed schematic and photos.

4.2 SOFTWARE DESIGN


The Software Design for Phantom Chess consists of five parts: configuring/setting up the
hardware we interfaced with, getting the data corresponding to the user’s move, sending the
data for that move from one board to the other, getting the motors to move in reaction to the
data received, and getting the actuator to engage underneath the moved chess piece and
getting the actuator to let go once it gets to the piece’s final location.
4.2.1 Setup
The following are hardware and modules we had to configure for our project: ports for buttons,
for UART, for the motors, and for our actuator; UART; our motors.

4.2.2 Getting User’s Move


On the Button Board there are 64 spaces and a button under each space. When a button is
pushed, a logic high is sent to the pin that the button is connected to. The microcontroller has
code that helps it determine what the location of that pressed button is. It sends the data of
the location of the pressed button to the other board via UART.

4.2.3 Relaying Move Data


In order for the data of a particular move to get from one microcontroller to the other, we used
UART serial communication. Since we simply needed one system to transfer data and for the
other system to receive data, we did not use RS-232, but just connected a wire from the
transferring pin on one microcontroller to the receiving pin on the other microcontroller. When
a button is pushed on the Button Board, the space’s column and row numbers are sent to the
other microcontroller. That data is then used to tell the motors how long to run for and in
which directions.

4.2.4 Moving Piece on Phantom Board (Motors)


We tested and got a value for the number of times we let the coils in our motors circulate
through activation in order for our setup to move one space on our chess board. That
predetermined value is multiplied by the number of spaces it needs to move. This provides
power to the motor for the exact amount of time needed for our arms to navigate to the spaces
we’re moving a piece from and to. The number of spaces the arms need to move is determined
by finding the difference between the x-value of the space the piece is moving from and the x-
value of the space the piece is moving to. The same is done to find the number of spaces the
arms will need to move in the y-direction.
Below is a schematic of the logic analyzer of the GPIO pins that were connected to the motors:

Figure 4 - Motor H-Bridge Logic Analyzer

4.2.5 Moving Piece on Phantom Board (Actuator)


When the motors have successfully maneuvered the actuator to be underneath the board
space we are moving the chess piece from, a logic high is sent to a relay that then applies 27
VDC to the actuator. When that voltage becomes apparent to the actuator then it engages its
arm.
We have magnets attached to the arm of the actuator so when it extends it reaches up and
touches the bottom of the chess board above it that has pieces resting on top of it. Each piece
has a piece of magnetized metal glued to the bottom of it so they can be grabbed by the
magnets on the end of the actuator. Once the motors have successfully dragged the chess
piece to the space the user indicated the piece should end up, the relay receives a logical low
and blocks the 27 VDC from the actuator thus disengaging its arm and letting go of the piece it
had connected to.
5 TESTING
The next five sections detail a series of tests performed to exhibit the functionality of each part
of our project requirements.

5.1 TEST 1 – HARDWARE


We first tested to ensure that all hardware functioned properly. The hardware was correctly
connected (see Appendix A) and the appropriate amount of power was supplied. It was verified
that 64 buttons were set up and used to allow a user to indicate the spaces a chess piece was
moved from and to. A cable connected the two microcontrollers for UART communication
purposes. Two stepper motors, connected to rubber belts moved a plank and an actuator
along metal tracks. The actuator extended when supplied with 24 V. All hardware passed all
tests to ensure correct functionality.

5.2 TEST 2 – INPUT FROM BUTTONS


To test to see if the signals from pushing buttons on our board was coming through correctly,
we singled out the pins and variables that were directly affected. As we polled through the pins
we observed when they went high (if a pin went high that meant a button was being pressed.)
We tested this code and it did indeed function correctly.

5.3 TEST 3 – LOCATION OF MOVE


When a pin went high we checked which pin it was and from there were able to determine the
location of the button being pressed. We made sure that each button resulted in filling the x
and y variables with the correct values when pressed. Those values were then transferred via
UART to the microcontroller connected to the Phantom Board. We tested this procedure by
observing the values received on the Phantom Board’s end. The correct values were always
received resulting in this test being passed.

5.4 TEST 4 – NAVIGATING TO SQUARES


Once the Phantom Board’s microcontroller received the correct values from the Button Board’s
microcontroller, those x and y values were stored and compared to the next pair of x and y
values received (the coordinates of the piece to be moved and the coordinates of where it
should be moved to). Those values were then compared and the difference between them was
found which gave us the number of spaces in each direction the piece should be moved. Also,
depending on whether the first x/y value was smaller or larger than the second x/y value, we
were able to determine which direction the motor should turn in order to get the piece to
where it needed to go. We tested this procedure and confirmed its functionality as well.
5.5 TEST 5 – DE/ACTIVATING ACTUATOR
For our final test we made sure that our actuator was correctly activated and deactivated. The
actuator was always connected to its 27 VDC power supply, but via a relay. We sent this relay a
high signal once our motors navigated the actuator to the spot directly underneath where the
piece was located that should be moved. When the relay received a high signal it allowed the
27 VDC to turn on the actuator thus extending the actuator’s arm and pressing the connected
magnet against the chess board and connecting to the piece resting on top of the board. Once
the piece was moved to its destination the relay received a low signal which cut the connection
between the actuator and the 27 VDC. This resulted in the actuator’s arm retracting and
disengaging from the piece it just moved. This final tested was tried and proven to work just as
the others were.
6 CONCLUSION
The Phantom Chess board will now allow you to make a move on the Button Board, and have that move
replicated on the Phantom Board. This will allow for a future project to extend this functionality such
that the boards could communicate with one another, and eventually allow two people to play chess in
different locations. This unit does need some future modifications to allow for this, but this is a good
starting point.

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)

Figure 5 - Hardware Schematic

Figure 6 - Button Board


Figure 7 - Phantom Board Base Unit

Figure 8 - Phantom Board Side View


APPENDIX B (CODE)

PHANTOM BOARD CODE


//This is for the ghost board
//PA will control the motors
//PB is for UART

#include "TM4C123GH6PM.h"

unsigned char *M4CP = (unsigned char *) 0xE000E000;


int motor[4] = {0x1, 0x2, 0x4, 0x8};
char directionX = 1; //is the motor for the x or the y on?

void initPorts(void){
SYSCTL->RCGC2 = 0x1A;
__nop();
__nop();

// Unlock PB
GPIOB->LOCK = 0x4C4F434B;

// Alternate function
// PB0, PB1 alt function enabled
GPIOB->AFSEL = 0x3;

// Configure pin mux for both PB0 and PB1


// PB0 = 1 (UART1_RX)
// PB1 = 1 (UART1_TX)
GPIOB->PCTL = 0x11;

// 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();

// set UART1 clock to precision


UART1->CC = 0x5;

// Disable UART for setup


UART1->CTL = 0x0;

// Baud Rate Divisor:


// BRD = 16 MHz / (16 * 9600)
// BRD = 104.1667

// integer = 0d104 => 0x68


// Set integer BaudRate
UART1->IBRD = 0x6868;

// fractional = int(0.1667*2^6 + 0.50) = 0d11 => 0xC


UART1->FBRD = 0xC;

// set serial parameters


// enable FIFO, 1 stop bit, no parity
UART1->LCRH = 0x70;

//interrupt set up
//receive fifo interrupts at 1/8 full
//M4CP[0x100] = 0x40;
//UART1->IFLS = 0x00;
//UART1->ICR = 0x10;

// Reenable UART1 as well as TX


UART1->CTL = 0x301;
}

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;
}

void Forward(char amount){


short hexagon= 0x55; //number of revolutions for one space
int j = 0x0, k = 0x0;
char i = 0x0;
//We will change while 1 to be the number of times we go around
if(directionX==1){ //going in x direction`
for(k=0;k<hexagon*amount;k++){
GPIOD->DATA = motor[i];
i = (i + 1) % 4;
j = 0x0;
while(j < 0x2FFF){
j++;
}
}
}
if(directionX==0){ //going in y direction
for(k=0;k<hexagon*amount;k++){
GPIOE->DATA = motor[i];
i = (i + 1) % 4;
j = 0x0;
while(j < 0x2FFF){
j++;
}
}
}
}

void Backward(char amount){

short hexagon= 0x55; //number of revolutions for one space


int j = 0x0, k = 0x0;
char i = 0xFF, temp;
//We will change while 1 to be the number of times we go around
if(directionX==1){ //going in x direction
for(k=0;k<hexagon*amount;k++){
GPIOD->DATA = motor[temp];
if(i==0){i = 0xFF;}
temp = i % 4;
i -= 1;
j = 0x0;
while(j < 0x2FFF){
j++;
}
}
}

if(directionX==0){ //going in y direction


for(k=0;k<hexagon*amount;k++){
GPIOE->DATA = motor[temp];
if(i==0){i = 0xFF;}
temp = i % 4;
i -= 1;
j = 0x0;
while(j < 0x2FFF){
j++;
}
}
}
}
void move(char x_old, char y_old, char x_new, char y_new){
//char magnet = 0;

char xTotal,yTotal; //compare the new position to the


current position

GPIOB->DATA = 0x4; //turn on the solenoid. Assuming it


is on PB2

// go down the x direction


directionX = 1;
if(x_new > x_old){
xTotal = x_new - x_old;
Backward(xTotal);
}
else{
xTotal = x_old - x_new;
Forward(xTotal);
}

// go down the y direction


directionX = 0;
if(y_new > y_old){
yTotal = y_new - y_old;
Forward(yTotal);
}
else{
yTotal = y_old-y_new;
Backward(yTotal);
}

GPIOB->DATA &= 0xFB; //turn off the solenoid.


Assuming it is on PB2
}

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);
}

BUTTON BOARD CODE


//This is for the main board
//PC will be the buttons
//PB is for UART

#include "TM4C123GH6PM.h"

// base addr for port B


unsigned char *PB = (unsigned char *) 0x40005000;
unsigned char *PC = (unsigned char *) 0x40006000;
unsigned char *PD = (unsigned char *) 0x40007000;
unsigned char *PE = (unsigned char *) 0x40024000;

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;

// Configure pin mux for both PB0 and PB1


// PB0 = 1 (UART2_RX)
// PB1 = 1 (UART2_TX)
GPIOD->PCTL = 0x11000000;

// GPIODIR
GPIOD->DIR = 0x0;

// GPIOCR
PD[0x524] = 0xC0;

//2mA Current Source


//GPIOB->DR2R = 0x10;

// 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();

// set UART2 clock to precision


UART2->CC = 0x5;

// Disable UART for setup


UART2->CTL = 0x0;

// Baud Rate Divisor:


// BRD = 16 MHz / (16 * 9600)
// BRD = 104.1667

// integer = 0d104 => 0x68


// Set integer BaudRate
UART2->IBRD = 0x6868;

// fractional = int(0.1667*2^6 + 0.50) = 0d11 => 0xC


UART2->FBRD = 0xC;

// set serial parameters


// enable FIFO, 1 stop bit, no parity
UART2->LCRH = 0x70;

// Reenable UART2 as well as TX


UART2->CTL = 0x101;
}

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);

x[3] =(((GPIOB->DATA)& 0xF0)>>4) + ((GPIOC->DATA)&0xF0);


x[4] =(GPIOD->DATA & 0xf) + ((GPIOE->DATA & 0xf)<<4);
//x[3] =(GPIOD->DATA) & 0xF;
//x[4] =(GPIOE->DATA) & 0x7; //0x3F
//x[5] =(GPIOF->DATA) & 0x1F;
xval=0;
y=0;

//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(state > 0x1){state = 0;};


switch(x[i]){
case 0x1:
y = 0x0;
break;
case 0x2:
y = 0x1;
break;
case 0x4:
y = 0x2;
break;
case 0x8:
y = 0x3;
break;
case 0x10:
y = 0x4;
break;
case 0x20:
y = 0x5;
break;
case 0x40:
y = 0x6;
break;
case 0x80:
y = 0x7;
break;
}
//}

//if(newx!=3||newx!=4){state = 2;}
/*

//groupings: PB[0-2], PB[3-5], PB[6,7] and PD[0], PD[1-3], PD[4-6],


PD[7] and PC[0-1], PC[2-4], PC[5-7],

rowSelect = (PE[0x3fc] & 0x10)>>4; //this is the group


select of the encoder of group selects. If using interrups, use this as the
trigger
if(rowSelect==1){
groupSelect = (PE[0x3fc]& 0xE)>>1; //3 pins, whatever its
value is is the row

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;
*/
/*
*/

//We poll continuously from PA,PB,PC, etc


//we take the values and send it on UART. There are 24 pins for
the board, 3 for the group select, and 1 for the row select.
/*
y = x[groupSelect]; //the value of the encoder of the
selected row will give the y value

*/
/*
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;
}

}
}
}

You might also like