Hi,
I would really appreciate any help with this programming, I am a beginner programmer and am really struggling to get anywhere with this.
I have a ADC input that I want to compare to an oscillating pattern like a sine wave and identify when the ADC input matches this known curve pattern. I have a microphone input to the PIC and I essentially want to determine when a siren is heard, which produces this sine wave at the ADC, and when it isnt.
I have thought that one way of achieving this is to store a number of ADC readings to an array and then compare this to an array of the values along the sine wave.
I have this programming so far but I'm not sure how to copy a number of ADC readings to an array.
Code:
//uController used: 16F684.
//This program uses the internal osc, set to 4 Mhz by default.
//A 10K POT is connected to AN2- the analogue input.
//The first 2 bit of the converted result is not used. We only use AHRESH to store bit 2 to 9.
#include <pic.h>
#include "delay.c"
#include "delay.h"
__CONFIG(WDTDIS & INTIO & PWRTEN & MCLRDIS & UNPROTECT & BORDIS);
main()
{
int ADCresult= 0;
CMCON0 = 7; //Turn off comparators
ANSEL = 0b00000100; //Pin 11- RA2/AN2 as analogue input.
TRISA= 0b00000100; //PortA as output except RA2 as input
TRISC = 0; //PortC as output
ADCON0= 0b00001001; //Result left justified format, voltage reference= VDD,
//AN2= analogue input, initiates ADC
ADCON1= 0b00010000; //For 4 Mhz, 8Tosc= 2 uS, which > 1.6 uS, the minimum
while(1)
{
DelayUs(50); //Wait minimum sample time.
GODONE = 1; //Start conversion.
while(GODONE== 1); //Wait until conversion is done.
ADCresult= ADRESH; //Transfer from ADRESH to ADCresult.
}
}
Thanks for any help or suggestions
C.Fry