uC - PIC18F4550 (Compiler: MPLAB MC18)
I'm trying to build a simple circuit using the built in ADC of the PIC to convert the analog values from an electret microphone.
Objective:
- Light up an LED if the sound amplitude is above a certain level
Brief Block Diagram:
Mic -----> Amplifier -----> PIC
Problem:
So far i've not been able to make the PIC work with the mic. Unsure whether the problem is in the amplifier stage or the coding of the ADC. Btw, i've tested the ADC using DC voltage and it works fine. (LED lights when ADC connected to +5V DC and vice versa). It just wouldn't work with the mic.
Circuit Used:
Mini Amplifier with LM386. The LM386 is a low voltage audio power amplifier, simple and easy to build a mini amplifier with only a few components. (7/3/2006)
(Using the general purpose amplifier from this site)
Any help would be much appreciated. I'm not very familiar with audio signals (as in mic and the amplifier stage). Thx! ....Very Very Much!
I'm trying to build a simple circuit using the built in ADC of the PIC to convert the analog values from an electret microphone.
Objective:
- Light up an LED if the sound amplitude is above a certain level
Brief Block Diagram:
Mic -----> Amplifier -----> PIC
Problem:
So far i've not been able to make the PIC work with the mic. Unsure whether the problem is in the amplifier stage or the coding of the ADC. Btw, i've tested the ADC using DC voltage and it works fine. (LED lights when ADC connected to +5V DC and vice versa). It just wouldn't work with the mic.
Circuit Used:
Mini Amplifier with LM386. The LM386 is a low voltage audio power amplifier, simple and easy to build a mini amplifier with only a few components. (7/3/2006)
(Using the general purpose amplifier from this site)
Code:
#include <p18cxxx.h>
#include <adc.h>
//Global Variables
int ADC_Output=0;
#pragma config FOSC = HS
#pragma config WDT = OFF /* Turn the watchdog timer off */
#pragma config LVP = OFF /* Turns Low Voltage Programming off */
#pragma config MCLRE = ON /* To enable MCLR - To enable PIC reset */
void main()
{
TRISA = 0xFF;
TRISC = 0x00; /*Configure Port C as All Output*/
LATC = 0x00;
// configure A/D convertor
OpenADC( ADC_FOSC_16 &
ADC_RIGHT_JUST &
ADC_12_TAD,
ADC_CH0 &
ADC_INT_OFF ,
ADC_VREFPLUS_VDD);
while (1)
{
ConvertADC(); // Start conversion
while( BusyADC() ); // Wait for completion
ADC_Output = ReadADC(); // Read result
if (ADC_Output>512){
LATC=0b11111111;
}
else {
LATC=0b00000000;
}
}
}
Any help would be much appreciated. I'm not very familiar with audio signals (as in mic and the amplifier stage). Thx! ....Very Very Much!