??? 05/05/01 19:32 Read: times |
#11372 - RE: Frequency Counter |
Making a frequency counter:
I have completely redesigned an existing frequency counter a few years ago. The counter was a PM6668 from Philips, one of the first reciprocal counters. Originally there was an 8048 processor in it. I replaced it by an SDA30C163 from Siemens, which is an 8052 derivative. The counter had 2 hardware counters, one to count the reference frequency, the other one to count the input frequency. Using hardware counters has the advantage that counting can be more accurate and higher frequencies can be counted. In school projects this is usually not the way it is done. There the counter should run preferably without any additional hardware. The principles of counting frequencies: Most counters use an exact gate time to count the pulses on the input. This will result in the input frequency without any further processing. Counters without the intelligence of a processor use this method, because it's the only way they can. But there is one big disadvantage to this method. Low frequencies can not be measured with acceptable accuracy. Suppose the input frequency is 100Hz. With a gate time of 1 second, we can count 100 pulses. But because the gate is not synchronised to the input frequency we could also count 99 or 101 pulses. This is the traditional +-1 count error. With only 100 pulses counted the actual frequency could differ +-1% without us noticing it. Adding the +-1 count error to that results in a 2% error. This inaccuracy is getting less when the input frequency increases. To count low input frequencies with a higher accuracy you could use a longer gate time. Then you count longer, so you count more pulses. An other way of counting low frequencies accurately is to measure the period time of a complete cycle. The period time is the reciprocal value of the frequency, so with a little math you can convert to Hz. Very low frequencies can be measured more accurate this way. But you still have quite a low accuracy around the 1000Hz. If you use a micro controller to count frequencies, you can use the reciprocal method. You need 2 counters to do that (and one in software to time the gate). One counter counts the reference frequency pulses during the gate time, the other counts the input pulses. The gate time can be counted in software, for it does not have to be very accurate. The overall accuracy depends on the accuracy of the reference frequency and the number of reference pulses that are counted. If you use a reference frequency of 1MHz (one of the 8052 timers running from the xtal frequency / 12) and count up to 1,000,000 pulses (1s gate time) you can measure the frequency with 6 meaningful digits, regardless of the input frequency. You can calculate the measured frequency with the following formula: f=eventcount/refcount*reffreq eventcount = number of events counted in event counter refcount = number of reference pulses counted in reference counter reffreq = the reference frequency It takes some floating point math to build such a frequency counter. But the end result is certainly worth the effort. This is how we generate the gate time: When we want to start a new count we wait for the falling edge of the input signal. When that arrives we start counting both the events and input pulses during the predetermined gate time of let's say 1 second. After one second we wait for the falling edge of the input signal again, but still continue to count the reference pulses. We stop when we receive the last falling edge of the input signal, or when we get tired of waiting in case the input signal is removed. This way we get rid of the traditional +-1 count error. In fact this error is still there, because we can only synchronise on the input signal, and not on the reference frequency. But the reference frequency is so high that we won't bother about 1 count more or less (on a count of 1,000,000). The counter I have redesigned had a hardware gate. This means that the event counter and the reference counter are started and stopped exactly at the right moment, without any lantecy. In software alone this is a little more difficult. You could use an edge triggered interrupt input at the highest priority level connected to the input frequency to start and stop the gate time. This is particularly important for low frequencies. I'm sorry I can't give you the source files. The total program is 10k in length because of the extra features, and it would be very difficult to cut out only those parts that you're interested in. Furthermore my program is designed for the Philips PM6668 counter, so the routines cannot be used for a total software solution anyway. Happy programming. |
Topic | Author | Date |
Frequency Counter | 01/01/70 00:00 | |
RE: Frequency Counter | 01/01/70 00:00 | |
RE: Frequency Counter | 01/01/70 00:00 | |
RE: Frequency Counter | 01/01/70 00:00 | |
RE: Frequency Counter | 01/01/70 00:00 | |
RE: Frequency Counter | 01/01/70 00:00 | |
RE: Frequency Counter | 01/01/70 00:00 | |
Frequency Counter based on 89c2051 | 01/01/70 00:00 | |
RE: Frequency Counter based on 89c2051![]() | 01/01/70 00:00 | |
RE: Frequency Counter | 01/01/70 00:00 | |
RE: Frequency Counter | 01/01/70 00:00 |