Email: Password: Remember Me | Create Account (Free)

Back to Subject List

Old thread has been locked -- no new posts accepted in this thread
???
04/20/00 01:13
Read: times


 
#2267 - RE: T0 count frequency
> I mean to counting the frequency
> 0-1 Mhz.

That's probably very easy with a little bit of external circuitry.

The first thing you need to do is convert what I'll assume is an analog sinusoidal signal of some frequency into a digital signal of ones and zeros. If you get a logic digital transition at every zero-crossing of the sine wave, you'll have what you need to load into the microprocessor.

The technique is basically this:
I assume that you use a 12Mhz crystal. Use counter/timer T0 and T1. Let counter/timer T0 run in mode 1 as a counter clocked by your digital signal tied to input pin T0. Let counter/timer T1 run in mode 1 as a timer clocked by the divide-by-12 of the system clock (its running at 1Mhz).

When you want a frequency reading, stop both counter/timers, clear the T0 count and load T1 so that it will timeout after 10ms and trigger a TF1 interrupt.

As soon as the interrupt vector fires, halt the T0 counter. Read the 16 bit value in TH0:TL0, if you multiply it by 100, it results in the frequency in Hz.

You probably would prefer to instead load the T1 timer for 1ms and then the result will be the frequency in KHz and that's commonly sufficient.

If you want KHz decimal points you can play around with the values.

If you want to detect both high and low frequencies, then you can try the above settings for Khz and if the result is too low, switch to a second test of longer timer duration. Always make sure the overflow wasn't set, when you use longer durations than 10ms. The 16bit counters will overflow if the input frequency is around 1 Mhz.

-Jay C. Box

List of 5 messages in thread
TopicAuthorDate
T0 count frequency            01/01/70 00:00      
RE: T0 count frequency            01/01/70 00:00      
RE: T0 count frequency            01/01/70 00:00      
RE: T0 count frequency            01/01/70 00:00      
RE: T0 count frequency            01/01/70 00:00      

Back to Subject List