在线看毛片网站电影-亚洲国产欧美日韩精品一区二区三区,国产欧美乱夫不卡无乱码,国产精品欧美久久久天天影视,精品一区二区三区视频在线观看,亚洲国产精品人成乱码天天看,日韩久久久一区,91精品国产91免费

<menu id="6qfwx"><li id="6qfwx"></li></menu>
    1. <menu id="6qfwx"><dl id="6qfwx"></dl></menu>

      <label id="6qfwx"><ol id="6qfwx"></ol></label><menu id="6qfwx"></menu><object id="6qfwx"><strike id="6qfwx"><noscript id="6qfwx"></noscript></strike></object>
        1. <center id="6qfwx"><dl id="6qfwx"></dl></center>

            新聞中心

            EEPW首頁 > 嵌入式系統(tǒng) > 設(shè)計應(yīng)用 > STM32F107VCT6的通用定時器的輸入捕獲功能配置

            STM32F107VCT6的通用定時器的輸入捕獲功能配置

            作者: 時間:2016-11-10 來源:網(wǎng)絡(luò) 收藏
            將TIM4配置成輸入捕獲功能用于計算矩形波的周期。

            #define NVIC_Priority_Timer4 1

            本文引用地址:http://www.biyoush.com/article/201611/317514.htm

            void TIM4_Init_Config(void)
            {
            GPIO_InitTypeDef GPIO_InitStructure;
            NVIC_InitTypeDef NVIC_InitStructure;
            TIM_ICInitTypeDef TIM_ICInitStructure; //輸入捕獲結(jié)構(gòu)體
            TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure; //時基結(jié)構(gòu)體

            RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM4, ENABLE);
            RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOD, ENABLE);

            /*
            *PD15-TIM4_Ch4 矩形方波的輸入管腳
            */
            GPIO_InitStructure.GPIO_Pin = GPIO_Pin_15;
            GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU;
            GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
            GPIO_Init(GPIOD, &GPIO_InitStructure);

            GPIO_PinRemapConfig(GPIO_Remap_TIM4 , ENABLE); //TIM4_CH4/PD15 硬件已經(jīng)映射好的,不能將TIM4_CH4用于其他管腳

            NVIC_InitStructure.NVIC_IRQChannel = TIM4_IRQn;
            NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = NVIC_Priority_Timer4;
            NVIC_InitStructure.NVIC_IRQChannelSubPriority = 4;
            NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
            NVIC_Init(&NVIC_InitStructure);

            /*

            * 設(shè)置TIM4的時基:(1+TIM_Prescaler )/72M)*(1+TIM_Period )=((1+0xFFFF)/72M)*(1+71) = 65536/1M

            * (定時器計滿16位用時,則計一個數(shù)用時1/1M)

            */
            TIM_TimeBaseStructure.TIM_Period = 0xFFFF;
            TIM_TimeBaseStructure.TIM_Prescaler = 71;
            TIM_TimeBaseStructure.TIM_ClockDivision = 0x0;
            TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;
            TIM_TimeBaseInit(TIM4, &TIM_TimeBaseStructure);

            TIM_ICInitStructure.TIM_Channel = TIM_Channel_4;
            TIM_ICInitStructure.TIM_ICPolarity = TIM_ICPolarity_Falling; //PD15管腳檢測下降沿
            TIM_ICInitStructure.TIM_ICSelection = TIM_ICSelection_DirectTI;
            TIM_ICInitStructure.TIM_ICPrescaler = TIM_ICPSC_DIV1;
            TIM_ICInitStructure.TIM_ICFilter = 0xF;
            TIM_ICInit(TIM4, &TIM_ICInitStructure);

            TIM_Cmd(TIM4, ENABLE);
            TIM_ITConfig(TIM4, TIM_IT_CC4, ENABLE);
            }

            stm32f10x_it.c文件中

            unsigned int IC4ReadValue1 = 0;
            unsigned int IC4ReadValue2 = 0;
            unsigned int CaptureNumber_ch4 = 0;
            unsigned int Capture_ch4 = 0;

            void TIM4_IRQHandler(void)
            {
            //每當(dāng)PD15管腳檢測到下降沿,就會進(jìn)入到該中斷處理函數(shù)
            if (TIM_GetITStatus(TIM4, TIM_IT_CC4) == SET)
            {

            TIM_ClearITPendingBit(TIM4, TIM_IT_CC4);

            if (CaptureNumber_ch4 == 0)
            {

            CaptureNumber_ch4 = 1;
            IC4ReadValue1 = TIM_GetCapture4(TIM4);
            }
            else if (CaptureNumber_ch4 == 1)
            {

            CaptureNumber_ch4 = 0;
            IC4ReadValue2 = TIM_GetCapture4(TIM4);
            if (IC4ReadValue2 > IC4ReadValue1)
            {
            Capture_ch4 = (IC4ReadValue2 - IC4ReadValue1);
            }
            else if (IC4ReadValue2 < IC4ReadValue1)
            {
            Capture_ch4 = ((0xFFFF - IC4ReadValue1) + IC4ReadValue2);
            }
            else
            {
            Capture_ch4 = 0;
            }
            }

            }
            }




            評論


            技術(shù)專區(qū)

            關(guān)閉