捕获输入信号
我在我的项目中使用 msp430f2013 微控制器..因为我需要计算传入的脉冲信号频率序列....我不知道该怎么做....任何人都可以帮助我..示例代码对我来说更有用......提前感谢
i'm using msp430f2013 micro controller in my project.. in that i need to calculate the incoming train of pulse signal frequency.... i don't know how to do it.... can anyone help me in this.. example code is more usefull to me.... advance thanks for
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您需要阅读微控制器的手册,然后了解如何设置一个计时器来测量两个脉冲沿之间的间隔(例如从一个前沿到下一个前沿)。频率 f 将是该时间间隔 t 的倒数,即
You need to read the manual for the micro-controller, then work out how to set up a timer which can measure the interval between two pulse edges (e.g. from one leading edge to the next). The frequency, f, will be the reciprocal of this time interval, t, i.e.
有多种方法可以做到这一点,也许最简单的理解是将计时器设置为简单的计数器。轮询输入引脚,当它改变状态时,保存计时器上的计数,当它再次改变状态时,保存计时器上的计数,从另一个时间中减去一个时间,即每秒有多少个频率 X 滴答的时钟滴答。您的差异是每个输入脉冲 y 个刻度。 y / x 刻度线相互抵消,您将得到每个脉冲的秒数。如果您正在测量整个周期的上升沿到上升沿或下降沿到下降沿,那么它是相同的解决方案,区别在于要减去哪个定时器采样(例如最后一个上升沿和当前上升沿)。
一些微控制器能够在输入引脚上发生状态变化(或至少相同的边沿、上升沿或下降沿)时中断,并且您可能更喜欢使用该方法对计时器进行采样,减去并获取每个周期的滴答声,等等以获得每秒的周期(频率)。
使用计时器可能很棘手,我总是先使用计时器让 LED 闪烁,首先每秒闪烁一次进入棒球场,然后每 5 秒或 10 秒或 30 秒闪烁一次,并将其与手表上的秒针进行比较或其他一些参考资料来验证您的准确性,并且不会以这种或那种方式减少百分之十几。这建立了对计时器及其除数的理解,从那里您可以开始使用它来测量输入。为了确保我对 GPIO 进行了正确编程(LED 练习已经涵盖了其中的一些内容),我对输入引脚进行采样并使用输入引脚状态更改 LED 状态,然后通常可以查看 LED 以看到闪烁或暗淡的光芒看到我能够对 GPIO 引脚进行采样。然后将它们放在一起,并在输入更改状态时对计时器进行采样,首先轮询,然后是否需要中断或其他。
There are various ways to do this, perhaps the simplest to understand is to setup a timer as a simple counter. Poll the input pin, when it changes state save the count on the timer, when it changes state again save the count on the timer, subtract one time from the other and that is how many clock ticks of some frequency X ticks per second. your difference is y ticks per input pulse. y / x the ticks cancel out and you get seconds per pulse. If you are measuring a full period rising edge to rising edge or falling edge to falling edge then it is the same solution the difference is which timer samples to subtract (last rising edge and current rising edge for example).
Some microcontrollers have the ability to interrupt when there is a state change on the input pin (or at least the same edge, rising or falling), and you may prefer to use that method to sample the timer, subtract and get ticks per period, etc to get cycles per second (frequency).
Using a timer can be tricky, I always start by using the timer to blink an led, first once per second to get in the ball park, then once every 5 or 10 or 30 seconds, and compare that to a second hand on a watch or some other reference to verify that you are accurate and not a dozen percent off this way or that. That establishes understanding of the timer and its divisor, from there you can start to work on using it to measure the input. to make sure I have the gpio programmed right (the led exercise covers some of that already) I sample the input pin and change the led state with the input pin state and can often then look at the led to see blinks or a dull glow to see that I am able to sample the gpio pin. then put it all together and sample the timer when the input changes state, first polling then if need be interrupts or other.