Ejemplo n.º 1
0
/**
 * @brief       Time init
 *
 * @param       None
 *
 * @return      None
 *
 * @details     Init Timer IP
 */
void Timer0_Timer1_Timer2_Init(void)
{
    SET_TMR0_CLKSRC(CLK_TMR0_HCLK);                       //Timer0 CLK = 22MHz
    SET_TMR2_CLKSRC(CLK_TMR2_HCLK);                       //Timer1 CLK = 22MHz
    APBCLK_ENABLE(CLK_TMR0 | CLK_TMR1 | CLK_TMR2)  ;      //Enable T0&T1 CLK

    /* Set MFP pin */
    GPIO_TMR0();										   //PB8 = T0 toggle output
    GPIO_T2EX();										   //PB2 = T2EX capture input
    GPIO_TMR1();										   //PB9 = TM1 counter input

    ////Timer0 configure. Toggle PIN64:PB8_TM0 every 10ms ///////////////////////////////////////////
    DrvTIMER_Init(TIMER0, 21/*prescale*/, 10000/*TCMPR*/, TIM_MODE_TOGGLE);
    DrvTIMER_EnableInt(TIMER0, TIM_INT_EN);
    TIM_ENABLE(TIMER0);

    //Timer1 configure. Count pulse from PIN32:PB9_TM1.//////////////////////////////////
    DrvTIMER_Init(TIMER1, 0/*prescale*/, 10/*TCMPR*/, TIM_MODE_PERIODIC);
    TIM_COUNT_MODE_ENABLE(TIMER1) ;                          //count mode
    TIM_COUNT_DEBOUNCE_ENABLE(TIMER1) ;                      //Enable count de-bounce
    TIM_UPDATA_TDR_ENABLE(TIMER1) ;
    DrvTIMER_EnableInt(TIMER1, TIM_INT_EN);
    TIM_ENABLE(TIMER1) ;

    ////Timer2 configure. Capture edge from PIN23:PB2_T2EX ////////////////////////////////
    DrvTIMER_Init(TIMER2, 22/*prescale*/, 10000/*TCMPR*/, TIM_MODE_CONTINUOUS);
    TIM_CAPTURE_DEBOUNCE_ENABLE(TIMER2) ;
    TIM_SET_CAP_EDGE_MODE(TIMER2,TIM_CAPTURE_EDGE);          //capture rise and fall edge.
    TIM_CAPTURE_ENABLE(TIMER2) ;
    DrvTIMER_EnableInt(TIMER2, TIM_TEX_INT_EN);
    TIM_ENABLE(TIMER2);
}
Ejemplo n.º 2
0
/*----------------------------------------------------------------------------------------
函数名: TimerInit
参数:
		None
返回值:
		None
描述:
		初始化定时器,并创建第一个虚拟定时器:1s为周期
----------------------------------------------------------------------------------------*/
void TimerInit(void)
{
	DrvTIMER_Init();
	DrvTIMER_Open(TMR1, 1000, PERIODIC_MODE);
	DrvTIMER_SetTimerEvent(TMR1,1000, (TIMER_CALLBACK)TMRCBForSysTick,0);
	DrvTIMER_EnableInt(TMR1);
	DrvTIMER_Ioctl(TMR1, TIMER_IOC_START_COUNT, 0);
}
Ejemplo n.º 3
0
void TIMER_Configuration()				   
{

    DrvTIMER_Init();														

	DrvSYS_SelectIPClockSource(E_SYS_TMR0_CLKSRC,0);					

	DrvTIMER_Open(E_TMR0,5,E_PERIODIC_MODE);								
	
 	DrvTIMER_SetTimerEvent(E_TMR0,1,(TIMER_CALLBACK) Timer0_Callback,0);

	DrvTIMER_EnableInt(E_TMR0);											

	DrvTIMER_Start(E_TMR0);												
}
Ejemplo n.º 4
0
/*************************************************************************//**
 * @brief   Delay 1 second exactly with timer.
 * @param   None
 * @return  None
*****************************************************************************/
void Delay1Sec(void)
{
    UNLOCKREG();
    SYSCLK->PWRCON.XTL12M_EN = 1;
    /* Waiting for 12M Xtal stable */
    while (DrvSYS_GetChipClockSourceStatus(E_SYS_XTL12M) != 1);
    
    /*Configure gpio p3.6 as OUTPUT for led*/
    DrvGPIO_Open(E_PORT3, E_PIN6, E_IO_OUTPUT);
    /* Example code */
    DrvTIMER_Init();
    DrvTIMER_Open(E_TMR0, 1000, E_PERIODIC_MODE);                   
    DrvTIMER_EnableInt(E_TMR0);     
    DrvTIMER_Start(E_TMR0);             /* Start counting */

    while (1)
    {
        DrvGPIO_SetBit(E_PORT3, E_PIN6);
        DrvTIMER_Delay(E_TMR0, 1000);       /*Delay 1000/1000 Sec*/
        DrvGPIO_ClrBit(E_PORT3, E_PIN6);
        DrvTIMER_Delay(E_TMR0, 1000);
    }
}