Microchip
直播中

王娟

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

输入捕获“慢”频率

我正在使用一个PIC24EP512GU810的应用程序。特别是,我需要测量一个旋转篮的周期/频率,每次一个完整的圆(或一部分)完成。通过读取数据表(HTTP://WW1.MICCHIP.COM/DeLoSs/En/DeViCIDOC/70616G.PDF),虽然输入捕获模块(第14节)可能是解决方案。离子。但是,我不确定。如果我理解正确,ICXTMR寄存器随着所选时钟源的每一个上升沿递增。假设我从time3得到这个源。每个计时器都有一个2位的预分频器,允许我最多把系统频率除以256。我的应用程序运行在60MHz(FCY),这意味着一个234×375赫兹的源到我的ICXTMR,它将在大约300毫秒内溢出16比特。现在,我需要处理的最低速度可以在脉冲之间给我一个200毫秒的间隔,这仍然足够快,以测量我是否重置了ICxTMR。每次注册。在这一点上,尽管我质疑这是否是这项工作的正确工具。总结一下,我的问题是:1。我理解正确吗?2。我知道,输入捕获模块是测量这种低频的正确工具吗?或者我最好用一个简单的中断在一个全局计数器上用A~1ms定时器单独增加。

以上来自于百度翻译


      以下为原文

    I'm working on an application with a PIC24EP512GU810. In particular, I need to measure the period/frequency of a rotating basket with a pulse every time a full circle (or a fraction of it) is completed.

By reading the Datasheet (http://ww1.microchip.com/downloads/en/DeviceDoc/70616g.pdf) I though the Input Capture module (section 14) could be the solution. However, I'm not sure about it.
If I understand correctly, the ICxTMR register is incremented with every rising edge of the selected clock source. Let's say I get that source from the Timer3.
Every timer has a 2 bit prescaler, allowing me to divide the system frequency by 256 at most. My application is running at 60MHz (Fcy), which means a source for 234'375 Hz to my ICxTMR, which would overflow the 16 bit in about 300 milliseconds.
Now, the lowest speed I need to handle could get me an interval of 200ms between pulses, which is still fast enough to measure if I reset the ICxTMR register every time. At this point though I'm questioning whether this is the right tool for the job.

Summing up, my questions are:
    1. Do I understand correctly?
    2. Granted I understand, is the Input Capture Module the right tool to measure such low frequencies, or would I be better off using a simple interrupt on edge with a global counter to be incremented separately by a ~1ms timer?

回帖(4)

康辅佑

2018-10-15 16:27:46
使用32位捕获模式来正确处理较低的输入频率。

以上来自于百度翻译


      以下为原文

    Use a 32-bit capture mode to correctly handle the lower input frequencies.
举报

李铭鑫

2018-10-15 16:40:40
嗨,是的,你的理解主要是正确的。为了测量长周期信号,你可以安排处理来自定时器(TMR3)和捕获模块的中断。如果在中断CP之前发生定时器中断,在32位整数变量UIT32 32中添加65536,清除中断标志和LE。当中断捕获发生时,将捕获寄存器的值添加到上述变量中,也可以将捕获寄存器值存储在单独的16位无符号变量UUT1616中,用作下一个间隔的开始时间。这样,你可以精确地捕捉每一个脉冲,而不必重置计时器。周期时间计算可能是这样的:间隔=(CopTraceEndo-CopTrimeRead)+(TimeRyLoop**xx10000);然后用无符号整数类型变量进行计时器和捕获值的计算,然后Calc。即使在一段时间内定时器翻转到零时,被调整的间隔也可以是正确的。或者,这些设备具有定时器和输入捕获,可以安排在32位模式下一起工作,参见寄存器ICXCON2 IC32位的数据表,以及寄存器TXCON-T32位。迈西尔

以上来自于百度翻译


      以下为原文

    Hi,
Yes, you understanding is mostly correct.
 
To measure long period signals,
you may arrange to handle interrupts from both the timer (TMR3)  and the capture module.
If interrupt from Timer happen before interrupt from CP, add 65536 in a 32 bit integer variable, uint32_t,
clear the interrupt flag and leave the interrupt handler.
When Capture interrupt happen, add value of capture register to the variable mentioned above.
 
You may also store the capture register value in a separate 16 bit unsigned variable, uint16_t
to use as start time for the next interval. This way, you may capture every pulse precisely, without having to reset the Timer.
Period time calculation may be something like this:
Interval =  (Capture_End - Capture_Previous) + (timer_cycles * 0x10000);
 
Do all calculations of timer and capture values with unsigned integer type variables,
then calculated intervals may be correct even when timer roll around to zero during a period.
 
Alternatively,
These devices have Timers and Input Capture, that may be arranged to work together in 32 bit mode,
See Datasheet about Register ICxCON2   IC32 bit,
and   Register TxCON  T32 bit.
 
   Mysil
举报

刘琴

2018-10-15 16:59:44
一个32位定时器(例如级联T2+T3)在捕获模式下使用16 MHz时钟(FCY)在大约268秒(4min 28秒)后翻滚。作为上升沿上的一个输入捕获,它将给你一个分辨率为62.5纳秒的周期时间。我在输入捕获中使用一个GPS PPS脉冲来确定我的CPU时钟偏离16兆赫,这样我就可以计算出输出脉冲的周期时间。我在输出比较模式中使用这个来产生非常精确的输出脉冲。

以上来自于百度翻译


      以下为原文

    A 32 bit timer (for example concatenate T2+T3) in capture mode using a 16 MHz clock (FCY) rolls over after approximately 268 seconds (4min 28s). Used as an input capture on the rising edge it will give you the period time with a resolution of 62.5 ns.
I use a GPS PPS pulse in Input Capture to determine my CPU clock's deviation from 16 MHz so I can calculate the period time of an output pulse with the accuracy of the crystal taken out of the picture.
I use this in Output Compare mode to generate extremely accurate output pulses.
举报

李天竹

2018-10-15 17:13:30
你不需要重置计时器。让它自由运行,然后减去连续捕获。如果测得的间隔小于定时器周期,则得到正确的结果。只需确保使用无符号变量.& lt;Edg≫此外,如果您知道间隔不能小于某个阈值,那么通过这样做,您可以扩展您的捕获范围,甚至超过定时器周期。

以上来自于百度翻译


      以下为原文

   


You do not need to reset the timer. Let it free run. Then subtract the consecutive captures. If the interval being measured is less than the timer period, you'll get the correct result. Just make sure you use unsigned variables.
 
Moreover, if you know that the interval cannot be less than a certain threshold then you can extend your capture range even past the timer period, by doing this:
 
if (captured_value < threshold) captured_value += timer_period;
 
举报

更多回帖

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