Software:
Our software covered many of the technical topics introduced throughout the course. This includes ABI compliant functions written in assembly, general-purpose timers, interrupts, and memory-mapped I/O interaction.
The software is split between C and assembly code. The C code controls the algorithms that determine which keys will be pressed and how much the motors need to be moved between key presses. These values are stored in external variables that can be used by the assembly code during interrupts. The C code also controls the LCD character display by determining the correct lines needed to be written and calling a simple assembly function to write the values to the memory mapped address.
The assembly code mostly consists of initialization of interrupts, LCD controls, and timers, as well as the interrupt service routine (ISR) code. The ISR turned out to be fairly lengthy and complex, and took a fair bit of work to get working properly. We are using two general purpose timers to control the timing of the motors and solenoids. One of these interrupts occurs on the “beat”, when the new note should be played. The other timer begins on the beat and counts to a certain value that will signal the solenoids to lift in order to give adequate time for the motors to move to position for the next beat.
The other two interrupts are generated in hardware on the IRQ1 and IRQ7 lines. One of these interrupts tells when both of the motors are in position and the corresponding routine simply sets a flag for the software to use. The other interrupt occurs from the keypad whenever any key is pressed. This interrupt routine calls a C function which will alter the LCD according to a finite state machine.
Click here for a high level view of the software.