Home
Prox / RFID
Verichips
Ladder Logic
[interfacing] †
Tube Joints
Key Code From Photo
SolveSpace (3d CAD)
SketchFlat (2d CAD)
Photographs
Miscellany
Resume / Consulting
Contact Me

LDmicro Forum - Accessing TMR0 as a counter.

(you are viewing a thread; or go back to list of threads)

Accessing TMR0 as a counter. (by Henrik Olsson)
Hi,
Is there a way to use TMR0 (16F88) as a highspeed counter?

I have a need to detect the absence/presence of a frequency that can be anywhere from 5kHz to 20kHz. I don't need to measure the actual frequency just checking if it's there or not.

The idea was to let TMR0 count the pulses and, at each cycle, comparing the TMR0 register the value it had the last cycle but I don't see an obvious way to access TMR0.

I'm also thinking if it's possible to it with "ordinary" logic but I'm afraid that, depending on the actual frequency, it might come "in sync" with cycletime and therefor the input will read as high or low every cycle or atleast during several consecutive cycles.

If anyone has any ideas I'm all ears, thanks!

/Henrik.
Sat Aug 8 2009, 03:47:26
(no subject) (by Jonathan Westhues)
There's unfortunately no way to use TMR0 (or any other hardware counter) as a high speed counter in LDmicro.

And you are correct that an implementation that sampled the pin every cycle is vulnerable to aliasing--if the input frequency is very close to an integer multiple of the cycle frequency, then the input will appear to stay constant for a long time.

A quick and ugly solution would be to AC-couple the signal into an ordinary digital pin through a peak detector. That's a handful of parts, but it lets you read "frequency present" as a simple digital level. The component values on the schematic will supply a good logic high down to 5 kHz, and will go low within a few ms of the signal disappearing.
Sat Aug 8 2009, 04:40:17, download attachment freq-det.png
(no subject) (by Henrik Olsson)
Many thanks Jonathan!
I certanly didn't expect you to come up with a schematic too, much appreciated!

/Henrik.
Sat Aug 8 2009, 11:45:10
closed loop control (by ANWAR basheer)
hi every body, i have a one project implementation of closed loop speed motor controller. its possible to do the ld micro.

give me any example.

If anyone has any ideas I'm all ears, thanks!
Sun Jun 19 2011, 13:10:01
Post a reply to this comment:
Your Name:
Your Email:
Subject:
(no HTML tags; use plain text, and hit Enter for a line break)
Attached file (if you want, 5 MB max):