找回密码
 立即注册

QQ登录

只需一步,快速开始

搜索
查看: 460|回复: 0
打印 上一主题 下一主题
收起左侧

stm32f1 PWM输入捕获程序

[复制链接]
跳转到指定楼层
楼主
ID:82098 发表于 2024-10-8 16:11 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
  1. #include "stm32f10x.h"   
  2. #include "pwm.h"
  3. #include "usart.h"

  4. __IO uint16_t IC1Value = 0;
  5. __IO uint16_t DutyCycle = 0;
  6. __IO uint32_t Frequency = 0;

  7. void Delay(u32 nCount)
  8. {
  9.         for(; nCount!=0; nCount--);
  10. }

  11. int main(void)
  12. {
  13.         USART1_Config();
  14.         TIM3_PWMIC_Config();
  15.        
  16.         while(1)
  17.         {
  18.                 Delay(0xffffff);
  19.                 printf("DutyCycle: %d%%\r\n", DutyCycle);
  20.                 printf("Frequency: %d\r\n", Frequency);
  21.         }
  22. }

  23. void TIM3_IRQHandler(void)
  24. {
  25.   /* Clear TIM3 Capture compare interrupt pending bit */
  26.   TIM_ClearITPendingBit(TIM3, TIM_IT_CC1);

  27.   /* Get the Input Capture value */
  28.   IC1Value = TIM_GetCapture1(TIM3);  

  29.   if (IC1Value != 0)
  30.   {
  31.     /* Duty cycle computation */
  32.     DutyCycle = (TIM_GetCapture2(TIM3) * 100) / IC1Value;//TIM_GetCapture2触发信号和下一个相反极性的边信号的计数个数

  33.     /* Frequency computation */
  34.     Frequency = SystemCoreClock / IC1Value;
  35.   }
  36.   else
  37.   {
  38.     DutyCycle = 0;
  39.     Frequency = 0;
  40.   }
  41. }
复制代码

原理图: 无
仿真: 无
代码: stm32f1 PWM输入捕获.7z (177.87 KB, 下载次数: 1)
分享到:  QQ好友和群QQ好友和群 QQ空间QQ空间 腾讯微博腾讯微博 腾讯朋友腾讯朋友
收藏收藏 分享淘帖 顶 踩
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

手机版|小黑屋|51黑电子论坛 |51黑电子论坛6群 QQ 管理员QQ:125739409;技术交流QQ群281945664

Powered by 单片机教程网

快速回复 返回顶部 返回列表