Frecuency Detection


Closed Thread
Results 1 to 9 of 9

Hybrid View

  1. #1

    Default Frecuency Detection

    I just dont get that Goertzel algorithm or the application from Microchip.

    What i intend is this, i have 4 frequencies 350,420, 480 and 620 Hz. I need to find if a certain frecuency is happening.

    These are by the way typical Multifrequency Signaling frequencies so detection has to be fast, like 40mS to determine wheter the frequency is present or not in a given signal.

    Microhip has an app about DTMF detection that seems to have a lead, i just need to find different Frequencies than those in DTMF. The Microchip app is made to 18F devices, i intend to use a cheaper 16F628A. Would this be impossible?.

    I tried using external components like a LM567 but i would need 4, since each lm567 can only get one of the signals, due to bandwidth restrains.

    Ok has anyone done something similar?, can anyone explain the algorithm?

    Thanks for any help!!

  2. #2
    Join Date
    Nov 2003
    Location
    Wellton, U.S.A.
    Posts
    5,924


    Did you find this post helpful? Yes | No

    Default

    Dave
    Always wear safety glasses while programming.

  3. #3
    Join Date
    Jul 2003
    Posts
    2,405


    Did you find this post helpful? Yes | No

    Default

    Measuring a frequency is pretty straight forward, and can be done on just about
    any PIC with a spare input pin.

    Here are a few ideas.

    1. Use the COUNT command.
    2. Use TIMER1.
    3. Use the hardware capture module.

    And here's a simple test program using all 3 options. Tested on a 16F627A.
    Code:
        @ DEVICE MCLR_OFF, INTRC_OSC, WDT_OFF, LVP_OFF, BOD_ON, PWRT_ON, PROTECT_OFF
        DEFINE OSC 4
        
        T1 VAR WORD
        T2 VAR WORD
        TRISB = %00001000 ' RB3 = input
    
        T1CON = 0
        TMR1L=0
        TMR1H=0
        
    '    GOTO Test3      ' using COUNT
    '    GOTO Test2      ' using capture
    '    GOTO Test1      ' using TMR1 with pin state watch
        
    Test1:
        WHILE PORTB.3=1  ' noise filter
        WEND
        WHILE PORTB.3=0  ' wait for low to high edge
        WEND
        T1CON=1          ' start TMR1 on rising edge
        WHILE PORTB.3=1  ' wait for high to low edge
        WEND
        WHILE PORTB.3=0  ' wait for 2nd rising edge (end of period)
        WEND
        T1CON=0          ' stop TMR1
        
       ' Record the period as T1. 
        T1.HighByte = TMR1H
        T1.LowByte = TMR1L
        HSEROUT ["Period = ",DEC T1,13,10]
        PAUSE 10000
        TMR1L=0
        TMR1H=0
        GOTO Test1
    '    Serial from PIC ' Shown on O-Scope    
    '    Period = 3143   ' 315 Hz
    '    Period = 2403   ' 412 Hz
    '    Period = 2113   ' 468 Hz
    '    Period = 1643   ' 603 Hz
    
    Test2:
        'Configure capture for rising edge.
        CCP1CON = %00000101 ' Capture mode, capture on rising edge
        'Setup & start Timer1.
        T1CON = 1           ' TMR1 prescale=1, clock=Fosc/4, TMR1=on.
    
    Loop:
        'Wait for the capture flag bit to be set.
        WHILE PIR1.2 = 0
        WEND
        
        'Record the first capture value as T1. 
        T1.HighByte = CCPR1H
        T1.LowByte = CCPR1L
        
        'Clear the capture flag. 
        PIR1.2 = 0
        
        'Wait for the capture flag to be set a 2nd time.
        WHILE PIR1.2 = 0
        WEND
        
        'Record the 2nd capture value as T2.
        T2.HighByte = CCPR1H 
        T2.LowByte = CCPR1L
        
        'Clear the capture flag
        PIR1.2 = 0
    
        'T2-T1 = the period in uS.
        HSEROUT ["Period = ",DEC T2-T1,13,10]
        PAUSE 1000
        GOTO Loop    
    '    Serial from PIC ' Shown on O-Scope
    '    Period = 3149   ' Freq = 315 Hz
    '    Period = 2410   ' Freq = 412 Hz
    '    Period = 2120   ' Freq = 468 Hz
    '    Period = 1648   ' Freq = 603 Hz
    
    Test3:
        COUNT PORTB.3,20,T1  'Count low to high transitions for 20mS
        HSEROUT ["Count = ",DEC T1,13,10]
        PAUSE 10000
        GOTO Test3
    '    Serial from PIC ' Shown on O-Scope    
    '    Count = 6       ' 315 Hz
    '    Count = 8       ' 412 Hz
    '    Count = 9       ' 468 Hz
    '    Count = 12      ' 603 Hz
    ' Resolution with COUNT isn't that great, but it works.
    ' 20mS/count value = the approximate period.
    
        END
    An 8-pin PIC was used for the frequency generator.

    Capture could be used with the capture flag generating an interrupt if
    you prefer not to wait for state changes.

    I'm sure there are several more ways to do this, but this should get you
    started.
    Last edited by Bruce; - 10th August 2007 at 18:23.
    Regards,

    -Bruce
    tech at rentron.com
    http://www.rentron.com

  4. #4


    Did you find this post helpful? Yes | No

    Default Hi Thanks for the replies

    Your ideas are pretty good Bruce, but maybe i wasnt clear enough, this frequencies can apper at the same time. And there can even be more components in the signal, like voice.

    Consider DTMF detection with uC but with these other frequencies, in fact these are the frequencies of multifrequency signaling. My guess is that this conventional procedures wouldn´t be as close to real as in your experiment. or Maybe not? i will anyway try.

    Thanks

  5. #5
    Join Date
    Oct 2005
    Location
    Loveland CO USA
    Posts
    83


    Did you find this post helpful? Yes | No

    Default 4 channel frequency detector in software

    Josuetas,

    I think a hardware frequency detector like the LM567 or a digital switched capacitor filter is the way to go.

    To ask a PIC16F to do a DSP function is pushing it. Last time I did something like this I had to move up to the PIC18F family because it handles RAM better and it multiplies much faster. If you only wanted to detect 350hz out of much noise and voice then I would try it. To detect 4 frequencies at the same time is no going to happen totally in software. I think you should move up to a DSP chip if you need to do it in software. Even then 4 frequencies at one time is a project!

  6. #6


    Did you find this post helpful? Yes | No

    Default seems too much hardware

    i would need 4 LM567, i already have this solution made and it works fine, but
    the size and cost are excesive.

    I am working on it right now, i have read AN257 from microchip wich has a Discrete Fourier Transform Implementation form uC (18F) with 1 Bit ADC that seems simple.

    I will post my results anyway, thanks for your advice.

Similar Threads

  1. Need some suggestion ignition coil pulse detection
    By phoenix_1 in forum Schematics
    Replies: 8
    Last Post: - 28th April 2009, 23:34
  2. Proximity detection - tuned loops
    By George in forum Off Topic
    Replies: 1
    Last Post: - 31st July 2007, 17:25
  3. Infrared Led Object Detection
    By alaaodeh in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 12th March 2007, 04:10
  4. Auto Baud Rate Detection
    By mytekcontrols in forum Serial
    Replies: 10
    Last Post: - 31st October 2005, 02:17
  5. Low Voltage Detection
    By Srigopal007 in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 5th January 2005, 18:29

Members who have read this thread : 0

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts