Software Design
The software in our system manipulated the data obtained from the touchscreen into workable Cartesian coordinates, with which we determined the movement on the touchscreen. The data could then be used to control the servos by setting their pulse-widths. Also, we had C code to control the LCD display.

Initially, we generated the pulse to the servos using the MPC823's timers, writing code to change the state of the servos within an interrupt handler. However, in testing, because the servo's max rotational speed is limited, in order to draw longer continuous lines on the Etch-A-Sketch, the important parameter in servo control was the number of cycles to keep the motor on with a given duty cycle. In order to control the number of cycles for servo control, delays had to be implemented in software. It became apparent, however, that these delays were slowing down the timer to such a degree that the actual pulses being sent to the servos were incorrect, causing wildly erratic behavior. Thus, we moved the servos' pulse-width control to hardware.

Otherwise, our software basically interpreted the data obtained from reading memory-mapped locations in hardware to operate the servos and LCD. Reading from address 0x2500000 on ADC channel 1 fetched the coordinate data from the x-coordinate of the touchscreen, and reading from ADC channel 0 fetched the data from the y-coordinate. During every sample, the distance traveled on the touchscreen between every sample was calculated using the x,y coordinates from the previous sample and the x,y coordinates from the current sample. The x-distance and y-distance are calculated separately and the distance vector is interpreted to determine how to control the servos by modulating their respective pulse-widths. Once the new pulse-widths and "on-cycles" (cycles that the servo is on) are determined, the software writes to a memory mapped location at address 0x2600000 to control the pulse to the servos. This process occurs every sample.

In absolute drawing mode, we use a software buffer, which is essentially a character array to hold the coordinates obtained from the touchscreen in order as they are being drawn. These coordinates are then used much as explained above, except that the touchscreen is essentially "mapped" to the Etch-A-Sketch. The buffer allows us to keep track of where we are on the Etch-A-Sketch and how to move.

In both modes, we use C code to draw the current position of the stylus on the touchscreen during each sample. In relative drawing mode, the line drawn while there is pressure on the touchscreen remains until pressure is lifted. In absolute drawing mode, everything drawn on the touchscreen while in that mode remains on the LCD as long as one remains in that mode. The software reads a memory-mapped location at address 0x2500000 to determine whether or not the touchscreen is being touched.

There is also minor interrupt handling code, as we mapped push-button 0 to IRQ0 as an edge-triggered interrupt which changes the drawing mode between absolute and relative. By default, the system starts in relative drawing mode.