Shop OBEX P1 Docs P2 Docs Learn Events
Microphone ADC - how does it work? — Parallax Forums

Microphone ADC - how does it work?

kenmackenmac Posts: 96
edited 2007-08-03 16:42 in Propeller 1
I have a small project which monitors the audio output of a smoke detector via a Electec microphone and an amplifier/interface to convert to a logic signal.
I see that the Propeller can accept audio input from a microphone, and wondered how that is achieved.
I've looked at Chip's Microphone_to_Headset.spin, which is some small Assembly code.
I know the basics of "sampling" for audio ADC, but I can't really understand what the Propeller is doing.
My requirement is a bit simpler - it just needs to create data to indicate the presence of loud audio, then convert to a digital alarm state.
If I can achieve this via the Prop, then I can do away with the external interface.
Is it possible to achieve this without using Assembly code, i.e. use Spin?

kenmac

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Perth, Western Australia
Time Zone = GMT + 8

Comments

  • rjo_rjo_ Posts: 1,825
    edited 2007-08-02 12:40
    Kenmac,

    There is plenty that I don't completely understand. Chip's code uses counters and self-modifying instructions. The best explanation for the counters is in the PE Kit lab. There have been several posts regarding self-modifying code.

    A further example of the technique can be found in microphone_to_vga.spin.

    I am in the process of hacking something like this with the partial understanding that I have... I'll post the hack. There is a call to "FASTIO" in the spectrum analyzer... that seems like a good place to hack.

    I am looking forward to other responses to your question.

    Thanks for posting

    Rich
  • Paul BakerPaul Baker Posts: 6,351
    edited 2007-08-02 16:27
    The Propeller ADC uses a technique called delta sigma, basically what it does is use two pins, one for input and one for feedback. The aim of the circuit is to get the input pin to be right at the threshold (the boundry between a high input and a low input), the way this accomplishes this is the feedback pin is made the opposite value of the input pin, there is a resistor tied between the two pins so the feedback pin "steers" the voltage at the input pin in the direction opposite of it's current value. The amount of steering required is dependent upon the sampled voltage, if it is very high, the feedback pin will be mostly low, if it is very low the feedback pin will be mostly high. The way a sample is made is that the value of the input pin is accumulated·a specified number of clock cycles. So lets say you count over 256 cycles and the input was high for 128 of them, the sampled value is 128/256 or 1/2 Vdd. Besides grabing the value and resseting it to 0, everything is done by the counters, the critical aspect is that the same number of cycles be waited for each time and waitcnt works for this in assembly or spin, with spin you will have to make sure that you allow enough time to execute the processing comands so the minimum number of clock cycles you can make you sample period will be much greater than with assembly.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Paul Baker
    Propeller Applications Engineer

    Parallax, Inc.

    Post Edited (Paul Baker (Parallax)) : 8/2/2007 4:33:04 PM GMT
  • nightflynightfly Posts: 2
    edited 2007-08-03 02:24
    Quite tricky wink.gif
    What's the max sampling rate i can achieve with this?
  • Paul BakerPaul Baker Posts: 6,351
    edited 2007-08-03 03:24
    Depends on how many bits of precision you want.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Paul Baker
    Propeller Applications Engineer

    Parallax, Inc.
  • kenmackenmac Posts: 96
    edited 2007-08-03 05:26
    Paul,
    This is a difficult concept to grasp.
    Looking at the example Assembly code, it seems that the accumulated level/number after each sample cycle is read from the PHSA register into a variable.
    What happens to the value in the variable, does it continue to grow with each cycle?
    Say there is a continuous sine wave input, can you please describe the steps that occur.

    I'm more interested in being able to detect a continuous signal over a period of about 5 seconds - the resolution isn't really a factor, just the presence of the signal.
    Also, I'd prefer to be able to do it in Spin code.
    I just need to understand better what it's doing.

    kenmac

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Perth, Western Australia
    Time Zone = GMT + 8
  • StefanL38StefanL38 Posts: 2,292
    edited 2007-08-03 08:27
    hello kenmac,

    i know the propeller is very versatile and can do even ADC

    but how about a simple operational amplifier like the LM358
    this 8DIP-Chip has 2 OPs inside

    build up with some resistors an amplifier for the microphone signal
    in the first OP

    and the second is build up with some resistors as a comparator with hysteresis
    then the output of the second OP is connected to one IO-PIN of the prop and you simple
    watch the logic level of this IO-PIN

    greetings

    Stefan
  • kenmackenmac Posts: 96
    edited 2007-08-03 09:32
    Stefan,
    Thanks for your interest.
    I already have a working external interface (amplifier/logic output) but I can eliminate that if I can incorporate the function into the Prop.
    So, I just need to work out how to implement the ADC part of the Prop.
    It's only 1 function in a Prop. that is nearly fully allocated (pins).

    kenmac

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Perth, Western Australia
    Time Zone = GMT + 8
  • nightflynightfly Posts: 2
    edited 2007-08-03 14:36
    ok, basically what i want is to take a signal from each of three murata ENC03 gyroscopes and later calculate the orientation of the propeller
    i'd say 8bit and something about 100 samples per s is enough.
  • Paul BakerPaul Baker Posts: 6,351
    edited 2007-08-03 16:34
    Kenmac, You somewhat misunderstood my explanation, my previous post was a discussion of what sigma delta ADC does for a single sample. IOW a single·point on the graph of a sine wave, it does not include any form of signal processing, such as tone detection. You should seriously consider using something like Beau's spectrum analyzer: http://forums.parallax.com/showthread.php?p=663985·It not only has the sigma delta conversion in it, but has the processing layer.·In order to detect the presence on a tone you only have to look to see how large the value is for the frequency you are looking for. And since you are only interested in looking for one frequency, you can alter his code so in only performs the analysis at the one frequency.

    Nightfly, it is possible to achieve that·sample rate, one thing to note though is that the Sigma·Delta conversion on the propeller is a bit noisy (the lower bits tend to fluctuate), for·your application you may need to use an external ADC to achieve your desired precision, or increase the number of bits the Propeller samples and throw·away the noisy bits.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Paul Baker
    Propeller Applications Engineer

    Parallax, Inc.
  • Tracy AllenTracy Allen Posts: 6,660
    edited 2007-08-03 16:42
    The rate of increase of PHSA is modulated by the input signal. In assembly, it would be easy to capture the peaks and valleys and return the amplitude of the signal, and PHSA is reset to zero at the start of each sample cycle. In SPIN, you could start the ADC and allow PHSA to free run. Also in SPIN run a very tight loop synced with waitcnt that captures the value of PHSA and subtracts from the previous value and keeps track of the maximum and minimum of the change. If the sampling is fast enough, that will follow the amplitude of the input signal, and after N samples the difference between the maximum and minimum can be used to assess the presence or absence of the signal. The horn on a smoke detector is usually a moderate frequency, 500 or 1000 hertz maybe, and very loud, so it might be possible.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Tracy Allen
    www.emesystems.com
Sign In or Register to comment.