[STM32 / MBED] [MED] Switch debouncing

아래 그림의 과 같이 스위치 입력 시 물리적인 문제로 바운싱 (채터링) 문제로 인한 오작동이 발생하는데 이를 해결하기 위한방법으로 하드웨어 적인 방법가 소프웨어 적인 방법이 구글링 하면 여러개 검색 된다.

/media/uploads/4180_1/switch_bounce.jpg


Timer를 할용하여 일정 시간 (200ms)동안 시간 주연을 주는 방식

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
#include "mbed.h"
InterruptIn button(p14);
DigitalOut led(LED1);       
DigitalOut flash(LED4);
Timer debounce;
 
void isr1() {
  if (debounce.read_ms() > 200) {
    led = !led;
    debounce.reset();
  }
}
 
int main() {
  debounce.start();
  button.rise(&isr1);                              
  while(true) {
    flash = !flash;
    wait(0.2);
  }
}


인터럽트의 Enable / Disable 방식 

Enabling and Disabling Interrupts

In some cases, you may want to ensure a section of code is not interrupted. For example, you might be talking to a peripheral where the whole transaction must happen in one go, and an interrupt could cause the operation to fail.

The simplest way to avoid this is to disable interrupts for the critical section of your code:

1
2
3
4
5
__disable_irq();    // Disable Interrupts
 
// do something that can't be interrupted
 
__enable_irq();     // Enable Interrupts

https://os.mbed.com/handbook/Working-with-Interrupts 









0
0
이 글을 페이스북으로 퍼가기 이 글을 트위터로 퍼가기 이 글을 카카오스토리로 퍼가기 이 글을 밴드로 퍼가기

임베디드 보드

번호 제목 글쓴이 날짜 조회수
118 아두이노 ESP32 Analog Inputs (ADC) +4 icon 양재동메이커 02-12 12,188
117 아두이노 TIP : Serial의 Port가 Open 시점 확인 icon 양재동메이커 01-21 9,372
116 아두이노 ESP32 Boot Mode icon 양재동메이커 12-28 8,867
115 아두이노 아두이노 에러 리스트(Arduino Error list) icon 양재동메이커 11-24 13,531
114 아두이노 ESP32 main.cpp +1 icon 양재동메이커 11-19 9,467
113 아두이노 ESP32 EEPROM 와 IR Remote icon 양재동메이커 08-06 9,546
112 아두이노 Learn ESP32 icon 양재동메이커 06-25 9,031
111 라즈베리 파이 라즈베리 파이 (Raspberry Pi) 기초 icon 양재동메이커 06-19 10,014
110 라즈베리 파이 (동영상 강의) 라즈베리 파이 강좌 Link icon 양재동메이커 06-17 9,495
109 STM32 / MBED [MED] Switch debouncing icon HellMaker 12-30 11,080
108 기타 [타이젠] 아두이노의 16x2 LCD Display라이브러리 LiquidCrystal_I2C의 타이젠 포팅 icon 양재동메이커 09-15 11,004
107 기타 [타이젠] GPIO의 디지탈 출력과 입력 인터럽트의 C++ Class 제작 icon 양재동메이커 09-12 10,513
106 마이크로비트 서보 모터 icon HellMaker 09-03 10,127
105 마이크로비트 아날로그 온도센서 (마이크로 비트 센서 활용) icon HellMaker 09-01 10,892
104 마이크로비트 터치센서 (마이크로 비트 센서 활용) icon HellMaker 09-01 10,144
103 마이크로비트 디지털 홀 센서 (마이크로 비트 센서 활용) icon HellMaker 08-29 9,244
102 마이크로비트 리니어 홀 센서 (마이크로 비트 센서 활용) icon HellMaker 08-29 8,911
101 마이크로비트 불꽃 감지 센서 (마이크로 비트 센서 활용) icon HellMaker 08-26 9,211
100 마이크로비트 로터리 엔코더 (마이크로 비트 센서 활용) icon HellMaker 08-25 9,266
99 마이크로비트 2컬러 LED(3mm) (센서 활용) icon HellMaker 08-22 9,276