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

임베디드 보드

번호 제목 글쓴이 날짜 조회수
78 마이크로비트 아날로그 홀 센서 활용 (아두이노 센서 활용) icon HellMaker 08-08 19,436
77 마이크로비트 마이크로비트로 가위바위보 게임 일산메이커 08-01 18,713
76 마이크로비트 마이크로 비트로 led 문자 출력하기 2 #microbit #마이크로비트 #led Wavy 07-31 18,332
75 마이크로비트 마이크로비트 - led로 문자출력하기 #마이크로비트 #led #문자 #microbit +1 Wavy 07-30 17,967
74 마이크로비트 마이크로 비트로 간단하게 led켜기 (microbit easy led) #microbit #LED #led Wavy 07-24 18,473
73 마이크로비트 마이크로비트 교육자료 - 반응속도 게임 +1 일산메이커 07-19 20,161
72 아두이노 C 언어 비교문에서 == 사용 방법 icon 양재동메이커 04-12 20,854
71 아두이노 [아두이노 실습] 푸쉬버튼 long press, short press 판단하기 icon 양재동메이커 03-27 21,263
70 아두이노 [아두이노 실습] Push button 스위치로 FND 카운트 증가/감소 icon 양재동메이커 03-27 25,818
69 아두이노 Blynk를 사용해 아두이노에서 IoT 맛보기 icon 양재동메이커 03-27 22,551
68 아두이노 아두이노에서 u8glib로 0.96" OLED 사용하기 icon 양재동메이커 03-27 22,283
67 아두이노 아두이노에서 여러개의 스위치를 1개의 analog input핀으로 검사하기 icon 양재동메이커 03-27 20,982
66 아두이노 아두이노에서 RTOS 사용하기 (FreeRTOS in Arduino) icon 양재동메이커 03-27 25,109
65 아두이노 아두이노에서의 delay() 함수 icon 양재동메이커 03-27 19,613
64 아두이노 아두이노의 pinMode()에서 INPUT과 INPUT_PULLUP의 차이 icon 양재동메이커 03-27 21,942
63 아두이노 아두이노등의 임베디드 시스템의 변수 값 오버플로우 문제 icon 양재동메이커 03-27 19,490
62 아두이노 아두이노에서 외부 라이브러리 설치하기 (Install library in arduino) icon 양재동메이커 03-27 21,414
61 아두이노 WS2812 color LED 사용하기 icon 양재동메이커 03-27 19,910
60 아두이노 WS2812와 APA102의 차이 비교 (Comparison between WS2812 and APA102) icon 양재동메이커 03-27 23,055
59 아두이노 [강좌] 51. 와이파이 통신 (5) - WebServer 예제 (2) icon 양재동메이커 03-21 19,444