STM32 TIM 輸入捕捉 雙邊沿檢測 TIM_ICPolarity_BothEdge

來源:互聯網
上載者:User
STM32 TIM 輸入捕捉 雙邊沿檢測 TIM_ICPolarity_BothEdge

直接來,先上代碼:

//初始化TIM1輸入捕獲參數TIM1_ICInitStructure.TIM_Channel = TIM_Channel_1; //CC1S=01     選擇輸入端 IC1映射到TI1上TIM1_ICInitStructure.TIM_ICPolarity = TIM_ICPolarity_BothEdge;  TIM1_ICInitStructure.TIM_ICSelection = TIM_ICSelection_DirectTI; //映射到TI1上TIM1_ICInitStructure.TIM_ICPrescaler = TIM_ICPSC_DIV1;   //配置輸入分頻,不分頻 TIM1_ICInitStructure.TIM_ICFilter = 0x00;//IC1F=0000 配置輸入濾波器 不濾波TIM_ICInit(TIM1, &TIM1_ICInitStructure);

首先,這樣寫代碼是實現不了雙邊沿輸入捕捉的,具體原因是ST這一塊沒做好,TIM_ICPolarity_BothEdge沒有用

多虧這個文章裡的大神,把問題解決了
http://www.openedv.com/thread-12644-1-1.html

按照文章所述,奉上代碼:

  /*********************使能雙邊沿檢測************************/   // http://www.openedv.com/thread-12644-1-1.html   TIM1->CCER &= (uint16_t)~((uint16_t)TIM_CCER_CC1E);   TIM1->CCMR1 |= 0x03;   TIM1->SMCR |= (1 << 6);   TIM1->SMCR &= ~((1 << 5) | (1 << 4));   TIM1->CCER |= ((uint16_t)TIM_CCER_CC1E);   /*********************使能雙邊沿檢測************************/

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.