[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
이 글을 페이스북으로 퍼가기 이 글을 트위터로 퍼가기 이 글을 카카오스토리로 퍼가기 이 글을 밴드로 퍼가기

임베디드 보드

번호 제목 글쓴이 날짜 조회수
98 마이크로비트 RGB LED 모듈 ( 센서 활용) icon HellMaker 08-22 18,498
97 마이크로비트 써미스터 온도 센서 (센서 활용) icon HellMaker 08-22 18,296
96 마이크로비트 수은 기울기 센서 (센서 활용) icon HellMaker 08-22 17,764
95 마이크로비트 마이크로 비트 기울기 센서 (센서 활용) icon HellMaker 08-22 18,728
94 마이크로비트 가속도 센서 (마이크로비트 기본 예제) icon 양재동메이커 08-22 18,262
93 마이크로비트 가속도 동서남북 (마이크로비트 기본 예제) icon 양재동메이커 08-22 17,212
92 마이크로비트 버튼 응용 예제 (마이크로비트 기본 예제) icon 양재동메이커 08-22 18,321
91 마이크로비트 버튼 예제 (마이크로비트 기본 예제) icon 양재동메이커 08-22 17,540
90 마이크로비트 매직 라이트 컵 모듈 (아두이노 센서 활용) icon HellMaker 08-14 17,029
89 마이크로비트 심박 센서 ( 아두이노 센서 활용) icon HellMaker 08-14 18,211
88 마이크로비트 충격 센서 (아두이노 센서 활용) icon HellMaker 08-08 19,797
87 마이크로비트 레이저 발광 모듈 (아두이노 센서 활용) icon HellMaker 08-08 18,481
86 마이크로비트 7 컬러 LED 모듈 (아두이노 센서 활용) icon HellMaker 08-08 17,494
85 마이크로비트 CDS 조도 센서 (아두이노 센서 활용) icon HellMaker 08-08 17,983
84 마이크로비트 매직라이트 컵 모듈 활용하기 (아두이노 센서 활용) icon HellMaker 08-08 25,256
83 마이크로비트 기울기 센서 활용 (아두이노 센서 활용) icon HellMaker 08-08 18,718
82 마이크로비트 노크 센서 활용 (아두이노 센서 활용) icon HellMaker 08-08 18,449
81 마이크로비트 수은 기울기 센서 활용 (아두이노 센서 활용) icon HellMaker 08-08 18,721
80 마이크로비트 써미스터 온도 센서 활용 (아두이노 센서 활용) icon HellMaker 08-08 18,705
79 마이크로비트 디지털 홀 센서 활용 (아두이노 센서 활용) icon HellMaker 08-08 21,404