Schematic of microphone and pre-amp for low-noise 8-bit ADC.
This post discusses how I went about integrating a microphone into the myki such that the low-resolution 8-bit ADC on the ATmega32U4 would be able to get a reasonable noise level.
In the myki light, this is done using the MAX9814, a single chip microphone amplifier with autogain control to prevent clipping and a low-noise microphone bias convenient for use with electrolet microphones.
For a detailed circuit schematic as well as an explanation of how to use the MAX9814, please see below the break.
Connecting up the Microphone and Input Noise:
In this circuit, we can see the microphone on the far left. It is a standard electrolet microphone, most of which require a 2V bias above a 2.2k resistor in series with the microphone and connected to ground. The microphone itself has a typical impedance of 2.2k, so this makes it so that the output voltage is centered around 1V.
Audio signals will change the impedance of the microphone, producing a time varying inverted representation of this change. The actual details inside are a bit more complicated, but in terms of just using the microphone the important part is that you must connect a very clean and low noise 2V bias voltage to a 2.2k resistor connected to pin 2 on the microphone, and connect pin 1 on the microphone to a low noise analog ground.
Here it is critical to keep noise low. If your microphone bias voltage has 100mV of noise on it, it will show up as 50mV of noise directly on your signal! Most electret microphones only output 10-100mV of signal anyway, so you can completely swamp your signal if you aren’t careful. On my board in order to handle this I have an entirely separate supply for most of my digital circuitry and this device so that if my LED turns on that won’t show up as transient noise on the power rails of the MAX9814. Additionally, the use of the built-in microphone bias output provides power supply noise reduction (PSNR), typically on the order of 1000x for a device like this. That is likely better than I can do even with extensive filtering, so this sort of bias makes the microphone signal much cleaner.
Next, you will notice a 100nF capacitor (C21) between the electret microphone and MICIN on the MAX9814. This acts as a high pass filter to only allow AC signals through to the MAX9814. This is basically just done because that’s how it is specified in the datasheet, but it is because the MAX9814 has an internal voltage reference centered around it’s amplifier circuitry that will provide a DC offset to the incoming AC signal appropriate for amplification internally.
Using the MAX9814 Chip’s Gain Features
The MAX9814 is a special little chip in that it offers a variable gain. You can get it to provide a default gain of 40, 50, or 60dB by setting the GAIN pin to either disconnected, 5V, or GND. This is the maximum gain seen, and the gain that will be used by default. If you never get a signal large enough to trigger the autogain control, it will be a constant at that level indefinitely.
After the ability to manually set a fixed default gain, there is also an AGC (auto gain control) amplifier. This is basically a compressor that kicks in automatically once the signal exceeds the AGC threshold (set with R16 and R17). In this case, if the output exceeds 1V, the AGC reduces the gain in order to prevent clipping. This allows you to be aggressive in setting the default gain with less risk of producing a damaged signal.
If you wish to turn off this feature, just connect the TH pin to MICBIAS. In this way you can guarantee that even if the input impedance of the electret goes to infinity, it will not exceed the AGC threshold at which it attempts to turn down the gain. If you need a perfectly time-even gain, this is the way to go.
Next, we have the attack:release ratio. This means how fast AGC will turn down gain relative to how slowly it will let the gain creep back to the default. You can set this using the A/R pin, which on the myki is a jumper. If you leave it disconnected, the A/R is 1:4000, at 5V it is 1:2000, and at GND it is 1:500. In my experience qualitatively, I prefer a quick attack and very slow recovery, so I am going to start with 1:4000.
Interfacing the MAX9814 output with the ATmega32U4.
The ATmega32U4 has quite a few 8-bit analog-to-digital converters (ADC). You can set using the Arduino programming environment what you want to use as an analog reference voltage. This is the voltage which will be represented as 0xFF (hexadecimal maximum for an 8-bit number). By default, the Arduino uses the AVCC of 5V as the reference voltage. In this case, that is not good.
The MAX9814 chip outputs an amplified version of the microphone signal on the MICOUT pin, with a bias voltage of 1.23V. This is actually extremely convenient, because it allows us to use the ATmega32U4 internal voltage reference of 2.56V and get a high resolution, centered measurement. With a 2.56V voltage reference, each bit on an 8-bit ADC is equal to precisely 10mV, which is also very convenient. So, a DC signal from the microphone (silence) would be a constant 123 in digital.
The Arduino environment defines the analog reference setting using the analogReference function.
analogReference(DEFAULT); // Uses the default of 5V. analogReference(INTERNAL2V56); // Uses the 2.56V internal reference.
In our case, we want to use the second option, configuring the myki to use the 2.56V internal reference voltage.
Now, we know that a quiet environment will result in a ADC output of approximately 123. Due to errors in manufacturing of the resistors and chips, this may not be exactly correct for you, and you should of course compensate in your code to automatically find the accurate DC offset at the converter.
In a later post, I will get into the details of doing audio reading from this circuit, doing beat detection, noise thresholding, and using it to control the color and intensity of light from the myki light in the standard audio responsive mode.