Software

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.

General Walkthrough

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
  1. Read input frequency
  2. Find closest note
  3. Compare to stored values to find direction and amount out of tune
  4. Display note, deviance, input frequency
  5. Repeat
Automatic Tuning
  1. While frequency is not within "in tune" range
    1. Read input frequency
    2. Display note, deviance, input frequency
    3. Find if input frequency is higher or lower than user setting note
    4. Run motor corresponding direction or stop if in tune
  2. End

Code Details

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

Code

fewernotes.c - complete Interactive C code for our tuner