Download presentation
Presentation is loading. Please wait.
Published byOsborn Whitehead Modified over 9 years ago
1
Timer & Watch Dog Test UNIT 16 로봇 SW 교육원 조용수
2
학습 목표 Timer Init Timer Delay Test Timer Interrupt Test –One Shot Mode –Periodic Mode Watch Dog Test 시계 만들어 보기 2
3
Timer Init Timer Clock Enable 3 void TMR0_Init(void) { CLK_EnableModuleClock(TMR0_MODULE); CLK_SetModuleClock(TMR0_MODULE, CLK_CLKSEL1_TMR0_S_HIRC, 4); }
4
Timer Delay Test Delay 함수 제작 Time-out period = (Period time of timer clock input) * (8-bit pre-scale counter + 1) * (24-bit TCMP) Timer 1ms Period Value = System Clock / (pre-scale + 1) / 1000 System Clock : 22,118,400 Hz 4
5
Timer Delay Test 5 int delay(int ms) { int prescaler =3; TIMER0->TCSR &=~(0xFF); TIMER0->TCSR |= prescaler; // Set Prescaler : 1ms period TIMER0->TCMPR = ms * (SystemCoreClock / (prescaler + 1)) / 1000; //printf("Timer Register TCSR = 0x%x\n", TIMER0->TCSR); //printf("Timer Register TCMPR = %d\n", TIMER0->TCMPR); TIMER0->TCSR &= ~(0x3 << 27) ; // One shot Mode TIMER0->TCSR |= (0x1 << 30 ); // Start Counting; while(TIMER0->TCSR & TIMER_TCSR_CACT_Msk); }
6
Timer Interrupt Test Timer Handler 6 void TMR0_IRQHandler(void) { /* Clears Timer time-out interrupt flag */ TIMER_ClearIntFlag(TIMER0); Count++; P2->DOUT &= ~0x7; if(Count > 0x7) { Count = 0x0; } P2->DOUT |= Count; }
7
Timer Interrupt Test One Shot Mode 7 void TMR0_Init(void) { CLK_EnableModuleClock(TMR0_MODULE); CLK_SetModuleClock(TMR0_MODULE, CLK_CLKSEL1_TMR0_S_HIRC, 4); TIMER_Open(TIMER0, TIMER_ONESHOT_MODE, 1); /* Enable the Timer time-out interrupt */ TIMER_EnableInt(TIMER0); /* Start Timer counting */ TIMER_Start(TIMER0); /* Enable TMR0 Interrupt */ NVIC_EnableIRQ(TMR0_IRQn); }
8
Timer Interrupt Test Periodic Mode 8 void TMR0_Init(void) { CLK_EnableModuleClock(TMR0_MODULE); CLK_SetModuleClock(TMR0_MODULE, CLK_CLKSEL1_TMR0_S_HIRC, 4); TIMER_Open(TIMER0, TIMER_PERIODIC_MODE, 1); /* Enable the Timer time-out interrupt */ TIMER_EnableInt(TIMER0); /* Start Timer counting */ TIMER_Start(TIMER0); /* Enable TMR0 Interrupt */ NVIC_EnableIRQ(TMR0_IRQn); }
9
Watch Dog Test Init 9 void WDT_Init(void) { SYS_UnlockReg(); CLK_EnableModuleClock(WDT_MODULE); CLK_SetModuleClock(WDT_MODULE, CLK_CLKSEL1_WDT_S_HCLK_DIV2048, 1); WDT->WTCR &= ~(0x7 << 8); WDT->WTCR |= (0x6 << 8); WDT->WTCR |= 0x3 << 6; WDT->WTCR |= 0x1 << 1; NVIC_EnableIRQ(WDT_IRQn); SYS_LockReg(); }
10
Watch Dog Test Watch Dog Handler 10 void WDT_IRQHandler(void) { WDT_CLEAR_TIMEOUT_INT_FLAG(); printf("WDT_Interrupt!!\n"); WDT->WTCR |= 0x1; // Reset WDT Counter }
11
Watch Dog Test Watch Dog Counter Clear 11 void WDT_Clear(void) { SYS_UnlockReg(); WDT->WTCR |= 0x1; SYS_LockReg(); }
12
Watch Dog Test Watch Dog Counter Clear (main) 12 int main(void) { int count = 0; SYS_Init(); … while(1) { … WDT_Clear(); }
13
Timer 를 이용한 시계 제작 Timer 를 이용하여 Uart 로 출력하는 시계를 작성하세요 13
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.