A method for calibrating the frequency of a chip internal clock source

By obtaining the internal clock frequency of the chip and determining the calibration value based on the preset range for storage, the problem of chip clock frequency deviation is solved, automatic calibration is achieved, costs and manual intervention are reduced, and production efficiency is improved.

CN117938154BActive Publication Date: 2024-09-17广芯微电子(广州)股份有限公司
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202410188593.2
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2024-02-20
Publication Date
2024-09-17
Estimated Expiration
2044-02-20

AI Technical Summary

Technical Problem

There is a large deviation in the internal clock frequency of existing chips, causing the chip functions to fail to function normally. Existing calibration methods require external hardware support or manual intervention, which is cumbersome and costly.

Method used

By obtaining the chip's internal low-speed clock frequency, determining the calibration value based on the preset expected range, and storing it in the pre-read information area, automatic calibration of the chip's internal clock source frequency is achieved without manual intervention or external hardware support.

Benefits of technology

It realizes automatic calibration of chip clock frequency, reduces labor and time costs, reduces external wiring requirements, and improves production efficiency.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN117938154B
    Figure CN117938154B
Patent Text Reader

Abstract

The present application belongs to the field of chip technology, and discloses a method for calibrating the frequency of the internal clock source of a chip, the method comprising: configuring the main frequency clock of the chip as an external high-speed crystal oscillator clock; the first acquisition step: acquiring the count value of the TIM timer in the chip; obtaining the internal low-speed clock frequency of the chip based on the count value; judging whether the internal low-speed clock frequency is within the first preset expected range; if not, determining the first calibration value based on the internal low-speed clock frequency, and returning to the first acquisition step; if so, inputting the first calibration value into the pre-read information storage area of ​​the chip. The clock calibration method of the present application can be performed without manual intervention or other external hardware support, which greatly saves manpower and time costs.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the field of chip technology, and in particular to a method for calibrating the frequency of a clock source inside a chip. Background Art

[0002] Generally, there are two types of working clock frequencies for chips: one is the frequency generated by the quartz crystal oscillator outside the chip, which is a stable and accurate clock signal; the other is generated by the clock oscillator inside the chip, but due to the limitations of the existing integrated circuit manufacturing process, this clock signal usually has a large deviation, which depends on the production process. Due to the large deviation of the internal clock frequency, various functions inside the chip that rely on the clock communication module cannot be used normally. For this reason, when the chip packaging production is completed and enters the testing phase, the chip clock frequency needs to be calibrated; most of the existing solutions require external input of the standard clock frequency for calibration, but this requires hardware support such as the signal generator output frequency and external wiring; or the clock calibration register value of the chip is modified by manually downloading the program continuously, but the manual operation is more cumbersome. Summary of the invention

[0003] The present application provides a method for calibrating the frequency of the internal clock source of a chip, which does not require manual intervention or other external hardware support, greatly saving manpower and time costs.

[0004] In a first aspect, an embodiment of the present application provides a method for calibrating the frequency of a clock source inside a chip, comprising:

[0005] Configure the chip's main clock to an external high-speed crystal oscillator clock;

[0006] The first acquisition step: acquiring the count value of the TIM timer in the chip;

[0007] The internal low-speed clock frequency of the chip is obtained based on the count value;

[0008] Determining whether the internal low-speed clock frequency is within a first preset expected range;

[0009] If not, determining a first calibration value based on the internal low-speed clock frequency, and returning to the first acquisition step;

[0010] If yes, the first calibration value is input into the pre-read information storage area of ​​the chip.

[0011] Further, the determining of the first calibration value based on the internal low-speed clock frequency includes:

[0012] If the internal low-speed clock frequency is greater than the maximum value of the first preset expected range, the first calibration value is reduced by 1;

[0013] If the internal low-speed clock frequency is less than the minimum value of the first preset expected range, the first calibration value is increased by 1.

[0014] Furthermore, the count value includes a first count value corresponding to the first rising edge and a second count value corresponding to the second rising edge.

[0015] Furthermore, the internal low-speed clock frequency of the chip obtained based on the count value includes:

[0016] If the second count value is greater than the first count value, a first difference between the second count value and the first count value is calculated, and the current clock frequency of the chip is divided by the first difference to obtain an internal low-speed clock frequency;

[0017] If the second count value is less than the first count value, the first count value is subtracted from the initial default value of the first calibration value and then added to the second count value to obtain a second difference value, and the current clock frequency of the chip is divided by the second difference value to obtain the internal low-speed clock frequency.

[0018] Furthermore, the method also includes:

[0019] Configure the chip's main clock frequency to the internal high-speed crystal oscillator clock;

[0020] Configure the clock source of the chip's low-power timer to an external low-speed crystal oscillator clock;

[0021] Second acquisition step: obtaining the standard frequency of the low power timer through the TIM timer;

[0022] The capture clock frequency of the chip is calculated based on the standard frequency;

[0023] Determining whether the capture clock frequency is within a second preset expected range;

[0024] If not, determining a second calibration value based on the capture clock frequency, and returning to the second acquisition step;

[0025] If yes, the second calibration value is input into the pre-read information storage area.

[0026] Furthermore, the above-mentioned calculation of the capture clock frequency of the chip according to the standard frequency includes:

[0027] Obtaining a third count value according to the first rising edge in the standard frequency;

[0028] Obtaining a fourth count value according to a second rising edge in the standard frequency;

[0029] A capture clock frequency is obtained based on the third count value and the fourth count value.

[0030] Further, obtaining the capture clock frequency based on the third count value and the fourth count value includes:

[0031] If the fourth count value is greater than the third count value, a third difference between the fourth count value and the third count value is calculated, and the target clock frequency of the chip is divided by the third difference to obtain a capture clock frequency;

[0032] If the fourth count value is less than the third count value, the third count value is subtracted from the initial default value of the second calibration value and then added to the fourth count value to obtain a fourth difference value, and the target clock frequency of the chip is divided by the fourth difference value to obtain a capture clock frequency.

[0033] Further, the determining of the second calibration value based on the capture clock frequency includes:

[0034] If the capture clock frequency is greater than the maximum value of the second preset expected range, the second calibration value is reduced by 1;

[0035] If the capture clock frequency is less than the minimum value of the second preset expected range, the second calibration value is increased by 1.

[0036] Furthermore, the target clock frequency of the chip is 32M.

[0037] Furthermore, the external low speed crystal oscillator clock is 32.768KHz.

[0038] In a second aspect, an embodiment of the present application provides a computer device, including a memory, a processor, and a computer program stored in the memory and executable on the processor. When the processor executes the computer program, the steps of the method for calibrating the frequency of the internal clock source of the chip as in any of the above embodiments are performed.

[0039] In a third aspect, an embodiment of the present application provides a computer-readable storage medium having a computer program stored thereon, which, when executed by a processor, implements the steps of a method for calibrating the frequency of an internal clock source of a chip as in any of the above embodiments.

[0040] In summary, compared with the prior art, the technical solution provided in the embodiment of the present application has at least the following beneficial effects:

[0041] An embodiment of the present application provides a method for calibrating the frequency of an internal clock source of a chip. A first calibration value is determined through a first preset expected range and the current internal low-speed clock frequency of the chip, and the first calibration value is placed in a pre-read information storage area of ​​the chip, thereby ensuring that the chip can pre-read the first calibration value the next time it is powered on, so that the internal low-speed clock frequency is the expected value. The present application implements a method for performing subsequent full-process automatic calibration after downloading a software program once, without the need for human intervention, and without the need for a signal generator to generate a standard frequency and then input it into the chip, thereby reducing external wiring of the board-level system and greatly saving manpower and time costs. BRIEF DESCRIPTION OF THE DRAWINGS

[0042] Figure 1 A flowchart of a method for calibrating the frequency of a chip internal clock source is provided as an exemplary embodiment of the present application.

[0043] Figure 2 A flowchart of a method for calibrating the frequency of a chip internal clock source is provided as another exemplary embodiment of the present application.

[0044] Figure 3 A flowchart of internal high-speed clock frequency calibration steps is provided for an exemplary embodiment of the present application.

[0045] Figure 4 A flowchart of internal high-speed clock frequency calibration steps is provided for yet another exemplary embodiment of the present application. DETAILED DESCRIPTION

[0046] The technical solutions in the embodiments of the present application will be clearly and completely described below in conjunction with the drawings in the embodiments of the present application. Obviously, the described embodiments are only part of the embodiments of the present application, rather than all of the embodiments.

[0047] Based on the embodiments in this application, all other embodiments obtained by ordinary technicians in this field without making any creative work shall fall within the scope of protection of this application.

[0048] See also Figure 1 and Figure 2 The embodiment of the present application provides a method for calibrating the frequency of a chip internal clock source, which is applied to a chip whose clock is to be calibrated. The method specifically comprises the following steps:

[0049] Step S11, configuring the main frequency clock of the chip to be an external high-speed crystal oscillator clock.

[0050] In the specific implementation process, the hardware chip is connected to an external crystal oscillator, so the present application configures the main clock frequency of the chip to be the clock frequency generated by the external crystal oscillator through software configuration.

[0051] Step S12, a first acquisition step: acquiring a count value of a TIM timer in the chip.

[0052] The count value includes a first count value corresponding to the first rising edge and a second count value corresponding to the second rising edge.

[0053] Specifically, the TIM timer of the chip is configured for rising edge capture, and the timer will collect two rising edge count values, the first rising edge count value is the timer capture value N1, and the second rising edge count value is the timer capture value N2.

[0054] Step S13, obtaining the internal low-speed clock frequency of the chip based on the count value.

[0055] Step S14, determining whether the internal low-speed clock frequency is within a first preset expected range.

[0056] Specifically, the first preset expected range is set according to the expected value of the internal low-speed clock frequency. When the low-speed clock frequency of the chip is to be calibrated to 32.768KHz, the first preset expected range may be 37.6KHz to 38KHz.

[0057] Step S15: if not, determine the first calibration value based on the internal low-speed clock frequency, and return to the first acquisition step.

[0058] Before calibration is performed, the first calibration value may be an initial default value of 0xFF; and then the count value of the capture timer is calculated to determine whether the first calibration value is to be increased by 1 or decreased by 1.

[0059] Specifically, if the internal low-speed clock frequency is greater than the maximum value of the first preset expected range, the first calibration value is reduced by 1;

[0060] If the internal low-speed clock frequency is less than the minimum value of the first preset expected range, the first calibration value is increased by 1.

[0061] Step S16: If yes, input the first calibration value into the pre-read information storage area of ​​the chip.

[0062] Among them, it is only necessary to write the first calibration value into the power-on pre-read area of ​​the chip to ensure that the chip can pre-read the first calibration value when it is powered on next time, so that the internal low-speed clock frequency of the chip is the expected value corresponding to the first preset expected range; therefore, after downloading the software program for calibrating the clock of this application into the chip and running it, the clock source can be automatically calibrated, and the internal low-speed clock calibration value can be quickly traversed without human intervention. In the process of mass production of small batch chips, compared with manual modification and writing of calibration values, this method can greatly save time and labor costs.

[0063] The above embodiment provides a method for calibrating the frequency of the internal clock source of a chip, which determines a first calibration value through a first preset expected range and the current internal low-speed clock frequency of the chip, and puts the first calibration value into the pre-read information storage area of ​​the chip, thereby ensuring that the next time the chip is powered on, the chip can pre-read the first calibration value to make the internal low-speed clock frequency the expected value; the present application realizes that after downloading a software program once, subsequent full-process automatic calibration can be performed without manual intervention, and there is no need for a signal generator to generate a standard frequency and then input it into the chip, thereby reducing the external wiring of the board-level system and greatly saving manpower and time costs.

[0064] In some embodiments, obtaining the internal low-speed clock frequency of the chip based on the count value includes:

[0065] If the second count value is greater than the first count value, calculate a first difference between the second count value and the first count value, and divide the current clock frequency of the chip by the first difference to obtain an internal low-speed clock frequency.

[0066] If the second count value is less than the first count value, subtract the first count value from the initial default value of the first calibration value, then add the second count value to obtain a second difference, and divide the current clock frequency of the chip by the second difference to obtain an internal low-speed clock frequency.

[0067] Specifically, assume that the first count value of the first rising edge is the capture value N1 of the timer, and the second count value of the second rising edge is the capture value N2 of the timer. Then, the sizes of N1 and N2 will be judged first. When N2 > N1, the calculated internal low-speed clock frequency output by the current chip = (the current clock frequency of the chip) / (N2 - N1). When N2 < N1, the calculated internal low-speed clock frequency output by the current chip = (the current clock frequency of the chip) / ((0xFFFF - N1) + N2).

[0068] In some embodiments, the method further includes:

[0069] Step S21: Configure the main clock of the chip as an internal high-speed crystal oscillator clock.

[0070] Step S22: Configure the clock source of the low-power timer of the chip as an external low-speed crystal oscillator clock.

[0071] Among them, the external low-speed crystal oscillator is determined according to the type of crystal oscillator used in the external hardware, generally with a frequency of 32.768 KHz. The internal high-speed clock frequency is the calibration target at this time, and the internal high-speed clock frequency for calibration can be adjusted as needed.

[0072] Step S23: Second acquisition step: Obtain the standard frequency of the low-power timer through the TIM timer.

[0073] In the specific implementation process, there are two timers inside the chip: the low-power timer G1 and the TIM timer G2. The internal low-speed clock is configured to the external low-speed crystal oscillator clock frequency of 32.768 KHz. At this time, the high-speed clock used by the chip is an inaccurate internal clock frequency, and the internal low-speed clock is an accurate 32.768 Hz frequency. In this application, the counting clock of the low-power timer G1 is configured to the internal low-speed clock, and then a PWM signal with a duty cycle of 1024 Hz is output through the low-power timer G1. At this time, the clock frequency used by the TIM timer G2 is an inaccurate internal high-speed clock, and then the TIM timer G2 is used to capture the 1024 Hz PWM signal generated by the low-power timer G1. After obtaining the standard frequency, that is, the PWM signal, the third count value is obtained according to the first rising edge in the standard frequency; the fourth count value is obtained according to the second rising edge in the standard frequency; the capture clock frequency is obtained based on the third count value and the fourth count value.

[0074] Step S24, calculate the capture clock frequency of the chip according to the standard frequency.

[0075] Specifically, if the fourth count value is greater than the third count value, calculate the third difference between the fourth count value and the third count value, and divide the target clock frequency of the chip by the third difference to obtain the capture clock frequency.

[0076] If the fourth count value is less than the third count value, subtract the third count value from the initial default value of the second calibration value, then add the fourth count value to obtain the fourth difference, and divide the target clock frequency of the chip by the fourth difference to obtain the capture clock frequency.

[0077] Among them, the target clock frequency is the expected value that the internal high-speed clock frequency needs to be calibrated, which can be 32M.

[0078] Similarly, assume that the third count value of the first rising edge is the capture value N3 of the timer, and the fourth count value of the second rising edge is the capture value N4 of the timer. Then, the sizes of N3 and N4 will be judged first. When N4 > N3, the current capture clock frequency is calculated as = (the target clock frequency of the chip, such as 32M) / (N4 - N3). When N4 < N3, the current capture clock frequency is calculated as = (the target clock frequency of the chip, such as 32M) / ((0xFFFF - N3) + N4).

[0079] If the calculated capture clock frequency is less than 1024 Hz, the second calibration value +1. If it is greater than 1024 Hz, the second calibration value -1. A margin can be left to set the second preset expected range between 1022 and 1025. Theoretically, if the target clock frequency of the chip is about the set 32M, the calculated capture clock frequency will also be about 1024 Hz.

[0080] Step S25, determining whether the capture clock frequency is within a second preset expected range.

[0081] Step S26: if not, determine a second calibration value based on the capture clock frequency, and return to the second acquisition step.

[0082] Among them, the initial default value of the second calibration value before the calibration starts can also be set to 0xFF, and the second preset expected range is also set according to the expected value of the internal high-speed clock frequency; if you want to calibrate the internal high-speed clock frequency of the chip to 32M, and the input frequency is known to be 1024Hz, you can use the above calculation method to get the obtained capture clock frequency = 32M / (the difference between the timer capture values ​​N4 and N3). Then theoretically, when the calculated capture clock frequency is 1024Hz, the internal high-speed clock frequency of the current chip is 32M, so the second preset expected range can be 1023~1025Hz.

[0083] Step S27: If yes, input the second calibration value into the pre-read information storage area.

[0084] Specifically, it is only necessary to write the second calibration value into the power-on pre-read area of ​​the chip to ensure that the chip can pre-read the second calibration value when it is powered on next time, so that the internal high-speed clock frequency of the chip is the target clock frequency.

[0085] It can be understood that the present application uses the external high-speed crystal oscillator clock as the working clock of the chip timer to self-calibrate the low-speed clock frequency inside the chip; and then uses the external low-speed crystal oscillator clock as the working clock of the chip low-power timer to self-calibrate the high-speed clock frequency inside the chip. During the calibration process, there is no need to generate a standard frequency such as a signal generator and then input it into the chip, which reduces the external wiring of the board-level system, thereby reducing the hardware requirements for chip clock calibration.

[0086] An embodiment of the present application provides a computer device, which may include a processor, a memory, a network interface and a database connected via a system bus. The processor of the computer device is used to provide computing and control capabilities. The memory of the computer device includes a non-volatile storage medium and an internal memory. The non-volatile storage medium stores an operating system, a computer program and a database. The internal memory provides an environment for the operation of the operating system and the computer program in the non-volatile storage medium. The network interface of the computer device is used to communicate with an external terminal via a network connection. When the computer program is executed by the processor, the processor executes the steps of a method for calibrating the frequency of an internal clock source of a chip as in any of the above embodiments.

[0087] The working process, working details and technical effects of the computer device provided in this embodiment can be found in the above embodiment of a method for calibrating the frequency of an internal clock source of a chip, and will not be described in detail here.

[0088] The embodiment of the present application provides a computer-readable storage medium, on which a computer program is stored, and when the computer program is executed by a processor, the steps of a method for calibrating the frequency of a chip internal clock source are implemented as in any of the above embodiments. Wherein, the computer-readable storage medium refers to a carrier for storing data, which may include but is not limited to a floppy disk, an optical disk, a hard disk, a flash memory, a USB flash drive and / or a memory stick (Memory Stick), etc., and the computer may be a general-purpose computer, a special-purpose computer, a computer network, or other programmable devices. The working process, working details and technical effects of the computer-readable storage medium provided in this embodiment can be found in the above embodiment of a method for calibrating the frequency of a chip internal clock source, which will not be repeated here.

[0089] Those skilled in the art can understand that all or part of the processes in the above-mentioned embodiment methods can be completed by instructing the relevant hardware through a computer program, and the computer program can be stored in a non-volatile computer-readable storage medium. When the computer program is executed, it can include the processes of the embodiments of the above-mentioned methods. Among them, any reference to memory, storage, database or other media used in the embodiments provided in the present application can include non-volatile and / or volatile memory. Non-volatile memory can include read-only memory (ROM), programmable ROM (PROM), electrically programmable ROM (EPROM), electrically erasable programmable ROM (EEPROM) or flash memory. Volatile memory can include random access memory (RAM) or external cache memory. As an illustration and not limitation, RAM is available in many forms, such as static RAM (SRAM), dynamic RAM (DRAM), synchronous DRAM (SDRAM), double data rate SDRAM (DDRSDRAM), enhanced SDRAM (ESDRAM), synchronous link (Synchlink) DRAM (SLDRAM), memory bus (Rambus) direct RAM (RDRAM), direct memory bus dynamic RAM (DRDRAM), and memory bus dynamic RAM (RDRAM).

[0090] The technical features of the above embodiments may be combined arbitrarily. To make the description concise, not all possible combinations of the technical features in the above embodiments are described. However, as long as there is no contradiction in the combination of these technical features, they should be considered to be within the scope of this specification.

[0091] The above-mentioned embodiments only express several implementation methods of the present application, and the descriptions thereof are relatively specific and detailed, but they cannot be understood as limiting the scope of the invention patent. It should be pointed out that, for a person of ordinary skill in the art, several variations and improvements can be made without departing from the concept of the present application, and these all belong to the protection scope of the present application. Therefore, the protection scope of the patent of the present application shall be subject to the attached claims.

Claims

1. A method for calibrating the frequency of a chip internal clock source, characterized in that: include: Configure the chip's main clock to an external high-speed crystal oscillator clock; The first acquisition step: acquiring the count value of the TIM timer in the chip; wherein the count value includes a first count value corresponding to the first rising edge and a second count value corresponding to the second rising edge; The internal low-speed clock frequency of the chip is obtained based on the count value; specifically, if the second count value is greater than the first count value, a first difference between the second count value and the first count value is calculated, and the current clock frequency of the chip is divided by the first difference to obtain the internal low-speed clock frequency; if the second count value is less than the first count value, the initial default value of the first calibration value is subtracted from the first count value, and the second count value is added to obtain a second difference, and the current clock frequency of the chip is divided by the second difference to obtain the internal low-speed clock frequency; Determining whether the internal low-speed clock frequency is within a first preset expected range; If not, determining a first calibration value based on the internal low-speed clock frequency, and returning to the first acquisition step; If yes, the first calibration value is input into the pre-read information storage area of ​​the chip.

2. The method for calibrating the frequency of the internal clock source of a chip according to claim 1, characterized in that: The determining of a first calibration value based on the internal low-speed clock frequency comprises: If the internal low-speed clock frequency is greater than the maximum value of the first preset expected range, subtract 1 from the first calibration value; If the internal low-speed clock frequency is less than the minimum value of the first preset expected range, the first calibration value is increased by 1.

3. The method for calibrating the frequency of the internal clock source of a chip according to claim 1, characterized in that: Also includes: Configuring the main frequency clock of the chip to be an internal high-speed crystal oscillator clock; Configuring the clock source of the low power consumption timer of the chip to be an external low speed crystal oscillator clock; Second acquisition step: acquiring the standard frequency of the low power consumption timer through the TIM timer; Calculating the capture clock frequency of the chip according to the standard frequency; Determining whether the capture clock frequency is within a second preset expected range; If not, determining a second calibration value based on the capture clock frequency, and returning to the second acquisition step; If yes, then the second calibration value is input into the pre-read information storage area.

4. The method for calibrating the frequency of the internal clock source of a chip according to claim 3, characterized in that: The step of calculating the capture clock frequency of the chip according to the standard frequency includes: Obtaining a third count value according to a first rising edge in the standard frequency; Obtaining a fourth count value according to a second rising edge of the standard frequency; The capture clock frequency is obtained based on the third count value and the fourth count value.

5. The method for calibrating the frequency of the internal clock source of a chip according to claim 4, characterized in that: The obtaining the capture clock frequency based on the third count value and the fourth count value comprises: If the fourth count value is greater than the third count value, a third difference between the fourth count value and the third count value is calculated, and the target clock frequency of the chip is divided by the third difference to obtain the capture clock frequency; If the fourth count value is less than the third count value, subtract the third count value from the initial default value of the second calibration value and add the fourth count value to obtain a fourth difference, and divide the target clock frequency of the chip by the fourth difference to obtain the capture clock frequency.

6. The method for calibrating the frequency of the internal clock source of a chip according to claim 3, characterized in that: The determining a second calibration value based on the capture clock frequency comprises: If the capture clock frequency is greater than the maximum value of the second preset expected range, subtract 1 from the second calibration value; If the capture clock frequency is less than the minimum value of the second preset expected range, the second calibration value is increased by 1.

7. The method for calibrating the frequency of the internal clock source of a chip according to claim 5, characterized in that: The target clock frequency of the chip is 32M.

8. The method for calibrating the frequency of the internal clock source of a chip according to claim 3, characterized in that: The external low-speed crystal oscillator clock is 32.768KHz.

9. A computer device comprising a memory, a processor and a computer program stored in the memory and executable on the processor, characterized in that: When the processor executes the computer program, the steps of the method for calibrating the frequency of the internal clock source of the chip as claimed in any one of claims 1 to 8 are implemented.

10. A computer-readable storage medium having a computer program stored thereon, characterized in that: When the computer program is executed by a processor, the steps of the method for calibrating the frequency of the internal clock source of a chip as claimed in any one of claims 1 to 8 are implemented.