Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Next revision
Previous revision
cublocapp:an41003:index [2026/02/09 01:03] – created - external edit 127.0.0.1cublocapp:an41003:index [Unknown date] (current) – removed - external edit (Unknown date) 127.0.0.1
Line 1: Line 1:
-====== AN41002 - 타임루프 프로그래밍 기법 응용 (채터링 제거 입력) ====== 
  
-이번에는 산업현장에서 흔히 등장하는 노이즈 (채터링) 제거후 입력받기 예제 프로그램입니다. 
-  
-아래 그림처럼 최초 2초간 신호가 유지되어야 비로소 출력을 On 하는 상황입니다. 출력도 2초간 On하고 꺼져야 합니다. (실제로는 2초까지 대기할 필요는 없습니다. 0.5초~1초미만이면 노이즈제거에 충분합니다.) 
- 
-{{ :cublocapp:an41003:chart1.jpg?nolink |}} 
- 
-이렇게 되면, 짧은 노이즈가 유입되어도 출력이 나오지 않게됩니다. 입력이 하나라면, 구지 타임루프 프로그래밍 기법을 사용하지 않아도 됩니다. 
-  
-하지만, 여러개 입력이 동시에 들어올 경우, 이 기법이 아니면 딱히 방법이 없습니다. 
- 
-<code c> 
-#include "moacon500.h" 
-int timerA = 0; 
-int timerB = 0; 
-  
-void cmain(void) 
-{ 
- portInit(1,0); // 1번 블록을 출력상태로 만듭니다. 
- startTimerEvent(100); // 타이머 이벤트의 시작 
-  
- while(1) {} // 무한루프 
-} 
-  
-void processInput(void) 
-{ 
-  if (portIn(0) == 0) timerA = 40; 
-  if (portIn(1) == 0) timerB = 40; 
-} 
-   
-void processOutput(void) 
-{ 
- if ((timerA > 0) && (timerA <20)) // 0 < timerA <20 일때 On 
-  portOn(10); 
- else 
-  portOff(10); 
-  
- if ((timerB > 0) && (timerB <20)) // 0 < timerB <20 일때 On 
-  portOn(11); 
- else 
-  portOff(11); 
-} 
-  
-void timer(void) 
-{ 
- if (timerA > 0) timerA--;    // 0 보다 크면 1감소 
- if (timerB > 0) timerB--; 
-} 
-   
-// 0.1초마다 이곳으로 옵니다. 
-  
-void timerEvent(void) 
-{ 
- timer(); 
- processInput(); 
- processOutput(); 
-} 
-</code> 
- 
-작동예입니다. 입력스위치를 짧게 On, Off 를 반복하면 출력이 On되지 않습니다.  
- 
-입력을 2초이상 On하고 있어야, 출력이 On 됩니다. 
- 
-<html><center> 
-<iframe width="560" height="315" src="https://www.youtube.com/embed/D5ABsYt3Pqg" frameborder="0" allowfullscreen></iframe> 
-</center></html> 
- 
-[[cublocapp:index#MOACON 어플리케이션 노트|MOACON 어플리케이션 노트]]