Method for quickly responding to mechanical microswitch, switch and control device
By connecting the first and second contacts of the mechanical micro switch to different pins of the main control chip respectively, and using elastic reed triggering and debounce algorithms, the jitter problem of the micro switch at the moment of pressing and releasing is solved, achieving faster response and lower delay time.
Patent Information
- Application Number
- CN202510818288.1
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-05-19
- Publication Date
- 2025-10-10
AI Technical Summary
When a mechanical micro switch is pressed and released, the elasticity of the contacts causes voltage instability and jitter, which causes the key operation to be mistakenly recognized as multiple times, increasing the delay time.
The method is to electrically connect the first and second contacts of the mechanical micro switch to different pins of the main control chip and use an elastic reed to trigger it. The main control chip detects the level change of the first contact and combines the debounce algorithm to determine whether the switch is pressed.
It can determine whether the micro switch is pressed more quickly, reduce the delay time, and meet the user's low-latency requirements.
Smart Images

Figure CN120767151A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of micro switch response algorithms, and in particular to a method, switch and control device for fast response of 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 micro switch are in a normally closed state, and the reed and bottom contact are in a normally open state. Common micro switch processing algorithms rely on the program to capture the contact and disconnection between the reed and the bottom contact of the switch to determine the switch pressing and releasing actions. However, at the moment of pressing and releasing, the mechanical micro switch will experience unstable voltage jitter due to the elastic effect of the contacts, which may cause a single key operation to be mistakenly recognized as multiple times. For this reason, the usual software de-bounce algorithm does not immediately determine that the switch pressing state is valid after detecting a change in the switch state (such as the level changes from high to low, which means the switch is pressed). Instead, it delays for a certain period of time (such as 10-20 milliseconds, this delay 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. Summary of the Invention
[0004] To address one or more problems existing in the prior art, the present invention provides a method for a fast-response mechanical microswitch. The present invention employs a technical solution to address the aforementioned problems, comprising: a method for a fast-response mechanical microswitch, comprising: wiring, 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;
[0005] First contact detection: the main control chip continuously detects whether the level of the pin electrically connected to the first contact changes. When the first contact is triggered, it outputs a trigger signal and records it as the first trigger signal. After receiving the first trigger signal, the main control chip performs debouncing. After the debouncing is completed, it is determined whether the first contact outputs a trigger signal. If a trigger signal is output, this signal is recorded as the second trigger signal;
[0006] 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.
[0007] In some embodiments, for the line connection, the pin of the main control chip electrically connected to the first contact and the second contact is configured as a GPIO input mode.
[0008] In some embodiments, the main control chip performs level status detection on the pin electrically connected to the first contact in an interrupt manner or a polling manner.
[0009] 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.
[0010] The technical effect achieved by the present invention is: compared with the traditional algorithm of detecting the bottom contact (second contact) of the micro switch to determine whether the micro switch is pressed, the method of the present application can determine whether the micro switch has been pressed more quickly by detecting the level state of the first contact before and after debounce, with a lower delay time, meeting the user's low latency requirements. BRIEF DESCRIPTION OF THE DRAWINGS
[0011] Figure 1 is a schematic block diagram of the present invention;
[0012] Figure 2 It is a schematic diagram of the process of the present invention;
[0013] Figure 3 This is a schematic diagram of the present invention combined with a de-jitter algorithm;
[0014] Figure 4 It is a structural diagram of a mechanical micro switch;
[0015] Figure 5 This is a level timing diagram during detection by the present invention.
[0016] 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
[0017] 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.
[0018] like Figure 1-Figure 2 As shown, the present invention discloses a method for fast-response 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 spring is provided between the first contact and the second contact;
[0019] Combine Figure 4 As shown, it can be seen that the first contact 60 is the upper contact of the mechanical micro switch, and the second contact 50 is the lower contact of the mechanical micro switch;
[0020] First contact detection: the main control chip continuously detects whether the level of the pin electrically connected to the first contact changes. When the first contact is triggered, it outputs a trigger signal and records it 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 outputs a trigger signal. If a trigger signal is output, this signal is recorded as the second trigger signal. The timing is a debounce action;
[0021] 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.
[0022] Specifically, combined Figure 4The mechanical micro switch structure shown is provided with a first terminal 4, a second terminal 5, and a third terminal 6 on the shell 1, which are used to electrically connect to the main control chip. A push rod 2 is installed on the shell 1, and a protrusion 10 that cooperates with the push rod 2 is provided in the cavity of the shell 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, and the third terminal 6 is connected to the first contact 60. 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, wherein the first contact 60 is the upper contact and the second contact 50 is the lower contact.
[0023] 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.
[0024] exist Figure 4 When 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.
[0025] Combine Figure 3 As shown, the above method for quickly responding to a mechanical micro switch is combined with an example of a specific debounce method as follows:
[0026] 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;
[0027] 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.
[0028] 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;
[0029] Regarding the line connection, the pin of the main control chip electrically connected to the first contact and the second contact is configured as a GPIO input mode; when in 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 consistent, the main control chip determines that the mechanical micro switch is pressed. Regarding the continuous detection of the main control chip, it is: using an interrupt method or a polling method to perform level status detection on the pin electrically connected to the first contact and the second contact, wherein the interrupt method is that when the pin level changes, the main control chip immediately responds and executes the corresponding interrupt processing 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;
[0030] Combine Figure 3 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.
[0031] Regarding the description of determining whether the mechanical micro switch is pressed by using the first trigger signal and the second trigger signal: Figure 4 、 Figure 5 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 4The level waveform 7 (first trigger signal) before the first contact is debounced appears, and then the level waveform 8 (second trigger signal) after the first contact is debounced 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 obtained (relative to detecting the second contact), thereby achieving a low-latency effect.
[0032] The present invention also discloses a switch, wherein the switch applies the above method for fast-response mechanical micro switch, for example Figure 4 The mechanical micro switch shown; a control device, the control device is provided with a first switch, the first switch applies the above-mentioned method for fast response of the mechanical micro switch.
[0033] To sum up, compared with the traditional algorithm of detecting the bottom contact (second contact) of the micro switch to determine whether the micro switch is pressed, the method of the present application can determine whether the micro switch has been pressed more quickly by detecting the level state of the first contact before and after debounce, and has a lower delay time, meeting the user's low latency requirements.
[0034] 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.
[0035] 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 method for fast response 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; First contact detection: the main control chip continuously detects whether the level of the pin electrically connected to the first contact changes. When the first contact is triggered, it outputs a trigger signal and records it as the first trigger signal. After receiving the first trigger signal, the main control chip performs debouncing. After the debouncing is completed, it is determined whether the first contact outputs a trigger signal. If a trigger signal is output, this signal is recorded as the second 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 micro switch is pressed.
2. The method for fast response mechanical micro switch according to claim 1, characterized in that: Regarding the line connection, the pin of the main control chip electrically connected to the first contact and the second contact is configured as a GPIO input mode.
3. The method for fast-response mechanical micro switch according to claim 1, characterized in that: The main control chip performs level status detection on the pin electrically connected to the first contact in an interrupt mode or a polling mode.
4. A switch, characterized in that: The switch is applied with the method described in any one of claims 1 to 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.