Disclosure of Invention
In view of the above, the present invention provides an oscillator device and an oscillator frequency calibration method, which can solve the problem that the oscillator is easily affected by the external environment change in the prior art, and thus the output clock signal frequency generates a larger error.
In order to solve the technical problems, the invention adopts the following technical scheme:
in a first aspect, an embodiment of the present invention provides an oscillator device, including:
A reference oscillator for outputting a reference oscillator signal;
A target oscillator for outputting a target oscillator signal;
The counting module is used for counting the period of the target oscillator signal within the period of time for counting the period of the reference oscillator signal to a preset count value to obtain a first count value;
the comparison module is used for comparing the first count value with a target count value to obtain a comparison result;
The correction module is used for correcting the frequency of the target oscillator signal output by the target oscillator according to the comparison result;
wherein the frequency of the reference oscillator signal is lower than the frequency of the target oscillator signal.
Optionally, the target count value is equal to a target output frequency of the target oscillator multiplied by the preset count value divided by a frequency of the reference oscillator signal.
Optionally, the comparing module includes:
A calculating unit configured to calculate a difference between the first count value and a target count value;
the oscillator device further includes:
and the error control module is used for controlling the correction module to correct the frequency of the target oscillator signal output by the target oscillator under the condition that the difference value exceeds a preset error range, and controlling the correction module to stop correcting the frequency of the target oscillator signal output by the target oscillator under the condition that the difference value does not exceed the preset error range.
Optionally, the correction module includes:
A first correction unit, configured to increase a frequency of a target oscillator signal output by the target oscillator, when the first count value is smaller than the target count value, until the first count value is equal to the target count value;
and the second correction unit is used for reducing the frequency of the target oscillator signal output by the target oscillator under the condition that the first count value is larger than the target count value until the first count value is equal to the target count value.
Optionally, the method further comprises:
And the tracking step length setting module is used for setting a tracking step length according to the comparison result, and the tracking step length is used for determining the correction amplitude of the correction module when correcting the frequency of the target oscillator signal output by the target oscillator.
Optionally, the tracking step size:
ERVAL=A*|(N-K)|,
Wherein ER VAL is the tracking step length, A is a preset coefficient, N is the target count value, and K is the first count value.
In another aspect, an embodiment of the present invention provides an oscillator frequency calibration method, including:
counting the period of the target oscillator signal output by the target oscillator within the period of time from counting the period of the reference oscillator signal output by the reference oscillator to the preset count value, so as to obtain a first count value;
comparing the first count value with a target count value to obtain a comparison result;
comparing the first count value with a target count value to obtain a comparison result;
Correcting the frequency of a target oscillator signal output by the target oscillator according to the comparison result;
wherein the frequency of the reference oscillator signal is lower than the frequency of the target oscillator signal.
Optionally, the target count value is equal to a target output frequency of the target oscillator multiplied by the preset count value divided by a frequency of the reference oscillator signal.
Optionally, the comparing the first count value with the target count value to obtain a comparison result includes:
Calculating a difference value between the first count value and a target count value;
the correcting the frequency of the target oscillator signal output by the target oscillator according to the comparison result comprises the following steps:
and correcting the frequency of the target oscillator signal output by the target oscillator under the condition that the difference value exceeds a preset error range.
Optionally, the correcting the frequency of the target oscillator signal output by the target oscillator according to the comparison result includes:
Under the condition that the first count value is smaller than the target count value, the frequency of a target oscillator signal output by the target oscillator is increased until the first count value is equal to the target count value;
and under the condition that the first count value is larger than the target count value, reducing the frequency of a target oscillator signal output by the target oscillator until the first count value is equal to the target count value.
Optionally, the method further comprises:
and setting a tracking step according to the comparison result, wherein the tracking step is used for determining a correction amplitude when correcting the frequency of the target oscillator signal output by the target oscillator.
Optionally, the tracking step size:
ERVAL=A*|(N-K)|,
Wherein ER VAL is the tracking step length, A is a preset coefficient, N is the target count value, and K is the first count value.
The technical scheme of the invention has the following beneficial effects:
According to the oscillator device provided by the embodiment of the invention, the frequency fluctuation of the target oscillator signal can be reduced by enabling the target oscillator signal to track the reference oscillator signal, and the target oscillator does not need to use an interface clock, so that the load is lower and the power consumption is lower.
Detailed Description
In order to make the objects, technical solutions and advantages of the embodiments of the present invention more clear, the technical solutions of the embodiments of the present invention will be clearly and completely described below with reference to the accompanying drawings of the embodiments of the present invention. It will be apparent that the described embodiments are some, but not all, embodiments of the invention. All other embodiments, which are obtained by a person skilled in the art based on the described embodiments of the invention, fall within the scope of protection of the invention.
Please refer to fig. 1, which is a schematic diagram of an RC oscillator in the prior art. As shown in fig. 1, the general RC oscillator has the advantages of simpler principle, smaller volume and lower power consumption, but has larger frequency change caused by temperature in the case of outputting a clock with higher frequency.
Fig. 2 is a schematic diagram of a high-speed oscillator using a phase-locked loop in the prior art. As shown in fig. 2, a common high-speed oscillator using a phase-locked loop (Phase Locked Loop, PLL) includes a phase detector, a charge pump, a loop filter, a voltage-controlled oscillator, a frequency divider, etc., which has a relatively complex principle, and has the advantages of small frequency variation of an output clock signal and real-time tracking of an output frequency, but such an oscillator has a large size and high power consumption, and in a display system, the use of the phase-locked loop is over-designed, which may cause an increase in cost.
Therefore, please refer to fig. 3, which is a schematic diagram of an oscillator device according to an embodiment of the present invention. As shown in fig. 3, an oscillator device provided in an embodiment of the present invention may include:
a reference oscillator 31 for outputting a reference oscillator signal;
a target oscillator 32 for outputting a target oscillator signal;
a counting module 33, configured to count the period of the target oscillator signal to obtain a first count value within a duration of counting the period of the reference oscillator signal to a preset count value;
A comparing module 34, configured to compare the first count value with a target count value to obtain a comparison result;
a correction module 35, configured to correct the frequency of the target oscillator signal output by the target oscillator according to the comparison result;
wherein the frequency of the reference oscillator signal is lower than the frequency of the target oscillator signal.
In the embodiment of the present invention, the frequency of the reference oscillator signal output by the reference oscillator 31 is low, and is affected by the environmental conditions (such as temperature, etc.) to which the reference oscillator signal is subjected, but the frequency of the reference oscillator signal output by the reference oscillator 31 is set to be a given value, it can be considered that the frequency of the reference oscillator signal output by the reference oscillator 31 will remain unchanged. The frequency of the target oscillator is relatively high and is more easily affected by environmental conditions (such as temperature, etc.), that is, after the target oscillator signal whose output frequency is set to a given value is set, if the temperature at the location increases or decreases, the frequency of the target oscillator signal will fluctuate, so when the frequency of the target oscillator signal output by the target oscillator fluctuates, it needs to be corrected to make the frequency of the target oscillator signal correct to the target output frequency.
In some embodiments of the invention, the lower the frequency of the reference oscillator signal, the higher the confidence level of the reference, over a range of frequencies. The reference oscillator signal may be a low-speed clock signal and the target oscillator signal may be a high-speed clock signal.
In the embodiment of the present invention, the reference oscillator signal output by the reference oscillator 31 is sent to the counting module 33 for counting, and at the same time, the target oscillator signal output by the target oscillator 32 is also sent to the counting module 33 for counting, where the counting refers to counting the period of the input signal by the counting module 33. The counting value of the reference oscillator signal may be preset, so that the period of the target oscillator signal is synchronously counted within the period of time from the period of the reference oscillator signal to the preset counting value, to obtain the first counting value, that is, the counting of the target oscillator signal is started while the period of the reference oscillator signal is started, and the counting of the reference oscillator signal and the target oscillator signal is stopped when the period of the reference oscillator signal is preset to obtain the first counting value of the period of the target oscillator signal within the period of time.
In the embodiment of the present invention, the comparing module 34 is configured to compare the first count value with a target count value to obtain a comparison result of the first count value and the target count value; wherein, since the reference oscillator signal is a given value and the target output frequency to be output by the target oscillator is also a determined value, the target count value is uniquely determined when the count value of the period of the reference oscillator signal is determined. Specifically, the target count value may be equal to the target output frequency of the target oscillator multiplied by the preset count value divided by the frequency of the reference oscillator signal. That is, since the reference oscillator signal is a given value and the target output frequency of the target oscillator is also a certain value, the ratio of the two is determined, and the target count value can be uniquely determined when the count value of the period of the reference oscillator signal is determined; for example, when the frequency of the reference oscillator signal is 1MHz and the target output frequency is 100MHz, and the preset count value of the reference oscillator signal is 1, that is, when the number of cycles of the reference oscillator signal is 1, the target count value should be equal to the target output frequency of 100MHz multiplied by the number of cycles 1 of the reference oscillator signal, and then divided by the frequency 1MHz of the reference oscillator signal, so as to obtain the target count value as 100; for another example, the target count value should be equal to 1000 when the preset count value of the reference oscillator signal is 10, i.e., when the number of cycles of the reference oscillator signal is 10.
Finally, the correction module 35 is configured to correct the frequency of the target oscillator signal output by the target oscillator according to the comparison result. Thus, by comparing the first count value with the target count value, the difference therebetween can be used to direct the correction of the target oscillator signal output by the target oscillator so that the frequency of the target oscillator signal tends to the target output frequency.
According to the oscillator device provided by the embodiment of the invention, the target oscillator signal output by the target oscillator tracks the reference oscillator signal output by the reference oscillator, so that the frequency fluctuation of the target oscillator signal output by the target oscillator can be reduced, and the interface clock is not needed because the reference oscillator is adopted, so that the load is lower and the power consumption is lower.
In some embodiments of the application, the comparison module comprises:
A calculating unit configured to calculate a difference between the first count value and a target count value;
the oscillator device further includes:
And an error control module 36, configured to control the correction module 35 to correct the frequency of the target oscillator signal output by the target oscillator 32 when the difference value exceeds a preset error range, and control the correction module to stop correcting the frequency of the target oscillator signal output by the target oscillator 32 when the difference value does not exceed the preset error range.
That is, the oscillator device according to the embodiment of the present invention further includes an error control module 36, the calculating unit in the comparing module 34 is configured to calculate a difference between the first count value and the target count value, and the error control module 36 is configured to determine whether to control the correcting module 35 to correct the frequency of the target oscillator signal output by the target oscillator 32 according to the difference calculated by the calculating unit. Specifically, the control correction module 35 corrects the frequency of the target oscillator signal output by the target oscillator 32 when the difference value exceeds the preset error range, and the control correction module stops correcting the frequency of the target oscillator signal output by the target oscillator 32 when the difference value does not exceed the preset error range. Therefore, by setting the preset error range in the error control module, the oscillator device corrects the frequency of the target oscillator signal only when the difference value exceeds the preset error range, so that the problem of power consumption rise caused by always keeping a correction mode is avoided.
Fig. 4 is a schematic diagram of a preset error range of a target oscillator according to an embodiment of the invention. As shown in fig. 4, the preset error range may be set according to the operating environment in which the target oscillator 32 is located. For example, in a scenario with a high precision requirement, the preset error range may be ±1MHz, and in a scenario with a relatively low precision requirement, the preset allowable error range may be ±2MHz, or even ±4MHz.
In an embodiment of the present application, optionally, the correction module 35 includes:
A first correction unit, configured to increase a frequency of a target oscillator signal output by the target oscillator, when the first count value is smaller than the target count value, until the first count value is equal to the target count value;
and the second correction unit is used for reducing the frequency of the target oscillator signal output by the target oscillator under the condition that the first count value is larger than the target count value until the first count value is equal to the target count value.
Since the difference between the first count value and the target count value characterizes the difference between the frequency of the target oscillator signal currently output by the target oscillator and the target output frequency, in the case that the first count value is smaller than the target count value, the frequency of the target oscillator signal currently output by the target oscillator is lower than the target output frequency, and the frequency of the target oscillator signal output by the target oscillator should be increased at the moment until the first count value is equal to the target count value, that is, the frequency of the target oscillator signal currently output by the target oscillator is equal to the target output frequency; and in the case that the first count value is greater than the target count value, it means that the frequency of the target oscillator signal currently output by the target oscillator is higher than the target output frequency, the frequency of the target oscillator signal output by the target oscillator should be reduced at this time until the first count value is equal to the target count value, that is, the frequency of the target oscillator signal currently output by the target oscillator is equal to the target output frequency.
Fig. 5 is a schematic diagram of a first count value according to an embodiment of the invention. As shown in fig. 5, for example, the number of cycles of the reference oscillator signal is 1, and the corresponding target count value is N, if the first count value is n+1 or n+2, this means that the frequency of the frequency signal currently output by the target oscillator is higher than the target output frequency, and the frequency of the target oscillator signal output by the target oscillator should be reduced at this time until the first count value is equal to N; and if the first count value is N-1 or N-2, which means that the frequency of the frequency signal currently output by the target oscillator is lower than the target output frequency, the frequency of the target oscillator signal output by the target oscillator should be increased at this time until the first count value is equal to N.
In other embodiments of the present invention, if a certain preset error range is set by using the error control module, only the frequency of the target oscillator signal output by the target oscillator needs to be adjusted until the difference between the first count value and the target count value falls within the preset error range. For example, the preset error range is ±10, that is, the absolute value of the difference between the target count value and the first count value is 10, and only the frequency of the target oscillator signal output by the target oscillator needs to be adjusted until the difference between the first count value and the target count value is less than 10.
In an embodiment of the present invention, optionally, the oscillator device further includes:
A tracking step setting module 37, configured to set a tracking step according to the comparison result, where the tracking step is used to determine a correction amplitude of the correction module when correcting the frequency of the target oscillator signal output by the target oscillator.
That is, in the embodiment of the present invention, since a certain change may occur in the difference between the first count value and the target count value, the embodiment of the present invention may further set the tracking step according to the difference between the first count value and the target count value, that is, even if the tracking step changes with the change of the difference, the target oscillator signal output by the target oscillator better tracks the reference oscillator signal, and at the same time, the power consumption may be reduced.
Optionally, the tracking step size:
ERVAL=A*|(N-K)|,
wherein ER VAL is the tracking step length, A is a preset coefficient, N is the target count value, and K is the first count value. The value of A may be set according to the magnitude of the value of I (N-K), and if the value of I (N-K) is reduced, the value of A may be set to be reduced accordingly, so that the tracking step size is reduced, and vice versa.
In other words, the change rule of the tracking step length with the difference | (N-K) | may be: the larger the difference value (N-K) is, the larger the tracking step length is, and the smaller the difference value (N-K) is, the smaller the tracking step length is; that is, the larger the difference value (N-K) is, indicating that the frequency of the target oscillator signal output by the target oscillator and the target output frequency are different, at this time, the tracking step should be increased, i.e., the correction amplitude should be increased, to quickly reduce the error, while the smaller the difference value (N-K) is, the frequency of the target oscillator signal output by the target oscillator is smaller than the target output frequency, the output frequency is more accurate, and the tracking step size can be reduced, namely the correction amplitude is reduced, so that the frequency of the target oscillator signal output by the target oscillator is corrected to be consistent with the target output frequency more accurately and more quickly.
Fig. 6 is a schematic diagram of a tracking step according to an embodiment of the present invention. As shown in fig. 6, in the embodiment of the present invention, the tracking step size changes with the change of the difference value, so that the target oscillator signal output by the target oscillator tracks the reference oscillator signal better, and the power consumption can be reduced.
According to the oscillator device provided by the embodiment of the invention, the frequency fluctuation of the target oscillator signal can be reduced by enabling the target oscillator signal to track the reference oscillator signal, and the target oscillator does not need to use an interface clock, so that the load is lower and the power consumption is lower.
Fig. 7 is a flowchart of an oscillator frequency calibration method according to an embodiment of the invention. As shown in fig. 7, another embodiment of the present invention further provides a method for calibrating an oscillator frequency, where the method is an embodiment of a method corresponding to the above-mentioned oscillator device, and the method may include the following steps:
Step 71: and counting the period of the target oscillator signal output by the target oscillator within the period of time from counting the period of the reference oscillator signal output by the reference oscillator to the preset count value, so as to obtain a first count value.
In the embodiment of the invention, specifically, a reference oscillator signal can be output through a reference oscillator, and the reference oscillator signal is a given value; then presetting a count value of the reference oscillator signal, namely counting the period of the reference oscillator signal by using a counter and presetting the count value, for example, the preset count value is 1, namely the preset period number of the reference oscillator signal is 1, the preset count value is 100, and the preset period number of the reference oscillator signal is 100; and counting the period of the target oscillator signal output by the target oscillator within the period of time from the period of counting the period of the reference oscillator signal to the preset count value, namely, within the period of time from the period of counting the period of time from 0 to the period of time from the period of counting the period of time to the preset count value of the reference oscillator signal, so as to obtain a first count value.
In the embodiment of the invention, the frequency of the reference oscillator signal is lower than the frequency of the target oscillator signal output by the target oscillator, the reference oscillator signal with lower frequency has better stability, is less influenced by external environment change, can ensure the accuracy of frequency reference, reduces the frequency change caused by temperature and the like, and generally, the lower the frequency of the reference oscillator signal is in a certain frequency range, the higher the credibility of reference is. The target oscillator signal output by the target oscillator may be a high-speed clock signal.
Step 72: and comparing the first count value with a target count value to obtain a comparison result.
In the embodiment of the invention, the first count value is compared with the target count value to obtain a comparison result of the first count value and the target count value; wherein, since the reference oscillator signal is a given value and the target output frequency to be output by the target oscillator is also a determined value, the target count value is uniquely determined when the count value of the period of the reference oscillator signal is determined.
In the embodiment of the present invention, the target count value may be equal to the target output frequency of the target oscillator multiplied by the preset count value and divided by the frequency of the reference oscillator signal. That is, since the reference oscillator signal is a given value and the target output frequency of the target oscillator is also a certain value, the ratio of the two is determined, and the target count value can be uniquely determined when the count value of the period of the reference oscillator signal is determined; for example, when the frequency of the reference oscillator signal is 1MHz and the target output frequency is 100MHz, and the preset count value of the reference oscillator signal is 1, that is, when the number of cycles of the reference oscillator signal is 1, the target count value should be equal to the target output frequency of 100MHz multiplied by the number of cycles 1 of the reference oscillator signal, and then divided by the frequency 1MHz of the reference oscillator signal, so as to obtain the target count value as 100; for another example, the target count value should be equal to 1000 when the preset count value of the reference oscillator signal is 10, i.e., when the number of cycles of the reference oscillator signal is 10.
Step 73: and correcting the frequency of the target oscillator signal output by the target oscillator according to the comparison result.
Finally, by comparing the first count value with the target count value, the difference therebetween can be used to guide the correction of the target oscillator signal output by the target oscillator so that the frequency of the target oscillator signal tends to the target output frequency.
According to the oscillator frequency calibration method provided by the embodiment of the invention, the target oscillator signal output by the target oscillator tracks the reference oscillator signal output by the reference oscillator, so that the frequency fluctuation of the target oscillator signal output by the target oscillator can be reduced, and an interface clock is not required to be used due to the adoption of the reference oscillator, so that the load is lower and the power consumption is lower.
In an embodiment of the present invention, optionally, comparing the first count value with the target count value to obtain a comparison result includes:
Calculating a difference value between the first count value and a target count value;
the correcting the frequency of the target oscillator signal output by the target oscillator according to the comparison result comprises the following steps:
and correcting the frequency of the target oscillator signal output by the target oscillator under the condition that the difference value exceeds a preset error range.
That is, in the embodiment of the present invention, the difference between the first count value and the target count value may be further calculated, and whether to correct the frequency of the target oscillator signal output by the target oscillator may be determined according to the calculated difference. Specifically, when the difference value exceeds the preset error range, the frequency of the target oscillator signal output by the target oscillator is corrected, and when the difference value does not exceed the preset error range, the frequency of the target oscillator signal output by the target oscillator is stopped. Therefore, by setting the preset error range in the error control module, the oscillator device corrects the frequency of the target oscillator signal only when the difference value exceeds the preset error range, so that the problem of power consumption rise caused by always keeping a correction mode is avoided.
The correcting the frequency of the target oscillator signal output by the target oscillator according to the comparison result comprises the following steps:
Under the condition that the first count value is smaller than the target count value, the frequency of a target oscillator signal output by the target oscillator is increased until the first count value is equal to the target count value;
and under the condition that the first count value is larger than the target count value, reducing the frequency of a target oscillator signal output by the target oscillator until the first count value is equal to the target count value.
Since the difference between the first count value and the target count value characterizes the difference between the frequency of the target oscillator signal currently output by the target oscillator and the target output frequency, in the case that the first count value is smaller than the target count value, the frequency of the target oscillator signal currently output by the target oscillator is lower than the target output frequency, and the frequency of the target oscillator signal output by the target oscillator should be increased at the moment until the first count value is equal to the target count value, that is, the frequency of the target oscillator signal currently output by the target oscillator is equal to the target output frequency; and in the case that the first count value is greater than the target count value, it means that the frequency of the target oscillator signal currently output by the target oscillator is higher than the target output frequency, the frequency of the target oscillator signal output by the target oscillator should be reduced at this time until the first count value is equal to the target count value, that is, the frequency of the target oscillator signal currently output by the target oscillator is equal to the target output frequency.
In some embodiments of the invention, optionally, the frequency calibration method further comprises:
and setting a tracking step according to the comparison result, wherein the tracking step is used for determining a correction amplitude when correcting the frequency of the target oscillator signal output by the target oscillator.
That is, in the embodiment of the present invention, since a certain change may occur in the difference between the first count value and the target count value, the embodiment of the present invention may further set the tracking step according to the difference between the first count value and the target count value, that is, even if the tracking step changes with the change of the difference, the target oscillator signal output by the target oscillator better tracks the reference oscillator signal, and at the same time, the power consumption may be reduced.
Optionally, the tracking step size:
ERVAL=A*|(N-K)|,
wherein ER VAL is the tracking step length, A is a preset coefficient, N is the target count value, and K is the first count value. The value of A may be set according to the magnitude of the value of I (N-K), and if the value of I (N-K) is reduced, the value of A may be set to be reduced accordingly, so that the tracking step size is reduced, and vice versa.
In other words, the change rule of the tracking step length with the difference | (N-K) | may be: the larger the difference value (N-K) is, the larger the tracking step length is, and the smaller the difference value (N-K) is, the smaller the tracking step length is; that is, the larger the difference value (N-K) is, indicating that the frequency of the target oscillator signal output by the target oscillator and the target output frequency are different, at this time, the tracking step should be increased, i.e., the correction amplitude should be increased, to quickly reduce the error, while the smaller the difference value (N-K) is, the frequency of the target oscillator signal output by the target oscillator is smaller than the target output frequency, the output frequency is more accurate, and the tracking step size can be reduced, namely the correction amplitude is reduced, so that the frequency of the target oscillator signal output by the target oscillator is corrected to be consistent with the target output frequency more accurately and more quickly.
According to the frequency calibration method provided by the embodiment of the invention, the frequency signal output by the oscillator tracks the reference oscillator signal, so that the frequency fluctuation of the frequency signal output by the oscillator can be reduced, and the oscillator does not need to use an interface clock, so that the load is lower and the power consumption is lower.
While the foregoing is directed to embodiments of the present invention, it will be appreciated by those skilled in the art that various modifications and changes can be made without departing from the principles of the present invention, and it is intended to cover the scope of the invention as defined in the appended claims.