Measuring Period & Hz


Closed Thread
Results 1 to 11 of 11
  1. #1
    MaurI's Avatar
    MaurI Guest

    Default Measuring Period & Hz

    Hello!

    Ihave following situation:
    I must build a LC-meter, I have an Idea that involves simple oscilator circuit but the tough part is to measure frequency using PIC16F628A. Default calibrating frequency is about 1MHz so I cant use COUNT comand and if I could I think that the result wouldn't be good enough because I need percise device. So then I thought about using timer0 but I don't know how to set a certain countig period. Simply I don't know how to count pulses and measure period at the same time. Is it possible? Maybe I am thinking wrong. Maybe you can give me other advices how to complete this task. Please Help ! I'm just learning + I'm at the very beginning of this long process!

    Thanks!

  2. #2
    Join Date
    May 2004
    Location
    brighton
    Posts
    149


    Did you find this post helpful? Yes | No

    Default

    I Think You Would Need To A Prescaler

  3. #3
    MaurI's Avatar
    MaurI Guest


    Did you find this post helpful? Yes | No

    Default

    Yes I can use a prescaler but that doesn't change the situation that I don't know how to set a counting period (THE TIME) Because Frequency is number of oscillations per period so I need to know number of impulses and the time in what these impulses appeared. OK then Is it possible to use Timer0 and Timer2 at the same time and stop them at the same time if yes then how. Don't think I'm crazy or stupid I couldn't find an answer to this one.

    Thanks

  4. #4
    Join Date
    May 2004
    Location
    brighton
    Posts
    149


    Did you find this post helpful? Yes | No

    Default

    Hi Mate
    i think the easiest route would be for you to use a hardware frequency
    divider chip the can divide your frequency down to the Khz range and then use the ccp capture or timer 1 and you should be ok
    BTW what frequency range are you gonna use


    Isaac

  5. #5
    MaurI's Avatar
    MaurI Guest


    Did you find this post helpful? Yes | No

    Default

    F range will be around 300kHz to 2MHz

    Well I don't want to use hardware f-divider, because I know that this task can be accomplishet without it but I really can't find any source. But if it comes to that there is no choice I will think of something.

  6. #6
    G8RPI's Avatar
    G8RPI Guest


    Did you find this post helpful? Yes | No

    Default Timer 1 for frequency measurement

    Hi MuarI,
    Use timer1 to count the pulses and PBP can still count the time interval.
    Here's a code snippet of a 16F676 for a low frequency meter (1s gate time)


    cmcon = 7 'for pic10F206
    ansel = 0 'for 16F676

    'for LCD on port c
    DEFINE LCD_DREG PORTC
    DEFINE LCD_DBIT 0
    DEFINE LCD_RSREG PORTC
    DEFINE LCD_RSBIT 4
    DEFINE LCD_EREG PORTC
    DEFINE LCD_EBIT 5
    DEFINE LCD_LINES 2


    ct0 var word 'total number of counts
    t1hi var ct0.byte1 'high byte of timer1
    t1lo var ct0.byte0 'low byte of timer1
    ovf var bit 'overflow flag bit
    sermode var byte 'serial port mode
    ctime var word 'counting time

    sermode = 6 '1200 Baud inverted

    ctime = 1000 'CPS 1000mS gate time
    Pause 500 'allow LCD to startup
    lcdout $fe,1 , "PIC Counter V1.1"
    lcdout $fe, $c0, " C G8RPI 2005 "
    Pause 1500
    lcdout $fe,1
    Goto main 'bypass subroutines



    getcount:

    porta.2 =1 'turn "gate" led on
    t1con = 7 'set timer 1 on, external clock, non sync = bit0 =1, bit1 =1, bit2 =1
    tmr1h = 0 'clear timer 1 high byte
    tmr1l = 0 'clear timer 1 low byte
    pir1 = 0 'clear overflow flag


    pause ctime 'wait

    t1con = 0 'stop timer 1 , bit0 =0
    porta.2 =0 'turn led off

    t1lo = tmr1l
    t1hi = tmr1h
    ovf = pir1

    if ovf = 1 then
    Serout porta.0,sermode,["OVER-RANGE" ,13 ,10]
    lcdout $fe, $c0,"OVER-RANGE"

    else

    Serout porta.0,sermode,[#ct0 ," "]

    lcdout $fe, $c0,#ct0, " "

    endif
    Return

    Main:
    gosub getcount
    goto main


    it outputs the frequency on an LCD and a serial port.
    HTH,
    Robert G8RPI.

  7. #7
    MaurI's Avatar
    MaurI Guest


    Did you find this post helpful? Yes | No

    Default

    Thanks, but this will work only for Low frequencies, I think a Hardware f-divider is good enough for this task.

  8. #8
    G8RPI's Avatar
    G8RPI Guest


    Did you find this post helpful? Yes | No

    Default Frequency measurement

    Hi,
    The timer 1 will work to at least 15MHz, more than enough for your application.
    My code will also work, just adjust the counting time, variable ctime in my code, to suit the frequency range. Use pauseus instead of pause for very short counting times.Setting ctime to 100 and changing the pause command to pauseus will give a reading up to 6.5535MHz with 100Hz resolution (100us count time). The 100Hz resolution is better thn .05% at 300KHz, much more than you need for a typical LCR meter.
    An external prescaler is not required, you don't even need to use timer1's internal prescaler.

    Regards,
    Robert G8RPI.

  9. #9
    MaurI's Avatar
    MaurI Guest


    Did you find this post helpful? Yes | No

    Default

    Hello

    Well the problem is that the resolution must be about 5 Hz. To achieve that the measuring period must be long enough. Timer1 can count up to 2bytes that is not enough. Using a prescaler gives an error too. So my LAST idea was to use some high speed hardware counter that has large registers I would then connect it to PIC which will control it and calculate.

    * Does anybody know a counter of this type aprt name/number?

    Besides those Pause and Pauseus aren't precise, I have measured the frequency on PICs pins using Pause and Pauseus with High and Low and =1, =0, the error of time is about 0,06%, well it is inconspicious but...

    Thanks

  10. #10
    G8RPI's Avatar
    G8RPI Guest


    Did you find this post helpful? Yes | No

    Default

    Hi,
    5Hz Resolution at 2MHz is is 1 in 400,000 or 0,00025%! This implies that you are either trying to measure very accurate capacitors or your circuit has a very small frequency change for a given capacitance change.
    Without knowing exactly what you are trying to acheive (parameters to be measured, range of values and accuracy) and the circuit you are using, it is hard to make reasonable suggestions. Is this just a project to make a LC meter for your own use, a special meter for a particular application or a commercial design?
    If you wish to use an external hardware counter look at the CMOS (CD/HEF) 4040 (12 bit, use two) or 4518 (dual 4 bit, use 3 ic's) chips but you will have to build your own gating and multiplexing circuits, or the Intersil 7226. The 7226 is an 8 digit frequency counter ic that will drive LED's but also has a multiplexed BCD output. It is however becoming obsolete.
    I do think howevr that if you need 5Hz resolution at 2MHz to measure at normal component accuracy (around 1%) your circuit needs to be reconsidered. Perhaps auto range switching when the PIC counter overflows? My code traps a counter overflow.

    A typical precision LCR meter costing around $4000 offers 0.05% accuracy, 0.2% will cost you $2000 and 1% about $200.
    I can recommend the Peak Atlas LCR meter at under £80 (UK Pounds) or about $150.

    HTH,
    Robert.

  11. #11
    leko's Avatar
    leko Guest


    Did you find this post helpful? Yes | No

Similar Threads

  1. Frecuency Detection
    By Josuetas in forum mel PIC BASIC Pro
    Replies: 8
    Last Post: - 4th February 2010, 02:01
  2. Timer + rc5
    By naga in forum mel PIC BASIC Pro
    Replies: 8
    Last Post: - 19th November 2009, 07:56
  3. Wheel speed sensor
    By Wax-um in forum mel PIC BASIC Pro
    Replies: 4
    Last Post: - 24th January 2009, 01:07
  4. RC5 decode on a 10F + Question
    By ultiblade in forum mel PIC BASIC Pro
    Replies: 8
    Last Post: - 11th September 2008, 08:20
  5. Frequency Generator
    By ExYu in forum Off Topic
    Replies: 2
    Last Post: - 22nd January 2008, 18:25

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