Test your Ears: Description of the Firmware
The firmware runs on a Freescale MC9S08QG8 microprocessor. This is a fully self contained micro which does not need any external components to run properly. Even the accuracy of the internal clock oscillator is sufficient for the serial communication to work fine.
For programming the chip and/or to modify the code you need the development environment of the "Spyder" project as it appeared in Elektor April 2007 (at least in the Dutch edition). The complete environment is available from Elektor for around € 12,= including the "Spyder Stick" for the actual programming.
Stack some extra DIL-8 sockets to adapt the 16-pins IC which is used in this project.

The code is mainly witten in standard C and consists of a few files.
- main.c
contains some startup and initialisation code. The main function
has an endless loop, because all activity is done in two interrupt
handlers.
- clocks.c initializes the clock circuit for the internal clock oscillator.
- TestYourEars.c contains the code for this project.
The function SciReceiverHandler is an interrupt handler which processes the incoming serial data and sends the return message.
The function Timers_TpmHandler is an interrupt handler which processes the blinking of the Led's and the monitoring of the buttons and the input signal level.
The function Debounce is used to make sure that the buttons work neatly. For a given button it tests if the button state is the same for 4 successive calls. Only than that state is registered. The function is called at 10 ms intervals.
The function AdConver8 does one A/D conversion per call. The result is used to calculate the peak-to-peak level of the analogue input signal.
The function SendDataToPGA sends two bytes of data to the PGA2311 chip. It is wiritten in assembly language for historical reasons on my side.
Note the "No Operation" instructions. They give the branches equal time, so the signals look better when diagnosing with an oscilloscope.
Finally you see some initialisation functions, called during startup. - The .h files are for the compiler and the linker to make that everything comes together properly.