Monday, April 18, 2011

Success with the Stepper Motors!

Today we figured out exactly how to wire the stepper motors, and got them fully functional. We were also able to write code that does output compare to input a specified number pulses into the STEP input of either the X-axis stepper motor or the Y-axis stepper motor. We could also specify the direction (clockwise or counterclockwise), by setting DIR = 0 or 1 respectively. We also thought it would be good to toggle the sleep mode on when the motors were not stepping, because they got warm when we were using them. Keeping them in sleep mode might prevent the larger motors that we’re getting soon from overheating the driver board. The driver board has an onboard temperature sensor that shuts off the driver if the temperature is too high.


The main issue was figuring out how to set the current limit on the board. We figured out that there is a small circular Vref pin in the center of the driver board. If everything is connected up correctly and the logical voltage and motor voltage is applied, this voltage can be measured. The current limit is then Vref/(8*.05). The value of Vref can be changed by adjusting the potentiometer on the back of the board with a screwdriver. We adjusted the current limit to 0.5A for this motor, but we’ll need 1.2A for the larger motors coming in the mail soon. 
Pull up resistors had to be used for logical inputs: DIR, STEP, MSx, SLEEP, RESET, ENABLE. We still need to decide whether to use single-step mode, half-step mode, or quarter-step mode. The exact circuit diagram we’ll use for each motor is shown below, wired for single step. All grounds are common.



Sunday, April 17, 2011

Converting Computer Moves into Physical Moves


Again, here I have done some more planning so that it will be straightforward when writing the code for moving the computer’s chess pieces when it outputs a move.

The moves will come in the form (letter,number,letter,number). For example a move could be C7C6, which would mean move the piece at square C7 to square C6. Again recall that the computer outputs in (column, row) coordinates instead of matrix coordinates (row, column). Thus we do an inverse coordinate transform as that shown in the previous post’s table to get the correct numerical coordinates. Thus C7 would correspond to (6,2), and C6 would correspond to (5,2). 

Now, we are going to design the X-Y magnet system so that it will transport the pieces along the lines in between the squares so that the pieces do not collide. This is another reason why our chessboard had to be large. Thus the X-Y magnet system will need to have a finer coordinate system so that it can both go to the location of the piece and go in between other pieces. The following grid shows the coordinate system of the X-Y magnet system. 

The coordinates now range from 0 to 16 in both X and Y directions. The actual chess squares are colored so that the coordinate system could be visualized overlaying the actual chessboard. The chess pieces can only be located at coordinates where both the X and Y coordinates are both odd.

Note that the transformed numerical move coordinates will again need to be changed to fit the granularity of the XY system coordinate system. This involves multiplying each coordinate by two and adding 1: (2x+1,2y+1). Thus if the instructions are move piece at (6,2) to space (5,2) are received, this would correspond to the XY system needing to move the piece at (13,5) to (11, 5).

We plan to have the XY system start at the center of the board, which is position (8,8). We can then recalibrate the XY system after each move by forcing it to return to the center position after delivering a piece to a square. This can be done by placing a magnet behind each stepper motor that triggers a Reed switch placed at the exact center of each motor’s movement track. 

So when the origin coordinates are received, we subtract (8,8) from the coordinates. For example, (13,5) – (8,8) = (5,-3). The X stepper motor then shifts up five coordinate steps; each coordinate step will have a specified number of motor steps that will be determined through testing. The Y stepper motor then shifts left 3 coordinate steps. The magnet is then flipped up with the servo motor to attract the piece.

Then the current coordinates are subtracted from the next coordinates. For example, (11,5) – (13,5) = (-2,0). Thus the X stepper motor will need to shift down 2 coordinate steps. The Y stepper motor will not need to shift in this case.  However, to avoid piece collision we want to travel along the lines instead of through the squares. Thus, each time we are moving a piece, we first shift up and right 1 coordinate step. So we’d go from (13,5) to (14,6). Then we’d do the (-2,0) shift, thus going from (14,6) to (12,6). Then we’d cancel out the offset shift by going down and left one coordinate, thus going from (12,6) to (11,5). The piece has then arrived at the destination coordinates.

The magnet is flipped down, and the stepper motors move the system and recalibrate to the center (8,8) coordinate by subtracting the current coordinates from (8,8). For example,  (8,8) – (11,5) = (-3, 3). If the first coordinate is negative, the X coordinate stepper motor moves down until the Reed switch is triggered. If the first coordinate is positive, the X coordinate stepper motor moves up until the Reed switch is triggered. If the second coordinate is negative, the Y coordinate stepper motor moves left until the Reed switch is triggered. If the second coordinate is positive, the Y coordinate stepper motor moves right until the Reed switch is triggered. 

Now the program is ready for the human to move a piece.

Converting Human Piece Moves to Chess Program Input

Here I have done some more planning so that it will be straightforward when writing the code for detecting human chess piece moves.
We will have an 8 by 8 matrix that stores the current state of the board. Recall the RTI will find a 0 logical input if there is a piece, and 1 logical input if there is no piece. For example when the game first starts out the program will obtain the following board state matrix:
{  {0, 0, 0, 0, 0, 0, 0, 0}
   {0, 0, 0, 0, 0, 0, 0, 0}
   {1, 1, 1, 1, 1, 1, 1, 1}
   {1, 1, 1, 1, 1, 1, 1, 1}
   {1, 1, 1, 1, 1, 1, 1, 1}
   {1, 1, 1, 1, 1, 1, 1, 1}
   {1, 1, 1, 1, 1, 1, 1, 1}
   {1, 1, 1, 1, 1, 1, 1, 1}  }

Note that the state matrix won’t look exactly like the chessboard. It will look like a flipped mirrored image because the matrix starts at (0,0) at the top left, whereas the chessboard starts at (A,1). This is ok, because the program just needs to extract the start coordinates and end coordinates of the piece the human moves. It will be a direct map from the board to this matrix.

 For example, say we move a pawn from C2 to C3 on the physical chessboard. The RTI system sees this as moving from (1,2) to (2,2). Note that chess labeling is not (row, column) like matrix notation, it’s (column, row). The program will catch the change from 0 to 1 in the board state matrix at coordinate (1,2), (we will incorporate some debouncing here). The program will have a four character long string and change the first two characters to “C2  “. Then the program will catch the change from 1 to 0 in the board state matrix at coordinate (2,2), (again some debouncing). The character string will then be updated to “C2C3”. This move of “C2C3” will then be passed into the computer program. The computer will then output it’s move.  

The following is the correspondence table. The row number (of the board state matrix) corresponds to the second coordinate, whereas the column number corresponds to a letter which is the first coordinate:
 
We still need to work out the exact details as to what will happen if a person makes an illegal move. We were thinking a red LED will be lit until the piece is moved back to where it started, and then the person could move again.

Reed Switch Wiring Diagram

The Reed Switches didn't come in yet, but I thought it would be a good idea to draw up the circuit diagram a while so that I can just build it as soon as they come. The 64 Reed switches will be mounted on a 2 foot by 2 foot punch-board. They will be equally spaced 3 inches apart so that they are exactly in the center of our chessboard. The chessboard will be rather large at 2 feet by 2 feet with 3 inch squares so that the magnets do not interfere each other. A more refined version of our project, if it were to be sold to consumers would be much smaller.


The chessboard’s layout is labeled as in the following diagram. 
 
This is also what the chess program we have outputs. Thus we need to perform two overall conversions to interface with the chess program. We need to convert the numerical move coordinates of the human’s chess move into a (letter, number) to (letter,number) coordinate. We also need to convert the computer’s letter, number coordinates to numerical coordinates for the XY table to perform its task. 

The 8x8 “keypad” will be connected to PORTA and PORTB, so that it can be read by scanning the columns and reading the state of the row lines. Each lettered column line (“a” to “h”) will be connected to microcontroller output pins PA0 to PA7, and each horizontal numbered row will be connected to microcontroller input pins PB0 to PB7. It will be necessary to connect input pins PB0 to PB7 to pull-up resistors of value 10kΩ to 5V. The circuit schematic is shown below.


By successively driving a single column line low, and the other columns high, the microcontroller can then read the input ports to see whether any of them are low. A coincidence of a row and column line being low means that a human’s piece is occupying that particular square. If the input to the microcontroller is high when the column is driven low, this means there is no piece on that particular square. The scanning of the column lines will be done using a real-time interrupt.


Friday, April 15, 2011

Friday, April 15

Today I was able to do some more construction on the XY table since we received the linear rack gears yesterday. I was also able to begin figuring out how to use the stepper motors and drivers.
The linear rack gears need to be glued in a perfectly straight line next to one of the X-axis tracks, and next to the Y-axis tracks. Since the tracks themselves are straight, it wasn't too difficult to mount the linear gears because I just had to push them flush against the metal lip of the tracks after applying glue. I was able to complete the bottom linear gear track as shown in the figure here, before and after gluing:



The stepper motors will have large circular gears attached to their axle that will come in contact with these linear gears. This will convert the circular motion of the stepper motors into linear motion.
The glue that we will use for the entire project is West Systems Epoxy. I had some left over from a different project. It is really good epoxy and I highly recommend it to anyone to use.

After working on this I went to look at the stepper motors. A picture of the driver, and actual motor is shown below:


The weaker motor that we received is a bipolar motor, and only has 4 leads. The more powerful one coming in the mail soon can be either unipolar or bipolar and has 6 leads. We will most likely use it as bipolar so that we don't have to use as many leads. Bipolar steppers have a single coil per phase and require more complicated control circuitry (typically an H-bridge for each phase). Here is an idea of how the wiring will look when interfaced with the HCS12:


If the logic circuits are pulled up to VDD, it is good practice to use a high value pull-up resistor in order to limit current to the logic inputs, should an overvoltage event occur. Logic inputs
include: MSx, SLEEP, DIR, ENABLE, RESET, and STEP. Here are a description of some of the inputs:

Step Input (STEP). A low-to-high transition on the STEP input sequences the translator and advances the motor one increment. The translator controls the input to the DACs and the direction of current flow in each winding. The size of the increment is determined by the combined state of inputs MS1, MS2, and MS3.

Microstep Select (MS1, MS2, and MS3). Selects the microstepping format, such as full step, half step, quarter step, eight step, and sixteenth step. MS2 and MS3 have a 100 kΩ pull-down resistance. Any changes made to these inputs do not take effect until the next STEP rising edge. If the MSx pins are pulled up to VDD, it is good practice to use a high value pull-up resistor in order to limit current to these pins, should an overvoltage event occur.   


Direction Input (DIR). This determines the direction of rotation of the motor. When low, the direction will be clockwise and when high, counterclockwise. Changes to this input do not take effect until the next STEP rising edge.

 The outputs to the bipolar stepper motor are pins 1A, 1B, 2A, and 2B. I still need to read more to figure out exactly what these do.

The driver datasheet makes it seem that it won't be too difficult to use. One issue that I saw was trying to figure it out was how to adjust the max / cutoff / output current to be 1.2A so that we can supply the larger motor with this much current.  There is a variable resistor potentiometer that must be tweaked to set the supplied current. However, what I am confused about is how to actually measure what the current output actually is, and I need to study the datasheet some more.
The second issue I saw was that the datasheet stated that when the current was above 1A, a heat sink or cooling method was recommended because the driver can easily overheat. We think that we will be alright when it comes to this because we won't need to have the two drivers confined in a small place or close to one another. Also, I have a small fan that I could put next to them just in case. I also have the heat sink from the Wii that I tore down...

Here is a link to the datasheet in case anyone is interested, or wants to help us out.

We are still waiting on the circular gears, the reed switches, and the strong motor.