搜索
bottom↓
回复: 10

怎么用stm32测量输出信号的脉冲个数和频率?

[复制链接]
头像被屏蔽

出0入0汤圆

发表于 2012-5-26 11:44:10 | 显示全部楼层 |阅读模式
提示: 作者被禁止或删除 内容自动屏蔽

出0入0汤圆

发表于 2012-5-26 11:50:17 | 显示全部楼层
外部中断+定时器

出0入0汤圆

发表于 2012-5-26 11:56:01 | 显示全部楼层
定时器输入捕获!
头像被屏蔽

出0入0汤圆

 楼主| 发表于 2012-5-26 18:12:57 | 显示全部楼层
提示: 作者被禁止或删除 内容自动屏蔽

出0入0汤圆

发表于 2012-5-26 18:31:26 | 显示全部楼层
大致过程如下: 频率不知到太大会不会有问题,低频下测试可以....
1、void EXIT_Configuration(void)
{
        /* 定义EXIT初始化结构体 EXTI_InitStructure */
        EXTI_InitTypeDef EXTI_InitStructure;

        /* 设置外部中断10,11,12通道在上升沿时触发中断 */  
          EXTI_InitStructure.EXTI_Line = EXTI_Line10 | EXTI_Line11 | EXTI_Line12;
          EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt;
          EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Rising; //三种触发方式可选
          EXTI_InitStructure.EXTI_LineCmd = ENABLE;
          EXTI_Init(&EXTI_InitStructure);
}
2.  中端配置 ......
3.  中断中记录脉冲
void EXTI15_10_IRQHandler(void)
{
                  /*----- 外部中断10:记录脉冲数 -----*/
         if(EXTI_GetITStatus(EXTI_Line10) != RESET)
         {              
                  printf("EXIT10 IRQHandler Enter.\r\n");         //串口调试
                  g_PulseCnt++;
                  EXTI_ClearFlag(EXTI_Line10);
         }
                //...
}
4.频率计算: 定时器或systick产生100ms标志
//...............
if(g_100msFlag == 1)
{
          g_100msFlag = 0;
      freq = g_PulseCnt*10;
         g_PulseCnt = 0;
}

出0入0汤圆

发表于 2012-5-26 19:08:48 | 显示全部楼层
定时器输入捕获的基本功能

出0入0汤圆

发表于 2012-5-26 19:11:12 | 显示全部楼层
可以用定时器的捕获,上升沿触发或下降沿触发都可以。

出0入0汤圆

发表于 2012-5-26 19:32:58 | 显示全部楼层
if the pulse train is of high frequencies, use a counter to count it within a given period of time. This approach is typically good for >10Mhz.

出0入0汤圆

发表于 2012-5-26 20:34:29 | 显示全部楼层
LS:
在低频下如何测量脉冲?

出0入0汤圆

发表于 2012-5-26 22:29:20 | 显示全部楼层
在低频下如何测量脉冲?


it depends on how slow your 低频 signal is and what your requirements are.

You can still use the same approach I outlined earlier for slow speed signals. However, if your signal is very slow (in terms of Hz), or you require higher precision in those cases, you may use capture, or external int - to time the duration between two interrupts.

It goes something like this:

1) set the timer to count cpu frequency. don't start yet.
2) when the 1st pulse arrives, turn on the timer and start counting.
3) when the 2nd pulse arrives, turn off the timer and the count in the timer + cpu frequency tells you how much time has elapsed -> you know the external pulse's period / frequency.

出0入0汤圆

发表于 2012-5-27 00:02:41 | 显示全部楼层
用stm32测量输出信号的脉冲个数和频率,既然是输出信号,发了多少脉冲个数CPU是可以知道的吧,输出时计数会方便些吧
回帖提示: 反政府言论将被立即封锁ID 在按“提交”前,请自问一下:我这样表达会给举报吗,会给自己惹麻烦吗? 另外:尽量不要使用Mark、顶等没有意义的回复。不得大量使用大字体和彩色字。【本论坛不允许直接上传手机拍摄图片,浪费大家下载带宽和论坛服务器空间,请压缩后(图片小于1兆)才上传。压缩方法可以在微信里面发给自己(不要勾选“原图),然后下载,就能得到压缩后的图片】。另外,手机版只能上传图片,要上传附件需要切换到电脑版(不需要使用电脑,手机上切换到电脑版就行,页面底部)。
您需要登录后才可以回帖 登录 | 注册

本版积分规则

手机版|Archiver|amobbs.com 阿莫电子技术论坛 ( 粤ICP备2022115958号, 版权所有:东莞阿莫电子贸易商行 创办于2004年 (公安交互式论坛备案:44190002001997 ) )

GMT+8, 2024-5-4 11:06

© Since 2004 www.amobbs.com, 原www.ourdev.cn, 原www.ouravr.com

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