Shop OBEX P1 Docs P2 Docs Learn Events
Simple Electret Mic test — Parallax Forums

Simple Electret Mic test

RaymanRayman Posts: 14,619
edited 2023-10-13 17:41 in Propeller 2

Just got this electret microphone test working.
Usually, one needs an amplifier to boost the signal level.
But here, I'm testing connecting directly to P2 pin.

The circuit is real simple, just a 2.2k resistor from VDD to mic and a capacitor from mic to P2 pin.

With P2 in 100X ADC mode, getting a possibly acceptable signal level.
I multiply what I get by 10X and send to speakers in this example to get a reasonable volume.

I'm not 100% happy with it, but might be good enough for basic needs.

Update: See post #8 for code that records from mic, plays it on speakers, then saves to uSD.

Comments

  • RaymanRayman Posts: 14,619

    The code is something whipped up fast...
    Hijacked the waveplayer code with a 16kHz mono wav test file.

    Records mic first to HUB RAM and then substitutes that data for the wav data from uSD.

    Definitely need a better code, but this shows what we have to work with...

  • RaymanRayman Posts: 14,619

    This sounds a lot better. Adding up 8 samples to create each output sample:

        ser.str(String("Recording from Mic...",13))
        pinh(52)   'recording on led
        t:=getct()
        j:=0
        k:=$7FFF_FFFF
        repeat  i from 0 to mic_samples-1
          r:=0
          repeat 8
            r+=rdpin(13)-$2000
            org
              waitx  ##1000
            end
          mic[i]:=r
          if r<k
            k:=r
          if r>j
            j:=r
          t+=clkfreq/16000 '==12500
          waitct(t)
        pinl(52)  'recording led off
    
  • RaymanRayman Posts: 14,619

    Added a simple low pass filter and sounds better:

        ser.str(String("Recording from Mic...",13))
        pinh(52)   'recording on led
        t:=getct()
        j:=0
        k:=$7FFF_FFFF
        x:=0
        repeat  i from 0 to mic_samples-1
          r:=0
          repeat 8
            r+=rdpin(13)-$2000
            org
              waitx  ##1000
            end
          x:=(3*x+r) SAR 2
          mic[i]:=x
          if x<k
            k:=x
          if x>j
            j:=x
          t+=clkfreq/16000 '==12500
          waitct(t)
        pinl(52)  'recording led off
    
  • What values do you use for pinstart ()? From the waitx ##1000 and the rdpin(13)-$2000 I can guess you use SINC2 sampling mode. Why? And instead of adding up 8 samples you could simply use a longer sampling period for the ADC.

  • RaymanRayman Posts: 14,619

    Hardware manual says SINC2 is best for DC and SINC3 is best for fast signals.

    I'm thinking this is some middle ground where doesn't really matter.
    Definitely worth exploring though...

  • I think SINC3 makes not much sense because the longest sample period is 512 clocks which is way too fast. SINC2 sampling is the most forgiving mode because you don't have to subtract the last accumulation value in software but the Z register always holds a valid sample value even if your rdpin()s are not synchronized. But you'll get aliasing effects if they aren't and this is definitely the case because the waitx ##1000 isn't very accurate in Spin. You should set an apropriate sampling period and wait for IN to become high, either by setting up an event or by polling with pinr().

  • RaymanRayman Posts: 14,619
    edited 2023-10-13 17:42

    Here's code that records a bit of audio from the mic, plays it, and then saves it as .wav file to uSD.

    Also, here's an example recording, MIC1.WAV (in mic1.zip). A version that is cleaned up a bit with Audacity is in MIC1_Filtered.WAV
    This recording was with mic about 1 foot away from mouth, spoken in a normal-ish volume

Sign In or Register to comment.