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 (audo)

    Quote Originally Posted by cncmachineguy View Post
    Are my eyes lying to me or are they the same-ish as for 1K? One must ask them selves How can this be?
    Good spot!

    Here's approx the Timer counts I'm seeing for different frequencies...

    82.4Hz (lowest note on a guitar) - 42,900 (ish)
    330Hz (top E) - 7,300(ish)
    600Hz - 1800 (ish)

    650Hz -1200(ish)

    & then when I go higher in frequency, the timer1 counts start going all over the place ..

    Here's 800 hz...

    4924
    177
    4940
    177
    4965
    179
    4987

    Oddly, when I dial 1000hz in, yep the counts go to 3,200 again ....so clearly something is wrong with my detection method using interrupts & timer1 counts

    (btw I know the frequencies the PIC is handling internally are correct, as I'm outputting the PIC's comparator output to an external pin & attaching a frequency counter to the pin)

    Hmm [strokes chin]
    Last edited by HankMcSpank; - 7th June 2012 at 16:05.

  2. #2
    Join Date
    Aug 2006
    Location
    Look, behind you.
    Posts
    2,818


    Did you find this post helpful? Yes | No

    Default Re: Frequency detection (audo)

    500 hz is the first harmonic negative of 1 Khz. some Pi filters might help or lower the input gain
    Last edited by Archangel; - 7th June 2012 at 16:33.
    If you do not believe in MAGIC, Consider how currency has value simply by printing it, and is then traded for real assets.
    .
    Gold is the money of kings, silver is the money of gentlemen, barter is the money of peasants - but debt is the money of slaves
    .
    There simply is no "Happy Spam" If you do it you will disappear from this forum.

  3. #3
    Join Date
    Mar 2009
    Posts
    653


    Did you find this post helpful? Yes | No

    Default Re: Frequency detection (audo)

    Quote Originally Posted by Archangel View Post
    500 hz is the first harmonic negative of 1 Khz. some Pi filters might help or lower the input gain
    I don't think that's the issue, here's a scope screenshot of what the PIC's internal comparator is seeing internally...





    The white parameters window to the right is my scope's take on the waveform it is displaying (1khz)

    The green text on the left is the PIC spitting out the TMR1 counts it's counted between comparator2 interrupts serially to my PC com port.
    Last edited by HankMcSpank; - 7th June 2012 at 16:51.

  4. #4
    Join Date
    Aug 2010
    Location
    Maryland, USA
    Posts
    869


    Did you find this post helpful? Yes | No

    Default Re: Frequency detection (audo)

    Hank,, how bout toggling a pin in your ISR to show when the PIC thinks it should start and stop counting.
    EDIT : OK I see youo have done that already DOH!!

    The numbers should be linear IMHO. so 330 HZ is about half of 600, but your numbers are *4. 330 = 7300 and 600 = 1800. Now between 600 and 650, we have a difference of 600. So that would say the count shoud be 600 per 50hz. so to get to 100hz, we would expect the count to be 10*600=6000 difference. or 7800 (ish). but you are at 49,000 for 82.4. either I am way off on my linear assumption (most likely) or something is really amiss.
    Last edited by cncmachineguy; - 7th June 2012 at 17:00.
    -Bert

    The glass is not half full or half empty, Its twice as big as needed for the job!

    http://foamcasualty.com/ - Warbird R/C scratch building with foam!

  5. #5
    Join Date
    Mar 2009
    Posts
    653


    Did you find this post helpful? Yes | No

    Default Re: Frequency detection (audo)

    Quote Originally Posted by cncmachineguy View Post
    Hank,, how bout toggling a pin in your ISR to show when the PIC thinks it should start and stop counting.
    EDIT : OK I see youo have done that already DOH!!
    No...I hadn't so put a toggle in my ISR (top tip - tks!)

    I've scoped the ISR 'toggled' pin & I'm seeing 250hz on there?!! (therefore 2 x 250hz = an interrupt rate of 500Hz ....this for a 1kHz audio signal?!)

    I confirmed my input to the comparator was 1Khz...and also the output from the PIC comparator is definitely 1khz (since I've brought it out on a PIC external pin & scoped it).

    So it looks like my comparator interrupt isn't working properly and my interrupt is only happening at half the rate it should???

    Any ideas?!!
    Last edited by HankMcSpank; - 7th June 2012 at 17:13.

  6. #6
    Join Date
    Mar 2009
    Posts
    653


    Did you find this post helpful? Yes | No

    Default Re: Frequency detection (audio)

    Ok, so I took the HSEROUT command out of the ISR ...... & then my ISR 'toggle pin' frequency scoped correct up to around 900hz audio input ....however, above that 900Hz audio input, even with just a basic 'toggle pin' in the ISR, the toggle pin frequency as seen on a scope starts going awry again....so the conclusion here ...it seems that DT's interrupts are taking a bit too long to get in & out for anything above 800hz comparator interrupt rate (this is with a 16Mhz oscillator).

    Anyone know of another way of approaching this? (I'd like to be able to to detect up to 1.5Khz)
    Last edited by HankMcSpank; - 7th June 2012 at 18:16.

  7. #7
    Join Date
    Aug 2010
    Location
    Maryland, USA
    Posts
    869


    Did you find this post helpful? Yes | No

    Default Re: Frequency detection (audio)

    Here I go out on a limb that has been broken already, change the type to ASM instead of PBP. The only thig I see in your ISR using PBP is HSEROUT and TMR=0 since you removed the hser, now its only TMR=0 Now keep in mind - YOU ARE NOT SUPPOSED to do this, but for the simple setting of TMR I think you can get away with it. Add BSR=0 as your first line in the ISR. That will stop all the system variables from getting saved and restored everytime you enter the ISR. Sound familiar?

    This may be enough to make it happen just as you want. The next approach I can think of is to use the comparitor as the gate for the timer, but that may be how you are doing it now

    Also, does the CMP fire an int twice or 4 times per cycle? or just 1 time?
    Last edited by cncmachineguy; - 7th June 2012 at 18:25.
    -Bert

    The glass is not half full or half empty, Its twice as big as needed for the job!

    http://foamcasualty.com/ - Warbird R/C scratch building with foam!

  8. #8
    Join Date
    Mar 2009
    Posts
    653


    Did you find this post helpful? Yes | No

    Default Re: Frequency detection (audio)

    Thanks for the input Bert, I changed the interrupt to ASM...
    Code:
    ASM
    INT_LIST  macro ; IntSource,    Label,         Type, ResetFlag?
        INT_Handler  CMP2_INT,  _CMP2_Interrupt,  ASM,  YES 
        endm
        INT_CREATE       ; Creates the interrupt processor
    ENDASM
    and modified my ISR...

    Code:
    CMP2_Interrupt:   ' COMPARATOR2 INTERRUPT.
    BSR=0 
    toggle portc.7
    TMR1=0
    @ INT_RETURN
    but I still can't my audio input above 900Hz, without the ISR toggle pin scoping wrong :-(

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