Microchip
直播中

阮浙临

7年用户 122经验值
私信 关注
[问答]

使用pic16F1508进行脉冲计数没有看到关于1508个文件的捕获模式

我试着总结一下如何测量一列0到300赫兹的方波脉冲的频率。脉冲源是一个速度传感器。最低的移动输入将是2Hz。我认为正确的方法是配置一个计时器来增加一个输入脉冲,第二个计时器设置一个固定的间隔。Microchip页面说16F1508有:4捕获/比较/ PWM外围设备,但我没有看到任何关于1508个文件的捕获模式,如16F627 / 8…

以上来自于百度翻译


      以下为原文

    I'm trying to wrap my head around how to measure the frequency of a train of square wave pulses that can range from 0 to 300hz.  the pulse source is a speed sensor.. it's lowest moving input would be 2hz.. 0hz when stopped.

am I right in thinking the best way is to configure a timer to increment on an incoming pulse, and a second timer to set up a fixed interval?
the microchip page says the 16f1508 has:  4 Capture/Compare/PWM Peripherals  but I don't see anything in the 1508 docs about a capture mode like the 16f627/8 does...

回帖(17)

tijing忽忽

2018-9-26 16:41:51
这张照片有几种不同的方法。在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.
举报

肖舒

2018-9-26 16:52:38
另一种方法是将信号馈入计时器0,并使用溢流A作为定时器1门的源。然后,可以通过计时器1的计数+溢出来计算频率。另一件需要考虑的是15F1508的内部振荡器的容差。这会给计算带来很大的误差。有关详细信息,请参阅数据表的图29至6。你可能想考虑在次级振荡器上使用手表晶体作为更稳定的频率基准。您将需要运行数学,看看是否有足够的分辨率在32.768 kHz。

以上来自于百度翻译


      以下为原文

    Another method is to use feed the signal into timer 0 and use the overflow a a source for timer 1 gate. The frequency can then be calculated from the count + overflow of timer 1.  The other thing to consider is the tolerance of the internal oscillator of the 15F1508.  This could add significant error to the calculation. See figure 29-6 of the data sheet for more details.  You might want to consider using a watch crystal on the secondary oscillator as a more stable frequency reference. You will need to run the math to see if there is enough resolution at 32.768kHz.      
举报

李晓欢

2018-9-26 16:59:40
好啊。。。。让我看看我是不是弄明白了。我设置Time0计数每次在T0CKII上发生一个低到高的转换,然后设置一个间隔的TimeR2周期寄存器(PR2)。说…250MS,它每250Ms产生一个中断。然后在每个中断中,我将Time1计数复制到内存位置并重置Time0计数。

以上来自于百度翻译


      以下为原文

    ok....  let me see if I have this figured out.. I set up Timer0 to count everytime a low to high transition occurs on T0CKI
 
i then setup timer2 Period register (PR2) for an interval.. say.. 250ms  and for it generate an interrupt every 250ms..
then with each interrupt, I copy the timer1 count to a memory location and reset the timer0 count.
 
would that work?
 
举报

吴键洪

2018-9-26 17:17:11
只需让Time0运行,并在下次读取时减去先前的计数,这就更准确了。这样就避免了在读取和清除之间到达的计数丢失。

以上来自于百度翻译


      以下为原文

    It's more accurate to just leave timer0 running, and subtract the previous count next time you read it.
That avoids you possibly missing a count that arrives between the read and the clear.
举报

更多回帖

发帖
×
20
完善资料,
赚取积分