Over-current protection method and system based on internal comparator of chip
By using the internal chip comparator in the controller to monitor the current and turn off the PWM output, the problem of traditional protection methods relying on external circuit components is solved, and efficient and low-cost overcurrent protection is achieved.
Patent Information
- Application Number
- CN202411776270.1
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-12-05
- Publication Date
- 2025-04-25
AI Technical Summary
Under extreme operating conditions, the controller needs to protect itself from irreversible damage, but the traditional protection method relies on the addition of external circuit components, resulting in increased costs.
A method and system based on an overcurrent protection based on an internal comparator of the chip is designed to monitor the current through the comparator module and turn off the PWM output through an interrupt mechanism when an overcurrent condition is detected, reducing dependence on external circuits and comparators.
It realizes effective overcurrent protection of the controller without adding external circuit components, reducing costs, and improving integration and response speed.
Smart Images

Figure CN119891087A_ABST
Abstract
Description
Technical Field
[0001] The present invention belongs to the technical field of automotive electronic systems, and in particular relates to an overcurrent protection method and system based on a chip internal comparator. Background Art
[0002] The coverage of automotive application conditions is increasing, which places higher demands on the performance of controllers. Especially under extreme conditions, controllers need to have self-protection functions to prevent irreversible damage. In order to effectively protect the controller under extreme conditions, traditional protection methods usually rely on adding external circuit components, but this will increase the cost of the controller. Summary of the invention
[0003] In view of the above problems, the main purpose of the present invention is to design an overcurrent protection method and system based on an internal comparator of a chip to solve the problem that the controller needs to add external circuit components when performing overcurrent protection.
[0004] In order to achieve the above purpose, the present invention adopts the following technical solutions: An overcurrent protection method based on an internal comparator of a chip is used in an MCU having an internal comparator module. The comparator module monitors the current and shuts down the PWM output through an interrupt mechanism when an overcurrent condition is detected. The method specifically includes the following steps: Power on the system to make the MCU work normally; Initialize the MCU's IO port and complete the MCU pin configuration; Configure the comparator module and interrupt mechanism, and execute the shutdown of PWM pin output in the interrupt.
[0005] As a further description of the present invention, initializing the IO port of the MCU includes the following steps: In the MCU, the IO port is initialized and configured as a multiplexing function, and the IO port is used as the IO port for the input of the comparator module; The comparator module receives system information through the IO port and compares the system information to monitor the current information in the system.
[0006] As a further description of the present invention, the configuration of the comparator module includes the following steps: respectively configuring the positive input terminal and the negative input terminal of the comparator module; Among them, the positive input terminal or the negative input terminal is connected to the system power supply voltage, the negative input terminal or the positive input terminal is connected to the output of the system circuit, the system power supply voltage is configured as the reference voltage, and the current output in the system circuit is converted and configured as the bus voltage.
[0007] As a further description of the present invention, the interrupt mechanism is that when the comparator module detects that the bus voltage is greater than the reference voltage, it indicates that an overcurrent has occurred in the system circuit, and an interrupt signal is generated. The MCU shuts down the PWM pin output according to the interrupt signal.
[0008] As a further description of the present invention, after the interrupt mechanism triggers the shutdown of the PWM pin output, the PWM pin is switched to a normal IO mode, and the time and cause of the fault are recorded.
[0009] An overcurrent protection system based on an internal comparator of a chip, the system at least comprises an MCU and a controller having an internal comparator module, and the MCU executes the above protection method to realize overcurrent protection of the system.
[0010] Compared with the prior art, the technical effects of the present invention are: The present invention provides an overcurrent protection method and system based on a chip internal comparator. The method is applicable to all MCUs containing a comparator module internally, and has high portability. The method monitors current through the comparator module, and when an overcurrent condition is detected, the PWM output is turned off through an interrupt mechanism. Specifically, the MCU is powered on to enable the MCU to work normally, the IO port of the MCU is initialized, the MCU pin configuration is completed, the comparator module and the interrupt mechanism are configured, and the PWM pin output is turned off in the interrupt. The implementation of the method relies on the comparator inside the chip, which reduces the cost of the external circuit and the external comparator, and has high integration and fast response speed. At the same time, compared with simple hardware protection, the method consumes less energy, has high flexibility and is more controllable. BRIEF DESCRIPTION OF THE DRAWINGS
[0011] Figure 1 It is a schematic flow chart of the overcurrent protection method of the present invention; Figure 2 It is a timing diagram of the protection strategy of the present invention; Figure 3 It is a schematic diagram of the monitoring principle of the comparator module of the present invention; Figure 4 This is a schematic diagram of the comparator module input of the present invention. DETAILED DESCRIPTION
[0012] The present invention is described in detail below in conjunction with the accompanying drawings: In one embodiment of the present invention, an overcurrent protection method based on a chip internal comparator is disclosed, referring to Figure 1-4 As shown in FIG. 1 , the method is used in an MCU having an internal comparator module and is portable. The current is monitored by the comparator module, and when an overcurrent condition is detected, the PWM output is turned off by an interrupt mechanism. Specifically, the method includes the following steps: Power on the system to make the MCU work normally; Initialize the MCU's IO port and complete the MCU pin configuration; Configure the comparator module and interrupt mechanism, and execute the shutdown of PWM pin output in the interrupt.
[0013] Specifically, in this embodiment, after the system is powered on, it is ensured that the MCU is powered normally.
[0014] Initialize the IO port of the MCU: The MCU initializes the specified IO port so that the IO port has basic input and output functions to facilitate the subsequent initialization of the comparator module; specifically, in the MCU, the specified IO port is initialized and configured as a multiplexing function, and the IO port is used as the IO port for the input of the comparator module; the comparator module receives system information through the IO port and compares the system information to realize the monitoring of the current information in the system.
[0015] In this embodiment, the comparator module function in the MCU is enabled, and the comparator module function register bit is configured to activate the comparator module. This involves the positive input and negative input of the comparator module, the triggering mode of the comparator module interrupt, and the clock source and filter parameter settings of the comparator module. Select a suitable clock source to ensure that the comparator module works at the expected frequency, set the filter parameters to eliminate voltage ripple and noise, improve the accuracy of comparison, and prevent false interrupts.
[0016] When initializing the comparator module to compare voltages, special attention should be paid to the comparator's clock selection, filter parameter configuration, and interrupt entry time and other related configuration properties. This should ensure that the system can quickly enter the interrupt to implement the protection strategy when overcurrent occurs and that the interrupt will not be entered by mistake. If necessary, the interrupt priority of the comparator module needs to be set to the highest to ensure that the interrupt execution of the comparator module will not be interrupted by other higher priority interrupts, thereby affecting the system circuit protection.
[0017] It should be noted that the above interrupt priority setting method is usually provided by the MCU manufacturer with relevant instruction codes, generally in the MCU's Mcal or library. Generally speaking, the smaller the number corresponding to the interrupt priority, the higher the priority, so the interrupt priority of the comparator module needs to be set to 0. Setting the interrupt priority to 0 is the highest setting. To describe this phenomenon through data, different priority interrupts need to be presented in the form of waveforms. During the execution of a higher priority interrupt, a lower priority interrupt will not be executed, and during the execution of a lower priority interrupt, a higher priority interrupt will be interrupted by a higher priority interrupt.
[0018] Specifically, in this embodiment, the configuration of the MCU comparator module is as follows: the positive input terminal and the negative input terminal of the comparator module are configured respectively; wherein the positive input terminal or the negative input terminal is connected to the system power supply voltage, and the negative input terminal or the positive input terminal is connected to the output of the system circuit, the system power supply voltage is configured as the reference voltage, and the current output in the system circuit is configured as the bus voltage after conversion. Figure 4 As shown, VREF is the actual voltage output by the system circuit. When overcurrent occurs in the circuit, the circuit voltage will increase and be converted into a voltage value through the operational amplifier chip as the embodiment of the actual voltage of the circuit. The output is I_DCLINK, which is used as an input of the comparator module. The system power supply voltage VCC is divided to obtain a more stable voltage value I_DCLINK_CMP, which is used as another input of the comparator module, namely, the reference voltage of the comparator module.
[0019] Usually the reference voltage should be a stable and accurate voltage value, usually provided by a voltage regulator, a voltage reference source or a precision resistor network; the system circuit should be able to convert the current value into a voltage value (bus voltage) for comparison with the reference voltage. Usually the system is implemented by a current sensor, a resistor or an operational amplifier circuit, but is not limited to the above. In the specific implementation process, the following functions are implemented by configuring the MCU comparator module. If the system circuit does not directly output the voltage value corresponding to the current, it is necessary to design a voltage response circuit to convert the current signal to ensure that the output range of the voltage response circuit matches the input range of the comparator module, and consider adding a filter to eliminate voltage ripple and noise. Add an appropriate filter, such as a low-pass filter, to the input end of the comparator to further eliminate the impact of voltage ripple and noise on the comparator output, or perform signal processing in the system, such as setting a suitable threshold or using a smoothing algorithm to reduce the possibility of false triggering of interrupts; configure the interrupt mechanism according to the output signal of the comparator module to ensure that the interrupt can be quickly triggered when the interrupt condition is met and execute the protection strategy.
[0020] The interrupt mechanism (the triggering mode of the comparator module interrupt) is: when the comparator module detects that the bus voltage is greater than the reference voltage (I_DCLINK>I_DCLINK_CMP), it indicates that an overcurrent has occurred in the system circuit, and an interrupt signal is generated. The MCU turns off the PWM pin output according to the interrupt signal. Figure 2 As shown, 1 represents that the reference voltage is greater than the bus voltage, and an overcurrent occurs in the comparator module. At this time, the interrupt mechanism of the comparator module is triggered to implement the protection strategy. 0 represents that the bus voltage is greater than the reference voltage, and no overcurrent occurs in the comparator module.
[0021] After the interrupt mechanism triggers the shutdown of the PWM pin output, the PWM pin is switched to normal IO mode, which can effectively protect the hardware of the system circuit from the impact of large current. At the same time, relevant information such as the time and cause of the fault is recorded to facilitate subsequent troubleshooting and system optimization. This is usually achieved by setting a fault flag and storing the fault information in a non-volatile memory.
[0022] Implement protection against overcurrent in the comparator module interrupt: When the comparator module detects that the input signal meets the interrupt condition, an interrupt request is generated, and the MCU responds to the request and enters the interrupt handler of the comparator module; In the interrupt handler, the interrupt flag in the comparator module register needs to be cleared first. This process is to confirm that the interrupt has been processed and prevent the interrupt handler from entering again for the same reason, causing system instability; The method of clearing the interrupt flag usually involves reading or writing a specific register bit. The specific method depends on the MCU model and the design of the comparator module. If the MCU does not actively clear the terminal flag, it will cause the interrupt to continue to affect the system as a whole, so the interrupt flag should be cleared after entering the interrupt. The operation of clearing the flag can be directly called through the relevant instruction code provided by the MCU manufacturer; After clearing the interrupt flag, the PWM output port of the MCU needs to be closed immediately, which is specifically achieved by modifying the PWM control register or related settings, reconfiguring the IO pin of the PWM function to a normal IO, and configuring its level to a low level to ensure that the PWM signal is no longer output, and closing the PWM output port prevents the hardware circuit from continuing to work under abnormal conditions, thereby generating excessive current and causing damage to the circuit. In addition, according to specific application requirements, other protection actions can also be performed in the interrupt handler, such as cutting off the power supply, sending an alarm signal, recording fault information, etc.; after completing the above steps, exit the interrupt handler of the comparator module so that the MCU can continue to execute other tasks.
[0023] Through the above content, an overcurrent protection method based on an internal comparator of a chip is disclosed. This method is applicable to all MCUs with an internal comparator and has high portability. The implementation of this method relies on the comparator inside the chip, reducing the cost of external circuits and external comparators, and has high integration and fast response speed. At the same time, compared with simple hardware protection, this method consumes less energy, is highly flexible and more controllable.
[0024] In another embodiment of the present invention, an overcurrent protection system based on an internal comparator of a chip is disclosed. The system includes at least an MCU and a controller having an internal comparator module. The above protection method is executed by the MCU to implement overcurrent protection of the system.
[0025] It should be noted that the above-mentioned system may be any electronic device that requires current protection function, such as a power management system, a motor control system, a battery charging system, etc., and is not limited to one of them.
[0026] The above embodiments are only used to illustrate the technical solution of the present invention rather than to limit it. Other modifications or equivalent substitutions made to the technical solution of the present invention by ordinary technicians in this field should be included in the scope of the claims of the present invention as long as they do not depart from the spirit and scope of the technical solution of the present invention.
Claims
1. An overcurrent protection method based on a chip internal comparator, characterized in that: This method is used in an MCU with a comparator module inside. The comparator module monitors the current and shuts down the PWM output through an interrupt mechanism when an overcurrent condition is detected. The specific steps include: Power on the system to make the MCU work normally; Initialize the MCU's IO port and complete the MCU pin configuration; Configure the comparator module and interrupt mechanism, and execute the shutdown of PWM pin output in the interrupt.
2. The overcurrent protection method based on the internal comparator of a chip according to claim 1, characterized in that: Initializing the IO port of the MCU includes the following steps: In the MCU, the IO port is initialized and configured as a multiplexing function, and the IO port is used as the IO port for the input of the comparator module; The comparator module receives system information through the IO port and compares the system information to monitor the current information in the system.
3. The overcurrent protection method based on the internal comparator of a chip according to claim 1, characterized in that: The configuration of the comparator module includes the following steps: respectively configuring the positive input terminal and the negative input terminal of the comparator module; Among them, the positive input terminal or the negative input terminal is connected to the system power supply voltage, the negative input terminal or the positive input terminal is connected to the output of the system circuit, the system power supply voltage is configured as the reference voltage, and the current output in the system circuit is converted and configured as the bus voltage.
4. The overcurrent protection method based on the internal comparator of a chip according to claim 3, characterized in that: The interrupt mechanism is that when the comparator module detects that the bus voltage is greater than the reference voltage, it indicates that an overcurrent has occurred in the system circuit and an interrupt signal is generated. The MCU turns off the PWM pin output based on the interrupt signal.
5. The overcurrent protection method based on the internal comparator of a chip according to claim 4, characterized in that: After the interrupt mechanism triggers the shutdown of the PWM pin output, the PWM pin is switched to normal IO mode, and the time and cause of the fault are recorded.
6. An overcurrent protection system based on an internal comparator of a chip according to the protection method of any one of claims 1 to 5, characterized in that: The system at least includes an MCU and a controller having a comparator module therein. The MCU executes the above protection method to achieve overcurrent protection of the system.