Share this

Microcontroller-based equal-precision digital frequency measurement

2026-04-06 04:49:01 · · #1
In the field of electronics, frequency is a fundamental parameter, closely related to the measurement of many other electrical parameters. Therefore, frequency measurement is of paramount importance, and currently, frequency measurement offers the highest accuracy in electronic measurements. 1. Block Diagram of Electronic Counting Frequency Measurement Principle [IMG=Block Diagram of Electronic Counting Frequency Measurement Principle]/uploadpic/THESIS/2007/12/2007121709473380059M.jpg[/IMG] First, the signal being measured is amplified and shaped to form counting pulses with consistent amplitude and shape. Then, N is applied to one input of a gate, whose closing time is controlled by a gate control signal. The counted pulses are sent to a decoder and then displayed on a monitor. A 1MHz oscillation signal generated by a crystal oscillator is amplified and shaped to form a square wave, which is then divided by 10 for 10s, 1s, 0.1s, 0.01s, and 1ms. Therefore, fx=N/T, which conforms to the definition of frequency measurement. According to f=N/T... It is easy to see that the measurement error of frequency measurement using a counter depends on two factors: firstly, the accuracy of the gate time T, i.e., the accuracy of the standard frequency provided by the crystal oscillator, ΔT/T = -(Δfo/fo); and secondly, the accuracy of the counter's reading, i.e., the "±1 error", ΔN/N = ±1/N = ±(1/○XTfx). Therefore, the error of direct frequency measurement using a counter mainly consists of two parts: ±1 error and standard frequency error. When measuring low frequencies, the frequency measurement error caused by ±1 error is alarmingly large, so direct frequency measurement is not advisable. Because when fX is low, the frequency measurement error caused by ±1 error when using a counter for direct frequency measurement will be unacceptably large. Therefore, to improve the accuracy of low-frequency measurements, i.e., to reduce the influence of ±1 error, it is advisable to first measure the period Tx and then calculate fx = 1/Tx. 2. Electronic Counter Period Measurement Principle: Tx is amplified and shaped to control a bistable trigger, generating a gate signal to control the opening and closing of the gate. Then, a 1MHz oscillation signal generated by the crystal is amplified and shaped into a square wave, producing counting pulses with consistent amplitude and shape. When the gate is open, the counting pulses are counted; when the gate is closed, counting stops. The counted pulses are decoded and displayed. 3. Microcontroller Timer Working Principle: Timing and counting are essentially both pulse counting, but the source of the counted pulses differs. In timing mode, the initial count value is related to the period of the counted pulses, while in counting mode, the initial count value is only related to the number of counted pulses (counting the high to low edges). [IMG=Microcontroller Timer Working Principle]/uploadpic/THESIS/2007/12/2007121709473955795Y.jpg[/IMG] [IMG=Microcontroller Timer Working Principle]/uploadpic/THESIS/2007/12/2007121709474695571E.jpg[/IMG] The 8031 ​​microcontroller contains two 16-bit programmable timer/counters. Both are programmable to count internal machine cycles (timing mode) or count pulses input from external pins (counting mode). When the CPU operates at a 12MHz clock frequency, the maximum external counting frequency is 500kHz, and the internal clock counting frequency reaches 1MHz. The timer's reference timing pulse period is 1μs. When using frequency measurement mode, T/C0 is programmed to count the frequency of the measured signal to generate the desired detection time. Since the longest timer duration is 65535s, a software counter is needed to generate a longer detection time. Multiple interrupts will yield the required detection time. When the measured frequency is low, the periodic measurement method is selected; T/C1 is programmed in timing mode to count the time elapsed for m input pulse cycles. 4. Block Diagram of Equal Precision Measurement Principle One of the main advantages of microprocessors is that their data processing capabilities can be used to reduce random and systematic errors during measurement, thereby improving measurement accuracy. Therefore, microcontrollers are often used in electronic measurement processes to improve measurement accuracy. [IMG= Equal Precision Measurement Principle Block Diagram]/uploadpic/THESIS/2007/12/2007121709475344754M.jpg[/IMG] The key to implementing the equal precision measurement principle is to ensure that Nx does not produce error, while No does not exceed ±1 error. Using PC bus technology, a corresponding control gate circuit was designed to count the measured frequency signal and implement precise gate timing, synchronizing the opening and closing of the gate with the effective transitions of the measured signal. The opening and closing of the preset gate is controlled by the measured signal and the preset measurement time. Counter Nx counts the frequency of the measured signal under the control of the preset gate, and the control gate generates a synchronization gate synchronized with the measured signal according to the preset gate. Counter No counts the time scale under the control of the synchronization gate to obtain the precise gate time Tg. Let the time scale period be To, then the measured frequency Fx = Nx / NoTo. The microcontroller uses a timed 1s frequency measurement method to first predict the signal. The software automatically selects the detection time or period extension factor according to the frequency level to ensure high measurement accuracy at each level. When the input signal frequency exceeds 100kHz, the signal is divided by the extended counter and sent to the 8031 ​​for frequency measurement. The frequency detection time has three levels: 0.01s, 0.1s, and 1s. After switching to period measurement, the signal is directly sent to the microcontroller, with five period expansion factors: 10⁴, 10³, 10², 10, and 1. Since the microcontroller's highest counting frequency is 500kHz, the measurement range is limited, necessitating frequency division for higher frequencies. Expanding the frequency divider by n will introduce a division error. This n-division will result in a division error of up to (n-1) periods of the measured frequency. This error is comparable to, or even greater than, a ±1" error. To improve the measurement resolution, we employ hardware synchronous frequency division technology: the 74LS591 frequency divider is reset to zero at the effective rising edge of the gate opening. At the gate closing moment, the division status is entered into the 74LS244 bus buffer, and the 8031 ​​reads its value through the buffer, thus eliminating the "division error." In this system, when T/C1 is programmed for timing mode, its maximum timing time is only 65.536ms with a 12MHz crystal oscillator, requiring software expansion of the counter's capacity. That is, every time the counter overflows and interrupts, the contents of the on-chip RAM are incremented by one, which greatly expands the counting range of the microcontroller. However, it also introduces the time error of the interrupt response, which we call "software error". The core of the frequency meter is the correctness of the time base, so when resetting the time constant of the timer after an interrupt, the reset method cannot be simply used. From the interrupt response system and response process of the microcontroller, we know that: (1) When the timer overflows and interrupts, the WAIT statement must be executed before the response can be made. The execution time of this instruction is 2μs, and we take its average delay time as 1μs; (2) The CPU needs at least 3 complete machine cycles to respond to the interrupt and execute the first instruction of the interrupt service routine, that is, a delay of 3μs; (3) The actual timing time in the interrupt service routine starts only after the time constant loading instruction is executed. The two loading instructions occupy 4μs. Based on the above analysis, after each interrupt, the timing will start after a delay of about 8μs. The actual timing time must take into account the 8μs delay. The frequency meter uses a software compensation method to reduce its impact. Because software correction is quite convenient and further adjustments can be made during instrument debugging, software errors can be largely eliminated. The frequency meter automatically switches the frequency detection time or automatically converts to period measurement based on the magnitude of the measured signal frequency. Its software design adopts a modular structure, making program design and debugging very convenient, and functional expansion is also very flexible. After the microcontroller is powered on and reset, it first executes the main program to complete the initialization of relevant chips and timers, setting the data buffer, display mode, initial value of the data counter, and initial frequency measurement mode, etc. After enabling interrupts, it continuously detects external interrupts and interrupt request signals issued by the timer. Once detected, it jumps to the corresponding interrupt service routine; otherwise, it returns to the display program to display the measured frequency value. 5. Conclusion This paper, through comparison and analysis of previous electronic counting frequency measurement principles and electronic counting period measurement principles, combined with the working principle of the microcontroller timer/counter, presents the principle of equal precision measurement and a method for eliminating software errors. It has the advantages of being simple and reliable to implement, having stable performance, high accuracy, and low cost-effectiveness.
Read next

CATDOLL 133CM Jao Shota Doll

Height: 133cm Male Weight: 28kg Shoulder Width: 31cm Bust/Waist/Hip: 64/59/73cm Oral Depth: 3-5cm Vaginal Depth: N/A An...

Articles 2026-02-22