Frequency detection (audio)


Closed Thread
Results 1 to 23 of 23

Hybrid View

  1. #1
    Join Date
    Mar 2009
    Posts
    653


    Did you find this post helpful? Yes | No

    Default Re: Frequency detection (audio)

    Just thinking out loud here...if all the overhead comes from entering & exiting the interrupt routine ...if I dedicate my main loop solely to measuring high/low transitions on a pin (ie feed the PICs comparator output from its output pin into another digital input pin), would this be workable?

    Just pondering how I can get the PIC to detect up to 1.5khz!

  2. #2
    Join Date
    Sep 2009
    Posts
    755


    Did you find this post helpful? Yes | No

    Default Re: Frequency detection (audio)

    Did you try COUNT or PULSIN or using TIMER to count freq...
    I have set TMR0 to overflow each second and trigger interrupt. In ISR read TMR3, then reset it.
    It goes to 50KHz without any problem. You also can use shorter time, but then you have lower resolution.

  3. #3
    Join Date
    Mar 2011
    Location
    Los Angeles, California
    Posts
    322


    Did you find this post helpful? Yes | No

    Default Re: Frequency detection (audio)

    Hi Hank!
    There are several approaches to solving what you wish to do. One site ( http://www.intmath.com/trigonometric...hase-shift.php ) will give you the math involved in determining a given musical note. Another is ( http://liutaiomottola.com/formulae/freqtab.htm ). If you look at the frequencies for each note notice that if you take the highest "C" note, the next octave of "C" below it is exactly 1/2 the frequency. Where things become "spritual" is that when mixing musical note the mix will give the sum, the difference, and the individual frequencies. The only way I can see to make the distictions would be with "band-pass" filters or a graphic equalizer. You would probably have to take the range of audio (20-20,000 Hz) and divide it into something like 10 or more ranges and then using a high pass and low pass filter "comb" the input sound. Or one big look-up table! The secondary problem would come from how perfectly the guitar is tuned. Hope this helps, Ed

  4. #4
    Join Date
    Mar 2009
    Posts
    653


    Did you find this post helpful? Yes | No

    Default Re: Frequency detection (audio)

    Thanks guys...I'm now approaching this in a slightly different way & getting reasonable results (I think!)

    I'm using timer1 gate & comparator2

    Here's the sequence....

    Comparator2 goes high....raises a gate on timer1...timer1 starts counting
    Comparator2 goes low ....gate drops ...timer1 stops counting
    When gate drops a timer1gate interrupt gets flagged
    A DT Interrupt traps this (T1GATE_INT) & my program jumps to an ISR
    I spit out the contents of timer1 in the ISR serially to my PC.
    clear timer1
    rinse repeat.

    It seems I can get trap upto 4khz audio frequency with nowhere near as many spurious readings as before (I'm still using a sig gen though)....above 4khz the counts start going a bit erratic.

    here's the timer1 readings for 4000hz (16Mz Oscillator)...

    495
    495
    495
    495
    494
    495
    495
    495
    494
    495
    495
    495
    494
    495
    495
    495
    494
    495
    495
    495
    494
    494
    495

    (the gate is only trapping 'half a waveform period' so the counts are half what you'd expect when detecting 4khz)

    Pretty steady (they should be 500...& I can't quite account for where the missing counts are going!)
    Last edited by HankMcSpank; - 10th June 2012 at 00:03.

  5. #5
    Join Date
    Mar 2011
    Location
    Los Angeles, California
    Posts
    322


    Did you find this post helpful? Yes | No

    Default Re: Frequency detection (audio)

    Hi Hank,
    This may sound like a dumb question and you are doing an analog to digital conversion at some point? Also if you only wish to work with half wave, a simple diode will do this for you. Best, Ed

  6. #6
    Join Date
    Mar 2009
    Posts
    653


    Did you find this post helpful? Yes | No

    Default Re: Frequency detection (audio)

    Firstly, I spoke to soon. Whilst this latest method mentioned in my last post has allowed me to detect higher frequencies....I'm still getting erratic results in & around the 450-700Hz audio frequency range!

    Ramius - re Ato D'ng....no this is purely to detect frequency (although I do intend using the pic's AtoD as an envelope detect to actually trigger the frequency detection).
    Last edited by HankMcSpank; - 10th June 2012 at 10:33.

  7. #7
    Join Date
    Mar 2009
    Posts
    653


    Did you find this post helpful? Yes | No

    Default Re: Frequency detection (audio)

    Ok, it looks like interrupts are a big no-no here so I've established a way of doing this without an interrupt...

    Code:
    T1GCON.4 = 1
    Loop1:
    pause 500
    T1GCON.3 = 1
    TMR1=0
    while  T1GCON.3 = 1
    wend
    count1=tmr1
    HSEROUT [dec count1,13,10]
    GOTO Loop1
    The above can detect up to 50khz audio input (can probably go higher...but the amount of timer1 counts between comparator edges gets less, so the 'percentage error' increases)

    Basically I'm using a Timer gate single pulse mode (T1GCON.4 = 1), then forcing the other part of the single pulse mechanism to a 1 ( Single-Pulse Acquisition Status bit T1GCON.3 = 1), after the comparator2 output drops then T1GCON.3 is dropped to a zero automatically, I therefore use a wend to loop until T1GCON.3 = 1 is a 0 ....then I ouput the timer1 counts. My only problem is I'm getting a zero reading intermittently, but other than that, the counts are pretty solid.

    here's the TMR counts for 1,000Hz....

    1824
    1824
    1825
    1825
    1826
    0
    1824

    just got to get to the bottom of why those readings of 0 are creeping in .....
    Last edited by HankMcSpank; - 10th June 2012 at 18:06.

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