Processing method for clock skew of single-chip microcomputer
Through the microcontroller clock offset processing method, the MCU is initialized, the sunroof status information is read and written, and the soft restart is carried out, which solves the abnormal reset problem caused by clock deviation after the PLL is lost in the automotive sunroof control system, and the normal operation of the sunroof system and the improvement of product quality is achieved.
Patent Information
- Application Number
- CN202510104273.9
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-01-23
- Publication Date
- 2025-06-06
AI Technical Summary
The existing automotive sunroof control system has a system clock deviation after the PLL is lost to lock, causing the watchdog to reset, which causes the sunroof system to be abnormal and cannot be automatically restored. In severe cases, the sunroof may derail.
Through the microcontroller clock offset processing method, the MCU is initialized, the sunroof status information is read, and the tasks are performed cyclically, including reading the PLL status, writing to the EEPROM, clearing the PLL register status flag bit, and forcing the system to soft restart, re-reading the EEPROM information to restore the sunroof status.
It solves the abnormal phenomenon of the sunroof control system caused by the abnormal reset of the ECU caused by PLL loss, improves product quality, reduces maintenance costs, and ensures that the sunroof system can operate normally.
Smart Images

Figure CN120103748A_ABST
Abstract
Description
Technical Field
[0001] The invention relates to the technical field of automobile sunroof controllers, and in particular to a method for processing a single-chip computer clock offset, which is suitable for sunroof controllers that have a sunroof system abnormality caused by a watchdog reset due to a system clock offset caused by a PLL (phase-locked loop) loss of lock. Background Art
[0002] At present, the sunroof controller in the automatic sunroof control system of a car may cause PLL unlocking due to software driver, hardware circuit, external electromagnetic interference and other reasons. After PLL unlocking, the system clock will be offset, the timer will deviate from the actual physical time, and the watchdog will time out. After the watchdog times out, the system does not record the current sunroof status information, and the ECU will be reset. After the reset, the sunroof status information in the EEPROM will be re-read. The information in the EEPROM is written at the last normal power-off or sleep time, which is inconsistent with the actual status of the current sunroof, which will cause the sunroof to work abnormally.
[0003] The technical solution for product sampling on the market currently is to use software to identify whether a reset caused by a watchdog timeout has occurred. If a watchdog reset occurs, the sunroof will be downgraded and initialization will be lost. However, this solution still has serious defects. After the sunroof loses initialization, functions such as automatic window closing when it rains, automatic window closing when the car is locked, automatic window closing at high speed, and voice control of the sunroof will all fail, and the sunroof control system cannot operate normally. It is necessary to determine whether a watchdog reset has occurred through the reset information saved in the reset register. If a watchdog reset occurs, the sunroof will be downgraded and initialization will be lost, and manual initialization operation is required for the sunroof to return to normal.
[0004] If the sunroof control system cannot automatically recover from the abnormality caused by PLL unlocking, the sunroof cannot work normally, and in serious cases, the sunroof will derail. Since the probability of abnormal reset caused by PLL unlocking is extremely low, and the frequency of sunroof operation by drivers and passengers is low, it is difficult to reproduce the abnormality, so this abnormality is ignored and no treatment is done. Considering product quality, such abnormality must be improved. Summary of the invention
[0005] The technical problem to be solved by the present invention is: in order to solve the problems existing in the prior art in the above-mentioned background technology, a method for processing the clock offset of the microcontroller is provided to solve the abnormal phenomenon of the sunroof control system caused by the watchdog reset, so that the product can operate normally.
[0006] The technical solution adopted by the present invention to solve the technical problem is: a method for processing a clock offset of a single-chip microcomputer, comprising the following steps:
[0007] Step 1: Initialize the MCU: configure or reset the various functional modules inside the MCU to put the MCU into normal working mode;
[0008] Step 2: Read the sunroof status information: Read the sunroof status information saved in the EEPROM when the power was off or in sleep mode last time;
[0009] Step 3: Loop execution of tasks: All threads and task scheduling are executed in this main function. This part is the main body of the function. 1MS executes a loop task and schedules the PLL state.
[0010] Furthermore, the specific steps of scheduling the PLL state in step 3 are as follows:
[0011] Step 3.1: Read the PLL status to see if it is unlocked. If not, continue with the next 1ms loop task. If yes, the PLL register in the kernel will set the corresponding status bit to 1, indicating that the PLL is unlocked. The software detects the PLL unlock and stops the motor immediately.
[0012] Step 3.2: Write the current sunroof status information into the EEPROM and update the EEPROM data;
[0013] Step 3.3: Clear the PLL register status flags and force the system to soft reset.
[0014] Furthermore, in step 1, the various functional modules inside the MCU are respectively an MCU frequency setting module, an input and output module, a time setting module and an ADC module, and the operating frequency in the setting frequency setting module of the detection channel, the input and output of the I / O port of the input and output module, the time of the timer and the detection channel of the ADC are configured or reset.
[0015] Furthermore, in step 2, the sunroof status information includes the position of the sunshade and the position of the glass.
[0016] Furthermore, the main function in step 3 refers to the main function in C language.
[0017] Beneficial effects of the present invention: The present invention solves the abnormal phenomenon of the sunroof control system caused by abnormal resetting of the ECU due to PLL unlocking, improves product quality, and reduces all maintenance costs caused by faulty parts. BRIEF DESCRIPTION OF THE DRAWINGS
[0018] The present invention is further described below in conjunction with the accompanying drawings and embodiments.
[0019] Figure 1 is a control block diagram of the present invention; DETAILED DESCRIPTION
[0020] The present invention will now be described in further detail with reference to the accompanying drawings. These drawings are simplified schematic diagrams, which only illustrate the basic structure of the present invention in a schematic manner, and therefore only show the components related to the present invention.
[0021] MCU: full name Microcontroller Unit, Chinese: micro control unit;
[0022] EEPROM: Full name: Electrically Erasable Programmable Read-Only Memory, Chinese: Programmable Erasable Read-Only Memory
[0023] like Figure 1 A method for processing a clock offset of a single-chip microcomputer is shown, comprising the following steps:
[0024] First, initialize the MCU: configure or reset the various functional modules inside the MCU to make the MCU enter the normal working mode, where the various functional modules inside the MCU are the MCU frequency setting module, the input and output module, the time setting module and the ADC module, and configure or reset the working frequency in the setting frequency setting module of the detection channel, the input and output of the I / O port of the input and output module, the time of the timer and the detection channel of the ADC;
[0025] Secondly, read the sunroof status information: read the sunroof status information saved in the EEPROM when the power was off or in sleep mode last time. The sunroof status information includes the position of the sunshade and the position of the glass.
[0026] Finally, the task is executed cyclically: all threads and task scheduling are executed in this main function. This part is the main body of the function. 1MS executes a cyclic task and schedules the PLL state.
[0027] Specifically: The specific steps of scheduling the PLL state in step 3 are as follows:
[0028] First, read the PLL status to see if it is unlocked. If not, continue with the next 1ms loop task. If so, the PLL register in the kernel will set the corresponding status bit to 1, indicating that the PLL is unlocked. After the PLL is unlocked, the system clock will deviate. When the deviation accumulates to a certain extent, the originally set watchdog time will not be able to meet the requirements of normal system operation, causing the watchdog timeout, which will cause the ECU to reset abnormally. The software detects that the PLL is unlocked and immediately stops the motor action.
[0029] Secondly, write the current sunroof status information into the EEPROM and update the EEPROM data;
[0030] Finally, the PLL register status flags are cleared and the system is forced to perform a soft restart.
[0031] After the system restarts, the EEPROM information is read again. This information is written before the restart and is consistent with the current sunroof status. Therefore, the sunroof status and system functions are normal, thus avoiding the sunroof system abnormality caused by system clock deviation due to PLL unlocking and subsequent ECU reset.
[0032] The main function in step 3 refers to the main function in C language, such as int main(void){}, which is the entry function of the C program. A C program has only one main function, and any C program always starts from the main function. After entering this function, the task scheduling of all sub-functions is performed in this function.
[0033] This application can be extended to all electronic products using MCU and used in software processing solutions after the PLL loses lock and the system clock deviates.
[0034] Based on the above ideal embodiments of the present invention, the relevant staff can make various changes and modifications without departing from the technical concept of the present invention through the above description. The technical scope of the present invention is not limited to the contents of the specification, and its technical scope must be determined according to the scope of the claims.
Claims
1. A method for processing a single-chip computer clock offset, characterized in that: The steps include: Step 1: Initialize the MCU: configure or reset the various functional modules inside the MCU to put the MCU into normal working mode; Step 2: Read the sunroof status information: Read the sunroof status information saved in the EEPROM when the power was off or in sleep mode last time; Step 3: Loop task execution: All threads and task scheduling are executed in this main function. This part is the main body of the function. 1MS executes a loop task and schedules the PLL state.
2. The method for processing a single chip computer clock offset according to claim 1, characterized in that: The specific steps of scheduling the PLL state in step 3 are as follows: Step 3.1: Read the PLL status to see if it is unlocked. If not, continue with the next 1ms loop task. If yes, the PLL register in the kernel will set the corresponding status bit to 1, indicating that the PLL is unlocked. The software detects the PLL unlock and stops the motor immediately. Step 3.2: Write the current sunroof status information into the EEPROM and update the EEPROM data; Step 3.3: Clear the PLL register status flags and force the system to soft reset.
3. The method for processing a single chip computer clock offset according to claim 1, characterized in that: In the step 1, the various functional modules inside the MCU are respectively an MCU frequency setting module, an input and output module, a time setting module and an ADC module, and the operating frequency in the setting frequency setting module of the detection channel, the input and output of the I / O port of the input and output module, the time of the timer and the detection channel of the ADC are configured or reset.
4. The method for processing a single chip computer clock offset according to claim 1, characterized in that: The sunroof status information in step 2 includes the position of the sunshade and the position of the glass.
5. The method for processing a single chip computer clock offset according to claim 1, characterized in that: The main function in step 3 refers to the main function in C language.