Methods of Improving Output Frequency Accuracy by Programmable Timer/Counter

Publisher:彭勇Latest update time:2012-02-20 Source: 单片机与嵌入式系统应用 Keywords:Counters Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

The built-in or dedicated programmable timer/counter of the microcontroller is used as a pulse generator. Generally, the input pulse is generated by the crystal oscillator and formed after shaping or frequency division. It has high frequency accuracy and stability. Assume that the input pulse frequency is fin and the expected output pulse frequency is f. The count value N=fin/f should be placed in the pulse generator. When f is a divisor of fin, N is an integer, and the accuracy of f and fin is the same; when f is not a divisor of fin, N is not an integer either, N=n+δ, where n is the integer part of N and δ is the pure decimal part of N. Since the count value can only be an integer, the actual count value Np can only be the approximate number n or n+1 of N, and the competing output pulse frequency fp=fin/Np. Due to the approximation of Np, there must be an error between fp and f, and this error component may be much larger than the error component caused by the limited accuracy and stability of fin. The accuracy of f is mainly affected by the approximation of Np. This paper analyzes the characteristics of f error caused by Np without considering the influence of f accuracy and stability, and explores the method of eliminating or reducing f error caused by Np, so as to improve the accuracy of f.

1 Analysis of the influence of Np approximation on output frequency accuracy when single clock source is used

When the pulse generator input pulse is fin, if the maximum count value is nmax, then Np may take values ​​of 1, 2, ..., nmax, with nmax possibilities. The corresponding fp is discretized into fin, fin/2, ..., fin/nmax, and there are also nmax possible values. Let fin/(nmax+1)=0. These discrete frequencies divide the 0-fin frequency band into nmax sub-bands. For any f∈(0,fin), there is always a corresponding n, so that f∈(fin/n+1),fin/n). Np takes n or n+1, approximating N. In fact, f is approximated by fin/n or fin/(n+1). When f is a divisor of fin, Np=N, fp=f, the absolute error Δf=fp-f=0, and the relative error r=Δf/f=0; when f is not a divisor of fin, Δf≠0, r≠0. The values ​​of Δf and r are related to the value scheme of Np. There are three cases:

①When Np=n, fp=fin/n>f, Δf>0, r>0, Δf decreases as f increases. When F approaches fin/(n+1), Δf and r tend to maximum values; when Δf approaches fin/n-fin/(n+1)=fin/[n(n+1)], r tends to 1/n. When this solution is adopted, the closer f is to fin/(n+1), the worse the accuracy of f, as shown in the Δf(f) curve in Figure 1.

②When Np=n+1, fp=fin/(n+1)

③ Taking |Δf| as the minimum principle, when f∈[fin/(n+1),fin/(n+1)+fin/2n(n+1)], Np=n+1, fp=fin/(n+1), then Δf<0, r<0; when f∈[fin/(n+1)+fin/2n(n+1),fin/n], Np=n, fp=fin/n, then Δf>0, r>0; when f=fin/(n+1)+fin/[2n(n+1)], |Δf| and |r| reach their maximum values. Δf=±fin/2[n(n+1)], r=±1/(2n+1). When this scheme is adopted, the closer f is to fin/(n+1)+fin/[2n(n+1)], the worse the accuracy of f (see Figure 2).

Based on the error conditions of the above three solutions, the output frequency error caused by Np approximation has the following characteristics:

① The Δf(f) curves of the three schemes are all composed of a set of parallel line segments with a resolution of -1. The wider the sub-band, the longer the oblique line segment. This shows that the maximum absolute error value max (|Δf|) and max (|r|) of each sub-frequency is proportional to the width of the sub-band, while the width of the sub-band is inversely proportional to n.

The max(|Δf|) and max(|r|) of each sub-band in Scheme ② and ③ are half of those in the previous schemes, which means that Scheme ③ is more reasonable than the previous two schemes. In the following discussion of Np value, Scheme ③ shall be followed.

③ To evaluate the accuracy of the generator, we use the maximum relative error in a given frequency band. The smaller the maximum relative error, the higher the accuracy of the generator. In the sub-band [fin/(n+1), fin/n], its maximum value is 1/(2n+1). From this, we can see that when fin is constant, the larger f is, the smaller n is; the larger the maximum value of |r| in the sub-band is, the lower the accuracy is. For the accuracy of a given output frequency band, the maximum value of |r| in the sub-band corresponding to the upper frequency limit of the frequency band can be used to evaluate it. In other words, improving the accuracy of the output high frequency band also improves the accuracy of the repaired output frequency band. [page]

Table 1 shows the indicators of the accuracy of f, which is affected by N approximation, when f = 10 7 Hz and f is in different frequency bands of different orders of magnitude.

Table 1

Frequency band 10 2 10 3 10 4 10 5
max(|γ|) 5×10 -6 5×10 -5 5×10 -4 5×10 -3
max(|Δf|)/Hz 5×10 -4 5×10 -2 5 446

It can be seen from Table 1 that for every increase of f by one order of magnitude, max (|r|) increases by one order of magnitude and max (|Δf|) increases by two orders of magnitude.

2 Methods for improving output frequency accuracy

Under given programmable timing/timer conditions, different methods can be used to eliminate or reduce the output frequency error due to the characteristics of Np, thereby improving the accuracy of the output frequency.

(2) When the pulse generator only needs to output a limited number of determined frequency points

When the pulse generator only needs to output a finite number of determined frequency points, the following two methods can eliminate the output frequency error caused by the approximate count value.

① Single clock common multiple method. If fin is taken as the common multiple of these frequency points, then the N of each frequency point f is an integer, thus eliminating the output frequency error caused by the approximate count value. When using this method, it should be noted that, first, fin must not exceed the upper limit of the allowable output frequency of the pulse generator; second, when determining the effective number of bits of a known frequency point, the accuracy and stability of the crystal oscillator must be considered.

② Multi-clock source common multiple method. When the fin determined by the single clock common multiple method exceeds the upper limit of the pulse generator input frequency, the two-clock source or multi-clock source common multiple method can be used. The specific method of the two-clock source common multiple method is to divide each output frequency point into two levels, and respectively calculate the common multiples fin1 and fin2 corresponding to each group. If one of fin1 or fin2 is greater than the upper limit of the pulse generator input frequency, then re-divide until the common multiples fin1 and fin2 of the two groups meet the upper limit of the input frequency. Set the corresponding two oscillation voltages and two-choice switches on the circuit, and switch the corresponding fin1 or fin2 to the input end of the pulse generator according to the output frequency. If after being divided into two groups, no matter how the grouping is adjusted, fin1 and fin2 cannot meet the upper limit of the input frequency at the same time, the multi-clock source common multiple method can be used. Considering the complexity brought to the hardware and software after increasing the number of clock sources, the number of clock sources should be as small as possible on the premise of meeting the upper limit of the input frequency.

(2) When the upper limit of the output frequency is known but the specific expected output frequency cannot be determined

When the upper limit of the output frequency is known but the expected output frequency cannot be determined, try to increase fin or increase the number of clock sources to reduce the width of the approximate sub-band and the possible max(|r|) and max(|Δf|) in the sub-band.

① Improve the clock source fin method. If the upper limit of the output frequency is required to be fmax, then the corresponding Nmin=fin/fmax=nmin+δ. The output frequency band may have max(|r|)=1/(2nmin+1). If fin can be increased, nmin will increase and max(|r|) will decrease accordingly, thereby improving the accuracy of the output frequency.

②Multi-clock source equal sub-band method. To improve the clock source fin, subject to the upper limit of the input frequency allowed by the pulse generator, if the output frequency accuracy needs to be improved, the number of clock sources can be increased, and the [fin/(nmin+1), fin/nmin] sub-band can be divided into M equal parts, which can reduce max (|r|) by M times.

Suppose there are M clock sources, whose frequencies are fin, fin1, ..., finM-1 respectively. One of them can be connected to the input of the pulse generator through M select switches. After nmin frequency division, [fin/(nmin+1), fin/nmin]M is divided equally, that is,

fin1/nmin=fin/nmin-fin/[M·nmin(nmin+1)]

fin2/nmin=fin/nmin-2fin/[M·nmin(nmin+1)]

fin/nmin=fin/nmin-jfin/[M·nmin(nmin+1)]

finM−1/min=fin/min−(M−1)/[M·min(min+1)]

That is, as long as: finj=fin[1-j/[M(nmin+1)](j=1,2,…,M-1), the sub-band [fin/(nmin+1), fin/nmin] can be equally divided into M sub-bands. The principle of using small |Δf| is to switch into the corresponding clock source, and f can be approximated by fin/(nmin+1), finM-1/nmin,…, fin1/nmin, fin/nmin. Each sub-band max(|r|M)=(|r|)/M. Generally, when n>nmin, M-1 additional clocks finj(j=1,2,…,M-1), after n-frequency division, may not necessarily divide [fin/(n+1), fin/n] into M parts, but this sub-band can be divided, and the width of each sub-band is less than fin/[M·nmin(nmin+1)], and the max (|r|) in each sub-band is less than max(|r|m).

3 Experimental Results

We have conducted experiments on the multiple clock source equal sub-band method. The programmable timer/counter uses Intel 8254-2, and takes fin=10MHz, fmax=10kHz, M=5, then nmin=1000. The output frequency of each oscillator is calibrated with a frequency meter as follows: fin=10MHz, fin1=9 998 002.0Hz, fin2=9 996 004.0Hz, fin3=9 994 006.0Hz, fin4=9 992 008.0Hz. Then, Intel 8254-2 is set to different count values, and the output frequency of Intel 8254-2 is measured when each clock source is input. The results are listed in Table 2.

Table 2

Input
Output
Count value
end=1000000 fin1=9998002.0 end2=99960 4.0 fin3=9994006.0 fin4=9992008.0
1000 10000.0 9998.0 9996.0 9994.0 9992.0
1001 9990.0 9988.0 9986.0 9984.0 9982.0
1002 9980.1 9978.0 9976.1 9974.1 9972.1
1003 9970.1 9968.1 9966.1 9964.1 9962.1

It can be seen from Table 2 that when there is a single clock source, the maximum difference between two adjacent actual output frequencies of the counter is 10.0 Hz, and the output frequency accuracy is ±5.0 Hz. When there are five clock sources, the maximum difference between two adjacent actual output frequencies of the counter is 2.0 Hz, and the output frequency accuracy is ±1.0 Hz. The output frequency accuracy is improved, which is 5 times that of the single clock source.

Keywords:Counters Reference address:Methods of Improving Output Frequency Accuracy by Programmable Timer/Counter

Previous article:Automatic dialer implemented with W78E51 single chip microcomputer
Next article:Discussion on Single Chip Microcomputer System in Measurement and Control Field

Latest Microcontroller Articles
  • Download from the Internet--ARM Getting Started Notes
    A brief introduction: From today on, the ARM notebook of the rookie is open, and it can be regarded as a place to store these notes. Why publish it? Maybe you are interested in it. In fact, the reason for these notes is ...
  • Learn ARM development(22)
    Turning off and on interrupts Interrupts are an efficient dialogue mechanism, but sometimes you don't want to interrupt the program while it is running. For example, when you are printing something, the program suddenly interrupts and another ...
  • Learn ARM development(21)
    First, declare the task pointer, because it will be used later. Task pointer volatile TASK_TCB* volatile g_pCurrentTask = NULL;volatile TASK_TCB* vol ...
  • Learn ARM development(20)
    With the previous Tick interrupt, the basic task switching conditions are ready. However, this "easterly" is also difficult to understand. Only through continuous practice can we understand it. ...
  • Learn ARM development(19)
    After many days of hard work, I finally got the interrupt working. But in order to allow RTOS to use timer interrupts, what kind of interrupts can be implemented in S3C44B0? There are two methods in S3C44B0. ...
  • Learn ARM development(14)
  • Learn ARM development(15)
  • Learn ARM development(16)
  • Learn ARM development(17)
Change More Related Popular Components

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews


Room 1530, 15th Floor, Building B, No.18 Zhongguancun Street, Haidian District, Beijing, Postal Code: 100190 China Telephone: 008610 8235 0740

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号