Rough 'n Ready Audio Frequency extraction with a PIC


Results 1 to 34 of 34

Threaded View

  1. #20
    Join Date
    Mar 2009
    Posts
    653


    Did you find this post helpful? Yes | No

    Default

    Ok, I think I have the loose makings of the necessary code for a rolling 1 second window to check whether the frequency has remained the same...

    (the signal to be monitored is fed into comparator1)

    Code:
    INCLUDE "DT_INTS-14.bas"
    INCLUDE "ReEnterPBP.bas"
    INCLUDE "Elapsed_INT.bas"  ; Elapsed Timer Routines
    
    ASM
    INT_LIST  macro    ; IntSource,        Label,  Type, ResetFlag?
            INT_Handler   TMR1_INT,  _timer1_interrupt,   PBP,  yes
            INT_Handler   CMP1_INT,  _comparator_interrupt,   PBP,  yes
        endm
        INT_CREATE            ; Creates the interrupt processor
    ENDASM
    
    @   INT_ENABLE  TMR1_INT  ; Enable Timer 1 Interrupts
    @   INT_ENABLE  CMP1_INT  ; Enable comparator1 Interrupts 
    
    nochange_count var word   'count number of 'timer overflows' where frequency hasn't changed
    
    comparator_count var word   'a variable to count number of comparator interrupts (frequency detection)
    
    loop:
    if nochange_count > 3 then     'ie frequency has remained the same for 1 second
    nochange_count = 0 
    gosub dostuff
    endif
    goto loop
    
    
    '---[Timer1 - interrupt handler]--------------------------------------------------
    timer1_interrupt:        'prescaler set for circa 250ms
    if comparator_count = previous_comparator_count then   'needs a 5% 'deviation' allowable error to go here!!
    nochange_count = nochange_count+1   'count how many times frequency has NOT changed
    else
    nochange_count = 0 ' if frequency has changed, then zero counter and start over
    endif
    previous_comparator_count =  comparator_count
    comparator_count = 0
    @ INT_RETURN
    
    '---[Comparator1 - interrupt handler]--------------------------------------------------
    comparator_interrupt:
    comparator_count = comparator_count +1
    @ INT_RETURN
    There may be some syntax errors in there (I'm at work!), but that's the basic framework - what I don't know how to do is the 'deviation' part (bolded in red above).

    How can I have an 'if' condition that checks to establish if present count is 'within 5%' of previous count' (plus or minus), therefore....

    if comparator_count = previous_comparator_count '+ or -' 5%

    Two 'AND'ed ifs?

    Many thanks!
    Last edited by HankMcSpank; - 26th August 2010 at 14:39.

Similar Threads

  1. Measuring change of frequency with PIC
    By Aussie in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 19th July 2007, 02:47
  2. PIC Audio
    By toofastdave in forum mel PIC BASIC Pro
    Replies: 28
    Last Post: - 27th June 2007, 14:49
  3. Pic driven digital audio delay
    By skimask in forum Off Topic
    Replies: 12
    Last Post: - 19th April 2007, 21:42
  4. Audio Encoding and playback in a PIC
    By Rob in forum mel PIC BASIC Pro
    Replies: 8
    Last Post: - 24th March 2005, 09:56
  5. Frequency Counter using PIC and PicBasic
    By PICtron in forum mel PIC BASIC Pro
    Replies: 31
    Last Post: - 28th January 2005, 07:20

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