Frequency measurement

Discussion in 'General Electronics Chat' started by RG23, Mar 21, 2011.

  1. RG23

    Thread Starter Active Member

    Dec 6, 2010
    301
    2
    I want to measure the frequency of the incoming signal using PIC 16F887

    I am not sure how to measure frequencies like eg. 2.3 Hz or 3.7 Hz

    i also want to display it on LCD

    If you have any idea please let me know

    Thanks
     
  2. Papabravo

    Expert

    Feb 24, 2006
    10,151
    1,792
    The usual method is to define something about the periodic waveform of interest that you can detect like a peak value, low to high transition, or zero crossing. Then you can either count the number of times per second that the event occurs or you can measure the elapsed time between two successive events and take the reciprocal to get the frequency.
     
  3. RG23

    Thread Starter Active Member

    Dec 6, 2010
    301
    2
    i am not clear with your idea
     
  4. RG23

    Thread Starter Active Member

    Dec 6, 2010
    301
    2
    i am using a timer and I want to measure the frequency using that timer
     
  5. RG23

    Thread Starter Active Member

    Dec 6, 2010
    301
    2
    i have defined a timer TMR0

    how should I measure the frequency of incoming signal ?

    Please let me know
     
  6. beenthere

    Retired Moderator

    Apr 20, 2004
    15,815
    282
  7. RG23

    Thread Starter Active Member

    Dec 6, 2010
    301
    2
    I have defined one of the ports as an input port in PIC 16f887

    Then when I connect the function generator to that port I wish to see the same frequency I set on generator whether its 2.7 Hz or 27 Hz etc

    I didn't understand counting the number of events per second
    which event????
     
  8. SgtWookie

    Expert

    Jul 17, 2007
    22,182
    1,728
  9. CVMichael

    Senior Member

    Aug 3, 2007
    416
    17
    Hi RG23,

    You need a timer to be at 10Hz (if you want 1 decimal), 100HZ (if you want 2 decimals), and so on... You will need a counter variable, so for every timer interrupt, have your counter increment, i.e. counter++;

    Then you need an interrupt, since you are using PIC16F887, it will have to be on RB0/INT, so connect your incoming signal on that pin.
    The counter should have your time since last interrupt, so display that value, you need to display "counter / 100" (for 2 decimals). Then right after that reset the counter back to 0 (zero).

    PS. What programming language do you plan to write this in?
     
  10. RG23

    Thread Starter Active Member

    Dec 6, 2010
    301
    2
    Assembly language
     
  11. RG23

    Thread Starter Active Member

    Dec 6, 2010
    301
    2
    Thank you for your suggestion
     
  12. RG23

    Thread Starter Active Member

    Dec 6, 2010
    301
    2
    Then you need an interrupt, since you are using PIC16F887, it will have to be on RB0/INT, so connect your incoming signal on that pin.
    The counter should have your time since last interrupt, so display that value, you need to display "counter / 100" (for 2 decimals). Then right after that reset the counter back to 0 (zero).

    _______________________________________________________________

    I am not clear with that
     
  13. RG23

    Thread Starter Active Member

    Dec 6, 2010
    301
    2
    can you please simplify?
     
  14. CVMichael

    Senior Member

    Aug 3, 2007
    416
    17
    Never mind my explanation, the link given by SgtWookie is much better
     
  15. RG23

    Thread Starter Active Member

    Dec 6, 2010
    301
    2
    i have still not figured out the problem

    I would appreciate any further help

    Thanks
     
  16. BillB3857

    Senior Member

    Feb 28, 2009
    2,400
    348
    You have me confused, which is not too unusual. I thought that the sample had to be 10 times LONGER to get 0.1 resolution and 100 times LONGER to get 0.01 resolution for low Hertz frequencies i.e. 1/10 Hz for 1 decimal and 1/100 Hz for 2 decimals. Can you enlighten me?
     
  17. SgtWookie

    Expert

    Jul 17, 2007
    22,182
    1,728
    Did you see the link I posted in reply #8?
    It's a complete project, that seems to be well-documented.
    It even has the assembly language source code posted.

    You will need to convert the souce code from a PIC16F628 to a PC16F887, or simply use a PIC16F628 as the author did.
     
  18. RG23

    Thread Starter Active Member

    Dec 6, 2010
    301
    2
    yes it is well documented but unfortunately too long for me to understand
     
  19. RG23

    Thread Starter Active Member

    Dec 6, 2010
    301
    2
    Is there any other alternative method easy to understand???????
     
  20. tom66

    Senior Member

    May 9, 2009
    2,613
    214
    You could set up the timer to measure the length of each pulse. The reciprocal of this is the frequency. Unfortunately doing a reciprocal on an 8-bit PIC will be a nightmare. Instead, I'd recommend you could the number of pulses in 10 seconds. 27 pulses = 2.7 Hz.
     
Loading...