Low frequency audio level detector using PIC ADC?


Closed Thread
Results 1 to 40 of 69

Hybrid View

  1. #1
    Join Date
    Mar 2009
    Posts
    653


    Did you find this post helpful? Yes | No

    Default Re: Low frequency audio RMS signal level detector using PIC ADC?

    Quote Originally Posted by Ioannis View Post
    Hank,

    1. why don't you make a full rectifier of your analog signal?

    2. is the signal always of the same amplitude?

    3. are you after a peak detector or an rms calculator? I am little confused by this thread...

    Ioannis
    Hi Ioannis,

    Ok, I came into this thinking I needed an RMS detector - I don't (despite the title ....which I'm unable to update/edit)....I really want to track 'peak' of a guitar signal. The incoming signal is of very wildly differing amplitude.....but fortunately it only goes up to 1.5khz max (the max fundamental on a guitar...I don't care about the harmonic content here - I'm only wanting to extract magnitude info, not accurately replicate the waveform digitally)

    So why not use conventional analogue components? Well I'm *very* pushed for PCB real estate ...the intended PCB will already have a PIC, but the PIC isn't doing much (basic switching, LED indicators etc) ...so that got me thinking, why not extract peak from the incoming analogue signal using the PIC - just like an analogue full wave rectifier into a peak detector (which is what my code above is doing ....'full wave rectifying a signal' but via code inside the PIC) ...if nothing else, my intention was to learn a little more about sampling an AC signal rapidly .....& like most journeys - you discover other stuff enroute. And that has proved to be the case - the special event trigger - it's been a revelation to me at least.

    Not only do I save components (PCB space)...I also avoid the forward voltage drop loss that an analogue peak detector suffers from (this is a relatively small signal I'm monitoring)...but it struck me I can also have on the fly varying 'discharge' rates to suit as my peak detector is now working in the digital domain.

    The nut has actually been cracked ....all that's happening here now is a bit of a wash up...trying to get to the bottom of a couple of quirks I'm hitting (specifically the calculations wrt sample rate, etc)


    Bert,

    Again...great ideas...I'll implement this later to get a handle on the sampling frequency (I concur that the datasheet is a bit scant with the 'meat' here!)
    Last edited by HankMcSpank; - 24th February 2011 at 19:50.

  2. #2
    Join Date
    Nov 2003
    Location
    Greece
    Posts
    4,132


    Did you find this post helpful? Yes | No

    Default Re: Low frequency audio RMS signal level detector using PIC ADC?

    The first that comes to mind is to use a DSP or dsPIC for the job as there seems to be a lot of maths.

    But then since the max frequency is just 1,5KHz then maybe the PIC used is good enough.

    Of course it has the speed to convert the input sample, but do you have time to proceess afterwards?

    The other matter is the form of the input signal. You mentioned that it is greatly varying. Are you feeding it directly to the ADC? Any pre-conditioning I thing is necessary (filtering, dc-level bias etc.).

    Ioannis

    P.S. I changed the thread title hoping you do not have any objection.
    Last edited by Ioannis; - 24th February 2011 at 20:25.

  3. #3
    Join Date
    Mar 2009
    Posts
    653


    Did you find this post helpful? Yes | No

    Default Re: Low frequency audio RMS signal level detector using PIC ADC?

    Quote Originally Posted by Ioannis View Post
    The first that comes to mind is to use a DSP or dsPIC for the job as there seems to be a lot of maths.

    But then since the max frequency is just 1,5KHz then maybe the PIC used is good enough.

    Of course it has the speed to convert the input sample, but do you have time to proceess afterwards?

    The other matter is the form of the input signal. You mentioned that it is greatly varying. Are you feeding it directly to the ADC? Any pre-conditioning I thing is necessary (filtering, dc-level bias etc.).

    Ioannis

    P.S. I changed the thread title hoping you do not have any objection.

    Actually, that's the beauty here - there's almost no complicated maths....ie just et the special event trigger grabbing ADC samples at a reasonably high sampling rate (& this is all done in the background without any recourse to interrupts etc), then in the main (fast) loop, just compare the present ADC sample to the last sample...if it is the same or bigger, keep it as the 'present peak'....if it's not the same or bigger. start decrementing the variable linearly.

    This approach wouldn't be right, if the PIC was already running intensively....but like I say, in my application the PIC isn't being too stressed.

    The signal is preconditioned in that it goes through a buffer.....this puts the AC signal on a DC level of half VCC (necessary to full wave rectify the signal inside the PIC).

    At the end of the day, I'm really just using the latent (otherwise wasted) power of the in-situ modest PIC to save on a few components (not for cost, but space) - .I don't want to start involving specific specialised ICs for what is after all a simple enough requirement.

    oh, btw I've no problem with the title being changed!

    Quote Originally Posted by languer View Post
    Hank, take a look at the Tips & tricks doc (http://ww1.microchip.com/downloads/e...Doc/01146B.pdf). Pay special attention to chapter3 (CCP and ECCP); tips #7 and #11.
    wow...a great doc.....need to digest - thanks!
    Last edited by HankMcSpank; - 24th February 2011 at 20:59.

  4. #4
    Join Date
    Mar 2009
    Posts
    653


    Did you find this post helpful? Yes | No

    Default Re: Low frequency audio RMS signal level detector using PIC ADC?

    Eeek, even a little bit of code like this....
    Code:
    main:
        toggle PortC.4   'pin 6
        'count1 = count1 +1 
        present_sample = ADRESH
        IF  present_sample < 128 then 
        present_sample = (127 - present_sample)
        else 
        present_sample = present_sample -128
        endif
    
        IF present_sample >= rolling_peak THEN
        rolling_peak = present_sample
        else
        if count1 =  50 and rolling_peak !=0 then   
        rolling_peak = rolling_peak -1       
        count1 = 0
        endif
        endif
        goto main
    is only toggling at 16khz - meaning that the main loop is only running at 30khz ...gulp (that's not leaving much room for anything else) bearing in mind I only have a 20khz sample rate going on...I wish the 16f1828 didn't have the ADC iissue about 8Mhz internal clock, becuase the obvious way of winning back por main loop time is to crank the internal clock up.
    Last edited by HankMcSpank; - 24th February 2011 at 21:53.

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


    Did you find this post helpful? Yes | No

    Default Re: Low frequency audio level detector using PIC ADC?

    what is your device ID and REV?
    -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!

  6. #6
    Join Date
    Mar 2009
    Posts
    653


    Did you find this post helpful? Yes | No

    Default Re: Low frequency audio level detector using PIC ADC?

    Quote Originally Posted by cncmachineguy View Post
    what is your device ID and REV?
    I don't know...and it's possible they've fixed the problem for the ones I have (purchased just a couple of weeks ago)

    I use a Pickit2 programmer & can't seem to find anything that tells me such device info?

    In the light of needing more 'main loop time', I've actually just cranked the Oscillator up to 16Mhz...and the ADC aspect still seems to be working ok.
    Last edited by HankMcSpank; - 24th February 2011 at 21:55.

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


    Did you find this post helpful? Yes | No

    Default Re: Low frequency audio level detector using PIC ADC?

    Per the errata, they have fixed it for all current stuff. So unless your supplier has old stock, you are prolly good. I didn't think to look at the date on the errata, that may shed some light on if it will work. It sounded like it will either work or not. It didn't sound like it could be interminent.

    And remember to change your ccpr values to reflect the faster clock. - unless you want to double the samples
    -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
    Jul 2003
    Location
    USA - Arizona
    Posts
    156


    Did you find this post helpful? Yes | No

    Default Re: Low frequency audio level detector using PIC ADC?

    Hank, take a look at the Tips & tricks doc (http://ww1.microchip.com/downloads/e...Doc/01146B.pdf). Pay special attention to chapter3 (CCP and ECCP); tips #7 and #11.

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