Hardware compensation device for software reset failure of microcontroller and control device
By using the RTC circuit of the microcontroller and the signal control circuit controlled by the I/O port, hardware reset when the software reset fails, solving the problem that the microcontroller cannot start normally, ensuring that the device operates stably in an electromagnetic interference environment.
Patent Information
- Application Number
- CN202510424315.7
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-04-07
- Publication Date
- 2025-07-22
AI Technical Summary
The microcontroller fails to work properly after the software reset and restart fails, resulting in the device not being able to operate normally.
Using the clock signal output from the RTC circuit of the microcontroller and the signal control circuit for I/O port status control, the microcontroller is hardware reset through the external reset pin until the microcontroller starts normally.
When the microcontroller software reset fails to restart, the hardware reset will be automatically repeated to ensure that the device returns to normal operation and improve the restart success rate.
Smart Images

Figure CN120353164A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to a hardware compensation device for software reset failure of a microcontroller (MCU). Background Art
[0002] Embedded devices often face challenges of electromagnetic interference in their working environments. These interferences can come from multiple aspects and may have an adverse impact on the normal operation of the devices. Therefore, considering the stability and reliability of the products, it is crucial to add countermeasures from both hardware and software aspects during the product design and R & D stages to reduce the impact of external electromagnetic interference (EMI) on the devices. Among them, implementing software reset and restart through the watchdog function inside the MCU is a common measure to deal with electromagnetic interference. The watchdog continuously detects the program loop running time. When it is found that the program loop time exceeds the maximum loop time, it is considered that the system has fallen into an "infinite loop", triggering the MCU reset. The watchdog is synchronously reset and needs to restart the watchdog function after the MCU restarts normally. At this time, if the electromagnetic interference factors affecting the device continue to exist, it will cause the restart failure after the MCU software reset. Since the watchdog is synchronously reset when the MCU is reset and cannot continue to send software reset instructions, the MCU will always be in a fault state, resulting in the product being unable to work properly. Summary of the Invention
[0003] The technical problem to be solved by the present invention is to overcome the technical problem that the MCU cannot work properly after the software reset restart fails, and provide a hardware compensation device for software reset failure of a microcontroller, which can automatically repeat the hardware reset of the microcontroller until the microcontroller starts normally when the software reset restart of the microcontroller fails.
[0004] The present invention specifically adopts the following technical solutions to solve the above technical problems: A hardware compensation device for software reset failure of a microcontroller, the microcontroller having an RTC circuit and a software reset function, the hardware compensation device being used to automatically repeat the hardware reset of the microcontroller until the microcontroller starts normally when the software reset restart of the microcontroller fails; the hardware compensation device includes a signal control circuit connected in series between the output end of the RTC circuit and the external reset pin of the microcontroller, and the control end of the signal control circuit is connected to an I / O port of the microcontroller; the RTC circuit is configured to continuously output a clock signal with a pulse width greater than the time required for the microcontroller to reset and start normally after power-on; the I / O port is configured to an output mode after each reset and start of the microcontroller, and sends a cut-off control signal to the signal control circuit; the signal control circuit immediately cuts off when receiving the cut-off control signal and delays conduction after the cut-off control signal disappears, and the delay time is greater than the time required for the microcontroller to reset and start normally.
[0005] Preferably, the signal control circuit includes a switching device and an RC charge and discharge circuit. The switching device has a control terminal circuit and an output terminal circuit. The charging input terminal of the RC charge and discharge circuit is connected to the I / O port, and the discharging output terminal of the RC charge and discharge circuit is connected to the control terminal circuit of the switching device. The output terminal circuit of the switching device is connected in series between the output terminal of the RTC circuit and the external reset pin of the microcontroller. The control terminal circuit controls the on / off of the output terminal circuit according to the input control signal.
[0006] More preferably, the switching device is an optocoupler.
[0007] Based on the above technical solutions, the following technical solutions can also be obtained: A control device includes a microcontroller which has an RTC circuit and a software reset function. It is characterized in that the control device further includes a hardware compensation device for the failure of the microcontroller software reset as described in any of the above technical solutions.
[0008] Compared with the prior art, the technical solution of the present invention has the following beneficial effects: The present invention uses the clock signal generated by the second output or clock calibration output function of the on-chip RTC inherent in the MCU as the hardware reset signal, combined with a signal control circuit automatically controlled by the I / O port state of the MCU, and performs hardware reset on the microcontroller through the external reset pin NRST of the MCU. When the software reset of the microcontroller fails to start, it can repeatedly perform hardware reset on the microcontroller until the microcontroller starts normally and the system resumes normal operation, ensuring the normal operation of the device. The present invention can be realized only by adding a simple signal control circuit on the basis of the existing MCU circuit. Its circuit structure is simple, easy to implement, and has a low cost. BRIEF DESCRIPTION OF THE DRAWINGS
[0009] Figure 1 is the basic structural block diagram of the control device of the present invention; Figure 2 is the circuit diagram of a specific embodiment of the control device of the present invention; Figure 3 is the schematic diagram of the working principle of the hardware compensation device for the failure of the microcontroller software reset; Figure 4 is the schematic diagram of the working process of the control device of the present invention. DETAILED DESCRIPTION OF THE EMBODIMENTS
[0010] For the technical problem that the MCU cannot work properly after the software reset restart fails, the solution idea of the present invention is to use the clock signal generated by the second output or clock calibration output function of the on-chip RTC inherent in the MCU as the hardware reset signal, combined with a signal control circuit automatically controlled by the I / O port state of the MCU, and perform a hardware reset on the microcontroller through the external reset pin NRST of the MCU. When the software reset startup of the microcontroller fails, it can repeatedly perform a hardware reset on the microcontroller until the microcontroller starts up normally.
[0011] The present invention specifically adopts the following technical solutions to solve the above technical problems: A hardware compensation device for software reset failure of a microcontroller, the microcontroller has an RTC circuit and a software reset function, and the hardware compensation device is used to automatically repeat a hardware reset on the microcontroller when the software reset restart of the microcontroller fails until the microcontroller starts up normally; the hardware compensation device includes a signal control circuit connected in series between the output end of the RTC circuit and the external reset pin of the microcontroller, and the control end of the signal control circuit is connected to an I / O port of the microcontroller; the RTC circuit is configured to continuously output a clock signal with a pulse width greater than the time required for the normal reset startup of the microcontroller after power-on; the I / O port is configured as an output mode after each reset startup of the microcontroller to send a cut-off control signal to the signal control circuit; the signal control circuit immediately cuts off when receiving the cut-off control signal and delays conduction after the cut-off control signal disappears, and the delay time is greater than the time required for the normal reset startup of the microcontroller.
[0012] Preferably, the signal control circuit includes a switching device and an RC charge and discharge circuit. The switching device has a control terminal circuit and an output terminal circuit. The charging input terminal of the RC charge and discharge circuit is connected to the I / O port, and the discharging output terminal of the RC charge and discharge circuit is connected to the control terminal circuit of the switching device; the output terminal circuit of the switching device is connected in series between the output end of the RTC circuit and the external reset pin of the microcontroller, and the control terminal circuit controls the on-off of the output terminal circuit according to the input control signal.
[0013] Further preferably, the switching device is an optocoupler.
[0014] Based on the above technical solutions, the following technical solutions can also be obtained: A control device includes a microcontroller, the microcontroller has an RTC circuit and a software reset function, and is characterized in that the control device further includes the hardware compensation device for software reset failure of the microcontroller according to any one of the above technical solutions.
[0015] For the convenience of public understanding, the technical solution of the present invention will be described in detail below through a specific embodiment in conjunction with the accompanying drawings: The basic structure of the control device in this embodiment is as Figure 1 shown, including a power supply circuit, a microcontroller, a reset circuit, a peripheral function circuit, and a signal control circuit.
[0016] Among them, the microcontroller is the control core of the system. It integrates a real-time clock (RTC) circuit internally. The RTC circuit has an independent backup area. This part includes an accumulative counter, an alarm clock, a frequency divider, and an RTC clock configuration register, which can keep the RTC clock working normally and send out clock signals when the MCU is reset; in this embodiment, the RTC circuit is configured to continuously output a clock signal with a pulse width greater than the time required for the microcontroller to normally reset and start up after power-on.
[0017] The reset circuit is used to reset the microcontroller by sending a reset signal to the external reset pin of the microcontroller after detecting the power supply stability when the system is powered on.
[0018] The power supply circuit is used to supply power to the microcontroller, the reset circuit, the peripheral function circuit, and the signal control circuit.
[0019] The peripheral function circuit (such as a display circuit, an alarm circuit, etc.) is used to execute various product functions under the control of the microcontroller.
[0020] The signal control circuit is connected in series between the output end of the RTC circuit and the external reset pin of the microcontroller. The control end of the signal control circuit is connected to an I / O port of the microcontroller; the I / O port is configured as an output mode after each reset and startup of the microcontroller, and sends a cut-off control signal to the signal control circuit; the signal control circuit immediately cuts off when receiving the cut-off control signal, and delays conduction after the cut-off control signal disappears, and the delay time is greater than the time required for the microcontroller to normally reset and start up.
[0021] To simplify the circuit as much as possible, the signal control circuit includes a switching device and an RC charge-discharge circuit. The switching device has a control terminal circuit and an output terminal circuit. The charging input terminal of the RC charge-discharge circuit is connected to the I / O port, and the discharging output terminal of the RC charge-discharge circuit is connected to the control terminal circuit of the switching device; the output terminal circuit of the switching device is connected in series between the output terminal of the RTC circuit and the external reset pin of the microcontroller. The control terminal circuit controls the on / off of the output terminal circuit according to the input control signal. When the I / O port is in the output mode, it outputs a high level to charge the capacitor of the RC charge-discharge circuit. At the same time, the control terminal circuit of the switching device receives the high level and the switching device is turned off (i.e., the output terminal circuit is turned off); when the I / O port returns to the input mode, it stops outputting the high level. At this time, the capacitor of the RC charge-discharge circuit discharges outward, and the control terminal circuit of the switching device receives the high level that lasts for a period of time. During this period, the switching device remains turned off until the discharge is completed and the switching device is turned on (i.e., the output terminal circuit is turned on).
[0022] Figure 2 Fig. shows a specific implementation circuit of the above control device. Taking the opto-coupler (hereinafter referred to as opto-isolator) as an example of the switching device, as Figure 2 shown, the I / O pin PB9 of the microcontroller MCU is connected to the control terminal K of the opto-isolator V1 through the resistor R3. When the MCU works normally, the pin PB9 is configured as an output pin, and outputs a high level signal to control the opto-isolator V1 to work in the cut-off state. When the MCU watchdog resets, the pin PB9 returns to the input pin, is in a high impedance state, and no longer outputs a high level; the pin PC13 of the microcontroller is connected to the output terminal E (emitter) of the opto-isolator V1, which is the clock output pin of the RTC circuit; the external reset pin NRST of the microcontroller is respectively connected to the output terminal C (collector) of the opto-isolator V1 and the nRset pin of the reset chip N1. When the MCU is powered on, the nRset pin of the reset chip N1 controls it at a low level. After the power supply is stable, the nRset pin of the reset chip N1 outputs a high level, and the microcontroller completes the reset.
[0023] The RTC circuit is a peripheral function circuit of the microcontroller. After the MCU is powered on, by configuring this function, the PC13 pin circuit becomes an AMPER-RTC function circuit, continuously outputting a 1Hz clock signal, that is, high and low level signals with a pulse width of 0.5s.
[0024] The signal control circuit consists of resistors R2, R3, R4, capacitor C6, and optocoupler V1. Among them, R3 and C6 form a capacitor charging circuit, and R4 is a current-limiting resistor at the power input terminal. When operating normally, a high level is output from pin PB9 to charge it. R2 and C6 form a discharging circuit. During the reset (reset provided by the reset chip or watchdog) and restart process of the MCU (about 10 ms), the level of the control terminal K of the optocoupler V1 is maintained at a high level to keep it cut off continuously. When the optocoupler V1 is cut off, the output terminal C does not output a signal, and the level of the external reset pin NRST of the microcontroller is controlled by the reset chip N1 and the pull-up resistor and remains at a high level. When the optocoupler V1 is conducting, the output terminal C outputs a clock signal of 1 Hz, and the external reset pin NRST of the microcontroller appears at a low level, causing the microcontroller to reset.
[0025] Among them, the power supply VCC, resistor R4, and the control terminal K of the optocoupler form the control terminal circuit, and the output terminal E (emitter) of the optocoupler V1 and the output terminal C (collector) of the optocoupler V1 form the output terminal circuit.
[0026] The working principle of the hardware compensation device for the software reset failure of the microcontroller in the present invention is as Figure 1 shown, specifically as follows: When the microcontroller is powered on, the reset chip N1 starts to work. After the power supply is stable, the level of the external reset pin NRST of the MCU is pulled from a low level to a high level, and the MCU starts. First, the RTC clock function is configured. The pin PC13 (AMPER-RTC) outputs a 1 Hz clock signal. The I / O pin PB9 is configured as an output state and outputs a high level signal. The capacitor C6 starts to charge, and the optocoupler V1 is in a cut-off state. The MCU starts to work; When there is external interference and the microcontroller software runs abnormally, it enters the watchdog reset. The I / O pin PB9 of the MCU resumes to the input mode and stops outputting a high level. At this time, the capacitor C6 discharges through the resistor R2, and the optocoupler V1 remains in the cut-off state. After 10 ms, if the microcontroller still fails to start, the capacitor C6 finishes discharging, and the level of the control terminal K of the optocoupler V1 is pulled to the low level by the resistor R2, and the optocoupler V1 conducts; the 1 Hz clock signal from the output terminal E of the optocoupler V1 is output from the output terminal C to the external reset pin NRST of the MCU. When the level of the external reset pin NRST changes from low level to high level, the MCU resets and restarts. At this time, if the startup still fails, the 1 Hz clock signal continues to be input to the external reset pin NRST of the MCU through the optocoupler V1 to trigger the next hardware reset; otherwise, after the MCU starts, it will configure the I / O pin PB9 and output a high-level signal again. The capacitor C6 starts to charge again. After the charging is completed, the input terminal K of the optocoupler V1 is pulled to the high level, making the optocoupler V1 enter the cut-off state (i.e., blocking the electrical signal transmission between the output terminal E and the output terminal C), and the output terminal C of the optocoupler V1 stops outputting the clock signal to the external reset pin NRST, and the MCU starts to work.
[0027] The working process of the control device in this embodiment is as Figure 4 shown as follows: Step 1: When the system is powered on, the microcontroller (MCU) runs the initialization code to configure the oscillator circuit, RTC real-time clock circuit, TIMER timer circuit, WDT watchdog circuit, GPIO port circuit, etc. Step 2: Enable the watchdog reset, configure the on-chip real-time clock (RTC), output a 1 Hz clock signal, configure the I / O pin as the output mode, output a high level, and the control signal control circuit is cut off. Step 3: The microcontroller detects the input signals of the peripheral function circuits, processes the data, outputs signals, and runs the product functions. Step 4: The microcontroller program runs abnormally, enters an "infinite loop", fails to "feed the dog" in time, and the watchdog triggers a system reset. Step 5: The microcontroller resumes to the initial state, the initialization fails, and it falls into a failure state. Step 6: In the initial state, the I / O pin resumes to the input mode, and the port level is set to the low level by the pull-down resistor, and the control signal control circuit conducts. Step 7: The 1 Hz clock signal is input to the external reset pin. When the pulse level of the clock signal is low, it triggers the hardware reset of the microcontroller. When the pulse level is high, the microcontroller executes the initialization program. Step Eight: If the initialization fails, after 1s, the pulse level becomes low, and repeat the operation of Step Six; if the initialization is successful, start the watchdog, configure the I / O pin as the output mode, output a high level, and the signal control circuit is cut off; Step Nine: The microcontroller detects the input signal of the peripheral function circuit, processes the data, outputs the signal, and runs the product function.
[0028] It can be seen that by adopting the above technical solution, when the software reset and restart of the microcontroller fails, the hardware compensation device can continuously provide a hardware reset signal for the microcontroller by using the clock signal output by the internal RTC circuit, ensuring that when the external interference weakens or disappears, the microcontroller can be immediately reset again and resume normal operation, greatly improving the success rate of MCU restart, and is particularly suitable for working occasions with harsh electromagnetic environments.
Claims
1. A hardware compensation device for the failure of the microcontroller software reset. The microcontroller has an RTC circuit and a software reset function, characterized in that, The hardware compensation device is used to automatically and repeatedly perform a hardware reset on the microcontroller until the microcontroller starts up normally when the software reset and restart of the microcontroller fails; the hardware compensation device includes a signal control circuit connected in series between the output end of the RTC circuit and the external reset pin of the microcontroller, and the control end of the signal control circuit is connected to an I / O port of the microcontroller; the RTC circuit is configured to continuously output a clock signal with a pulse width greater than the time required for the normal reset and startup of the microcontroller after power-on; the I / O port is configured as an output mode after each reset and startup of the microcontroller to send a cut-off control signal to the signal control circuit; the signal control circuit immediately cuts off when receiving the cut-off control signal and delays conduction after the cut-off control signal disappears, and the delay time is greater than the time required for the normal reset and startup of the microcontroller.
2. The hardware compensation device for the failure of the software reset of the microcontroller according to claim 1, wherein the signal control circuit includes a switching device and an RC charge and discharge circuit, the switching device has a control end circuit and an output end circuit, the charging input end of the RC charge and discharge circuit is connected to the I / O port, and the discharge output end of the RC charge and discharge circuit is connected to the control end circuit of the switching device; the output end circuit of the switching device is connected in series between the output end of the RTC circuit and the external reset pin of the microcontroller, and the control end circuit controls the on / off of the output end circuit according to the input control signal.
3. The hardware compensation device for the failure of the software reset of the microcontroller according to claim 2, wherein the switching device is an optocoupler.
4. A control device includes a microcontroller which has an RTC circuit and a software reset function, characterized in that, The control device further includes the hardware compensation device for the failure of the software reset of the microcontroller according to any one of claims 1 to 3.