I want to make a small controller that can be turned on with a touch and turned off with a delay
Using an ordinary touch switch seems ugly, and the switch is not convenient to fix. It is not a good idea to put the control panel outside, right?
I want to use a touch switch, but I haven't found a suitable one after searching online for a long time. There is a capacitive sensing switch in the official STC document.
It needs to occupy 2 IO, one to generate PWM signal and one for AD judgment. In addition, it also needs 2 resistors, 2 diodes and 1 capacitor.
It felt a bit complicated, so I tried it and finally got it done with just one IO port, one resistor and one capacitor.
The idea is this:
A 2M resistor connects the power supply and IO port (I used p3.3)
A 33p capacitor is connected between the IO port and ground.
Connect a wire from the IO port to a metal sheet or something for touch.
Set p3.3 to 0 to discharge the capacitor first, then set it to high impedance state. At this time, the power supply will charge the capacitor through the resistor.
The time constant 2M*33p is about 66μs. The timer is used to count the time when the io port becomes high level.
If you don't use a timer, you may be affected by interruptions and there may be errors.
This time may need to be smoothed to avoid interference.
When the device is turned on, no one touches it, so record the charging time as a benchmark.
If someone touches it, the charging time will be longer, so check the charging time regularly.
If you find that the charging time is much longer than the benchmark charging time (I used twice the benchmark time for comparison), you can assume that someone has touched it.
It has been completed and put into use, and its reliability and anti-interference capabilities can meet the requirements.
void mw(){//main working loop
unsigned int i;
static unsigned int cdsj=0,bzz; //Charging time, standard value
static unsigned char csh=10; //initialize count
T2H=T2L=0; //Counter 2 count value is initialized to 0
P3M1 |=0x8; //p3.3 is set to open drain state
P3M0 |= 0x8; //
P3_3=0; //p3.3 output cleared to 0
delay(100);
P3M1 |=0x8; //p3.3 is set to high impedance state
P3M0 &=0xf7;//
AUXR |= 0x10; //Start counter 2
P3_3=1; //p3.3 output is 1, input state
IE1=0; //Clear the status of external interrupt 1
EX1=1; //Open external interrupt 1
while(EX1); //External interrupt is not completed and waiting in loop
i=cdsj>>3;
cdsj=cdsj-i+T2L; //smoothing
if(csh){
csh--;
if(csh==0){//The initial 10 counts are completed, and the current value is taken as the standard value
bzz=i+i;
};
return;
};
if(i>bzz){
This condition is met to indicate that the switch is touched
};
}
Previous article:STM32 PCB touch button (RC detection method)
Next article:Special registers in ARM
Professor at Beihang University, dedicated to promoting microcontrollers and embedded systems for over 20 years.
- Innolux's intelligent steer-by-wire solution makes cars smarter and safer
- 8051 MCU - Parity Check
- How to efficiently balance the sensitivity of tactile sensing interfaces
- What should I do if the servo motor shakes? What causes the servo motor to shake quickly?
- 【Brushless Motor】Analysis of three-phase BLDC motor and sharing of two popular development boards
- Midea Industrial Technology's subsidiaries Clou Electronics and Hekang New Energy jointly appeared at the Munich Battery Energy Storage Exhibition and Solar Energy Exhibition
- Guoxin Sichen | Application of ferroelectric memory PB85RS2MC in power battery management, with a capacity of 2M
- Analysis of common faults of frequency converter
- In a head-on competition with Qualcomm, what kind of cockpit products has Intel come up with?
- Dalian Rongke's all-vanadium liquid flow battery energy storage equipment industrialization project has entered the sprint stage before production
- Allegro MicroSystems Introduces Advanced Magnetic and Inductive Position Sensing Solutions at Electronica 2024
- Car key in the left hand, liveness detection radar in the right hand, UWB is imperative for cars!
- After a decade of rapid development, domestic CIS has entered the market
- Aegis Dagger Battery + Thor EM-i Super Hybrid, Geely New Energy has thrown out two "king bombs"
- A brief discussion on functional safety - fault, error, and failure
- In the smart car 2.0 cycle, these core industry chains are facing major opportunities!
- Rambus Launches Industry's First HBM 4 Controller IP: What Are the Technical Details Behind It?
- The United States and Japan are developing new batteries. CATL faces challenges? How should China's new energy battery industry respond?
- Murata launches high-precision 6-axis inertial sensor for automobiles
- Ford patents pre-charge alarm to help save costs and respond to emergencies
- Let you know about brushless DC motor
- EETalk: What pitfalls have you encountered during PCB design?
- Harbin Institute of Technology and Harbin Engineering University are banned from using genuine MATLAB software. What do you think about this?
- How to design an RC oscillator circuit with an output frequency of 1k to 3.2MHz
- Will power management integrated circuits (PMIC) be the mainstream direction in the future?
- Some experience on DSP parallel FLASH booting
- Summary of EMC principles for PCB design
- TI UCC28782 makes a miniaturized adapter
- What does N/A mean in TI chip manuals?
- How non-isolated switching power supplies work