My MAX9814 Electret Micropohone results fail so far

SolidWorksMagi

Senior Member
I bought one of these MAX9814 based Electret Microphones so a loud sound could trigger actions for a robot. I've looked at a few dozen websites for ideas how to make it work, but have not been able to get a usable wiring or software configuration.

I've been trying the sample code from: http://www.picaxe.com/docs/picaxe_sound.pdf

do
gosub green
pause 1000
readadc B.1,b1 ; read value into w1 from B.1 pin ... also tried A.0 pin
debug ; to see w1 value
if b1 > 1 then gosub red ; Loud Sound was Heard
pause 1000
loop

My connections are GND, Vcc, OUT (B.1) and when that failed I added a Pull-Down 220Ω resistor from OUT to GND
 
Last edited:

hippy

Technical Support
Staff member
It always helps to provide a link to the product being discussed. I'm guessing it's this -

https://datasheets.maximintegrated.com/en/ds/MAX9814.pdf

In short it's a pre-amp which boosts a low voltage microphone signal to a voltage more detectable with a PICAXE.

It seems READADC should be usable to read its voltage in and detect when over a particular level but, because sound is rising and lowering one has to be lucky enough to read at a point of voltage being present not voltage absence so timing of read can be critical.

You could consider it a bit like car spotting with your eyes shut. A one second delay between READADC is like covering your ears most of the time then briefly exposing them and hoping that coincides with a car going past. The more frequently you expose your ears the more likely you'll hear one. You could try this ...

Code:
SetFreq fastest
Do
   Do
    ReadAdc AMP_INPUT, b1
  Loop Until b1 >= TRIGGER_LEVEL
  Gosub LightLed
Loop
You can also extend the period for which sound voltage is present by running it through an RC though sampling as quickly as possible should avoid the need for that.

It might also be worth looking at my 'composite video signal detector' which was designed to detect low voltages which would probably apply to using the MAX9814 -

http://www.picaxeforum.co.uk/showthread.php?19289-Composite-video-signal-detector
 

erco

Senior Member
Crank the amp gain up and check the output signal. As long as a clap or loud sound goes over 1.4V, just have a fast sample loop and exit on any high input.

LISTEN:if pinb.1=0 then LISTEN
etc...
 

premelec

Senior Member
@SolidWorksMagi - have you connected a microphone to the amplifier? - the MAX9814 is not an electret microphone as you have stated in OP... ;-0
 

SolidWorksMagi

Senior Member
Hi,

In my original post I said I was using that .PDF for a reference. It's a better solution than others I found online, but I'm not getting the results I hoped for.
 

premelec

Senior Member
Great - that has the microphone... ;-] can you see any output change for audio input when you make a noise with power connected?
 

SolidWorksMagi

Senior Member
I put a DSO Nano on the OUT/28X2 Pin A.0 IN and see about a 15mV signal that as the program loops shows a 40ms drop to about -5mV blip looks like an inverted Yosemite Half-Dome.

I have a 220Ω resistor pulling the gain to 5V.
 

rq3

Senior Member
That link is to a board that includes the electret microphone AND the actual Maxim MAX9814 integrated circuit.
Here's a datasheet from Adafruit that appears to describe exactly the board you have:
https://cdn-learn.adafruit.com/downloads/pdf/adafruit-agc-electret-microphone-amplifier-max9814.pdf
 

SolidWorksMagi

Senior Member
I've looked at the Adafruit pages, they're mostly useless and designed for people that are not programming, but just copy/paste the libraries to make a couple of Adafruit kits. I'm using a PICAXE not an Arduino so I need to write my own subroutines in PICAXE BASIC not use c libraries.
 

rq3

Senior Member
I've looked at the Adafruit pages, they're mostly useless and designed for people that are not programming, but just copy/paste the libraries to make a couple of Adafruit kits. I'm using a PICAXE not an Arduino so I need to write my own subroutines in PICAXE BASIC not use c libraries.
The Adafruit PDF I linked to has nothing to do with Arduino or C libraries. Did you read it, or just blow off Adafruit datasheets because you didn't happen to stumble across that particular one?

It explicitly expounds on the ANALOG connections to YOUR board. The fact that the audio output has a severe DC offset, which must be accounted for when the output is introduced to an Analog to Digital Converter (ADC) as you are doing. The fact that, at high gain, (and the analog gain is adjustable), the output may be so severely clipped that it almost never goes low (and your application requires the output go low).

You can program until the cows come home, and the cows will starve to death when the farmer doesn't understand that cows, microphones, and microphone amplifiers are analog. Not digital. When the farmer can program a digital cow feeder to keep his analog cows happy, he may succeed at farming cows. Or even succeed at interfacing an analog microphone and its associated analog amplifier to a digital microprocessor.

I'd suggest that sometimes it's worthwhile to re-visit sources of data you may think you know by heart. Sometimes the owner of another pair of eyes can say, "Yeah, but..."

Just sayin'.
 

rq3

Senior Member
The Adafruit PDF I linked to has nothing to do with Arduino or C libraries. Did you read it, or just blow off Adafruit datasheets because you didn't happen to stumble across that particular one?

It explicitly expounds on the ANALOG connections to YOUR board. The fact that the audio output has a severe DC offset, which must be accounted for when the output is introduced to an Analog to Digital Converter (ADC) as you are doing. The fact that, at high gain, (and the analog gain is adjustable), the output may be so severely clipped that it almost never goes low (and your application requires the output go low).

You can program until the cows come home, and the cows will starve to death when the farmer doesn't understand that cows, microphones, and microphone amplifiers are analog. Not digital. When the farmer can program a digital cow feeder to keep his analog cows happy, he may succeed at farming cows. Or even succeed at interfacing an analog microphone and its associated analog amplifier to a digital microprocessor.

I'd suggest that sometimes it's worthwhile to re-visit sources of data you may think you know by heart. Sometimes the owner of another pair of eyes can say, "Yeah, but..."

Just sayin'.
Now that I'm curious enough, I went back to your original post and followed the thread through to the end. I think you are assuming that the two meager lines of code you are attempting to use are applicable to ANY circuit other that the one specifically illustrated in the reference you give.

While the example is valid, you are assuming that the illustrated circuit will act, in an analog fashion, exactly the same as the board you have. It most definitely will not, for many reasons. That's no fault of the microphone, the amplifier chain, or the Picaxe. Only your understanding of their interaction. A brief example from your first post is that you are storing an 8 bit ADC read into a 16 bit word. There isn't enough of your code or circuit to determine if you are clipping, in either an analog or digital fashion, the data you need.

As always, a complete code list, and a detailed schematic of your circuit, would be of immense help. Everyone is here to help.
 

hippy

Technical Support
Staff member
I have a 220Ω resistor pulling the gain to 5V.
Perhaps remove the resistor and see what happens. Looking at the silkscreen the maximum gain is when the gain input is left floating.

Perhaps try a different module to see if that behaves the same.
 

AllyCat

Senior Member
Hi,

To reiterate what rq3 has said. "Sound" is an "alternating" (ac) signal whilst a microcontroller always detects an instantaneous (dc) voltage level. A single measurement (digital or via an ADC) will almost NEVER tell you anything useful about an ac signal:

You need either additional hardware to convert the ac "sound level" to a dc voltage (which is what the circuit linked by technical in #4 does), or need a more complex program which makes multiple measurements (certainly NOT separated by a PAUSE 1000) and takes into account the "dc bias" on which the ac signal sits.

Even with that done, an " IF ... > 1" is unlikely to produce a satisfactory result with an ADC byte value (0 - 255) derived from an audio channel.

Cheers, Alan.
 

hippy

Technical Support
Staff member
The first thing to do is to get the MAX9814 module working without a PICAXE.

As there is a DSO available that should be fairly easy; power the MAX9814, monitor the output voltage on the scope. Any noise picked up by the microphone should produce some significant output signal change.

Once that's working, and what output voltages seen are noted, then we can move on to connecting it to a PICAXE and coding for it and what it produces.

If it's not working then there is something wrong with the module or the way it is wired, and that can be investigated.
 

SolidWorksMagi

Senior Member
Hi,

I like the nice tight embedded and recursive looping ... but right now I have no idea what to put in place of "Trigger_Level" other than in the "Composite video signal detector" check bit0 to go high, but that seems like it could be a random number albeit toggling from incoming sound.
 

hippy

Technical Support
Staff member
See post #16. Get the MAX9814 proven to be working before worrying about connecting to the PICAXE or its software.
 

SolidWorksMagi

Senior Member
Hi,

I did some initial testing:


Here is the current program;

#picaxe 28X2
SetFreq m16

' BEGIN Declare and Initialize Variables & Constants * * * * * * * * * * * * * * *

symbol MIC = A.0

; END Declare & Initialize Constants & Variables * * * * * * * * * * * * * * *

; BEGIN Main Body * * * * * * * * * * * * * * *
do
gosub green
do
readadc MIC, b1
loop until b1 >= 1
gosub red
loop
; END Main Body * * * * * * * * * * * * * * * *
 
Last edited:

oracacle

Senior Member
for starters debug is slow, sertxd the single variable instead, there will be less chance of missing reading.
from the work I have done with detecting sounds I have always used the comparator interrupt. there are a few reason for this. sounds are very short and may well not last long enough to be read by the comparatively slow adc read times.
I have always used a circuit that contains and envelope follower, this allows the peak to last for longer giving more time for the picaxe to detect what is going on. Better still a peak detector with envelope follower.

I made a spark fun sound detector, replacing the LM324 with a LM224N
https://learn.sparkfun.com/tutorials/sound-detector-hookup-guide
its a great little circuit, adjusting C1, R8 and R9 allows you to tweak characteristics of the envelope follower.
As you may notice there are a few diodes in there, these are for rectifying the signal to remove AC signals and stop them getting to the picaxe. I have found with a little bit of experimenting, that allowing even the slightest AC type signal through to an ADC will cause it to reset, this includes sound wave forms.

something that I did notice while reading through this thread, is there is no Arduino hook circuit, and everything just point to this being an amplifier. adding Arduino to something like this just to try and make it sell is a pain the backside, that along side the fact that I am not sure if the ADC on the ATmega chips are more tolerant of AC type wave forms the PIC chips.
my first suggestion is to add and diode between the amp unit and the picaxe input and see what happens.
 

inglewoodpete

Senior Member
; BEGIN Main Body * * * * * * * * * * * * * * *
do
gosub green
do
readadc MIC, b1
loop until b1 >= 1
gosub red
loop
; END Main Body * * * * * * * * * * * * * * * *
The video shows that the microphone and amplifier are working fine. What is not clear to me is where the zero voltage level is on the oscilloscope screen. Is it the centre of the screen or at the bottom?

Either way, your code will almost always read anything but zero, so your Red routine will be called 99.99% of the time. Since you haven't post the code in "Red" and "Green", it's hard the tell what happens with the LEDs. They both appear to be on all of the time.
 

hippy

Technical Support
Staff member
#picaxe 28X2
symbol MIC = A.0
readadc MIC, b1

That will not work as expected. On the X2, READADC requires an ADC channel number. PICAXE Editor will auto-magically convert a pin name to an ADC channel number when the pin name is given in the READADC command, but not when specified through a SYMBOL definition.

You need to use -

readadc A.0, b1

or

symbol MIC = 0 ; ADC0, A.0
readadc MIC, b1
 

SolidWorksMagi

Senior Member
Hi,

red and green subroutines just turn ON either a red LED or a green LED of a 3-color LED then return to the loop, the other red led is the LED on the audio amplifier a part of the RoboGuts™ circuit board and has nothing to do with the microphone in use.

The ground on the screen is the horizontal green line at the vertical center.
 

SolidWorksMagi

Senior Member
Hi,

Thanks for that tip HIPPY ... I made the change in the program to reference readadc A.0,b1

I made a video showing the test2 ... but now I am a little confused because my DSO Nano is showing the baseline for the signal to be about -1.5V! When there is any noise pretty much any volume, the signal doesn't go above the ground reference! ???

I tried adding a 220Ω resistor from +5 to Gain ... that made the signal out smaller so I shifted the resistor to GND and Gain and got the exact same results ... a smaller signal out. I'm not sure why this microphone board creates its reference 1.5V below common ground to power and the RoboGuts™ circuit board.

In the video you can see the LED ON for programming the chip, then cycles through red, green and blue before going into the actual do loop. The scope is set at 1V/division with the scopes green horizontal ground reference set at the vertical center. ALL grounds (RoboGuts™ circuit board, Scope and Microphone board) are tied to the same power source!


20180330-MAX9814-Front.jpg
 
Last edited:

rq3

Senior Member
Hi,

Thanks for that tip HIPPY ... I made the change in the program to reference readadc A.0,b1

I made a video showing the test2 ... but now I am a little confused because my DSO Nano is showing the baseline for the signal to be about -1.5V! When there is any noise pretty much any volume, the signal doesn't go above the ground reference! ???

I tried adding a 220Ω resistor from +5 to Gain ... that made the signal out smaller so I shifted the resistor to GND and Gain and got the exact same results ... a smaller signal out. I'm not sure why this microphone board creates its reference 1.5V below common ground to power and the RoboGuts™ circuit board.

In the video you can see the LED ON for programming the chip, then cycles through red, green and blue before going into the actual do loop. The scope is set at 1V/division with the scopes green horizontal ground reference set at the vertical center. ALL grounds (RoboGuts™ circuit board, Scope and Microphone board) are tied to the same power source!
Looks like the microphone and amplifier are working perfectly. When there is no connection to Gain, the gain is 60dB (crazy high). When Gain is connected to ground, the gain is 50 dB (smaller output). When Gain is connected to the positive supply (Vdd), the gain is 40 dB (an even smaller output).

The output has a 1.25 volt DC offset at all times. In other words, in an absolutely quiet environment, the output will be +1.25 volts referred to ground. Are you sure you don't have the scope leads reversed?
 

SolidWorksMagi

Senior Member
Hi,

IF I reverse the scope leads there is no signal other than a signal ground showing on the scope screen. The leads are connected correctly.

IMG_7349-20180504-MAX9814-2-RoboGuts-Connections-ec800T.jpg

Some of the data from the serial port:
72 59 75 107 93 82 52 73 72 70 64 53 76 76 63 72 62 78 76 67 50 60 64 72 61 59 68 84 71 72 48 64 62 78 77 61 72 57 65 73 55 70 75 76 62 71 66 75 71 63 81 62 111 89 58 62 68 69 62 58 69 79 71 71 63 56 90 69 65 40 80 70 79 53 62 69 89 66 72 51 104 67 68 74 49 71 99 41 93 42 88 77 58 58 65 81 83 82 60 61 68 78 75 72 70 65 80 51 65 57 63 81 94 61 61 75 68 73 83 95 90 78 79 72 72 72 71 58 56 77 63 45 70 68 70 75 74 74 73 79 75 65 60 68 77 76 55 52 65 65 78 60 72 73 87 67 73 77 78 56 64 61 57 81 66 60 54 73 84 75 67 57 77 80 57 57 59 85 79 66 61 45 88 84 59 49 69 78 57 80 77 70 76 75 80 37 83 87 57 58 66 93 85 73 57 73 67 65 69 54 64 82 81 57 66 71 75 73 70 57 81 80 77 57 54 77 84 83 83 63 62 72 79 65 45 69 90 72 58 90 68 44 54 76 68 69 49 61 76 77 86 73 72 50 69 81 57 60 60 65 82 66 68 52 57 67 63 78 77 74 71 63 64 74 79 65 64 71 70 66 66 61 70 76 64 62 74 64 72 63 70
 
Last edited:

premelec

Senior Member
I don't know what your circuit is however I suggest putting a silicon diode in series from the amplifier to the PICAXE input ADC - put a 20000 ohm [roughly] resistor from the PICAXE input to V- and if you can stand some delay a capacitor of a few uF in parallel with that resistor. The voltage drop on the diode will cancel some of the DC offset and also allow only positive peaks through to the ADC input... capacitor would smooth out changes some. Readings will be pretty low unless you have changed your READADC parameters to use lower reference voltage...
 

inglewoodpete

Senior Member
Hi,

red and green subroutines just turn ON either a red LED or a green LED of a 3-color LED then return to the loop, the other red led is the LED on the audio amplifier a part of the RoboGuts™ circuit board and has nothing to do with the microphone in use.

The ground on the screen is the horizontal green line at the vertical center.
Is there any code anywhere to turn the LEDs off is there is no signal?
 

SolidWorksMagi

Senior Member
Hi,

green LED ON means no input from the MAX9814 Microphone board and Red LED ON means there is a signal from the MAX9814 Microphone board ... as stated in the DO LOOP.

The MAX9814 Microphone board shouldn't need any other components when connected to any MCU chip. Getting this to work as a MCU and MAX9814 Microphone board only is the goal here.

20180330-MAX9814-Front.jpg
 

AllyCat

Senior Member
Hi,

Some of the data from the serial port: ...............
You've not given any indication of the time-span of that data, nor how the "sound" was changing but it looks completely plausible.

The average (bias) level is around 75 (about 30% of a 4.5v supply rail) with (presumably) "loud" peak samples of >100 and <50. Either (or both) of those tests should detect a "loud" sound, or change the thresholds as required.

But to do the job better, you should calculate a "rolling average" of the detected values and subtract it from each instantaneous value (or vice versa to always produce a positive value). Then select a threshold level (probably in the range 5 to 50) as required.

Cheers, Alan.
 

inglewoodpete

Senior Member
Hi,

green LED ON means no input from the MAX9814 Microphone board and Red LED ON means there is a signal from the MAX9814 Microphone board ... as stated in the DO LOOP.
That's not answering the question: Is there any code to turn the LEDs off?
Ie:
  • The green LED lights at boot-up.
  • The red LED lights up as soon as a non-zero value is read from the ADC port.
  • They both stay on until the circuit is powered down.
 

hippy

Technical Support
Staff member
The scope trace looks fine, the data you showed looks fine, so it would seem the problem is in the software. As noted the input is offset to 1.25V so what you are seeing is like this -

Code:
2.50V $7F -----------------------------
                  /\       /\      /\ - - $5F
1.25V $3F __/\_  /  \  /\_/  \    /  \_
               \/    \/       \  /    
                               \/ - - - - $1F
0.00V $00 -----------------------------
I would start by turning the sound detected on LED when the input is >= $5F or <= $1F, see if that sort of flickers when sound is present ...

Code:
#Picaxe 28X2
SetFreq M32
Do
  Do
    ReadAdc A.0, b0
  Loop Until b0 <= $1F Or b0 >= $5F
  High RED_LED
  Pause 1000
  Low RED_LED
Loop
 

SolidWorksMagi

Senior Member
Hi,

When one LED is turned ON, the other LED is turned OFF ... simple HIGH and LOW in the same subroutine for each color.
 

SolidWorksMagi

Senior Member
Hi,

Here's the program as I used it for test3;

; 28X2+MAX9814-MicTests3.bas

#picaxe 28X2 ; Define the MCU
#terminal 9600
;SetFreq m16

' BEGIN Declare and Initialize Variables & Constants * * * * * * * * * * * * * * *

; Electret Microphone = A.0

; hserout PIN 10 = C.0
hsersetup B9600_8, %00000 ; 9600 baud, non-inverted polarity

; END Declare & Initialize Constants & Variables * * * * * * * * * * * * * * *
; BEGIN Main Body * * * * * * * * * * * * * * *
gosub red
pause 2000
gosub green
pause 2000
gosub blue
pause 3000

do
; Same LED settings as in gosub green subroutine
high B.7 ; red LED OFF
low B.6 ; green LED ON
high B.5 ; blue LED OFF

do
readadc A.0, b0
loop Until b0 <= $1F or b0 >= $5F
;debug
sertxd (b0," ")
; Same LED settings as in gosub red subroutine
high B.5 ; blue LED OFF
high B.6 ; green LED OFF
low B.7 ; red LED ON
pause 1000
loop
; END Main Body * * * * * * * * * * * * * * * *
end

Here's the resulting data;

I tried moving the $1F to 2F and $5F to $FF but got essentially the same results.
 

AllyCat

Senior Member
Hi,

=<1F (i.e. 31) or =>FF (i.e. 255) are not going to work because none of those values appear in your sample data in post #26.

But =<2F (i.e. 47, although <56 probably would be better) or =>5F (i.e. 95) should work, provided that any of those values are still being reported by the terminal. Is that your video or somebody else's?

Cheers, Alan.
 

hippy

Technical Support
Staff member
This will allow you to determine what minimum and maximum readings you are getting -

Code:
#Picaxe 28X2
#Terminal 9600
ReadAdc A.0, b0 
b1 = b0
b2 = b0
Do
  SetFreq M16
  Do
    ReadAdc A.0, b0 
  Loop Until b0 < b1 Or b0 > b2
  SetFreq MDEFAULT
  b1 = b1 Max b0
  b2 = b2 Min b0
  SerTxd( "Min = ", #b1, TAB, "Max = ", #b2, CR, LF )
Loop
 

SolidWorksMagi

Senior Member
Hi,

Great little test program hippy, thanks ... here's the data I got back ... seems the louder the noise (my parrot Poncho Villa) the lower the minimum ??? the higher the maximum.

Min = 53 Max = 61
Min = 53 Max = 62
Min = 53 Max = 70
Min = 53 Max = 76
Min = 53 Max = 79
Min = 50 Max = 79
Min = 50 Max = 80
Min = 46 Max = 80
Min = 46 Max = 81
Min = 46 Max = 83
Min = 43 Max = 83
Min = 43 Max = 86
Min = 41 Max = 86
Min = 41 Max = 89
Min = 41 Max = 93
Min = 41 Max = 95
Min = 39 Max = 95
Min = 34 Max = 95
Min = 29 Max = 95
Min = 29 Max = 99
Min = 24 Max = 99
Min = 24 Max = 104
Min = 24 Max = 109
Min = 23 Max = 109
Min = 20 Max = 109
Min = 20 Max = 130
Min = 13 Max = 130
Min = 7 Max = 130
Min = 0 Max = 130

The higher max (Poncho) is still not as loud as the lobby area when there's a party going on, but he can get pretty loud.

I changed the range in the other DO LOOP to; loop Until w0 <= $1F or w0 >= $12C

But get this data ??? [1F] [1B] [1A] [1B] [1B] [18] [1D] [1F] [1F] [1F] [1E] [1B] [1D] [1F] [1F] [1E] [17] [12] [1E] [16] [18] [18] [18] [1E] [01] [1D] [1E] [1E] [19] [1D] [1F] [1E] [1C]

The red LED turns ON with no sounds and the program delivers the [hex codes] until there's a sound then I get the decimal number [18], [17] [12], [16] [18] [18] [18] hence if I create an action besides the red LED it will occur between sounds.
 
Last edited:

lbenson

Senior Member
Regarding the hex numbers in brackets, have you added a sertxd statement within the code which runs at 16mHz? That's the kind of output you would get with a mismatch between picaxe speed and terminal baud rate.
 

SolidWorksMagi

Senior Member
Hi,

The hex codes are not the problem. The problem is the triggering by no sound still occurs. I think I have a working system now setting the trigger level lower to $F

; 28X2+MAX9814-MicTests3.bas

#picaxe 28X2 ; Define the MCU
#terminal 9600

; Electret Microphone = A.0

; BEGIN Main Body * * * * * * * * * * * * * * *
gosub red
pause 1000
gosub green
pause 1000
gosub blue
pause 1000

do
SetFreq M16
high B.7 ; red LED OFF
low B.6 ; green LED ON
high B.5 ; blue LED OFF
do
readadc A.0, w0
loop Until w0 <= $f ; Trigger Leve to $10
;debug
SetFreq MDEFAULT
sertxd (#w0," ")
high B.5 ; blue LED OFF
high B.6 ; green LED OFF
low B.7 ; red LED ON
pause 1000
loop

Now I guess if somebody wanted to "fine tune" the software, they could make a volume meter with it. I just want to trigger a skull to turn it's head to the loudest talking people and say "hello there."

Thanks again hippy, it's always good to have somebody that knows more to learn from.
 
Top