Tunedra (Atmega8 based tuner)
I have wanted to undertake a solid project involving microcontrollers for quite some time. Lack of time and skills (electronics) for sure was a big obstacle - but in the end you can always learn as you go (as long as you don't pick a project that is way too ambitious) and if you really want to do something you can go a long way just to find some spare time for it. My real problem was not simply not having a good idea for such a project, everything was either way too simple, or way too difficult - so I either spent time playing with Arduino Nano and testing some relatively basic components, or kept getting frustrated at failing at something way above my abilities.
As an avid bass guitar player I finally realised that I can pick a project that would combine my passions - audio, electronics and programming. From digital effects, loopers and other toys tuner seemed the easiest to make, so I went with that.
I started prototyping on Arduino nano, roughly following the instructions found here. I quickly went my own way as that project wasn't really satisfying. I wanted to have a different display, to use a wider range of frequencies (so I can tune both bass and guitar, as well as tune lower/higher than standard) and not to use two separate power sources. I stuck with using the frequency detection algorithm from mentioned project (link) and decided to redo everything else myself.
How it works:
The guitar signal is first biased, so that the middle point of the AC signal is 2.5V instead of 0V. The signal is fed into an operational amplifier to exaggerate the difference between highs and lows and make the wave more readable. The algorithm then determines how often the wave crosses the mid-point. This allows to calculate the wave's period and the sound frequency. The Atmega finds which note does the frequency correlate to and what is the deviation between current and desired frequency. The closest note and deviation is displayed using LEDs. Using this tuner doesn't differ much from using actual commercial products - the tuner is responsive and accurate.
First challenge was to get rid of the dual power supply. At the time I didn't know what biasing an opamp and how alternating current even differs from direct current. Fortunately I realised there is an easy solution to that - by putting two same resistors in series I could access halved voltage. Combining that with with guitar signal allowed me to feed that signal into a single power source operated opamp.
Second challenge was to move the project to an Atmega8. I wanted to keep the Arduino and it would fit into the tight case I ordered (in fact, the whole device barely fits in the case and I am worried that if I ever replace the battery I won't be able to close it again). Fortunately most of the code was compatible with AVR so only small adjustments were needed. The only thing causing problems was determining the note by frequency - I couldn't just hardcode all the values as I did before as I was running low on memory. I have implemented a system that only requires one hardcoded octave and calculates higher frequencies on the fly.
Next challenge was the five diodes displaying deviation from desired frequency. On Arduino I had five PWM pins available, one per each LED. But on Amega I only had three PWM pins, meaning I wouldn't be able to control the brightness of two of the diodes. I found out that using ws2812 diodes I can chain a big number of diodes and control their brightness and colour with just one Atmega pin. I rewrote the code to use ws2812 using this library.
The last challenge is one I wasn't able to overcome. Initially I intended to place a small lever on the tuner allowing the user to choose whether they want the guitar signal to pass through the pedal while tuning, or whether they want to mute the signal. I unfortunately I wasn't able to pass a clean signal - ws2812 use pulse width modulation, meaning that they create small and rapid voltage spikes that the amplifier treated as sound signal. I could hear unbearable high pitched noise that changed with the number, brightness and colour of the LEDs. I tried to solve it by implementing a low pass filter, but I wasn't successful in eliminating all the noise. Then I tried to decouple the diodes using capacitors, but doing it as shown in the official datasheet brought no results. I thought of using a bigger capacitors, but I didn't want to risk them not fitting in the case and I didn't want to redesign the solder board. In the end, I decided to drop that idea (even though I already drilled a hole for the lever in the case). At least I think I learned why most products of this kind mute the guitar while tuning.
- Tuning: The tuner displays all the notes and half-notes in the 16hz - 508hz range.
- True bypass: Usage of the 3DPT switch allows the guitar signal to pass unchanged through the pedal when turned off.
- Optional power adapter: The tuner can be powered by a standard 9V DC adapter or by an internal battery. Inserting a power jack opens the battery circuit.
- Battery wastage prevention: Removing the input jack opens the circuit, turning the pedal off when not used.
In this section I discuss the diagrams that can be found in the gallery section below. Note that I decided to skip the 3DPT footswitch in the diagrams - it makes them clearer and there is a lot of resources showing how to wire those properly.
In the diagram showing the power section of the circuit we can see that all ground passes through the ring and sleeve of the audio input. The audio socket used is stereo, while guitar cables are mono. This means that ring and sleeve of the audio socket will be connected together when audio jack is inserted. Doing it this way makes sure that removing the input jack will open the circuit, preventing battery loss when unused.
The circuit will use the battery then the power jack is not inserted (pin 3 and 2 are connected when adapter is not in). Inserting the adapter will disconnect pins 3 and 2, but the power will flow directly from pin 2.
D1 diode prevents and complications if an adapter with + on outside and - on inside is inserted. The voltage is then regulated to 5V as it is a safe and useful voltage when working with Atmega8.
R1 and R2 are used to half the voltage. The halved voltage is later used for biasing the opamp. C1 helps keep the 2.5V stable.
Next, in the input the input section, the guitar signal is shown to be connected to ground through a 10M ohm resistor R3. This pull-down resistor prevents lout popping noises when the pedal is turned on. Next, C2 is used to filter the signal from DC. 2.5V is added to the signal and fed to opamp. The ratio between R4 and R5 will determine how much the signal gets amplified. C4 makes sure only AC gets amplified. This signal is fed into the Atmega and gets processed. LEDs are used to display the outcome of the frequency analysis.