The software part on the tuner on the Handy Board microcontroller controls the tuner. We initially looked into ways of calculating the frequency using the Handy Board, but decided that it would be simpler, more robust, and more efficient to do the bulk of the frequency measuring in hardware. The only math the software must do now is to turn the period of the signal into a frequency (the more standard way of identifying notes). This leaves the software with the task of reading user commands, matching the inputted frequency to a note, telling the motor what to do, and displaying the screen output.
The code begins by waiting for a signal from the tuner. It does this by waiting for the amplified guitar signal to move from zero into a preset range. This helps eliminate any aberrant behavior that occurs when the tuner starts program without an input signal.
Next the code reads which setting the user has chosen - manual tuning or automatic tuning for a specific string. Each mode uses a different control method, both of which are explained below.
Manual Tuning
|
Automatic Tuning
|
Code Parameters
In tune - within 0.5% of ideal note frequency
Close to note - less than half a note away from ideal note but not in tune
Very far out of tune - close to note but more than 1/4th of a note away from ideal note
Far out of tune - less than 1/4th of a note away from ideal note but not in tune
Subroutines
The code uses four subroutines to accomplish its tasks. They are read_input_signal, read_setting, freq_match, and run_motor. Each is explained below.
read_input_signal
Read digital inputs
Convert inputs to number of counts
Calculate frequency based on RC time constant
If necessary divide frequency by 2 to normalize to a preset octave
read_setting
Read setting from knob
Set appropriate variables to indicate setting
freq_match
Compare note to preset ranges around E, A, D or G to find closest string
Test if note is above or below closest string
Test if note is range for "very far" above or below, "far" above or below, or "in tune"
Print to display note, deviance, signal frequency
run_motor
While string is not "in tune"
Test if signal frequency is higher or lower than user set string note
Run motor forward or backward accordingly or stop if in tune
fewernotes.c - complete Interactive C code for our tuner