Thread: Identifying pattern in ADC for PIC16F684

  1. #1
    Registered User
    Join Date
    May 2011

    Identifying pattern in ADC for PIC16F684


    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.

    //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"
       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
         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

  2. #2
    Registered User
    Join Date
    Mar 2011
    Congrats on the use of CODE tags. Your whitespace/indentation needs work (edit the post)

    Now, to your code question...

    Make some functions to clean up main()
    a) InitADC() to initialize the ADC and other things
    b) ReadADC() and have its return value be the reading
    c) in main() then call InitADC once and then ReadADC over and over in a loop, each time taking the reading and copying it into an array you've declared as int Readings[MAX_NUM_READING];

    Making a loop like above, at some point you are going to run out of array space. You need to handle that.

    However, you have some fundamental issues if I understand what it is you are trying to do.
    Let me see if I have it correct: You have a look-up table to which you are going to compare the array of inbound ADC readings taken essentially from a microphone?

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. PIC16F684 Interfacing with Hitachi 44780
    By JTerry in forum C Programming
    Replies: 36
    Last Post: 12-13-2010, 12:13 PM
  2. Identifying a C++ idiom
    By kovacsbv in forum C++ Programming
    Replies: 2
    Last Post: 08-10-2009, 02:50 PM
  3. Identifying Triangles
    By howeezy in forum C++ Programming
    Replies: 5
    Last Post: 10-08-2005, 12:14 PM
  4. identifying string input
    By winsonlee in forum C Programming
    Replies: 1
    Last Post: 05-06-2004, 08:18 AM
  5. identifying machine in the networl
    By Unregistered in forum C++ Programming
    Replies: 2
    Last Post: 10-04-2001, 10:33 PM

Tags for this Thread