**51 Magic: some perhaps relevant information about homework 14 in EE 51 This was written in fall 2005; much of it is no longer relevant, and the rest may not be relevant either. This is information that you are supposed to find out from your TA, I believe. I see no harm in distributing it here. Most of it could be gathered just as easily from the schematic of the RoboTrike hardware interface or from common sense. I make no guarantee of correctness or sensicality. The drive motors are on port C. The stepper for the turret and the laser are on port B. The proper mode for the 8255 is: group A mode 0 port A output port C upper output group B mode 0 port B output port C lower output You can look up the control word in the datasheet. The laser appears to be on pin 7 of port B To control DC motors (i.e. drive motors): 10 backward 01 forward 00 stop Backward/forward may need to be flipped under certain circumstances. (I believe the two motor controllers that were built last year were not the same.) Motors are on port C pins 0-3. The left motor is bits 0 and 1; the right is bits 2 and 3. The speed of the motors is controlled by PWM. 32 speed steps is enough; then you can just have a timer interrupt that happens every millisecond or so and increments a counter mod 32. If the counter is greater than the speed step turn the motor on; otherwise turn it off. The stepper motor for the turret is on B0-B3, I think. You want to move it by half-steps, which I believe are 0.9 degree increments. You make it turn by sending the following bit patterns in order: 1000 1001 0001 0101 0100 0110 0010 1010 (Reverse the order to reverse direction, of course.) You should do this with a timer interrupt called every 50ms or so that checks if the turret has to move and, if so, sends the next one. Controlling the turret is a big pain in the ass, because you're supposed to give it the absolute angle to turn to, not a relative angle to turn by. Zero is straight ahead. The HW14 assignment specifies that the turret should rotate through the shortest legal angle to the new position, which makes it so much more of a pain. According to my comments, I used the following algorithm to figure out which way to turn: if TurretAngle - TargetTurretAngle > 180 or -180 < TurretAngle - TargetTurretAngle < 180, turn clockwise else turn counterclockwise This doesn't make any sense, so I must have made a mistake when commenting. In fact, I seem to move clockwise if -180 < TurretAngle - TargetTurretAngle < 0 or TurretAngle - TargetTurretAngle > 180, otherwise counterclockwise.