본문 바로가기
임베디드.일렉트로닉스/EFM8

EFM8 SB1 의 Programmable Counter Array(PCA), Watch Dog Timer

by i.got.it 2015. 5. 1.

 

 

개요 - EFM8 SB1 의 PCA

 

 

- PCA 는 enhanced timer 3개 채널 제공하며, PWM(Pulse Width Modulation) 기능도 제공한다.

- PCA 는 표준 counter/timer 보다 CPU 개입이 덜 요구된다.

- PCA 의 counter/timer 클럭소스는 여러가지 가능하다.

- PCA 구성 : 1개의 16bit counter/timer 와 각 채널별로 16bit capture/compare 로 구성된다.

- 각 채널의 Capture/Compare 모듈은 5개 모드 중 하나로 설정될 수 있다. 5개 모드 : Edge-Triggered Capture, Software
Timer, High-Speed Output, Frequency Output, Pulse-Width Modulated (PWM) Output.

- 각 채널의 Capture/Compare 모듈은 고유의 핀 (CEX0, CEX1, CEX2) 으로 연결될 수 있다.

- Watch Dog Timer 가 3개 채널(0,1,2)중 2를 이용하여 구현될 수 있다.

 

 

 

 

 

 

PCA 주요특징.

 • 16-bit time base.
• Programmable clock divisor and clock source selection.
• Up to three independently-configurable channels
• 8, 9, 10, 11 and 16-bit PWM modes (edge-aligned operation).
• Frequency output mode.
• Capture on rising, falling or any edge.
• Compare function for arbitrary waveform generation.
• Software timer (internal compare) mode.
• Integrated watchdog timer.

 

 본 글의 내용은 EFM8SB1 레퍼런스 매뉴얼 페이지 179~ 참조.

 

PCA0 레지스터.

 

PCA0CN0 : PCA0 Control0.

PCA0MD : PCA0 mode.

PCA0PWM : PCA0 PWM Configuration.

PCA0L : PCA0 Counter/Timer Low Byte.

PCA0H : PCA0 Counter/Timer High Byte.

PCA0CPM0 : PCA0 Channel 0 Capture/Compare Mode.

PCA0CPL0 : PCA0 Channel 0 Capture Module Low Byte.

PCA0CPH0 : PCA0 Channel 0 Capture Module High Byte.

PCA0CPM1 : PCA0 Channel 1 Capture/Compare Mode.

PCA0CPL1 : PCA0 Channel 1 Capture Module Low Byte.

PCA0CPH1 : PCA0 Channel 1 Capture Module High Byte.

PCA0CPM2 : PCA0 Channel 2 Capture/Compare Mode.

PCA0CPL2 : PCA0 Channel 2 Capture Module Low Byte.

PCA0CPH2 : PCA0 Channel 2 Capture Module High Byte.

 

 

 

 

 

 

 

Watch Dog Timer

 

- WDT 는 PCA 채널2를 통하여 사용가능하다.

- WDT enable/disable 은 PCA0MD 의 WDTE 비트에 기록된 값으로 제어된다. PCA0MD 의 WDTE 비트 에 1이 기록되면 채널2 모듈이 WDT 로 작동하게 된다.

-  EFM8 의 WDT는 normal, idle 전력모드에서만 작동한다. sleep 모드에선 작동하지 않는다.

 

Watchdog Timer Operation
While the WDT is enabled:
• PCA counter is forced on.
• Writes to PCA0L and PCA0H are not allowed.
• PCA clock source CPS field is frozen.
• PCA Idle control bit (CIDL) is frozen.
• Module 2 is forced into software timer mode.
• Writes to the Module 2 mode register (PCA0CPM2) are disabled.

 

 

Watchdog Timer Usage
To configure the WDT, perform the following tasks:
1. Disable the WDT by writing a 0 to the WDTE bit.
2. Select the desired PCA clock source (with the CPS field).
3. Load the WDT PCA0CPL with the desired WDT update offset value.
4. Configure the PCA Idle mode (set CIDL if the WDT should be suspended while the CPU is in Idle mode).
5. Enable the WDT by setting the WDTE bit to 1.
6. Reset the WDT timer by writing to PCA0CPH2.

 

 

 

 

 

 

 

Coding Tip - Watch Dog Timer

   

 

워치도그 타임아웃 시간계산법.

 

Time = Offset x (PCA에서 사용하는 클럭소스의 주기)   로 계산되며,

위 식에서 Offset 은 PCA의 PCA0CPL5, PCA0L 의 값에 따라 아래 식으로 계산된다.

Offset = (256xPCA0CPL5) + 256 - PCA0L

 

계산예. PCA에서 사용하는 클럭소스를 SYSCLK/12 로 선택했고, SYSCLK를 3062500 Hz 로 선택 했다면 그 주기는 12/SYSCLK이며, 

 PCA0CPL5 = 0xFF, PCA0L = 0x00 으로 했다면

먼저 Offset = 256 x 256 + 256 - 0 => 65792 이므로

TimeOut = 65792 x 12/SYSCLK = 0.25779초. ~ 258msec.

즉, 258msec 동안 WDT 를 초기화 하지 않으면 WDT는 MCU를 리셋하게된다.

 

 

 

 

펌웨어 에서 직전 리셋이 워치도그에 의한것인지 확인하기.

아래 굵은 글자로 된 RSTSRC 값이 0x08인 경우 워치도그 리셋된 경우이다.

단 이 값을 체크하기 전에 RSTSRC 의 PORSF 비트를 점검하여 그 값이 1인 경우는 리셋소스(RSTSRC) 정보 없는 경우이므로 PORSF  값이 0인경우에만 점검한다.

 

 if ((RSTSRC & 0x02) == 0x00)        // First check the PORSF bit. if PORSF
 {                                               // is set, all other RSTSRC flags are
                                                 // invalid
   // Check if the last reset was due to the Watch Dog Timer

   if (RSTSRC == 0x08) // 워치도그 리셋을 의미.

   {
     // 직전 리셋이 워치도그에 의한 것인 경우 처리할 것 있으면 수행.

   }
 }

 

Watchdog Timer 리셋.

 

PCA0CPH2 = 0x00;

 

 

 

 

 

 

 

 

 

 

 본 글이 포함된 상위 정리장소 : http://igotit.tistory.com/244

 

 

///296.

댓글



 

비트코인




암호화폐       외환/나스닥/골드       암호화폐/외환/나스닥/골드 암호화폐/외환/나스닥/골드   암호화폐/외환/나스닥/골드
     
현물 |선물 인버스 |선물 USDT       전략매니저(카피트레이딩)     롤오버 이자 없는 스왑프리계좌
( 스왑프리 암호화폐도 거래 가능 )    
MT4, MT5 , cTrader 모두 지원     FTMO 계좌 매매운용. MT4,MT5