A debounce method for a mechanical micro switch, a switch and a control device
By setting the state judgment of the elastic reed and mark A in the mechanical micro switch, the voltage instability problem caused by the reed jitter is solved, low-latency and high-stability switching operation is achieved, and misidentification and delay phenomena are reduced.
Patent Information
- Application Number
- CN202510637836.0
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2025-05-19
- Publication Date
- 2025-09-16
- Estimated Expiration
- 2045-05-19
AI Technical Summary
Mechanical micro switches are prone to unstable voltage jitter at the moment of pressing and releasing due to the elastic effect of the contacts, causing one key operation to be mistakenly recognized as multiple times, increasing the delay and instability of switch pressing, which is especially obvious in high-speed micro switches.
By setting an elastic reed between the first contact and the second contact of the mechanical micro switch, and using the main control chip to detect the level change of the trigger signal, and combining the status of mark A to judge the invalid signal caused by the reed jitter, software and hardware debouncing is achieved to avoid repeated output of the press signal.
It effectively reduces invalid signals caused by reed jitter, reduces the error of repeated output of pressing signals by the main control chip, and improves the stability and response speed of the switch operation.
Smart Images

Figure CN120165670B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of micro switch response algorithms, and in particular to a debouncing method, a switch and a control device for a mechanical micro switch. Background Art
[0002] A mechanical microswitch typically consists of a housing, a reed, contacts, and a push rod. When the microswitch is pressed: When 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 is forced downward, squeezing the reed and causing it to elastically deform. As the reed deformation increases, when it reaches a certain level, the reed and the bottom contact of the switch come into contact. After contact, a circuit is formed, allowing current to flow, thereby generating an electrical signal. This electrical signal is transmitted along the internal circuit of the device to the main control chip, which converts it into a corresponding key command and transmits it to the host computer, which performs the corresponding operation 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 due to its own elastic force. As the reed resets and separates from the bottom contact of the switch, the circuit is disconnected, and the electrical signal transmission stops. The host receives the signal change and knows that the switch has been released, thus completing a complete microswitch operation test.
[0003] Generally speaking, the reed and top contact of a mechanical microswitch are in a normally closed state, and the reed and bottom contact are in a normally open state. Common microswitch processing algorithms rely on the program to capture the contact and disconnection between the reed and the bottom contact of the switch to determine whether the switch is pressed or released. However, at the moment of pressing and releasing, the mechanical microswitch will experience unstable voltage jitter due to the elasticity of the contacts, which may cause a single key operation to be mistakenly recognized as multiple key operations. For this reason, the usual software debounce algorithm does not immediately determine that the switch is pressed and valid after detecting a change in switch state (such as the voltage level changing from high to low, which means the switch is pressed). Instead, it delays for a certain period of time (such as 10-20 milliseconds, which refers to the time from when the switch is pressed to when the computer receives the signal). During this period, the program continuously detects the switch status. If the switch status remains stable during the delay period (always in the pressed state), the switch status change is confirmed to be valid. If the switch status changes again during the delay period, it is considered to be jitter and the change is ignored. Because the debounce delay time is increased, the time it takes for the switch pressing action to be sent to the host end is also delayed accordingly. In addition, it takes time for the reed to reach the bottom contact from the top contact. Different brands of micro switches have different product batches, and this time may vary (2-15 milliseconds). These will increase the delay of the micro switch.
[0004] Repeated clicks caused by reed jitter in mechanical micro switches are particularly common in high-speed micro switches, such as those used in mice, game controllers, and customized keyboards. The reed's shape, material, and the force applied when the user presses the switch all affect subsequent debounce. While targeted reed jitter testing and adjusting the debounce time during software debounce can significantly reduce repeated clicks caused by jitter, the high number of clicks required for high-speed micro switches and the rapid changes in reed jitter performance make the software debounce time adjusted through targeted testing increasingly unreliable. Summary of the Invention
[0005] To address one or more problems existing in the prior art, the present invention provides a debouncing method for a mechanical microswitch. The present invention employs a technical solution to address the aforementioned problems, comprising: a circuit connection, wherein a first contact and a second contact of the mechanical microswitch are electrically connected to different pins of a main control chip, respectively; a triggering elastic spring is disposed between the first contact and the second contact;
[0006] a trigger signal, wherein pressing the mechanical micro switch 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 a first trigger signal. After receiving the first trigger signal, the main control chip performs timing. After the timing ends, it is determined whether the first contact outputs a trigger signal. If a trigger signal is output, 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 the single press action is completed;
[0007] 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.
[0008] 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.
[0009] In some embodiments, the main control chip determines that the mechanical micro switch is pressed when the levels of the first trigger signal and the second trigger signal are consistent.
[0010] In some embodiments, the timing is a delay time of software debouncing and / or hardware debouncing.
[0011] 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.
[0012] The technical effect achieved by the present invention is: by detecting the state of the above-mentioned mark A to determine whether the mechanical micro switch has completed a single switch press, that is, the first and second contacts are both triggered by the reed and output corresponding signals, wherein the state of mark 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 preventing the main control chip from determining that the signals output multiple times by the first contact are switch press signals, and avoiding the main control chip from repeatedly outputting press signals during a single switch press process and causing user control errors. BRIEF DESCRIPTION OF THE DRAWINGS
[0013] Figure 1 is a schematic block diagram of the present invention;
[0014] Figure 2 This is a schematic diagram of the single-press process of the present invention;
[0015] Figure 3 It is a structural diagram of a mechanical micro switch;
[0016] Figure 4 This is a level timing diagram during detection by the present invention.
[0017] In the figure, 1. housing; 10. protrusion; 2. push rod; 3. reed; 30. contact; 4. first terminal; 5. second terminal; 50. second contact; 6. third terminal; 60. first contact; 7. level waveform of the first contact before debouncing; 8. level waveform of the first contact after debouncing; 9. level waveform of the second contact. DETAILED DESCRIPTION
[0018] To make the above-mentioned objects, features, and advantages of the present invention more readily understood, specific embodiments of the present invention are described in detail below with reference to the accompanying drawings. The following description sets forth many specific details to facilitate a full understanding of the present invention. However, the present invention can be implemented in many other ways than those described herein, and those skilled in the art can make similar modifications without departing from the scope of the present invention. Therefore, the present invention is not limited to the specific embodiments disclosed below.
[0019] like Figure 1 、 Figure 2 As shown, the present invention discloses a debouncing method for a mechanical micro switch, which includes: circuit connection, wherein a first contact and a second contact of the mechanical micro switch are electrically connected to different pins of a main control chip, and a triggering elastic reed is provided between the first contact and the second contact;
[0020] 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 determined whether the first contact has a trigger signal output. If a trigger signal is 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 determined that a single press action is completed. When the levels of the first trigger signal and the second trigger signal are consistent, the main control chip determines that the mechanical microswitch is pressed. The timing is the delay time of software debouncing and / or hardware debouncing;
[0021] 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.
[0022] 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.
[0023] Specifically, combined Figure 3 The mechanical micro switch structure shown is provided with a first terminal 4, a second terminal 5, and a third terminal 6 on the housing 1, which are used to electrically connect to the main control chip. A push rod 2 is installed on the housing 1, and a protrusion 10 that cooperates with the push rod 2 is provided in the cavity of the housing 1. The first end of the reed 3 is fixed to the first terminal 4, the reed 3 rests on the protrusion 10 and can be pressed by the push rod 2 to trigger deformation, the second terminal 5 is connected to the second contact 50, the third terminal 6 is connected to the first contact 60, and the second end of the reed 3 is provided with a contact 30, and the contact 30 is located between the first contact 60 and the second contact 50.
[0024] Under normal conditions, 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 move away from 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 create and release the closed circuit until the swing amplitude of the reed 3 is insufficient to support it to continue.
[0025] exist Figure 3When the switch shown above is used in the above method, the second terminal 5 and the third terminal 6 are respectively connected to different pins of the main control chip.
[0026] Specifically, for the line connection, the pin of the main control chip electrically connected to the first contact and the second contact is configured in GPIO input mode; when in use, the main control chip continuously detects the first contact and the second contact to obtain a trigger signal. When the levels of the first trigger signal and the second trigger signal are consistent, the main control chip determines that the mechanical microswitch is pressed. The main control chip continuously detects the level status of the pin electrically connected to the first contact and the second contact using an interrupt mode or a polling mode. The interrupt mode is that when the pin level changes, the main control chip immediately responds and executes a corresponding interrupt handler. The polling mode is that the main control chip periodically checks the pin level status at a certain time interval and executes a corresponding handler based on the pin level status.
[0027] Regarding the description of determining whether the mechanical micro switch is pressed by using the first trigger signal and the second trigger signal: Figure 3 、 Figure 4 Under normal conditions, the contact 30 of the reed 3 and the first contact 60 form a normally closed circuit, so the level state 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 debounce appears, and then the level waveform 8 (second trigger signal) after the first contact debounce appears after timing (debounce), and the level waveform 9 (third trigger signal) of the second contact appears last (completing a single switch press); the level state of the pin connected to the first contact changes first, and the level state change of the corresponding pin of the second contact is later than the level state change of the corresponding pin of the first contact. Therefore, by detecting the level state of the corresponding pin of the first contact, a faster response can be achieved (relative to detecting the second contact), thereby achieving a low latency effect.
[0028] In combination with the above, after the first contact debounces level waveform 8 (second trigger signal), the main control chip determines that the switch is pressed and outputs a press signal. At this time, the reed contact has not yet reached the second contact and there is jitter. The jitter will cause the reed contact to contact the first contact again. Since the second trigger signal has been sent, the first contact is now in contact with the jittered reed contact, and the 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 used directly as a valid signal, the press signal will be repeatedly sent. The shorter the timing (debounce delay) between the first trigger signal and the second trigger signal, the faster the response can be achieved, but the more invalid signals will be caused by jitter, and the more repeated press signals will be generated.
[0029] Combine Figure 2 As shown, by establishing a flag A and switching its state when the main control chip receives the second and third trigger signals, the main control chip can determine the current switch pressing state when receiving the first trigger signal, that is, whether the switch has not completed a pressing action or has completed a pressing action. The switch pressing action is considered to be completed when both the first contact and the second contact are contacted by the contact points of the reed. Based on the result of the judgment of the current switch pressing state, the main control chip determines whether the first trigger signal output by the first contact is an invalid signal, ultimately reducing invalid signals caused by reed jitter and avoiding the repeated issuance of pressing signals.
[0030] The present invention also discloses a switch, wherein the switch applies the above-mentioned debounce method, for example Figure 3 The present invention also discloses a control device, wherein the control device is provided with a first switch, and the first switch is a switch to which the above-mentioned debounce method is applied.
[0031] In summary, by detecting the state of the above-mentioned mark A, it is determined whether the mechanical micro switch has completed a single switch press, that is, the first and second contacts are both triggered by the reed and output corresponding signals. Among them, the state of mark A is used to determine whether the signal output when the first contact is triggered is an invalid signal or noise caused by the reed jitter, thereby preventing the main control chip from determining the signals output by the first contact multiple times as switch press signals, avoiding the main control chip from repeatedly outputting press signals during a single switch press process and causing user control errors.
[0032] In the description of the present invention, it should be noted that the terms "center," "up," "down," "left," "right," "vertical," "horizontal," "inside," and "outside" and the like, indicating orientations or positional relationships, are based on the orientations or positional relationships shown in the accompanying drawings and are intended only to facilitate the description of the present invention and simplify the description. They do not indicate or imply that the devices or components referred to must have a specific orientation, be constructed, or operate in a specific orientation. Therefore, they should not be construed as limitations on the present invention. Furthermore, the terms "first" and "second" are used for descriptive purposes only and should not be construed as indicating or implying relative importance. The terms "first position" and "second position" refer to two different positions.
[0033] The embodiments described above merely represent one or more embodiments of the present invention. While the descriptions are relatively specific and detailed, they should not be construed as limiting the scope of the present invention. It should be noted that a person skilled in the art may make various modifications and improvements without departing from the scope of the present invention, all of which fall within the scope of protection of the present invention. Therefore, the scope of protection of the present invention shall be determined by the appended claims.
Claims
1. A debounce method for a mechanical micro switch, characterized in that: 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 a triggering elastic spring is provided between the first contact and the second contact; a trigger signal, wherein pressing the mechanical micro switch once causes the elastic 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 a first trigger signal. After receiving the first trigger signal, the main control chip performs timing. After the timing ends, it is determined whether the first contact outputs a trigger signal. If a trigger signal is output, 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 the single press action is completed; 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. Debouncing: When the main control chip receives the first trigger signal, the main control chip detects the state of the flag A. If the state of the flag 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 flag A is the second state, the main control chip determines that the current first trigger signal is a valid signal; 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; the timing is the delay time of software debouncing and / or hardware debouncing.
2. A switch, characterized in that: The switch applies the method described in claim 1.
3. 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 2.
Citation Information
Patent Citations
Relay zero-crossing protection method and circuit
CN113936961A
Electronic equipment data protection method and system and nonvolatile storage medium
CN119442354A