Difference between revisions of "Microphones"

From Mech
Jump to navigationJump to search
 
(57 intermediate revisions by 4 users not shown)
Line 1: Line 1:
== Original Assignment ==
== Overview ==


A "clapper" device was built using a PIC 18F4520 and an [http://en.wikipedia.org/wiki/Electret_microphone electret condenser microphone] (in this case, the [http://www.knowles.com/search/prods_pdf/MD9745APA-1.pdf 423-1024-ND] from digikey) as an analog input. The device operates on the principle that the microphone will convert the sound into an analog input to the PIC and, as the sound increases in volume, the analog input's amplitude will increase. This input is then converted into an output on the set of LEDs soldered onto the PIC's circuit board. This output works as a light bar; it displays the minimum one LED for quiet sound levels and activates additional LEDs as the sound becomes louder -- up to a maximum of eight. The sensitivity of the microphone is adjustable through a gain potentiometer.
This project is to demonstrate a "clapper" device using an electret microphone (e.g., the 423-1024-ND from digikey). Build an appropriate circuit and write a program to continuously display the volume of the sound it receives as a "light bar" on the PIC board LEDs.


[[image:ElectretMicrophone.gif|thumb|300px|[[Interior of Electret Microphone]]|right]]
== Overview ==
[[image:Electret_condenser_microphone_capsules.jpg|thumb|350px|[[Electret condenser microphone capsules]]|left]]

The most commonly used microphones for audio use capacitance charge (condenser microphones), electromagnetic generation (dynamic microphones), or piezoelectric generation. In a [http://en.wikipedia.org/wiki/Condenser_microphone#Condenser.2C_capacitor_or_electrostatic_microphones condenser microphone], a thin membrane of the microphone acts as one plate of a capacitor and a nearly constant charge is maintained on the capacitor. The voltage maintained across the capacitor plates changes with the vibrations in the air, according to the capacitance equation:
:<math>Q = C \cdot V</math> where Q = charge in coulombs, C = capacitance in farads and V = potential difference in volts, resulting in a change in output voltage. Power is necessary for establishing the capacitor plate voltage, and is also needed for internal amplification of the signal to a useful output level. Electret microphones, a type of condenser microphone, replace the externally-applied charge with a permanently fixed-charged material. The electret is a stable dielectric material with a permanently-embedded static charge. Electret microphones require no polarizing voltage but, due to their integrated pre-amplifier, require a small amount of power either from microphone inputs as phantom power or from a small battery. Due to mass-production of these devices, electret microphones lack the precision needed for high-quality microphones.

Due to the variable nature of ambient noise, a calibration "reset" button was included that would reset the output LEDs based on the environment's baseline noise level. This calibration was done via software averaging of the ambient volume level. The device that is built currently follows the principles of the clapper device in that the higher the analog input is received, the more LEDs will be shown. However, due to the brevity of the audio input peak for shorter signals such as a clap, it is sometimes difficult to see the correspondingly brief output. A further step would be to install a software switch that would detect the characteristic sound pattern of a clap and activate a digital output upon recognition.

Of the three microphones tested for the clapper device (Electret Microphone, [http://www.sonystyle.com/webapp/wcs/stores/servlet/ProductDisplay?catalogId=10551&storeId=10151&langId=-1&productId=11037550 Sony F-V100], and a small dynamic microphone), the electret microphone showed the greatest sensitivity to varying noise levels.

=== Problems ===


We ran into several problems using this configuration, and other configurations similar to this one. First of all, the sensitivity of the microphone was poor even at the most sensitive potentiometer setting. Because of the way the code worked, we were able to register a loud clap within about a foot of the microphone, but we weren't able to get a good response from a constant sound, like a hum. This would work well for a device that just needed to register when a loud noise occurs, but would not be suitable for any sort of recording or signal processing.
A "clapper" device will be built using a PIC 18F4520 and to take various audio analog inputs. An electret microphone (in this case, the 423-1024-ND from digikey) was used to pick up the external sound and send it to the PIC. The device operates on the principle that as the sound increases in volume, the audio input's frequency will increase. This input is received by the PIC and converted into an output on a set of LED displays that were originally placed on a circuit board (as shown). This output emits the minimum one LED for minimal sound levels as an input to all 7 LEDs for the maximum input that the PIC can receive.


Another approach we tried was to run the signal through a simple non-inverting [[Operational Amplifiers (Op-Amps) | operational amplifier]]. This was even less successful as it amplified the noise to the level where a clap or hum was indistinguishable from the noise. We experimented with a gain of 2 and a gain of 11. The gain of 2 made no significant difference and the gain of 11 simply amplified too much noise.
Due to the nature of possible ambient noise, a calibration "reset" button was placed that would reset the output LEDs to the minimum surrounding sound. This calibration was done via software. The device that is built currently follows the principles of the "clapper" device in that the higher the analog input is received, the more LEDs will be shown. However, due to the brevity of the audio input frequency itself, for shorter audio signals received it is difficult for the LEDs to display the signal. A further step would be to extend the time that each LED displayed.


== Circuit ==
== Circuit ==
Line 13: Line 23:
The circuit built for this example uses an electret microphone to listen to external sound and displays the volume level as a light bar on the PIC board LEDs. The microphone uses a single analog input pin of the PIC.
The circuit built for this example uses an electret microphone to listen to external sound and displays the volume level as a light bar on the PIC board LEDs. The microphone uses a single analog input pin of the PIC.


Optional features present in the shown circuit diagram include a potentiometer gain knob for adjusting the microphone's sensitivity and a calibration button for setting the baseline ambient noise level. The code governing the operation of the calibration button is included below; the button itself is wired into a digital input of the PIC. Refer to the photo and diagram for details.
Optional features present in the shown circuit diagram include a potentiometer gain knob for adjusting the microphone's sensitivity and a calibration button for setting the baseline ambient noise level. The code governing the operation of the calibration button is included below; the button itself is wired into a digital input of the PIC. Refer to the photo and diagram for details. Although the potentiometer is good for calibration, we found that we can get a decent sensitivity by simply using a 2.2K-ohm resistor.




[[image:microphone_circuit.JPG|left|400px|[[help:contents|Microphone Circuit and PIC photo]]]] [[image:mic_circuit_diagram.JPG|right|400px|[[help:contents|Microphone Circuit and PIC diagram]]]]
[[image:400px-Microphone_circuit.JPG|thumb|400px|[[Microphone Circuit and PIC photo]]|right]] [[image:Mic_circuit_diagram4.JPG|thumb|400px|[[Microphone Circuit and PIC diagram]]|left]]




<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
Line 46: Line 72:
#use delay(clock=20000000)
#use delay(clock=20000000)


int16 valuebuff[100]; // Initialize variables
signed int16 value;
signed int16 value;
int32 valueinit=0;
int16 valueinit=0;
int k=0;
int k=0;
void initialize();
void initialize();
Line 54: Line 79:
void main() {
void main() {


initialize();
setup_adc_ports(AN0); // Enable analog inputs AN0;
setup_adc_ports(AN0); // Enable analog inputs AN0;
setup_adc(ADC_CLOCK_INTERNAL);
setup_adc(ADC_CLOCK_INTERNAL);
initialize();


while (TRUE) {
while (TRUE) {
if (input(PIN_C0)>0) initialize(); //Initialize the base output to match ambient noise

set_adc_channel(0); // there's only one ADC so select which input to connect to it; here pin AN0
set_adc_channel(0); // there's only one ADC so select which input to connect to it; here pin AN0
delay_us(10); // wait 10uS for ADC to settle to a newly selected input
delay_us(10); // wait 10uS for ADC to settle to a newly selected input
if (input(PIN_C0)>0) initialize(); //Initialize the base output to match ambient noise
value = read_adc(); // now you can read ADC as frequently as you like
value = read_adc(); // now you can read ADC as frequently as you like
//Create a gain to dramatically differentiate the input level from ambient noise
//Create a gain to dramatically differentiate the input level from ambient noise
if ((value-valueinit)<0) value=0;
if ((value-valueinit)<0) value=0;
value=(value-valueinit)*4;
value=(value-valueinit)*20;
if (value<32) //Easy to read volume meter
if (value<32) //Easy to read volume meter
Line 84: Line 112:
else if (value<224)
else if (value<224)
output_d(0b1111111);
output_d(0b1111111);
else if (value<1000)
else
output_d(0b11111111);
output_d(0b11111111);
delay_ms(10);
if (value>128) delay_ms(200);
}
}
}
}
Line 99: Line 127:
//Read 100 input levels and take their average. This a measure of the ambient noise
//Read 100 input levels and take their average. This a measure of the ambient noise
for (k=0;k<100;k++) {
for (k=0;k<100;k++)
{
set_adc_channel(0);
set_adc_channel(0); // there's only one ADC so select which input to connect to it; here pin AN0
delay_us(10);
delay_us(10); // wait 10uS for ADC to settle to a newly selected input
valuebuff[k] = read_adc();
valueinit+=valuebuff[k];
valueinit+=read_adc();
}
}
valueinit = (valueinit/100);
valueinit = (valueinit/100);
}
}

</pre>
</pre>

== References ==

1. [http://en.wikipedia.org/wiki/Microphone Microphone - From Wikipedia, the free encyclopedia] <br>
2. [http://www.national.com/nationaledge/dec02/article.html Integrated Circuits for High Performance Electret Microphones] <br>

== External Links ==

[http://www.hosiden.co.jp/web/english/web/products/pdf/e_on06_mic.pdf Guide for Electret Condenser Microphones] <br>
[http://www.soundonsound.com/sos/1995_articles/jun95/microphones.html CHOOSING A MICROPHONE: Microphone types and uses] <br>

Latest revision as of 16:39, 2 March 2008

Overview

A "clapper" device was built using a PIC 18F4520 and an electret condenser microphone (in this case, the 423-1024-ND from digikey) as an analog input. The device operates on the principle that the microphone will convert the sound into an analog input to the PIC and, as the sound increases in volume, the analog input's amplitude will increase. This input is then converted into an output on the set of LEDs soldered onto the PIC's circuit board. This output works as a light bar; it displays the minimum one LED for quiet sound levels and activates additional LEDs as the sound becomes louder -- up to a maximum of eight. The sensitivity of the microphone is adjustable through a gain potentiometer.

The most commonly used microphones for audio use capacitance charge (condenser microphones), electromagnetic generation (dynamic microphones), or piezoelectric generation. In a condenser microphone, a thin membrane of the microphone acts as one plate of a capacitor and a nearly constant charge is maintained on the capacitor. The voltage maintained across the capacitor plates changes with the vibrations in the air, according to the capacitance equation:

where Q = charge in coulombs, C = capacitance in farads and V = potential difference in volts, resulting in a change in output voltage. Power is necessary for establishing the capacitor plate voltage, and is also needed for internal amplification of the signal to a useful output level. Electret microphones, a type of condenser microphone, replace the externally-applied charge with a permanently fixed-charged material. The electret is a stable dielectric material with a permanently-embedded static charge. Electret microphones require no polarizing voltage but, due to their integrated pre-amplifier, require a small amount of power either from microphone inputs as phantom power or from a small battery. Due to mass-production of these devices, electret microphones lack the precision needed for high-quality microphones.

Due to the variable nature of ambient noise, a calibration "reset" button was included that would reset the output LEDs based on the environment's baseline noise level. This calibration was done via software averaging of the ambient volume level. The device that is built currently follows the principles of the clapper device in that the higher the analog input is received, the more LEDs will be shown. However, due to the brevity of the audio input peak for shorter signals such as a clap, it is sometimes difficult to see the correspondingly brief output. A further step would be to install a software switch that would detect the characteristic sound pattern of a clap and activate a digital output upon recognition.

Of the three microphones tested for the clapper device (Electret Microphone, Sony F-V100, and a small dynamic microphone), the electret microphone showed the greatest sensitivity to varying noise levels.

Problems

We ran into several problems using this configuration, and other configurations similar to this one. First of all, the sensitivity of the microphone was poor even at the most sensitive potentiometer setting. Because of the way the code worked, we were able to register a loud clap within about a foot of the microphone, but we weren't able to get a good response from a constant sound, like a hum. This would work well for a device that just needed to register when a loud noise occurs, but would not be suitable for any sort of recording or signal processing.

Another approach we tried was to run the signal through a simple non-inverting operational amplifier. This was even less successful as it amplified the noise to the level where a clap or hum was indistinguishable from the noise. We experimented with a gain of 2 and a gain of 11. The gain of 2 made no significant difference and the gain of 11 simply amplified too much noise.

Circuit

The circuit built for this example uses an electret microphone to listen to external sound and displays the volume level as a light bar on the PIC board LEDs. The microphone uses a single analog input pin of the PIC.

Optional features present in the shown circuit diagram include a potentiometer gain knob for adjusting the microphone's sensitivity and a calibration button for setting the baseline ambient noise level. The code governing the operation of the calibration button is included below; the button itself is wired into a digital input of the PIC. Refer to the photo and diagram for details. Although the potentiometer is good for calibration, we found that we can get a decent sensitivity by simply using a 2.2K-ohm resistor.























Code


/*
microphone.c by JJ Darling, Alex Leung, Ben Schriesheim
This code will take an analog microphone input and display the power of the single 
as an easily read LED array. One light on means the input matches the ambient noise,
and all eight lights on means the microphone is receiving a loud noise.

The reset button can be used to match the lowest output to the ambient noise.

This code was derived off of the analog input code written by Prof. Michael Peshkin, which
can be found in the source code repository on this wiki.
*/

#include <18f4520.h>

#DEVICE ADC=8                  // set ADC to 8 bit accuracy.

#fuses HS,NOLVP,NOWDT,NOPROTECT
#use delay(clock=20000000)

signed int16 value;
int16 valueinit=0;
int k=0;
void initialize();

void main() {

   setup_adc_ports(AN0);        // Enable analog inputs AN0;
   setup_adc(ADC_CLOCK_INTERNAL);     
   initialize(); 
    
   

   while (TRUE) {
   
      set_adc_channel(0);     // there's only one ADC so select which input to connect to it; here pin AN0
      delay_us(10);           // wait 10uS for ADC to settle to a newly selected input
      
      if (input(PIN_C0)>0)  initialize();   //Initialize the base output to match ambient noise
      
      value = read_adc();     // now you can read ADC as frequently as you like
      
      //Create a gain to dramatically differentiate the input level from ambient noise
      if ((value-valueinit)<0) value=0;   
      value=(value-valueinit)*20;
      
   if (value<32)              //Easy to read volume meter
      output_d(0b1);
   else if (value<64)
      output_d(0b11);
   else if (value<96)
      output_d(0b111);
   else if (value<128)
      output_d(0b1111);
   else if (value<160)
      output_d(0b11111);
   else if (value<192)
      output_d(0b111111);
   else if (value<224)
      output_d(0b1111111);
   else
      output_d(0b11111111);           
      
   if (value>128) delay_ms(200);
   }
}

//Take samples to establish an initial value to 'tare' the ambient noise.
void initialize() {
   
   delay_ms(1000);       //Give enough time for the user to release the "reset" button     
   
   valueinit=0;
   
   //Read 100 input levels and take their average. This a measure of the ambient noise
   for (k=0;k<100;k++) 
   {
      set_adc_channel(0);     // there's only one ADC so select which input to connect to it; here pin AN0
      delay_us(10);           // wait 10uS for ADC to settle to a newly selected input
      valueinit+=read_adc();
   }
   
   valueinit = (valueinit/100);
   
}

References

1. Microphone - From Wikipedia, the free encyclopedia
2. Integrated Circuits for High Performance Electret Microphones

External Links

Guide for Electret Condenser Microphones
CHOOSING A MICROPHONE: Microphone types and uses