說明文件

Timer Toggle 使用邏輯分析儀量測timer toggle (by M460)

Timer Toggle 使用邏輯分析儀量測timer toggle (by M460)

Timer0 電路位置

blog圖片的連結

由pinconfigure 可以知道Timer0 在 pin 1 (PB5) 接著

設定 Timer0 pin 角

//—PIN—- /* Set timer toggle out pin */ SET_TM0_PB5();

Timer Delay

Delay 1 秒:

TIMER_Delay(TIMER0, 1000000);

Timer init_TIMER0_Toggle

TIMER_Open(TIMER0, TIMER_TOGGLE_MODE, 250000);

開啟TIMER0 反轉250K

邏輯分析儀量測

  1. 邏輯分析儀 桶著 Pin1 blog圖片的連結
  2. 開 Salease 邏輯分析儀 SW blog圖片的連結

可以發現訊號是125K Hz 波峰 +波谷 就250K Hz

/*---------------------------------------------------------------------------------------------------------*/
/* Global Interface Variables Declarations                                                                 */
/*---------------------------------------------------------------------------------------------------------*/
volatile uint32_t g_au32TMRINTCount[4] = {0};
//----------------- TIMER0 --------------------
void TMR0_IRQHandler(void)
{
    if(TIMER_GetIntFlag(TIMER0) == 1)
    {
        /* Clear Timer0 time-out interrupt flag */
        TIMER_ClearIntFlag(TIMER0);
        g_au32TMRINTCount[0]++;
			
			PH4 ^= 1;
			
    }
}
void TMR0_Init(void)
{
    /* Enable TIMER module clock */
    //---clock---
    CLK_EnableModuleClock(TMR0_MODULE);
    CLK_SetModuleClock(TMR0_MODULE, CLK_CLKSEL1_TMR0SEL_HXT, 0);
     
    //---PIN----
    /* Set timer toggle out pin */
    SET_TM0_PB5();
     
    /* Open Timer0 in periodic mode, enable interrupt and 1 interrupt tick per second */
    TIMER_Open(TIMER0, TIMER_PERIODIC_MODE, 1);
    /* Start Timer0 ~ Timer3 counting */
    TIMER_Start(TIMER0);
 
    //--- NVIC ----
    TIMER_EnableInt(TIMER0);
    /* Enable Timer0 ~ Timer3 NVIC */
    NVIC_EnableIRQ(TMR0_IRQn);
     
    /* Check Timer0 ~ Timer3 interrupt counts */
    //g_au32TMRINTCount[0];
     
}

void init_TIMER0_Toggle(void)
{
    /* Enable TIMER module clock */
    //---clock---
    CLK_EnableModuleClock(TMR0_MODULE);
    CLK_SetModuleClock(TMR0_MODULE, CLK_CLKSEL1_TMR0SEL_HXT, 0);
    //---PIN----
    /* Set timer toggle out pin */
    SET_TM0_PB5();
    /* Open Timer0 in periodic mode, enable interrupt and 1 interrupt tick per second */
    TIMER_Open(TIMER0, TIMER_TOGGLE_MODE, 250000);
    /* Start Timer0 ~ Timer3 counting */
    TIMER_Start(TIMER0);
}


//-------------- HCLK  -------------
void init_HCLK(void){
 
    SYS_UnlockReg();
 
 
    /*---------------------------------------------------------------------------------------------------------*/
    /* Init System Clock                                                                                       */
    /*---------------------------------------------------------------------------------------------------------*/
    /* Set PCLK0 and PCLK1 to HCLK/2 */
    CLK->PCLKDIV = (CLK_PCLKDIV_APB0DIV_DIV2 | CLK_PCLKDIV_APB1DIV_DIV2);
    /* Set core clock to 200MHz */
    CLK_SetCoreClock(200000000);
    /* Enable all GPIO clock */
    CLK->AHBCLK0 |= CLK_AHBCLK0_GPACKEN_Msk | CLK_AHBCLK0_GPBCKEN_Msk | CLK_AHBCLK0_GPCCKEN_Msk | CLK_AHBCLK0_GPDCKEN_Msk |
                    CLK_AHBCLK0_GPECKEN_Msk | CLK_AHBCLK0_GPFCKEN_Msk | CLK_AHBCLK0_GPGCKEN_Msk | CLK_AHBCLK0_GPHCKEN_Msk;
    CLK->AHBCLK1 |= CLK_AHBCLK1_GPICKEN_Msk | CLK_AHBCLK1_GPJCKEN_Msk;
    /* Enable HXT clock */
    CLK_EnableXtalRC(CLK_PWRCTL_HXTEN_Msk);
    CLK_WaitClockReady( CLK_STATUS_HXTSTB_Msk);
     
     
    SYS_LockReg();
   
}


/*---------------------------------------------------------------------------------------------------------*/
/*  Main Function                                                                                          */
/*---------------------------------------------------------------------------------------------------------*/
int32_t main(void)
{
    uint16_t cnt = 0;
    uint8_t STA = 0;

    /* Unlock protected registers */
    SYS_UnlockReg();
    /* Init System, peripheral clock and multi-function I/O */
    SYS_Init();
    /* Lock protected registers */
    SYS_LockReg();
    /* Init UART0 for printf */
    UART0_Init();


	init_HCLK();
	init_TIMER0_Toggle();
	
    // PH4 LED R
	GPIO_SetMode(PH, BIT4, GPIO_MODE_OUTPUT);

    while(1) {


    }

}
comments powered by Disqus