Thanks for the help... This is the final code I ended up using. Its not sexy, but it works so far..
Thanks again.
.#include <LiquidCrystal.h>
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
//clipping indicator variables
boolean clipping = 0;
//data storage variables
byte newData = 0;
byte prevData = 0;
unsigned int time = 0;//keeps time and sends vales to store in timer[] occasionally
int timer[10];//sstorage for timing of events
int slope[10];//storage fro slope of events
unsigned int totalTimer;//used to calculate period
unsigned int period;//storage for period of wave
byte index = 0;//current storage index
float frequency;//storage for frequency calculations
int maxSlope = 0;//used to calculate max slope as trigger point
int newSlope;//storage for incoming slope data
//variables for decided whether you have a match
byte noMatch = 0;//counts how many non-matches you've received to reset variables if it's been too long
byte slopeTol = 3;//slope tolerance- adjust this if you need
int timerTol = 10;//timer tolerance- adjust this if you need
void setup(){
Serial.begin(9600);
pinMode(13,OUTPUT);//led indicator pin
pinMode(12,OUTPUT);//output pin
cli();//diable interrupts
//set up continuous sampling of analog pin 0 at 38.5kHz
//clear ADCSRA and ADCSRB registers
ADCSRA = 0;
ADCSRB = 0;
ADMUX |= (1 << REFS0); //set reference voltage
ADMUX |= (1 << ADLAR); //left align the ADC value- so we can read highest 8 bits from ADCH register only
ADCSRA |= (1 << ADPS2) | (1 << ADPS0); //set ADC clock with 32 prescaler- 16mHz/32=500kHz
ADCSRA |= (1 << ADATE); //enabble auto trigger
ADCSRA |= (1 << ADIE); //enable interrupts when measurement complete
ADCSRA |= (1 << ADEN); //enable ADC
ADCSRA |= (1 << ADSC); //start ADC measurements
sei();//enable interrupts
}
ISR(ADC_vect) {//when new ADC value ready
//PORTB &= B11101111;//set pin 12 low
prevData = newData;//store previous value
newData = ADCH;//get value from A0
if (prevData < 127 && newData >=127){//if increasing and crossing midpoint
newSlope = newData - prevData;//calculate slope
if (abs(newSlope-maxSlope)<slopeTol){//if slopes are ==
//record new data and reset time
slope[index] = newSlope;
timer[index] = time;
time = 0;
if (index == 0){//new max slope just reset
PORTB |= B00010000;//set pin 12 high
noMatch = 0;
index++;//increment index
}
else if (abs(timer[0]-timer[index])<timerTol && abs(slope[0]-newSlope)<slopeTol){//if timer duration and slopes match
//sum timer values
totalTimer = 0;
for (byte i=0;i<index;i++){
totalTimer+=timer[i];
}
period = totalTimer;//set period
//reset new zero index values to compare with
timer[0] = timer[index];
slope[0] = slope[index];
index = 1;//set index to 1
PORTB |= B00010000;//set pin 12 high
noMatch = 0;
}
else{//crossing midpoint but not match
index++;//increment index
if (index > 9){
reset();
}
}
}
else if (newSlope>maxSlope){//if new slope is much larger than max slope
maxSlope = newSlope;
time = 0;//reset clock
noMatch = 0;
index = 0;//reset index
}
else{//slope not steep enough
noMatch++;//increment no match counter
if (noMatch>9){
reset();
}
}
}
if (newData == 0 || newData == 1023){//if clipping
PORTB |= B00100000;//set pin 13 high- turn on clipping indicator led
clipping = 1;//currently clipping
}
time++;//increment timer at rate of 38.5kHz
}
void reset(){//clea out some variables
index = 0;//reset index
noMatch = 0;//reset match couner
maxSlope = 0;//reset slope
}
void checkClipping(){//manage clipping indicator LED
if (clipping){//if currently clipping
PORTB &= B11011111;//turn off clipping indicator led
clipping = 0;
}
}
void loop(){
checkClipping();
frequency = 38462/float(period);//calculate frequency timer rate/period
// set up the LCD's number of columns and rows:
lcd.begin(16, 2);
lcd.setCursor(0, 1);
// Print a message to the LCD.
if (frequency > 15 && frequency < 34 )
{
lcd.print('C1');
}
else if (frequency > 35 && frequency < 38 )
{
lcd.print('D1');
}
else if (frequency > 39 && frequency < 42 )
{
lcd.print('E1');
}
else if (frequency > 42 && frequency < 46 )
{
lcd.print('F1');
}
else if (frequency > 46 && frequency < 52 )
{
lcd.print("G1");
}
else if (frequency > 52 && frequency < 58 )
{
lcd.print("A1");
}
else if (frequency > 58 && frequency < 63 )
{
lcd.print("B1");
}
else if (frequency > 63 && frequency < 69 )
{
lcd.print("C2");
}
else if (frequency > 69 && frequency < 78 )
{
lcd.print("D2");
}
else if (frequency > 78 && frequency < 84 )
{
lcd.print("E2");
}
else if (frequency > 84 && frequency < 95 )
{
lcd.print("F2");
}
else if (frequency > 95 && frequency < 105 )
{
lcd.print("G2");
}
else if (frequency > 105 && frequency < 116 )
{
lcd.print("A2");
}
else if (frequency > 116 && frequency < 127 )
{
lcd.print("B2");
}
else if (frequency > 127 && frequency < 139)
{
lcd.print("C3");
}
else if (frequency > 139 && frequency < 155 )
{
lcd.print("D3");
}
else if (frequency > 155 && frequency < 170 )
{
lcd.print("E3");
}
else if (frequency > 170 && frequency < 185 )
{
lcd.print("F3");
}
else if (frequency > 185 && frequency < 208 )
{
lcd.print("G3");
}
else if (frequency > 208 && frequency < 233 )
{
lcd.print("A3");
}
else if (frequency > 233 && frequency < 255 )
{
lcd.print("B3");
}
else if (frequency > 255 && frequency < 277 )
{
lcd.print("C4");
}
else if (frequency > 277 && frequency < 311 )
{
lcd.print("D4");
}
else if (frequency > 311 && frequency < 240 )
{
lcd.print("E4");
}
else if (frequency > 240 && frequency < 370 )
{
lcd.print("F4");
}
else if (frequency > 370 && frequency < 415 )
{
lcd.print("G4");
}
else if (frequency > 415 && frequency < 466 )
{
lcd.print("A4");
}
else if (frequency > 466 && frequency < 515 )
{
lcd.print("B4");
}
else if (frequency > 515 && frequency < 555 )
{
lcd.print("C5");
}
else if (frequency > 555 && frequency < 600 )
{
lcd.print("D5");
}
else if (frequency > 600 && frequency < 670 )
{
lcd.print("E5");
}
else if (frequency > 670 && frequency < 740 )
{
lcd.print("F5");
}
else if (frequency > 740 && frequency < 830 )
{
lcd.print("G5");
}
else if (frequency > 830 && frequency < 933 )
{
lcd.print("A5");
}
else if (frequency > 933 && frequency < 1027 )
{
lcd.print("B5");
}
else if (frequency > 1027 && frequency < 1109 )
{
lcd.print("C6");
}
else if (frequency > 1109 && frequency < 1244 )
{
lcd.print("D6");
}
else if (frequency > 1244 && frequency < 1370 )
{
lcd.print("E6");
}
else if (frequency > 1370 && frequency < 1480 )
{
lcd.print("F6");
}
else if (frequency > 1480 && frequency < 1661 )
{
lcd.print("G6");
}
else if (frequency > 1661 && frequency < 1864 )
{
lcd.print("A6");
}
else if (frequency > 1864 && frequency < 2020 )
{
lcd.print("B6");
}
else if (frequency > 2020 && frequency < 2217 )
{
lcd.print("C7");
}
else if (frequency > 2217 && frequency < 2489 )
{
lcd.print("D7");
}
else if (frequency > 2489 && frequency < 2725 )
{
lcd.print("E7");
}
else if (frequency > 2725 && frequency < 2960 )
{
lcd.print("F7");
}
else if (frequency > 2960 && frequency < 3322 )
{
lcd.print("G7");
}
else if (frequency > 3322 && frequency < 3729 )
{
lcd.print("A7");
}
else if (frequency > 3729 && frequency < 4500 )
{
lcd.print("B7");
}
}
//print results
//Serial.print(frequency);
//Serial.println(" hz");
//delay(1000);//