这张照片有几种不同的方法。在PWM模块上没有输入捕获模式的能力是不可预知的,该特性具有良好的硬件解决方案。可以使用定时器(Time2)设置周期中断(该周期将定义您确定未知频率的分辨率),然后对输入进行轮询。启动/停止信号(检测上升沿或下降沿)或使用外部中断输入(IOC可能或使用比较器模块来生成一个IUPUT)。在定时器的ISR中保持“嘀嗒声”-每1中断的运行计数,并使用这来获得上升沿上升沿的周期。如果你使用一个中断来检测“边缘”,那么只需从“最后的蜱”中减去“当前蜱”来获得ISR中的周期。如果轮询输入,则在检测轮询函数/例程中的输入边沿后进行减法运算。
以上来自于百度翻译
以下为原文
There are a few dufferent ways to do this with this pic. It is unfortuante that it does not have input capture mode capability on the PWM modules, that feature makesa good hardware solution.
You can use a timer (timer2) set for a periodic interrupt (the period will define your resolution of determining the unknown frequency) and then either poll the input signal for start/stop (detect the rising or falling edges) or use an external interrupt input (IOC maybe or use the comparator module to generate an interupt). In the ISR for the timer keep a running count of "ticks" - +1 each interrupt- and use this to get period of rising edge to rising edge. If you use an interrupt to detect the "edges" then just subtract "current ticks" from "last ticks" to get period in the ISR. If you poll the input then do the subtract after detecting the input edge in the poll function/routine.
这张照片有几种不同的方法。在PWM模块上没有输入捕获模式的能力是不可预知的,该特性具有良好的硬件解决方案。可以使用定时器(Time2)设置周期中断(该周期将定义您确定未知频率的分辨率),然后对输入进行轮询。启动/停止信号(检测上升沿或下降沿)或使用外部中断输入(IOC可能或使用比较器模块来生成一个IUPUT)。在定时器的ISR中保持“嘀嗒声”-每1中断的运行计数,并使用这来获得上升沿上升沿的周期。如果你使用一个中断来检测“边缘”,那么只需从“最后的蜱”中减去“当前蜱”来获得ISR中的周期。如果轮询输入,则在检测轮询函数/例程中的输入边沿后进行减法运算。
以上来自于百度翻译
以下为原文
There are a few dufferent ways to do this with this pic. It is unfortuante that it does not have input capture mode capability on the PWM modules, that feature makesa good hardware solution.
You can use a timer (timer2) set for a periodic interrupt (the period will define your resolution of determining the unknown frequency) and then either poll the input signal for start/stop (detect the rising or falling edges) or use an external interrupt input (IOC maybe or use the comparator module to generate an interupt). In the ISR for the timer keep a running count of "ticks" - +1 each interrupt- and use this to get period of rising edge to rising edge. If you use an interrupt to detect the "edges" then just subtract "current ticks" from "last ticks" to get period in the ISR. If you poll the input then do the subtract after detecting the input edge in the poll function/routine.
举报