Some issues about key detection in STM32

Publisher:火箭少年Latest update time:2019-01-14 Source: eefocusKeywords:STM3 Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

1. Compare the method of detecting keystrokes by delay and debouncing with the method of detecting keystrokes by interruption: For the method of detecting keystrokes by interruption, if you do not do some processing in the program to detect whether the keystrokes are pressed again, its accuracy is not as reliable as the method of detecting keystrokes by delay and debouncing.


2. The reason is: when we use interrupts to detect buttons, there is no delay in the interrupt program, then there will be a problem. When the button is pressed, there may be multiple jitters. Although we set the falling edge to trigger the interrupt, there may also be multiple falling edges in these multiple jitters, so the interrupt may be triggered multiple times.


3. The only solution is to use delay. The corrected code is shown in Figure 3 below. However, the code in P90 of the "STM32 Library Development Practical Guide" will cause false triggering.


Figure 1: Traditional delay debounce detection key program

Figure 2: Rough delay function


Figure 3: Corrected code for detecting keystrokes using interrupts


4. So the question is, if delay is also used in the interrupt program, what is the difference between it and the traditional delay debouncing?


The difference is: the traditional delay debouncing program should be written in the while loop of the main function, constantly detecting whether the button is pressed, occupying CPU resources in vain; while the interrupt method will not affect the execution of other programs. Only when the button is pressed will the interrupt be triggered and the interrupt service program will be entered.


Keywords:STM3 Reference address:Some issues about key detection in STM32

Previous article:STM32 software key debounce
Next article:STM32F1xx serial port control light switch experiment

Latest Microcontroller Articles
Change More Related Popular Components

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews


Room 1530, 15th Floor, Building B, No.18 Zhongguancun Street, Haidian District, Beijing, Postal Code: 100190 China Telephone: 008610 8235 0740

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号