Circuit and method for detecting high and low levels of electric tool through GPIO (General Purpose Input / Output) port

By connecting the RC circuit in the power tool and setting the high and low level state voltage range of the GPIO port, the problem of inaccurate direct charging detection is solved, more accurate switching state detection is achieved, and the product reliability is improved.

CN119044581APending Publication Date: 2024-11-29ZHANGJIAGANG HUAJIE ELECTRONICS
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202411180892.8
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-08-27
Publication Date
2024-11-29

AI Technical Summary

Technical Problem

In the prior art, the direct charging method is used to detect the level status of the GPIO port inaccurately, and the default voltage status range is not suitable for actual power tool applications, resulting in the MCU being unable to accurately determine the switch status.

Method used

By connecting the RC circuit in parallel to the high-level power supply, set the GPIO port to output a low level to discharge the capacitor, then switch to the input state detection voltage, use the dual RC circuit to perform level state detection, and set the high and low level state voltage range of the GPIO port to display high and low level state voltage range. To filter out interference and improve detection accuracy.

Benefits of technology

It effectively improves the accuracy of GPIO port to detect power tool switches or steering status, enhances product reliability, avoids interference from electrical components, and improves the reliability of detection applications.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119044581A_ABST
    Figure CN119044581A_ABST
Patent Text Reader

Abstract

The invention relates to the technical field of electric tool switch or steering state detection, and particularly provides a circuit and a method for detecting high and low levels of an electric tool through a GPIO (General Purpose Input / Output) port, the circuit comprises a high-level power supply, and the high-level power supply is connected in parallel with an RC circuit and a switch button; a detection point is arranged on the RC circuit, and the GPIO port is connected to the detection point; the method comprises the following steps: S1, setting the level of a GPIO port of an MCU; s2, setting a GPIO port to be in an output state, and outputting a low level first; s3, the GPIO port is set to be in an input state, and the current level state of the GPIO port is read; s4, judging the on-off state of the switch key according to the level state; the mode that the GPIO port is firstly discharged and then charged is adopted, and interference existing in the using process of the electric tool switch can be filtered out; by setting the voltage range of the high and low level states of the GPIO port, the interference caused by the application of an electric appliance element can be avoided, the scheme design is flexible, and the reliability of product detection application is effectively improved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the technical field of electric tool switch or steering state detection, and in particular to a circuit and method for detecting high and low levels of an electric tool through a GPIO port. Background Art

[0002] Currently, in tools, the switch or steering state of the tool, the steering state, etc. are all detected using the GPIO port of the MCU. The default voltage state of the 3.3V voltage GPIO port is 0 to 0.9V for low level, and 2.2V to 3.3V for high level. By detecting the high and low levels of the GPIO port, the forward and reverse rotation of the tool can be judged. Different microcontrollers have different high and low level thresholds, but generally there is an empty area between the voltage used to judge the low level and the voltage used to judge the high level. For example, when the voltage detected by the 3.3V voltage GPIO port is 1.5V, the MCU cannot actually accurately judge whether the voltage is high voltage or low voltage, which will cause the MCU to fail to judge.

[0003] Theoretically, as long as the voltage detected by the GPIO port is lower than 0.9V or higher than 2.2V, the method of detecting high and low levels by the GPIO port can accurately determine the state of the switch. However, in actual applications, we found that due to the resistance of the switch itself and the interference in the circuit, when the switch is closed to reduce the voltage of the GPIO port, the voltage cannot drop below 0.9V normally, resulting in the MCU being unable to detect the low level.

[0004] The published Chinese patent, with publication number CN109002410A, discloses a GPIO port detection method, including: setting the GPIO port to an output high level mode, setting the GPIO port to a high impedance input mode after a first set time, detecting the level of the GPIO port to obtain a first level; setting the GPIO port to an output low level mode, setting the GPIO port to a high impedance input mode after a first set time, detecting the level of the GPIO port to obtain a second level; and obtaining the identification state of the GPIO port based on the two detection results.

[0005] The detection method disclosed in the above patent uses direct charging to detect the level state, but due to factors such as interference from electrical operation and electronic components themselves, the accuracy of the detection will be affected; in addition, due to interference from the electronic components themselves, such as the contact resistance of the switch button, vibration interference from the machine operation, etc., when the switch is pressed, the port voltage of the GPIO port may exceed 0.9V. Therefore, the default voltage state range of the GPIO port is no longer suitable for actual detection applications of power tools. Summary of the invention

[0006] In view of the shortcomings of the prior art mentioned above, the object of the present invention is to provide a circuit and method for detecting the high and low levels of an electric tool through a GPIO port, so as to solve the problems in the prior art of inaccurately detecting the level status of the GPIO port by direct charging and the default voltage state range being not suitable for actual electric tool application detection.

[0007] To achieve the above-mentioned object and other related objects, the present invention provides a circuit for detecting high and low levels of an electric tool through a GPIO port, the circuit comprising a high-level power supply, an RC circuit and a switch button connected in parallel to the high-level power supply; A detection point is provided on the RC circuit, and the GPIO port is connected to the detection point.

[0008] In an embodiment of the present invention, the high-level power supply is used to provide a 3.3V voltage.

[0009] In one embodiment of the present invention, two RC circuits are provided, and the two RC circuits are connected in parallel to the high-level power supply.

[0010] In one embodiment of the present invention, the two RC circuits are each composed of a resistor R and a capacitor C, the detection point is set between the resistor R and the capacitor C, and the other end of the capacitor C is grounded; a low level is first output through the GPIO port to discharge the capacitor C of the RC circuit.

[0011] In one embodiment of the present invention, the resistance of the resistor R is 100K, and the capacity of the capacitor C is 0.1uF.

[0012] A method for detecting high and low levels of an electric tool through a GPIO port, comprising the circuit, comprises the following steps: S1. Set the level of the MCU's GPIO port to large hysteresis; S2, set the GPIO port to output state, first output low level, keep it for 5ms, and discharge the capacitor C of the RC circuit; S3, set the GPIO port to input state, wait 30ms, and read the current level state of the GPIO port; S4. Determine the on / off state of the switch button by detecting the current level state of the GPIO port.

[0013] In one embodiment of the present invention, the low level state of the GPIO port is set to 0-2.2V, and the high level state is set to 2.3-3.3V.

[0014] As described above, the circuit and method for detecting the high and low levels of an electric tool through a GPIO port of the present invention have the following beneficial effects: 1. The present invention can discharge first and then charge by setting the GPIO port to output first and then input, and detect the GPIO port voltage after charging. This method can effectively filter out the interference of residual current during the use of the power tool switch; by setting the voltage range of the high and low level states of the GPIO port, it can avoid the current interference caused by the application of the electrical components themselves, effectively improve the accuracy of using the GPIO port to detect the switch or steering state of the power tool, and thus improve the reliability of the product; 2. By setting two parallel RC circuits, the two RC circuits are connected to the GPIO ports respectively to detect the level status at the same time. The two RC circuits can calibrate each other. If and only if the detection value of the GPIO port connected to the two RC circuits is within a reasonable error range, the detection value is considered valid. Then, the power tool switch or steering state is judged by the effective detection value, thereby improving the reliability of using the GPIO port to detect the power tool switch or steering state; 3. The present invention adopts the method of discharging the GPIO port first and then charging it, which can filter out the interference existing in the process of using the power tool switch; setting the voltage range of the high and low level states of the GPIO port according to the actual use of the power tool can avoid the interference caused by the application of the electrical components themselves. The scheme is flexible in design and effectively improves the reliability of product detection applications; this scheme adopts a dual RC circuit to perform two groups of detections at the same time, which increases the comparability of the detection data and further improves the reliability of product detection applications. BRIEF DESCRIPTION OF THE DRAWINGS

[0015] Figure 1 The diagram shows the circuit principle for detecting the high and low levels of the electric tool through the GPIO port disclosed in Example 1.

[0016] Figure 2 It is a schematic diagram showing the detection level state of the dual RC circuit disclosed in the first embodiment.

[0017] Component number description High-level power supply 1; RC circuit 2; switch button 3; detection point 4. DETAILED DESCRIPTION

[0018] The following is a description of the implementation of the present invention by means of specific embodiments. Those skilled in the art can easily understand other advantages and effects of the present invention from the contents disclosed in this specification.

[0019] See also Figure 1 to Figure 2It should be noted that the structures, proportions, sizes, etc. illustrated in the drawings in this specification are only used to match the contents disclosed in the specification for people familiar with this technology to understand and read, and are not used to limit the conditions under which the present invention can be implemented. Therefore, they have no substantial technical significance. Any structural modification, change in proportion or adjustment of size should still fall within the scope of the technical contents disclosed in the present invention without affecting the effects and purposes that can be achieved by the present invention.

[0020] Example 1, please refer to Figure 1 This embodiment provides a circuit for detecting high and low levels of an electric tool through a GPIO port, wherein the circuit includes a high-level power supply 1, which is used to provide a 3.3V voltage; an RC circuit 2 and a switch button 3 are connected in parallel to the high-level power supply 1; a detection point 4 is provided on the RC circuit 2, and the GPIO port is connected to the detection point 4.

[0021] The RC circuit 2 is provided with two, and the two RC circuits 2 are connected in parallel to the high-level power supply 1; the two RC circuits 2 are composed of a resistor R and a capacitor C, the resistance value of the resistor R is 100K, and the capacity of the capacitor C is 0.1uF; the detection point 4 is set between the resistor R and the capacitor C, and the other end of the capacitor C is grounded; the GPIO port is first output with a low level to discharge the capacitor C of the RC circuit 2, and then the GPIO port is set to the input state, the capacitor C is charged, and finally the level state of the GPIO port is detected. The specific working principle of the present invention is: the capacitor C is discharged by first using the GPIO port to output a low level, and then switched to the detection state to detect the positive electrode voltage of the capacitor C. At this time, the voltage detected by the GPIO port has a trend of changing from 0V upward. If the switch button 3 is closed, even if the high-level power supply 1 cannot be completely short-circuited due to the influence of the switch resistance or other factors, the voltage detected by the GPIO port will not rise to 2.2V. Since the voltage of the GPIO port detected by the MCU has not reached 2.2V or above, it still determines that the current GPIO port detects a low-level state, and then determines that the power tool is in a low-level state; if the switch button 3 is disconnected, the voltage detected by the GPIO port will quickly rise to above 2.2V. At this time, the GPIO port is in a high-level state. If the MCU determines that the GPIO port is high, it determines that the power tool is in a high-level state.

[0022] The present invention sets two RC circuits 2 connected in parallel. The two RC circuits 2 are respectively connected to the GPIO ports to perform level status detection at the same time. The two RC circuits 2 can calibrate each other. If and only if the detection value of the GPIO port connected to the two RC circuits 2 is within a reasonable error range, the detection value is deemed valid. Then, the power tool switch or steering state is judged by the effective detection value, thereby improving the reliability of using the GPIO port to detect the power tool switch or steering state.

[0023] Example 2, please refer to Figure 2 , Figure 2 The X-axis is voltage, and the Y-axis is logic state; this embodiment provides a method for detecting the high and low levels of an electric tool through a GPIO port, including the circuit for detecting the high and low levels of an electric tool through a GPIO port as described in Embodiment 1, specifically comprising the following steps: S1. Set the level of the GPIO port of the MCU to large hysteresis. Setting the level to large hysteresis means setting the hysteresis of the level to a larger value in an electronic circuit or system. Hysteresis is a common characteristic in electronic systems to avoid unstable output when the signal fluctuates frequently near a certain threshold. In a system with hysteresis, when the input signal rises to a certain threshold (called the upper threshold), the output state changes; and when the input signal drops, the output state will change again only when it drops to another lower threshold (called the lower threshold). Larger hysteresis means a larger gap between the upper threshold and the lower threshold. This can enhance the system's ability to resist noise or interference and reduce frequent output switching due to small fluctuations in the input signal.

[0024] S2, set the GPIO port to output state, first output low level, keep it for 5ms, and discharge the capacitor C of RC circuit 2; S3, set the GPIO port to input state, at this time the voltage detected by the GPIO port is changing from 0V upward; wait for 30ms and read the current level state of the GPIO port; S4. Determine the on / off state of the switch button 3 by detecting the current level state of the GPIO port; if the switch button 3 is closed, even if the high-level power supply 1 cannot be completely short-circuited due to the influence of the switch resistance or other factors, the voltage detected by the GPIO port will not rise to 2.2V. Since the GPIO port voltage detected by the MCU has not reached 2.2V or above, it still determines that the current GPIO port detects a low-level state, and then determines that the power tool is in a low-level state; if the switch button 3 is disconnected, the voltage detected by the GPIO port will quickly rise to above 2.2V, and the GPIO port is in a high-level state. If the MCU determines that the GPIO port is high, it determines that the power tool is in a high-level state.

[0025] This embodiment sets the GPIO port to output first and then input, so that it can discharge first and then charge, and detect the GPIO port voltage after charging. This method can effectively filter out the interference of residual current when the power tool switch is used.

[0026] Example 3, based on Example 2, this example sets the low level state of the GPIO port to 0-2.2V and the high level state to 2.3-3.3V. For this setting range, this example detects the levels of the on and low level states of multiple groups of electric tools through the GPIO port of the MCU, and the detection results are shown in the following table:

[0027] As can be seen from the above table, the detection voltage value of the power tool in the low-level state will exceed 0.9V, but be lower than 2.2V; the detection voltage value of the power tool in the high-level state is higher than 2.3V. Therefore, setting the low-level state of the GPIO port to 0-2.2V and the high-level state to 2.3-3.3V can effectively detect the switch or steering state of the power tool. This embodiment can avoid the current interference caused by the application of the electrical components themselves by setting the voltage range of the high and low level states of the GPIO port, effectively improve the accuracy of using the GPIO port to detect the switch or steering state of the power tool, and thus improve the reliability of the product.

[0028] In summary, the method described in the present invention can overcome the interference problem when the MCU detects the switch state, and effectively improve the MCU's detection accuracy of the start switch or the steering switch. In addition, the present solution uses a dual RC circuit 2 to perform two sets of detections at the same time, which increases the comparability of the detection data and further improves the reliability of product detection applications. Therefore, the present invention effectively overcomes various shortcomings in the prior art and has a high industrial utilization value.

[0029] The above embodiments are merely illustrative of the principles and effects of the present invention, and are not intended to limit the present invention. Anyone familiar with the art may modify or alter the above embodiments without departing from the spirit and scope of the present invention. Therefore, all equivalent modifications or alterations made by a person of ordinary skill in the art without departing from the spirit and technical concept disclosed by the present invention shall still be covered by the claims of the present invention.

Claims

1. A circuit for detecting high and low levels of an electric tool through a GPIO port, characterized in that: The circuit comprises a high-level power supply, to which an RC circuit and a switch button are connected in parallel; A detection point is provided on the RC circuit, and the GPIO port is connected to the detection point.

2. The circuit for detecting high and low levels of electric tools through the GPIO port according to claim 1, characterized in that: The high-level power supply is used to provide a 3.3V voltage.

3. The circuit for detecting high and low levels of electric tools through the GPIO port according to claim 1, characterized in that: There are two RC circuits, and the two RC circuits are connected in parallel to the high-level power supply.

4. The circuit for detecting high and low levels of electric tools through the GPIO port according to claim 3, characterized in that: The two RC circuits are composed of a resistor R and a capacitor C. The detection point is set between the resistor R and the capacitor C, and the other end of the capacitor C is grounded. A low level is first output through the GPIO port to discharge the capacitor C of the RC circuit.

5. The circuit for detecting high and low levels of electric tools through the GPIO port according to claim 4, characterized in that: The resistance value of the resistor R is 100K, and the capacity of the capacitor C is 0.1uF.

6. A method for detecting high and low levels of an electric tool through a GPIO port, comprising the circuit described in any one of claims 1 to 5, characterized in that: The steps include: S1. Set the level of the MCU's GPIO port to large hysteresis; S2, set the GPIO port to output state, first output low level, keep it for 5ms, and discharge the capacitor C of the RC circuit; S3, set the GPIO port to input state, wait 30ms, and read the current level state of the GPIO port; S4. Determine the on / off state of the switch button by detecting the current level state of the GPIO port.

7. The method for detecting multiple voltage ranges using a GPIO port according to claim 6, characterized in that: The low level state of the GPIO port is set to 0-2.2V, and the high level state is set to 2.3-3.3V.