Accurate Freq Measurment


Closed Thread
Results 1 to 23 of 23

Hybrid View

  1. #1


    Did you find this post helpful? Yes | No

    Default freq ccp

    yes....resolution and overhead

    use ccp (capture/compare) module in capture mode....
    count at 10MHZ,(Fosc/4 from 40MHZ) set for every 16th rise or fall edge to get counts directly, at 4000.0 hz, count is 40000
    -at 3999 hz count is 40010
    -at 4001 hz count is 39990

    freq then = (40,000 +/- difference)/10 hz down to .1HZ

    i think?
    don

  2. #2


    Did you find this post helpful? Yes | No

    Default freq math

    actual hz calculation........

    HZ = 16x10^7/count (from ccp) within range of 2500hz to 10MHZ ?
    for ccp @ every 16 edges.

    don f

  3. #3
    Join Date
    Dec 2005
    Posts
    24


    Did you find this post helpful? Yes | No

    Default

    skimask your last description is exactly what I am trying to do. My code essentially does just that over a 200 cycle period but not very gracefully as written, the start and stop of Timer1 I don't thinks is well done as I am using software to do it rather than hardware. In my attempt to measure the frequency fast, the physics of the problem limits how fast the measurement can be done for a given accuracy, but when comparing to a frequency counter approach I would need a 10 second period for 0.1Hz resolution, where by measuring the period as you point out can provide great resolution fast relative to a frequency counter, I guess I should have been more clear in my original posting, because my target is ~100 msecs for the measurement time. After doing more research it looks like the approach of using the capture/compare module with Timer1 as you point out Don is the way to go. I have not used the capture mode in the PIC's in an interrupt mode, are there any good code examples.
    Terry

  4. #4
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by Terry View Post
    I guess I should have been more clear in my original posting, because my target is ~100 msecs for the measurement time. After doing more research it looks like the approach of using the capture/compare module with Timer1 as you point out Don is the way to go. I have not used the capture mode in the PIC's in an interrupt mode, are there any good code examples.
    As they say, you can have 2 of 3 things...fast,good,cheap...
    You can have it fast, you can have it good, it won't be cheap.
    You can have it good, and you can have it cheap, but it won't be fast.
    You can have it cheap, and you can have it fast, but it won't be good

    I think you're method will work, and I wouldn't doubt that what you are using right now could work well enough. Why not 'remember' the last bunch of readings, say the last 10 readings, then average them out, discard the oldest, plug in the newest...a moving average if you will. You won't necessarily gain resolution, well, yes you will since you've increased the effective sampling time. You can keep your 100ms measurement time, and still get fairly decent resolution.

  5. #5


    Did you find this post helpful? Yes | No

    Default ccp

    Terry, I don't know specifically of capture code examples, the microchip data books lay out general routines. You probably know;
    -set ccp for capture on 16 rise edge
    -tmr1 prescale to 1
    -make int routine in asm and add int pointer name for basic
    -set pie and pir's for interrupt enables
    ---on int -- check for tmr1 overflow(not usable count)
    ---stop ccp and tmr1
    ---move count high and low to basic count word
    ---reset flags capture and tmr1 overflow
    ---tmr1h and tmr1L = 0
    ---start ccp and tmr1

    basic prog can start and stop interrupts as desired.
    took me some good head scratching for int's but is very reliable when working.
    Once working, pic will just keep spitting out counts automatically.
    don

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


    Did you find this post helpful? Yes | No

    Default

    See this thread for a few examples http://www.picbasic.co.uk/forum/showthread.php?p=23401

    You might want to download the .PDF Steve linked to in that thread for more info on using capture. It's very handy once you get the hang of using it.

    If you really want to have some fun, take a peek at the 18F2431 series. This one has a TON of options for measuring frequency, pulse width, PWM motor control, high-speed simultaneous 2-channel A/D sampling, and lots of other goodies.
    Regards,

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

  7. #7
    Join Date
    Dec 2005
    Posts
    24


    Did you find this post helpful? Yes | No

    Default

    Bruce,
    Thanks for the link, I just found it a shortly before you posted your message, I also found a few more of your posts with code for using the capture mode with Timer1, once I realized I needed to search on Capture I think you are the expert on the hardware Timers! I hope I can now greatly improve my code.
    Terry

Similar Threads

  1. Easy and Accurate Clocks without RTC IC
    By paul borgmeier in forum Code Examples
    Replies: 18
    Last Post: - 28th October 2013, 21:28
  2. reducing shiftout clock freq and PS2/PC interfacing ....
    By wireless magic in forum mel PIC BASIC Pro
    Replies: 18
    Last Post: - 26th February 2008, 20:15
  3. accurate vref < 1vdc 16F876 comparator
    By mslaney in forum Schematics
    Replies: 1
    Last Post: - 23rd March 2005, 01:44
  4. HPWM on a 628 is not changing freq.
    By dtit in forum General
    Replies: 2
    Last Post: - 25th February 2005, 09:34
  5. More accurate resolution from the A/d converters
    By pjsmith in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 5th August 2004, 22:49

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