Reply by Tauno Voipio February 1, 20052005-02-01
James Johnson wrote:
> > I need to know the frequency of a signal that varies from about 1 Hz to > 20 Hz. I was thinking of setting up an external interrupt that interrupts > when the RPM magnet goes by and to read one of the 3 timers in the > processor to compute the period of the signal. > > Does that sound like the correct way to do this? It seems that I could do > something with interrupting the timer directly instead, for example, with > tioa2 but I'm not sure how that would work. > > I'd probably get timer overflows at the lower rpm's. > > Does anyone have a short example of how to do this? >
You're on the correct path for such low frequencies. The proper way is to time the cycles - tunrning it to a period measurement (time instead of frequency). Let a timer free run in the capture mode and catch the sensor events with the timer capture. You can extend the counter with software count triggered with timing overflow, if the amount of full timer cycles cannot be detected with some other method. HTH -- Tauno Voipio tauno voipio (at) iki fi
Reply by February 1, 20052005-02-01
James Johnson wrote:
> I need to know the frequency of a signal that varies from about 1 Hz
to
> 20 Hz. I was thinking of setting up an external interrupt that
interrupts
> when the RPM magnet goes by and to read one of the 3 timers in the
Different frequency ranges, but I did this to give tach feedback on an ATtiny26 in a project in my recent book. Email me and I will send you the schematic and sourcecode. It also has some SPI and software PWM stuff in there that you might (might) find useful.
Reply by James Johnson February 1, 20052005-02-01

I need to know the frequency of a signal that varies from about 1 Hz to
20 Hz. I was thinking of setting up an external interrupt that interrupts
when the RPM magnet goes by and to read one of the 3 timers in the
processor to compute the period of the signal.

Does that sound like the correct way to do this? It seems that I could do
something with interrupting the timer directly instead, for example, with
tioa2 but I'm not sure how that would work.

I'd probably get timer overflows at the lower rpm's.

Does anyone have a short example of how to do this?

Jim