A touch key capacitance detection method and system applied to an MCU
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- HITENX (WUXI) TECH CO LTD
- Filing Date
- 2023-02-07
- Publication Date
- 2026-05-29
AI Technical Summary
Existing capacitive touch button detection methods require external large-value capacitors, which increases application costs, occupies MCU chip I/O interfaces, comparator performance affects detection reliability, and detection speed is slow.
An internally integrated capacitance detection method is adopted. Charge transfer is controlled by a switch. By combining a hysteresis comparator and a voltage-controlled oscillator, stable control and frequency detection of the sampled capacitor voltage are achieved. A counter is used to determine button triggering.
No external capacitors are required, saving costs, improving I/O interface utilization, enhancing detection accuracy and speed, and increasing detection sensitivity.
Smart Images

Figure CN116203411B_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of touch button technology, specifically to a method and system for detecting the capacitance of touch buttons in an MCU. Background Technology
[0002] In modern electronic products, touch sensing technology is receiving increasing attention because capacitive touch buttons have advantages over traditional mechanical buttons in many aspects such as lifespan, appearance, and stability, and are thus being used more widely.
[0003] With the development of touch sensing technology, new technologies and ICs are constantly emerging. However, the mainstream capacitive touch button detection method usually uses charge migration. Its working principle is roughly as follows: the small capacitance of the touch button is repeatedly charged and discharged, transferring the charge to a larger external capacitor. During this process, the number of switching operations during charge transfer is counted, and the button press is determined based on the change in the counted number. The above-mentioned traditional capacitive touch button detection technology, which determines whether a button is pressed based on the number of charging cycles, has the following drawbacks:
[0004] 1. An external capacitor is required, typically larger than 1uF, which increases the application cost;
[0005] 2. The MCU chip will have an extra I / O port to house an external capacitor, reducing the utilization rate of the I / O interface;
[0006] 3. The performance of the comparator directly affects the reliability of the detection results;
[0007] 4. During the charge transfer process, using a capacitor with a larger capacitance value will increase the detection time and limit the detection speed. Summary of the Invention
[0008] The purpose of this invention is to provide a method and system for detecting the capacitance of touch buttons in an MCU, so as to solve the problems mentioned in the background art.
[0009] To solve the above-mentioned technical problems, the present invention provides the following technical solution: a method for detecting the capacitance of touch buttons in an MCU, the method comprising the following steps:
[0010] Step 1: Switch S1 is closed, switch S1b is open, and the power supply terminal VDD charges the button capacitor Ct;
[0011] Step 2: Switch S1 is open, switch S1b is closed, the button capacitor Ct charges the sampling capacitor Cs, and the voltage VCs of the sampling capacitor increases.
[0012] Step 3: When the voltage on the sampling capacitor Cs is charged to a level higher than the reference voltage Vref of the hysteresis comparator, the output signal of the hysteresis comparator will close the switch S2, and the sampling capacitor Cs will start to discharge to ground, and the voltage VCs of the sampling capacitor will decrease.
[0013] Step 4: When the voltage VCs of the sampled capacitor discharges to below the threshold voltage of the hysteresis comparator, the output signal of the hysteresis comparator will open switch S2, and the sampled capacitor Cs will stop discharging to ground, returning to steps 1 and 2.
[0014] Step 5: Repeat steps 1, 2, 3 and 4 until the voltage VCs of the sampling capacitor Cs finally stabilizes within the set range;
[0015] Step 6: The voltage VCs of the sampling capacitor Cs is fed into the voltage-controlled oscillator (VCO). The frequency of the output signal of the VCO changes with the voltage VCs of the sampling capacitor Cs. The VCO outputs a clock signal, which is counted by a counter.
[0016] Step 7: When the button is pressed, the human touch generates an inductive capacitor Cp. The inductive capacitor Cp and the button capacitor Ct are connected in parallel, and the node equivalent capacitance X1 increases. The amount of charge injected into the sampling capacitor Cs in each switching cycle increases, which will eventually increase the average voltage value of the sampling capacitor Cs when it is stable. The frequency of the output signal of the voltage-controlled oscillator VCO increases, and the change in the counter result is used as the detection standard.
[0017] Figure 1 The schematic diagram of the detection circuit of this invention shows three switches: switch S1, switch S1b, and switch S2; three capacitors: a sensing capacitor, a button capacitor, and a sampling capacitor; and components such as a power supply, a hysteresis comparator, a voltage-controlled oscillator, and a counter. The control signals for switches S1 and S1b are provided by the internal clock of the MCU. The clock is fundamental to the operation of the microcontroller, driving various parts within the microcontroller to execute corresponding instructions. Switches S1 and S1b are inverted signals. When switch S1 is closed, switch S1b is open, and the power supply terminal VDD is connected to the button capacitor Ct. Positive and negative charges in the power supply move to the positive and negative terminals of the button capacitor under the influence of the potential difference. Because the two terminals of the capacitor are insulated, the positive and negative charges cannot cancel each other out, resulting in a large accumulation of positive and negative charges at the capacitor terminals. The resulting electric field force further constrains the accumulated charges at the capacitor terminals, thus retaining a certain amount of charge at both ends of the capacitor. When switch S1 is open, switch S1b is closed, and the button capacitor Ct is connected to the sampling capacitor Cs. Under the action of the potential difference, the charge retained at both ends of the button capacitor will move to the sampling capacitor with a lower voltage, thereby increasing the voltage of the sampling capacitor and completing the charging process.
[0018] By employing the above technical solutions and using different switching methods to close or open the switches, the process of transferring charge from the power source to the sampling capacitor is completed, thereby charging the sampling capacitor.
[0019] The switch S2 connects the current-limiting resistor Rs to the hysteresis comparator. The hysteresis comparator is a comparator with hysteretic lap-loop transmission characteristics, and can also be understood as a single-threshold comparator with positive feedback. By introducing a positive feedback network into the inverting input single-threshold voltage comparator, a dual-threshold inverting input hysteresis comparator is formed. Due to the feedback, the threshold voltage of this comparator changes with the output voltage, resulting in lower sensitivity but significantly improved anti-interference capability. When the voltage on the sampling capacitor Cs is within the hysteresis voltage range, the hysteresis comparator output signal does not operate on switch S2. When the voltage on the sampling capacitor Cs is higher than the reference voltage Vref, the hysteresis comparator output signal controls switch S2 to close, and the sampling capacitor Cs discharges to ground through the current-limiting resistor Rs. When the voltage on the sampling capacitor Cs is lower than the threshold voltage, the hysteresis comparator output signal controls switch S2 to open, and the sampling capacitor Cs stops discharging to ground. The current-limiting resistor effectively limits the current, preventing excessive discharge current that could affect detection accuracy.
[0020] The above technical solution uses a hysteresis comparator to control switch S2 to limit the voltage on the sampling capacitor Cs, so that it can fluctuate within a certain range.
[0021] The sampling capacitor Cs can be configured with different capacitance values and speeds depending on the sensitivity requirements. The capacitance value and speed determine the time required for the sampling capacitor to reach the specified voltage. Shorter time requirements necessitate smaller capacitance values and faster speeds, while longer time requirements require larger capacitance values and slower speeds. The configuration is based on specific needs. Similarly, the hysteresis voltage and hysteresis value of the hysteresis comparator also need to be configured according to the required voltage values. The hysteresis voltage refers to the difference between the reference voltage and the threshold voltage. The reference voltage determines the upper limit of the hysteresis comparator voltage, and the threshold voltage determines the lower limit. Hysteresis refers to the range between the reference voltage and the threshold voltage. The larger the hysteresis, the larger the range and the wider the voltage range; the smaller the hysteresis, the smaller the range and the narrower the voltage range. The corresponding hysteresis voltage and hysteresis are configured according to the voltage requirements of the circuit. The positive terminal of the hysteresis comparator is connected to the sampling capacitor Cs to collect the voltage information of the sampling capacitor Cs. The negative terminal is connected to the reference voltage Vref to compare whether the voltage of the sampling capacitor Cs is within the range between the reference voltage and the threshold voltage. If it is within the range, no processing is performed. If it is not within the range, the output signal of the hysteresis comparator directly controls the closed or open state of the switch S2.
[0022] By using the above technical solutions, different specifications of sampling capacitors and hysteresis comparators can be selected to achieve voltage control of the button capacitor for circuits with different sensitivity requirements.
[0023] A voltage-controlled oscillator (VCO) refers to an oscillation circuit whose output frequency corresponds to the input control voltage. The frequency is a function of the input signal voltage. The operating state of the oscillator or the component parameters of the oscillation circuit are controlled by the input control voltage, thus forming a VCO. This type of device is specifically designed to provide an output signal whose frequency changes within a reasonable range with the voltage amplitude of the input signal. A counter is used to collect the frequency of the VCO's output signal. By analyzing the counting results, it is determined whether the circuit is affected by external factors, i.e., whether the key capacitor is triggered. The judgment conditions for the counting results are generally divided into two types:
[0024] 1. The counter uses the number of cycles of the output signal of the voltage-controlled oscillator (VCO) within a certain time as the judgment condition: when no button is pressed, the voltage value of the sampling capacitor remains within a stable range due to continuous charging and discharging. The frequency of the output signal of the voltage-controlled oscillator has a certain periodicity, and the counter result is a fixed number of cycles. Figure 2 This is a schematic diagram of the equivalent capacitance change of the human touch button in this invention. When the button is pressed, the human touch will generate an inductive capacitance Cp. Since the inductive capacitance Cp and the button capacitance Ct are connected in parallel, the node equivalent capacitance X1 increases. The amount of charge injected into the sampling capacitor Cs in each switching cycle increases, which will eventually increase the average voltage value of the sampling capacitor Cs when the voltage VCs is stable. The output frequency of the voltage-controlled oscillator VCO increases, and the number of cycles will increase or decrease accordingly.
[0025] 2. The counter uses the time required for the VCO output signal within a certain number of cycles as a judgment condition: When no button is pressed, the voltage value of the sampling capacitor fluctuates within a stable range due to continuous charging and discharging, and the frequency of the VCO output signal has a certain periodicity. The time required for the counter to reach the corresponding number of cycles is fixed. When a button is pressed, the human body touches the button and generates an inductive capacitor Cp. Since the inductive capacitor Cp and the button capacitor Ct are connected in parallel, the equivalent capacitance X1 of the node increases. The amount of charge injected into the sampling capacitor Cs in each switching cycle increases, which eventually increases the average voltage value of the sampling capacitor Cs when it stabilizes. The output frequency of the VCO increases, and the time to reach the corresponding number of cycles will increase or decrease accordingly.
[0026] Both of these measurement methods determine whether the button capacitance has been triggered by comparing the measured value with a pre-set threshold value. The threshold value needs to be properly calibrated to avoid affecting the switch's sensitivity. Initial calibration of the threshold value is required for all switches during initial use. In a dynamically changing environment, periodic calibration of the threshold value should also be added. If the threshold value is set too far from the value when the switch is not pressed, the button trigger event may be difficult to detect. Conversely, if the threshold value is set too close to the value when the switch is not pressed, a false trigger event may be detected before the button capacitance is actually triggered. Because the analysis focuses on changes in capacitance value, a larger change range is desirable. Several factors influence the switch capacitance and its change range: 1. The size, shape, and configuration of the switch on the PCB; 2. The material used between the PCB traces and the user's finger; 3. The characteristics of the traces connecting the switch and the MCU. Generally, the larger the switch and the more traces in a specific area, the higher the idle capacitance of that switch. The type of material used above the switch also affects the rate of capacitance change. To maximize capacitance variation, materials with high dielectric constants or thinner materials should be used to increase the absolute capacitance of the switch.
[0027] The above technical solution uses a voltage-controlled oscillator (VCO) to convert the voltage value of the sampled capacitor and outputs it. A counter is used to collect the output frequency of the VCO, and the abnormality of the frequency is used to determine whether the button capacitor is triggered.
[0028] A capacitance detection system for touch buttons in an MCU, the system comprising: a charging module, a discharging module, and a detection module;
[0029] The charging module charges the button capacitor Ct via the power supply terminal VDD, and then the button capacitor Ct charges the sampling capacitor Cs, thereby increasing the voltage of the sampling capacitor Cs. The discharging module refers to the capacitor Cs discharging to ground through the current-limiting resistor Rs, thereby reducing the voltage of the sampling capacitor Cs. The detection module uses a voltage-controlled oscillator (VCO) combined with a counter to detect the voltage change of the sampling capacitor Cs, and determines whether the capacitive touch-sensitive button switch has been triggered based on the counter output data.
[0030] The above technical solution combines various circuit components to achieve the functions of charging, discharging and detecting the sampling capacitor, and analyzes the detection results to determine whether the touch button has been triggered.
[0031] The charging module consists of a power supply terminal VDD, a button capacitor Ct, and a sampling capacitor Cs. When the system starts working, switch S1 is closed and switch S1b is open, forming a circuit between the power supply terminal VDD and the button capacitor Ct. Positive and negative charges in the power supply move to the positive and negative terminals of the button capacitor under the influence of the potential difference. Because the two terminals of the capacitor are insulated, the positive and negative charges cannot cancel each other out, resulting in a large accumulation of positive and negative charges at the capacitor terminals. The resulting electric field force further constrains the accumulated charges at the capacitor terminals, so a certain amount of charge is retained at the capacitor terminals. When switch S1 is open and switch S1b is closed, the button capacitor Ct is connected to the sampling capacitor Cs. Under the influence of the potential difference, the charge retained at the terminals of the button capacitor moves to the sampling capacitor with a lower voltage, increasing the voltage of the sampling capacitor and completing the charging process.
[0032] The above technical solution uses a switch-closing and opening method to realize the process of charge transfer from the power source to the sampling capacitor, thereby completing the charging control of the sampling capacitor.
[0033] The discharge module consists of a hysteresis comparator, switch S2, and current-limiting resistor Rs. The operating state of switch S2 (closed and open) is controlled by the output signal of the hysteresis comparator. When the system starts working, the voltage VCs on the sampling capacitor gradually rises. The hysteresis comparator collects the voltage value on the sampling capacitor in real time. When the voltage value is higher than the reference voltage Vref set by the hysteresis comparator, the output signal of the hysteresis comparator controls switch S2 to close, and the sampling capacitor begins to discharge to ground through the current-limiting resistor Rs. When the voltage VCs on the sampling capacitor gradually falls below the threshold voltage set by the hysteresis comparator, the output signal of the hysteresis comparator controls switch S2 to open, the discharge path of the sampling capacitor Cs to ground is broken, and the discharge stops. The system automatically calls the charging module to continue charging the sampling capacitor Cs through the power supply until the output of the hysteresis comparator flips again.
[0034] The above technical solution uses a hysteresis comparator to collect data on the voltage across the sampling capacitor, and controls the discharge of the sampling capacitor by opening and closing a control switch.
[0035] The detection module consists of a voltage-controlled oscillator (VCO) and a counter. The VCO is specifically designed to provide an output signal whose frequency varies within a reasonable range with the voltage amplitude of the input signal. The input signal voltage refers to the voltage of the sampling capacitor. The counter is the logic circuit that performs the counting. In a digital system, the counter mainly counts the number of pulses to achieve measurement, counting, and control functions. The counter collects the frequency of the VCO output signal, and the counting results can be judged by relevant software. The results are compared with the counting results when no button is pressed to identify any anomalies. This completes the detection of voltage changes in the sampling capacitor and the determination of whether the touch button has been triggered.
[0036] Touch buttons utilize the principle of capacitive sensing, using the human body's capacitance to detect the presence of a finger. When no finger is pressed, the button itself has a static capacitance Ct, approximately 10pF to 30pF. When a person touches the button, the human body generates a capacitance Cp with the ground, which acts on the button, increasing the total capacitance by several pF. This human capacitance is then combined with the button's static capacitance, increasing the total capacitance. Therefore, the detection principle is based on this capacitance change. Traditional capacitive touch button detection methods typically use the number of charging cycles as a criterion, but this approach has several drawbacks. Building upon this technology, a large external capacitor is integrated into the chip, with a capacitance value in the hundreds of pF range. Lowering the capacitance value does not affect detection performance, and the capacitance value can be adjusted within a certain range depending on the application, requiring a trade-off between accuracy and speed. The basic principle is that a lower internal sampling capacitor capacitance speeds up the charge transfer process, allowing the internal sampling capacitor Cs voltage to reach the comparator threshold more quickly, but at the cost of sampling accuracy. Conversely, higher capacitance increases accuracy and conversion speed. On the other hand, the present invention further improves the detection sensitivity by using the average voltage on the sampling capacitor as the detection criterion, and can detect even tiny inductive capacitance generated on the button.
[0037] The above technical solution uses a combination of voltage-controlled oscillator and counter to detect voltage changes in the sampling capacitor, thereby determining whether the touch button has been triggered.
[0038] Compared with the prior art, the beneficial effects achieved by the present invention are:
[0039] 1. This invention does not require the use of external components during the detection process. It can achieve touch button trigger detection by using a combination of internal components on the circuit board, saving the cost of external components and improving economic feasibility.
[0040] 2. This invention utilizes an internal hysteresis comparator to control the voltage on the sampling capacitor to maintain it within a stable range, thereby controlling the output frequency of the voltage-controlled oscillator (VCO). By comparing the output frequency when the button is not triggered with the output frequency when the button is triggered, it can accurately determine whether the button has been triggered, achieving high resolution.
[0041] 3. The capacitance value and speed of the capacitor, as well as the hysteresis voltage and hysteresis amount of the hysteresis comparator used in this invention, can be customized according to actual usage, thereby improving the reusability of components. Attached Figure Description
[0042] The accompanying drawings are provided to further illustrate the invention and form part of the specification. They are used in conjunction with embodiments of the invention to explain the invention and do not constitute a limitation thereof. In the drawings:
[0043] Figure 1 This is a schematic diagram of the detection circuit of a method and system for detecting the capacitance of touch buttons in an MCU, according to the present invention.
[0044] Figure 2 This is a schematic diagram illustrating the change in equivalent capacitance when a human touches a button, as described in this invention, which is a method and system for detecting the capacitance of touch buttons in an MCU. Detailed Implementation
[0045] The technical solutions of the embodiments of the present invention will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of the present invention, and not all embodiments. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of the present invention.
[0046] This invention provides a capacitance detection system for touch buttons in an MCU, the system comprising: a charging module, a discharging module, and a detection module;
[0047] The charging module charges the button capacitor Ct via the power supply terminal VDD, and then the button capacitor Ct charges the sampling capacitor Cs, thereby increasing the voltage of the sampling capacitor Cs. The discharging module refers to the capacitor Cs discharging to ground through the current-limiting resistor Rs, thereby reducing the voltage of the sampling capacitor Cs. The detection module uses a voltage-controlled oscillator (VCO) combined with a counter to detect the voltage change of the sampling capacitor Cs, and determines whether the capacitive touch-sensitive button switch has been triggered based on the counter output data.
[0048] The above technical solution combines various circuit components to achieve the functions of charging, discharging and detecting the sampling capacitor, and analyzes the detection results to determine whether the touch button has been triggered.
[0049] The charging module consists of a power supply terminal VDD, a button capacitor Ct, and a sampling capacitor Cs. When the system starts working, switch S1 is closed and switch S1b is open, forming a circuit between the power supply terminal VDD and the button capacitor Ct. Positive and negative charges in the power supply move to the positive and negative terminals of the button capacitor under the influence of the potential difference. Because the two terminals of the capacitor are insulated, the positive and negative charges cannot cancel each other out, resulting in a large accumulation of positive and negative charges at the capacitor terminals. The resulting electric field force further constrains the accumulated charges at the capacitor terminals, so a certain amount of charge is retained at the capacitor terminals. When switch S1 is open and switch S1b is closed, the button capacitor Ct is connected to the sampling capacitor Cs. Under the influence of the potential difference, the charge retained at the terminals of the button capacitor moves to the sampling capacitor with a lower voltage, increasing the voltage of the sampling capacitor and completing the charging process.
[0050] The above technical solution uses a switch-closing and opening method to realize the process of charge transfer from the power source to the sampling capacitor, thereby completing the charging control of the sampling capacitor.
[0051] The discharge module consists of a hysteresis comparator, switch S2, and current-limiting resistor Rs. The operating state of switch S2 (closed and open) is controlled by the output signal of the hysteresis comparator. When the system starts working, the voltage VCs on the sampling capacitor gradually rises. The hysteresis comparator collects the voltage value on the sampling capacitor in real time. When the voltage value is higher than the reference voltage Vref set by the hysteresis comparator, the output signal of the hysteresis comparator controls switch S2 to close, and the sampling capacitor begins to discharge to ground through the current-limiting resistor Rs. When the voltage VCs on the sampling capacitor gradually falls below the threshold voltage set by the hysteresis comparator, the output signal of the hysteresis comparator controls switch S2 to open, the discharge path of the sampling capacitor Cs to ground is broken, and the discharge stops. The system automatically calls the charging module to continue charging the sampling capacitor Cs through the power supply until the output of the hysteresis comparator flips again.
[0052] The above technical solution uses a hysteresis comparator to collect data on the voltage across the sampling capacitor, and controls the discharge of the sampling capacitor by opening and closing a control switch.
[0053] The detection module consists of a voltage-controlled oscillator (VCO) and a counter. The VCO is specifically designed to provide an output signal whose frequency varies within a reasonable range with the voltage amplitude of the input signal. The input signal voltage refers to the voltage of the sampling capacitor. The counter is the logic circuit that performs the counting. In a digital system, the counter mainly counts the number of pulses to achieve measurement, counting, and control functions. The counter collects the frequency of the VCO output signal, and the counting results can be judged by relevant software. The results are compared with the counting results when no button is pressed to identify any anomalies. This completes the detection of voltage changes in the sampling capacitor and the determination of whether the touch button has been triggered.
[0054] Touch buttons utilize the principle of capacitive sensing, using the human body's capacitance to detect the presence of a finger. When no finger is pressed, the button itself has a static capacitance Ct, approximately 10pF to 30pF. When a person touches the button, the human body generates a capacitance Cp with the ground, which acts on the button, increasing the total capacitance by several pF. This human capacitance is then combined with the button's static capacitance, increasing the total capacitance. Therefore, the detection principle is based on this capacitance change. Traditional capacitive touch button detection methods typically use the number of charging cycles as a criterion, but this approach has several drawbacks. Building upon this technology, a large external capacitor is integrated into the chip, with a capacitance value in the hundreds of pF range. Lowering the capacitance value does not affect detection performance, and the capacitance value can be adjusted within a certain range depending on the application, requiring a trade-off between accuracy and speed. The basic principle is that a lower internal sampling capacitor capacitance speeds up the charge transfer process, allowing the internal sampling capacitor Cs voltage to reach the comparator threshold more quickly, but at the cost of sampling accuracy. Conversely, higher capacitance increases accuracy and conversion speed. On the other hand, the present invention further improves the detection sensitivity by using the average voltage on the sampling capacitor as the detection criterion, and can detect even tiny inductive capacitance generated on the button.
[0055] The above technical solution uses a combination of voltage-controlled oscillator and counter to detect voltage changes in the sampling capacitor, thereby determining whether the touch button has been triggered.
[0056] A method for detecting the capacitance of touch buttons in an MCU, the method comprising the following steps:
[0057] Step 1: Switch S1 is closed, switch S1b is open, and the power supply terminal VDD charges the button capacitor Ct;
[0058] Step 2: Switch S1 is open, switch S1b is closed, the button capacitor Ct charges the sampling capacitor Cs, and the voltage VCs of the sampling capacitor increases.
[0059] Step 3: When the voltage on the sampling capacitor Cs is charged to a level higher than the reference voltage Vref of the hysteresis comparator, the output signal of the hysteresis comparator will close the switch S2, and the sampling capacitor Cs will start to discharge to ground, and the voltage VCs of the sampling capacitor will decrease.
[0060] Step 4: When the voltage VCs of the sampled capacitor discharges to below the threshold voltage of the hysteresis comparator, the output signal of the hysteresis comparator will open switch S2, and the sampled capacitor Cs will stop discharging to ground, returning to steps 1 and 2.
[0061] Step 5: Repeat steps 1, 2, 3 and 4 until the voltage VCs of the sampling capacitor Cs finally stabilizes within the set range;
[0062] Step 6: The voltage VCs of the sampling capacitor Cs is fed into the voltage-controlled oscillator (VCO). The frequency of the output signal of the VCO changes with the voltage VCs of the sampling capacitor Cs. The VCO outputs a clock signal, which is counted by a counter.
[0063] Step 7: When the button is pressed, the human touch generates an inductive capacitor Cp. The inductive capacitor Cp and the button capacitor Ct are connected in parallel, and the node equivalent capacitance X1 increases. The amount of charge injected into the sampling capacitor Cs in each switching cycle increases, which will eventually increase the average voltage value of the sampling capacitor Cs when it is stable. The frequency of the output signal of the voltage-controlled oscillator VCO increases, and the change in the counter result is used as the detection standard.
[0064] Please see Figure 1 The diagram shows the detection circuit of this invention, which includes three switches: switch S1, switch S1b, and switch S2; three capacitors: a sensing capacitor, a button capacitor, and a sampling capacitor; and components such as a power supply, a hysteresis comparator, a voltage-controlled oscillator, and a counter. The control signals for switches S1 and S1b are provided by the internal clock of the MCU. The clock is fundamental to the operation of the microcontroller, driving various parts within the microcontroller to execute corresponding instructions. Switches S1 and S1b are inverted signals. When switch S1 is closed, switch S1b is open, and the power supply terminal VDD is connected to the button capacitor Ct. Positive and negative charges in the power supply move to the positive and negative terminals of the button capacitor under the influence of the potential difference. Because the capacitor terminals are insulated, the positive and negative charges cannot cancel each other out, resulting in a large accumulation of positive and negative charges at the capacitor terminals. The resulting electric field force further constrains the accumulated charges at the capacitor terminals, thus retaining a certain amount of charge at both ends of the capacitor. When switch S1 is open, switch S1b is closed, and the button capacitor Ct is connected to the sampling capacitor Cs. Under the action of the potential difference, the charge retained at both ends of the button capacitor will move to the sampling capacitor with a lower voltage, thereby increasing the voltage of the sampling capacitor and completing the charging process.
[0065] By employing the above technical solutions and using different switching methods to close or open the switches, the process of transferring charge from the power source to the sampling capacitor is completed, thereby charging the sampling capacitor.
[0066] The switch S2 connects the current-limiting resistor Rs to the hysteresis comparator. The hysteresis comparator is a comparator with hysteretic lap-loop transmission characteristics, and can also be understood as a single-threshold comparator with positive feedback. By introducing a positive feedback network into the inverting input single-threshold voltage comparator, a dual-threshold inverting input hysteresis comparator is formed. Due to the feedback, the threshold voltage of this comparator changes with the output voltage, resulting in lower sensitivity but significantly improved anti-interference capability. When the voltage on the sampling capacitor Cs is within the hysteresis voltage range, the hysteresis comparator output signal does not operate on switch S2. When the voltage on the sampling capacitor Cs is higher than the reference voltage Vref, the hysteresis comparator output signal controls switch S2 to close, and the sampling capacitor Cs discharges to ground through the current-limiting resistor Rs. When the voltage on the sampling capacitor Cs is lower than the threshold voltage, the hysteresis comparator output signal controls switch S2 to open, and the sampling capacitor Cs stops discharging to ground. The current-limiting resistor effectively limits the current, preventing excessive discharge current that could affect detection accuracy.
[0067] The above technical solution uses a hysteresis comparator to control switch S2 to limit the voltage on the sampling capacitor Cs, so that it can fluctuate within a certain range.
[0068] The sampling capacitor Cs can be configured with different capacitance values and speeds depending on the sensitivity requirements. The capacitance value and speed determine the time required for the sampling capacitor to reach the specified voltage. Shorter time requirements necessitate smaller capacitance values and faster speeds, while longer time requirements require larger capacitance values and slower speeds. The configuration is based on specific needs. Similarly, the hysteresis voltage and hysteresis value of the hysteresis comparator also need to be configured according to the required voltage values. The hysteresis voltage refers to the difference between the reference voltage and the threshold voltage. The reference voltage determines the upper limit of the hysteresis comparator voltage, and the threshold voltage determines the lower limit. Hysteresis refers to the range between the reference voltage and the threshold voltage. The larger the hysteresis, the larger the range and the wider the voltage range; the smaller the hysteresis, the smaller the range and the narrower the voltage range. The corresponding hysteresis voltage and hysteresis are configured according to the voltage requirements of the circuit. The positive terminal of the hysteresis comparator is connected to the sampling capacitor Cs to collect the voltage information of the sampling capacitor Cs. The negative terminal is connected to the reference voltage Vref to compare whether the voltage of the sampling capacitor Cs is within the range between the reference voltage and the threshold voltage. If it is within the range, no processing is performed. If it is not within the range, the output signal of the hysteresis comparator directly controls the closed or open state of the switch S2.
[0069] By using the above technical solutions, different specifications of sampling capacitors and hysteresis comparators can be selected to achieve voltage control of the button capacitor for circuits with different sensitivity requirements.
[0070] A voltage-controlled oscillator (VCO) refers to an oscillation circuit whose output frequency corresponds to the input control voltage. The frequency is a function of the input signal voltage. The operating state of the oscillator or the component parameters of the oscillation circuit are controlled by the input control voltage, thus forming a VCO. This type of device is specifically designed to provide an output signal whose frequency changes within a reasonable range with the voltage amplitude of the input signal. A counter is used to collect the frequency of the VCO's output signal. By analyzing the counting results, it is determined whether the circuit is affected by external factors, i.e., whether the key capacitor is triggered. The judgment conditions for the counting results are generally divided into two types:
[0071] 1. The counter uses the number of cycles of the VCO output signal within a certain time period as the judgment condition: When no button is pressed, the voltage value of the sampling capacitor fluctuates within a stable range due to continuous charging and discharging. The frequency of the VCO output signal has a certain periodicity, and the counter result is a fixed number of cycles; please refer to [link to relevant documentation]. Figure 2 When the button is pressed, the human touches the button and generates an inductive capacitor Cp. Since the inductive capacitor Cp and the button capacitor Ct are connected in parallel, the node equivalent capacitance X1 increases. The amount of charge injected into the sampling capacitor Cs in each switching cycle increases, which will eventually increase the average voltage value of the sampling capacitor Cs when it is stable. The output frequency of the voltage-controlled oscillator VCO increases, and the number of cycles will increase or decrease accordingly.
[0072] 2. The counter uses the time required for the VCO output signal within a certain number of cycles as a judgment condition: When no button is pressed, the voltage value of the sampling capacitor fluctuates within a stable range due to continuous charging and discharging, and the frequency of the VCO output signal has a certain periodicity. The time required for the counter to reach the corresponding number of cycles is fixed. When a button is pressed, the human body touches the button and generates an inductive capacitor Cp. Since the inductive capacitor Cp and the button capacitor Ct are connected in parallel, the equivalent capacitance X1 of the node increases. The amount of charge injected into the sampling capacitor Cs in each switching cycle increases, which eventually increases the average voltage value of the sampling capacitor Cs when it stabilizes. The output frequency of the VCO increases, and the time to reach the corresponding number of cycles will increase or decrease accordingly.
[0073] Both of these measurement methods determine whether the button capacitance has been triggered by comparing the measured value with a pre-set threshold value. The threshold value needs to be properly calibrated to avoid affecting the switch's sensitivity. Initial calibration of the threshold value is required for all switches during initial use. In a dynamically changing environment, periodic calibration of the threshold value should also be added. If the threshold value is set too far from the value when the switch is not pressed, the button trigger event may be difficult to detect. Conversely, if the threshold value is set too close to the value when the switch is not pressed, a false trigger event may be detected before the button capacitance is actually triggered. Because the analysis focuses on changes in capacitance value, a larger change range is desirable. Several factors influence the switch capacitance and its change range: 1. The size, shape, and configuration of the switch on the PCB; 2. The material used between the PCB traces and the user's finger; 3. The characteristics of the traces connecting the switch and the MCU. Generally, the larger the switch and the more traces in a specific area, the higher the idle capacitance of that switch. The type of material used above the switch also affects the rate of capacitance change. To maximize capacitance variation, materials with high dielectric constants or thinner materials should be used to increase the absolute capacitance of the switch.
[0074] The above technical solution uses a voltage-controlled oscillator (VCO) to convert the voltage value of the sampled capacitor and outputs it. A counter is used to collect the output frequency of the VCO, and the abnormality of the frequency is used to determine whether the button capacitor is triggered.
[0075] It should be noted that, in this document, relational terms such as "first" and "second" are used only to distinguish one entity or operation from another, and do not necessarily require or imply any such actual relationship or order between these entities or operations. Furthermore, the terms "comprising," "including," or any other variations thereof are intended to cover non-exclusive inclusion, such that a process, method, article, or apparatus that comprises a list of elements includes not only those elements but also other elements not expressly listed, or elements inherent to such process, method, article, or apparatus.
[0076] Finally, it should be noted that the above descriptions are merely preferred embodiments of the present invention and are not intended to limit the present invention. Although the present invention has been described in detail with reference to the foregoing embodiments, those skilled in the art can still modify the technical solutions described in the foregoing embodiments or make equivalent substitutions for some of the technical features. Any modifications, equivalent substitutions, improvements, etc., made within the spirit and principles of the present invention should be included within the protection scope of the present invention.
Claims
1. A method for detecting the capacitance of touch buttons in an MCU, characterized in that, The method includes the following steps: Step 1: Switch S1 is closed, switch S1b is open, and the power supply terminal VDD charges the button capacitor Ct; Step 2: Switch S1 is open, switch S1b is closed, the button capacitor Ct charges the sampling capacitor Cs, and the voltage VCs of the sampling capacitor increases. Step 3: When the voltage on the sampling capacitor Cs is charged to a level higher than the reference voltage Vref of the hysteresis comparator, the output signal of the hysteresis comparator will close the switch S2, and the sampling capacitor Cs will start to discharge to ground, and the voltage VCs of the sampling capacitor will decrease. Step 4: When the voltage VCs of the sampled capacitor discharges to below the threshold voltage of the hysteresis comparator, the output signal of the hysteresis comparator will open switch S2, and the sampled capacitor Cs will stop discharging to ground, returning to steps 1 and 2. Step 5: Repeat steps 1, 2, 3 and 4 until the voltage VCs of the sampling capacitor Cs finally stabilizes within the set range; Step 6: The voltage VCs of the sampling capacitor Cs is fed into the voltage-controlled oscillator (VCO). The frequency of the output signal of the VCO changes with the voltage VCs of the sampling capacitor Cs. The VCO outputs a clock signal, which is counted by a counter. Step 7: When the button is pressed, the human touch of the button generates an inductive capacitor Cp. The inductive capacitor Cp and the button capacitor Ct are connected in parallel. The node equivalent capacitance X1 increases, and the amount of charge injected into the sampling capacitor Cs in each switching cycle increases. This will eventually increase the average voltage value of the sampling capacitor Cs when it is stable, and the frequency of the output signal of the voltage-controlled oscillator VCO will increase. The change in the counter result is used as the detection standard. The sampling capacitor Cs is configured with different capacitance values and speeds according to different sensitivity requirements; the hysteresis voltage and hysteresis amount of the hysteresis comparator are configured according to the required stable voltage value. The positive terminal of the hysteresis comparator is connected to the sampling capacitor Cs, the negative terminal is connected to the reference voltage Vref, and the output signal directly controls the state of switch S2. The counting result is determined under two conditions:
1. The counter uses the number of cycles of the output signal of the voltage-controlled oscillator (VCO) within a certain time. When no button is pressed, the counter result is a fixed number of cycles. When a button is pressed, the number of cycles will increase or decrease accordingly.
2. The counter uses the time required for the output signal of the VCO within a certain number of cycles. When no button is pressed, the time for the counter to reach the corresponding number of cycles is a fixed value. When a button is pressed, the time to reach the corresponding number of cycles again will increase or decrease accordingly.
2. The method for detecting the capacitance of touch buttons in an MCU according to claim 1, characterized in that: The control signals for switches S1 and S1b are provided by the internal clock of the MCU. Switches S1 and S1b are inverted signals. When switch S1 is closed, switch S1b is open; when switch S1 is open, switch S1b is closed.
3. The method for detecting the capacitance of touch buttons in an MCU according to claim 1, characterized in that: The switch S2 is connected to the current-limiting resistor Rs and the hysteresis comparator. When the switch S2 is closed, the sampling capacitor Cs discharges to ground through the current-limiting resistor Rs, and the voltage decreases.
4. A touch button capacitance detection system for use in an MCU, used to execute the touch button capacitance detection method for use in an MCU as described in claim 1, characterized in that, The detection system includes: a charging module, a discharging module, and a detection module; The charging module charges the button capacitor Ct via the power supply terminal VDD, and then the button capacitor Ct charges the sampling capacitor Cs, thereby increasing the voltage of the sampling capacitor Cs. The discharging module refers to the capacitor Cs discharging to ground through the current-limiting resistor Rs, thereby reducing the voltage of the sampling capacitor Cs. The detection module uses a voltage-controlled oscillator (VCO) combined with a counter to detect the voltage change of the sampling capacitor Cs, and determines whether the capacitive touch-sensitive button switch has been triggered based on the counter output data. The discharge module consists of a hysteresis comparator, a switch S2, and a current-limiting resistor Rs. The operating state of the switch S2 is controlled by the output signal of the hysteresis comparator. When the voltage VCs on the sampling capacitor is higher than the reference voltage Vref, the switch S2 is closed, and the sampling capacitor begins to discharge to ground through the current-limiting resistor Rs. When the voltage VCs on the sampling capacitor is lower than the threshold voltage, the output of the hysteresis comparator flips, the switch S2 is opened, the sampling capacitor Cs stops discharging to ground, and the charging module continues to charge the sampling capacitor Cs until the output of the hysteresis comparator flips again. The detection module consists of a voltage-controlled oscillator (VCO) and a counter; the VCO is an oscillation circuit whose output frequency corresponds to the input control voltage; the counter counts the number of pulses in the digital system, enabling measurement, counting, and control functions. The voltage value of the sampling capacitor is used as the input signal of the voltage-controlled oscillator (VCO). After the VCO processes the signal, the counter counts the frequency of the VCO's output signal. The software compares the count result with the count result when no button is pressed to identify any abnormalities. Based on the comparison result, it is determined whether the touch button has been triggered.
5. The touch button capacitance detection system for MCUs according to claim 4, characterized in that: The charging module consists of a power supply terminal VDD, a button capacitor Ct, and a sampling capacitor Cs. The charging process includes: charging the button capacitor Ct from the power supply terminal VDD and charging the sampling capacitor Cs from the button capacitor Ct.