piclist 2001\01\31\163646a >
Thread: Measuring Frequency with a PIC
face picon face BY : Olin Lathrop email (remove spam text)

> I need to measure the frequency of a square(ish) wave at about 1000 -
> to about 20Hz resolution using a PIC16C710/711/715 PIC. Absolute accuracy
> not required, I just need to check for an approx 90Hz change in input
> frequency from normal.
> Anybody got any ideas?
> My first thought was to change to a PIC with a CCP unit and use that but
> when I read up on the CCP it doesn't look as if it's really that suitable.

Yes, you could switch to a 16C712 or '716 which have CCP modules.  These are
ideally suited to measuring period.  I've done this many times.  What was
the problem you saw with measuring period with a CCP module?

> My current thinking is to feed the signal into RA4/T0CKI and use timer 0.
> The idea would be that when I need to read the frequency I disable all
> interrupts, change Timer 0 over from whatever it was doing to external
> clock,
> clear it and do a software delay of 0.1 sec. Then I read the value from
> Timer 0, set timer 0 back as it was (probably generating tick interrupts)
> and re enable interrupts.

That would work, but there are other approches too.  Fortunately you have a
relatively low frequency and only need 20Hz resolution.  You could therefore
just count cycles over a 50mS period, or longer if you can tolerate getting
an answer less often.  1500Hz is slow enough to allow an interrupt every
cycle.  You could use timer 0 to set up a periodic 50mS or 100mS interrupt,
then have your input frequency trigger an RB0 interrupt every cycle.  You
save the old value then clear the counter every timer 0 interrupt, and
increment the counter every RB0 interrupt.

Olin Lathrop, embedded systems consultant in Devens Massachusetts
(978) 772-3129, KILLspamolinspam_OUTspamembedinc.com, http://www.embedinc.com

http://www.piclist.com hint: To leave the PICList

<001701c08bca$a2742830$260bf6cd@pc> 7bit

See also: www.piclist.com/techref/microchip/devices.htm?key=pic
Reply You must be a member of the piclist mailing list (not only a www.piclist.com member) to post to the piclist. This form requires JavaScript and a browser/email client that can handle form mailto: posts.
Subject (change) Measuring Frequency with a PIC

month overview.

new search...