Our Goal
This project is to make frequency counter/frequency meter that can measure the frequency of incoming analog signal. This project has two input leads. Up to now, this application can measure the frequency of both leads from 0 Hz to 920 kHz with six digit display. We have calibrated this project with fabrication-made frequency counter. This project has only 0.01 % error. So if we measure a frequency above 100kHz, the error may be happen below 20 Hz. And if we measure the a frequency between 10kHz and 100kHz, the last digit may be toggle between two values.
This project is to make frequency counter/frequency meter that can measure the frequency of incoming analog signal. This project has two input leads. Up to now, this application can measure the frequency of both leads from 0 Hz to 920 kHz with six digit display. We have calibrated this project with fabrication-made frequency counter. This project has only 0.01 % error. So if we measure a frequency above 100kHz, the error may be happen below 20 Hz. And if we measure the a frequency between 10kHz and 100kHz, the last digit may be toggle between two values.
By adding prescaler, we hope the range of frequency that can be measured can be increase to 100 MHz. And by some additional methods, we also hope the accuracy of measurements of lower frequency can be greatly increased so we can display the frequency from 1.0 Hz to 100 MHz. To do this, we will need to perform some mathematical operations. We rely on an AT89S52 microcontroller (8051 family) to perform them in this project.
We try to use minimal component so the price of this project not so expensive. The main component is an AT89S52 microcontroller and a LCD display. The only one advantage of AT89S52 than AT89S51 that we use is there is one additional 16-bit timer called timer 2.
Target Specifications:
Channel Input: 2
Frequency range: 1.0Hz ~ 35MHz (auto-scale)
Display: 6-Digit LCD
Gate time: 0.1s ~ 1s
Error: less than 0.01%
Input sensitivity: minimum 0.1V
Power consumption: less than 1W
DC Power Supply Input: 4.5V ~ 5.5V
We make open discussion forum, so all of you can contribute to this forum to share our ability.
Overview
Overview
A processor is one of main components of frequency counter. It must has ability to count and then perform arithmetic operations. To reduce price of the frequency counter become more competitive, then this research is used a microcontroller as substitute for a processor. This paper presents the design of frequency counter based on AT89S52 that it has three independent timers.
This Frequency Counter, based on counter program, can measure up to 920 kHz of incoming frequency. This will be enough to trace and debug most of circuits, to adjust 555 timers frequency and perform all kind of frequency measurements in Digital circuits. This device has 0.01% error, so it can display up to 5 digits at frequency above 100 kHz. The upper limit of frequency can be extended up to 256 MHz by adding a frequency divider. The analysis of the accuracy of measuring presented in this article can support to determine the number of digit to display.
To understand the basic of operation of this project, recall the simplest definition of frequency: the number of occurrences within a given time period. What we are trying to do is to count the number of electric pulses during a time of one second. To do this, we need a counter. The counters count the high-to-low transition of incoming pulses. A timer stop that after 1000 milliseconds.
Counter Methods
This frequency counter work by using a counter which accumulates the number of events occurring within a specific period of time. After a preset period, that is 1 second, the value in the counter is transferred to a memory and the counter is reset to zero. After that, microcontroller runs a subroutine to prepare to display and a subroutine to display some character that representing a value of incoming frequency.
If the event being measured repeats itself with sufficient stability and the frequency is considerably lower than that of the clock oscillator being used, the resolution of the measurement can be greatly improved by measuring the time required for an entire number of cycles, rather than counting the number of entire cycles observed for a pre-set duration (often referred to as the reciprocal technique). The second method can be used for measure the incoming frequency below 1kHz effectively. The accuracy for this can be improved so I can display the one tenth of frequency.
Using T0 and T1 of AT89S52 as Counter
In this application we use 2 timers that operate as mode 1 counter. They are Counter 0 and Counter 1, and can be independently configured to operate in a variety of modes as a an event counter. When operating as a counter, the counter runs for a programmed length of time, then issues an interrupt request. They counts negative transitions on an external pin. After a preset number of counts, the counter issues an interrupt request.
In this application we use 2 timers that operate as mode 1 counter. They are Counter 0 and Counter 1, and can be independently configured to operate in a variety of modes as an event counter. The timer register counts the negative transitions on the Tx external input pin. The external input is sampled every peripheral cycle. When
the sample is high in one cycle and low in the next one, the counter is incremented.
Since it takes 2 cycles (12 peripheral clock periods) to recognize a negative transition, the maximum count rate is FPER/12, i.e. FOSC/24 in standard mode or FOSC/ 12 in X2 mode. Because we use standard mode at 24 MHz clock operation, theoretically the maximum count rate is 1 MHz. In fact, the count rate can not exceed 920 kHz.
Two Input Channels
We use two input channels. The first input directly fed to the T0 (P3.4) pin of the AT89S52, and the other fed to T1 (P3.5). In order to make any kind of measurements on some circuits, the ground of the measurement device and the ground of the all circuits being tested must be connected together. The incoming signal must be match to TTL level. But in the future, by adding a signal conditioning, we hope all type of analog signal can be fed to this device. The signal conditioning must take off any DC offset from the signal and then convert it into a square wave.
Counter 0 counts the incoming clock pulse at T0 (P3.4) and Counter 1 counts the incoming clock pulse at T1 (P3.5). By resetting all counter before running, they count 0000h~FFFFh. After a value of FFFFh of counts, the counter issues an interrupt request. At the each of interrupt vector of their interrupt, we put some commands to increase a value that is an accumulator of each of overflow event of each counter.
Timer 2 In Auto-Reload Mode
The interval of 1 second is held by timer 2 that acts as auto-reload mode. The auto-reload mode functions just like Timer 0 and Timer 1 in auto-reload mode, except that the Timer 2 auto-reload mode performs a full 16-bit reload (recall that Timer 0 and Timer 1 only have 8-bit reload values). When a reload occurs, the value of TH2 will be reloaded with the value contained in RCAP2H and the value of TL2 will be reloaded with the value contained in RCAP2L.
To operate Timer 2 in auto-reload mode, the CP/RL2 bit (T2CON.0) must be clear. In this mode, Timer 2 (TH2/TL2) will be reloaded with the reload value (RCAP2H/RCAP2L) whenever Timer 2 overflows; that is to say, whenever Timer 2 overflows from FFFFh back to 0000h. An overflow of Timer 2 will cause the TF2 bit to be set, which will cause an interrupt to be triggered, if Timer 2 interrupt is enabled. Note that TF2 will not be set on an overflow condition if either RCLK or TCLK (T2CON.5 or T2CON.4) are set.
By setting RCAP2H and RCAP2L to 3CB0h, timer 2 runs for 50 ms. Timer 2 runs 40 times, so we get 1 second delay.
We use ISP Flash Microcontroller Programmer Ver 3.0a to burning the hex code. Listing program can be found at here. Look schematic diagram.
2X16 LCD Display
We choose 2X16 LCD for display. The LCD display is “lighter” than 7-segment LED display. The second display much more needs microcontroller attention to scan some LED. The attention may be could be reduced by replacing subroutine for scanning with some driver like 74LS46/7. But its need more complex circuit for it.
Sir,
ReplyDeleteI would like to information related to "burning the hex code using isp".
Thanks
If you need much more information about burning hex code using isp, please visit the link I listed above.
ReplyDelete