Shake elimination method for mechanical microswitch, switch and control device
By setting an elastic spring between the first contact and the second contact of the mechanical microswitch, and judging the signal validity by the status switching of the mark A, the repeated pressing problem caused by the jitter of the mechanical microswitch is solved, and lower delay and more accurate user control are achieved.
Patent Information
- Application Number
- CN202510637836.0
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-05-19
- Publication Date
- 2025-06-17
- Estimated Expiration
- 2045-05-19
AI Technical Summary
The mechanical micro switch will experience unstable voltage jitter due to the elastic action of the contacts during the moment of pressing and releasing, which may cause a single key press to be misidentified as multiple times, which increases the time delay of the switch pressing action to the host.
By setting a resilient spring for triggering between the first contact point and the second contact point of the mechanical micro switch, the main control chip detects the state of the reed trigger signal, and determines whether the signal output by the first contact is an invalid signal caused by jitter through the state switching of the mark A, thereby preventing the main control chip from repeatedly outputting the pressed signal.
It effectively avoids invalid signals caused by reed jitter, reduces the occurrence of repeated pressing signals, reduces the time delay of the switch pressing action to the host, and improves the accuracy of user control.
Smart Images

Figure CN120165670A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of microswitch response algorithms, and particularly to a debouncing method, switch and control device for a mechanical microswitch. Background Art
[0002] A mechanical microswitch generally consists of components such as a housing, a reed, a contact, and a push rod. When the microswitch is pressed: when an external pressure is applied to the switch, the pressure is transmitted through the switch structure to the push rod of the switch. The push rod moves downward under the force, squeezing the reed to cause elastic deformation. As the deformation degree of the reed increases, when it reaches a specific degree, the reed contacts the bottom contact of the switch. After contact, the circuit forms a path, and current can pass through, thereby generating an electrical signal. This electrical signal will be transmitted along the internal circuit of the device to the main control chip. The main control chip converts it into a corresponding key command and transmits it to the host, and the host performs corresponding operations accordingly. When the microswitch is released: when the external force applied to the switch disappears, that is, when the switch is released, the pressure on the push rod is released. At this time, the reed returns to its initial state by virtue of its own elastic force. As the reed resets and separates from the bottom contact of the switch, the circuit is disconnected, the electrical signal stops transmitting, and the host receives the signal change and knows that the switch has been released. Thus, a complete detection of the microswitch operation is completed.
[0003] Generally speaking, the reed and the top contact of a mechanical microswitch are in a normally closed state, and the reed and the bottom contact are in a normally open state. Common microswitch processing algorithms rely on programs to capture the contact and disconnection of the reed and the bottom contact of the switch to determine the pressing and releasing actions of the switch. However, at the moment of pressing and releasing a mechanical microswitch, due to the elastic effect of the contact, there will be a voltage instability jitter phenomenon, which may cause a single key operation to be misrecognized as multiple operations. Therefore, usually, after detecting a change in the switch state (such as the level changing from high to low, considering the switch is pressed), the software debouncing algorithm does not immediately recognize the pressed state of the switch as valid, but delays for a certain period of time (such as 10 - 20 milliseconds. This delay refers to the time from pressing the switch to the computer receiving the signal). During this period, the program continuously detects the switch state. If the switch state remains stable during the delay (always in the pressed state), the changed state of the switch is confirmed as valid; if the switch state changes again during the delay, it is considered a jitter and this change is ignored. Because the debouncing delay time is increased, the time for the pressing action of the switch to be sent to the host side is also correspondingly delayed. In addition, it takes time for the reed to reach the bottom contact from the top contact. For microswitches of different brands and different product batches, this time is different and may range from 2 - 15 milliseconds. All these will increase the delay of the microswitch.
[0004] The phenomenon of repeated pressing caused by the reed jitter of a mechanical microswitch is particularly likely to occur in high-speed microswitches, such as mice, game pads, and customized keyboards. The shape and material of the reed, as well as the force applied by the user when pressing, will all affect subsequent debouncing. Although adjusting the debouncing time of the software debouncing process by directionally testing the reed jitter can significantly reduce the repeated pressing phenomenon caused by jitter, the number of presses required for high-speed microswitches is too large, and the change in the jitter performance of the reed is too fast, which also makes the software debouncing time obtained by directional test adjustment become less and less reliable. Summary of the Invention
[0005] To solve one or more problems existing in the prior art, the present invention provides a debouncing method for a mechanical microswitch. The technical solution adopted by the present invention to solve the above problems is: a debouncing method for a mechanical microswitch, which includes: circuit connection, the first contact and the second contact of the mechanical microswitch are respectively electrically connected to different pins of the main control chip, and an elastic reed for triggering is provided between the first contact and the second contact; Trigger signal, pressing the mechanical microswitch once causes the reed to trigger the first contact and the second contact in sequence. When the first contact is triggered, a trigger signal is output and recorded as the first trigger signal. After receiving the first trigger signal, the main control chip performs timing. After the timing ends, it is judged whether there is a trigger signal output at the first contact. If there is a trigger signal output, this signal is recorded as the second trigger signal. When the second contact is triggered, a trigger signal is output and recorded as the third trigger signal. When the main control chip receives the third trigger signal, it is judged that a single pressing action is completed; Marking, when the main control chip receives the second trigger signal, it performs recording and records it as mark A. At this time, the state of mark A switches to the first state. When the main control chip receives the third trigger signal, it performs recording and switches the state of mark A to the second state; Debouncing, when the main control chip receives the first trigger signal, the main control chip detects the state of mark A. If the state of mark A is the first state, the main control chip judges that the current first trigger signal is an invalid signal. If the state of mark A is the second state, the main control chip judges that the current first trigger signal is a valid signal.
[0006] In some embodiments, when the levels of the first trigger signal and the second trigger signal are the same, the main control chip judges that the mechanical microswitch is pressed.
[0007] In some embodiments, the timing is the delay time of software debouncing and / or hardware debouncing.
[0008] A switch is implemented by the above method. A control device is provided with a first switch, and the first switch is a switch implemented by the above method.
[0009] The technical effect achieved by the present invention is that by detecting the state of the above-mentioned marker A to determine whether the mechanical micro switch has completed a single switch press, that is, both the first and second contacts are triggered by the reed and corresponding signals are output. Among them, the state of the marker A is used to determine whether the signal output when the first contact is triggered is an invalid signal or noise caused by reed jitter, thereby avoiding the main control chip from determining the signals output by the first contact multiple times as switch press signals, and avoiding the main control chip from repeatedly outputting press signals during a single switch press and causing errors in user control. BRIEF DESCRIPTION OF THE DRAWINGS
[0010] Figure 1 is a schematic block diagram of the present invention; Figure 2 is a schematic flowchart of a single press of the present invention; Figure 3 is a schematic structural diagram of a mechanical micro switch; Figure 4 is a timing diagram of the electrical level during detection of the present invention.
[0011] In the figure, 1 is the housing; 10 is the protrusion; 2 is the push rod; 3 is the reed; 30 is the contact; 4 is the first terminal; 5 is the second terminal; 50 is the second contact; 6 is the third terminal; 60 is the first contact; 7 is the level waveform of the first contact before debouncing; 8 is the level waveform of the first contact after debouncing; 9 is the level waveform of the second contact. DETAILED DESCRIPTION OF THE EMBODIMENTS
[0012] In order to make the above objects, features, and advantages of the present invention more understandable, the following detailed description of the specific embodiments of the present invention will be given with reference to the accompanying drawings. Many specific details are set forth in the following description in order to fully understand the present invention. However, the present invention can be implemented in many other ways different from the description herein, and those skilled in the art can make similar improvements without departing from the connotation of the present invention. Therefore, the present invention is not limited by the specific embodiments disclosed below.
[0013] As Figure 1 , Figure 2 shown, the present invention discloses a debouncing method for a mechanical micro switch, which includes: circuit connection, the first contact and the second contact of the mechanical micro switch are respectively electrically connected to different pins of the main control chip, and an elastic reed for triggering is provided between the first contact and the second contact; Trigger signal. Pressing the mechanical microswitch once causes the reed to trigger the first contact and the second contact in sequence. When the first contact is triggered, a trigger signal is output and recorded as the first trigger signal. After receiving the first trigger signal, the main control chip starts timing. After the timing ends, it judges whether there is a trigger signal output from the first contact. If there is a trigger signal output, this signal is recorded as the second trigger signal. When the second contact is triggered, a trigger signal is output and recorded as the third trigger signal. When the main control chip receives the third trigger signal, it judges that a single press action is completed. When the levels of the first trigger signal and the second trigger signal are the same, the main control chip judges that the mechanical microswitch is pressed. The timing is the delay time for software debounce and / or hardware debounce; Mark. When the main control chip receives the second trigger signal, it performs recording and records it as mark A. At this time, the state of mark A switches to the first state. When the main control chip receives the third trigger signal, it performs recording and switches the state of mark A to the second state; Debounce. When the main control chip receives the first trigger signal, the main control chip detects the state of mark A. If the state of mark A is the first state, the main control chip judges that the current first trigger signal is an invalid signal. If the state of mark A is the second state, the main control chip judges that the current first trigger signal is a valid signal.
[0014] Specifically, in combination with Figure 3 the shown mechanical microswitch structure, a first terminal 4, a second terminal 5, and a third terminal 6 are provided on the outer shell 1, which are used for electrical connection with the main control chip. A push rod 2 is installed on the outer shell 1. A protrusion 10 that cooperates with the push rod 2 is provided in the cavity of the outer shell 1. The first end of the reed 3 is fixed to the first terminal 4. The reed 3 abuts against the protrusion 10 and can be pressed and deformed by the push rod 2. The second terminal 5 is connected to the second contact 50, and the third terminal 6 is connected to the first contact 60. A contact 30 is provided at the second end of the reed 3, and the contact 30 is located between the first contact 60 and the second contact 50.
[0015] In the normal state, the contact 30 of the reed 3 forms a normally closed circuit with the first contact 60. When the push rod 2 is pressed, the reed 3 deforms, causing its contact 30 to leave the first contact 60 and contact the second contact 50 to form a new closed circuit. During the deformation of the reed 3, the contact 30 at its second end will swing between the first contact 60 and the second contact 50, causing the first contact 60 and the second contact 50 to continuously form and release the closed circuit until the swing amplitude of the reed 3 is not sufficient to support its continuation.
[0016] In Figure 3When the switch shown is applied with the above method, the second terminal 5 and the third terminal 6 are respectively connected to different pins of the main control chip.
[0017] Specifically, for the circuit connection, the pins of the main control chip electrically connected to the first contact and the second contact are configured in the GPIO input mode; during use, the main control chip continuously detects the first contact and the second contact to obtain a trigger signal, and when the levels of the first trigger signal and the second trigger signal are the same, the main control chip determines that the mechanical microswitch is pressed. For the continuous detection of the main control chip, it is: the level status detection is performed on the pins electrically connected to the first contact and the second contact by using the interrupt method or the polling method, where the interrupt method is that when the pin level changes, the main control chip immediately responds and executes the corresponding interrupt handling program, and the polling method is that the main control chip periodically checks the pin level status at a certain time interval and executes the corresponding processing program according to the pin level status.
[0018] Regarding the description of determining that the mechanical microswitch is pressed through the first trigger signal and the second trigger signal: Combining Figure 3 、 Figure 4 , under normal conditions, the contact 30 of the reed 3 forms a normally closed circuit with the first contact 60, so the level status of the pin connected to the first contact 60 changes first, that is, Figure 4 the level waveform 7 (first trigger signal) of the first contact before debouncing, and then after timing (debouncing), the level waveform 8 (second trigger signal) of the first contact after debouncing appears, and the level waveform 9 (third trigger signal) of the second contact appears last (completing a single switch press); the level status of the pin connected to the first contact changes first, and the change in the level status of the corresponding pin of the second contact is later than the change in the level status of the corresponding pin of the first contact, so faster response can be obtained by detecting the level status of the corresponding pin of the first contact (relative to detecting the second contact), thereby achieving the effect of low latency.
[0019] Combined with the above, after the level waveform 8 (the second trigger signal) of the first contact debounce appears, the main control chip determines that the switch is pressed and outputs a press signal. At this time, the contact of the reed has not reached the second contact and there is jitter. Then, the jitter will cause the contact of the reed to contact the first contact again. Since the second trigger signal has been sent and the first contact is contacted by the jittery contact of the reed at this time, a first trigger signal will be sent (the trigger signal output by the first contact switches between the first trigger signal and the second trigger signal). At this time, the first trigger signal is an invalid signal caused by jitter. If it is directly used as a valid signal, it will cause the press signal to be sent repeatedly. The shorter the timing (debounce delay) between the first trigger signal and the second trigger signal, the faster the response can be obtained, but the more invalid signals caused by jitter will be, and the more repeated press signals will be generated.
[0020] Combined Figure 2 As shown, by establishing a flag A and switching the state of the flag A when the main control chip obtains the second trigger signal and the third trigger signal, the main control chip can judge the current switch pressing state when obtaining the first trigger signal, that is, judge whether the switch has not completed a single press action or the switch has completed a single press action. Among them, when both the first contact and the second contact are contacted by the contact of the reed, it is considered that a single switch press action is completed. The main control chip determines whether the first trigger signal output by the first contact is an invalid signal according to the judgment result of the current switch pressing state, and finally reduces the invalid signals caused by the reed jitter, thereby avoiding the repeated sending of the press signal.
[0021] The present invention also discloses a switch, and the switch applies the above debounce method, for example Figure 3 the mechanical microswitch shown. The present invention also discloses a control device, and the control device is provided with a first switch, and the first switch is a switch applying the above debounce method.
[0022] To sum up, by detecting the state of the above flag A to judge whether the mechanical microswitch has completed a single switch press, that is, both the first and second contacts are triggered by the reed and output corresponding signals. Among them, the state of the flag A is used to judge whether the signal output when the first contact is triggered is an invalid signal or noise caused by the reed jitter, thereby avoiding the main control chip from determining the signals output by the first contact multiple times as switch press signals, and avoiding the main control chip from repeatedly outputting press signals during a single switch press and causing errors in user control.
[0023] In the description of the present invention, it should be noted that the orientation or positional relationship indicated by the terms "center", "upper", "lower", "left", "right", "vertical", "horizontal", "inner", "outer", etc. is based on the orientation or positional relationship shown in the drawings. It is only for the convenience of describing the present invention and simplifying the description, rather than indicating or implying that the device or element referred to must have a specific orientation, be constructed and operated in a specific orientation, and therefore should not be construed as a limitation to the present invention. In addition, the terms "first" and "second" are only used for descriptive purposes and cannot be construed as indicating or implying relative importance. Among them, the terms "first position" and "second position" are two different positions.
[0024] The embodiments described above only represent one or more implementation manners of the present invention. The description is relatively specific and detailed, but it should not be construed as a limitation to the patent of the present invention. It should be noted that for those of ordinary skill in the art, without departing from the concept of the present invention, several modifications and improvements can still be made, and these all belong to the protection scope of the present invention. Therefore, the protection scope of the present invention should be subject to the appended claims.
Claims
1. A debouncing method for a mechanical micro switch, characterized in that: Line connection, the first contact and the second contact of the mechanical micro switch are electrically connected to different pins of the main control chip respectively, and a triggering elastic spring is provided between the first contact and the second contact; A trigger signal, pressing the mechanical micro switch once causes the reed to trigger the first contact and the second contact in sequence, and when the first contact is triggered, a trigger signal is output and recorded as a first trigger signal. After receiving the first trigger signal, the main control chip performs timing, and after the timing ends, it is determined whether the first contact has a trigger signal output, and if so, this signal is recorded as a second trigger signal. When the second contact is triggered, a trigger signal is output and recorded as a third trigger signal. When the main control chip receives the third trigger signal, it is determined that a single press action is completed; Mark, when the main control chip receives the second trigger signal, it executes recording and records it as mark A, at which time the state of mark A is switched to the first state, and when the main control chip receives the third trigger signal, it executes recording and switches the state of mark A to the second state; Debouncing: when the main control chip receives the first trigger signal, the main control chip detects the state of the mark A. If the state of the mark A is the first state, the main control chip determines that the current first trigger signal is an invalid signal. If the state of the mark A is the second state, the main control chip determines that the current first trigger signal is a valid signal.
2. The debouncing method for a mechanical micro switch according to claim 1, characterized in that: When the levels of the first trigger signal and the second trigger signal are consistent, the main control chip determines that the mechanical micro switch is pressed.
3. The debouncing method for a mechanical micro switch according to claim 1, characterized in that: The timing is the delay time of software debouncing and / or hardware debouncing.
4. A switch, characterized in that: The switch is applied with the method described in any one of claims 1-3.
5. A control device, characterized in that: The control device is provided with a first switch, and the first switch is the switch according to claim 4.
Citation Information
Patent Citations
Signal generator with wave shape shaking-eliminating effect and shake-eliminating method
CN103178810A
Relay detection device and method, relay, high-voltage distribution box and electric vehicle
CN111665437A
Relay zero-crossing protection method and circuit
CN113936961A
Touch microswitch implementation method based on Hall element and touch microswitch
CN118554937A
Electronic equipment data protection method and system and nonvolatile storage medium
CN119442354A