標題:
stm32f1 PWM輸入捕獲程序
[打印本頁]
作者:
zlkj
時間:
2024-10-8 16:11
標題:
stm32f1 PWM輸入捕獲程序
#include "stm32f10x.h"
#include "pwm.h"
#include "usart.h"
__IO uint16_t IC1Value = 0;
__IO uint16_t DutyCycle = 0;
__IO uint32_t Frequency = 0;
void Delay(u32 nCount)
{
for(; nCount!=0; nCount--);
}
int main(void)
{
USART1_Config();
TIM3_PWMIC_Config();
while(1)
{
Delay(0xffffff);
printf("DutyCycle: %d%%\r\n", DutyCycle);
printf("Frequency: %d\r\n", Frequency);
}
}
void TIM3_IRQHandler(void)
{
/* Clear TIM3 Capture compare interrupt pending bit */
TIM_ClearITPendingBit(TIM3, TIM_IT_CC1);
/* Get the Input Capture value */
IC1Value = TIM_GetCapture1(TIM3);
if (IC1Value != 0)
{
/* Duty cycle computation */
DutyCycle = (TIM_GetCapture2(TIM3) * 100) / IC1Value;//TIM_GetCapture2觸發(fā)信號和下一個相反極性的邊信號的計數(shù)個數(shù)
/* Frequency computation */
Frequency = SystemCoreClock / IC1Value;
}
else
{
DutyCycle = 0;
Frequency = 0;
}
}
復(fù)制代碼
原理圖: 無
仿真: 無
代碼:
stm32f1 PWM輸入捕獲.7z
(177.87 KB, 下載次數(shù): 1)
2024-10-9 02:07 上傳
點擊文件名下載附件
下載積分: 黑幣 -5
歡迎光臨 (http://www.torrancerestoration.com/bbs/)
Powered by Discuz! X3.1