完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
|
我试着总结一下如何测量一列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个回答
|
|
|
这张照片有几种不同的方法。在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. |
|
|
|
|
|
另一种方法是将信号馈入计时器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. |
|
|
|
|
|
好啊。。。。让我看看我是不是弄明白了。我设置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? |
|
|
|
|
|
只需让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. |
|
|
|
|
|
这样地?现在使用Time2预分频器设置为64∶1,在0kHz处得到0x98,0x30在100kHz,在2MHz处使用FoSC,PR2设置为255(使用固定的FRQ时钟发生器)
以上来自于百度翻译 以下为原文 like this? ISR BANKSEL TMR0 MOVF TMR0,W MOVWF VSS3 ;store timer value in vss3 MOVF VSS2,W ;previus count in Vss2 SUBWF VSS3,W ;subtract vss2, from vss3 and leave in W MOVWF VSS ;copy subtraction into VSS MOVF VSS3,W MOVWF VSS2 ;move current coutnt to ;vss2 banksel PIR1 BCF PIR1,TMR2IF ;clear interrupt flag retfie right now with the timer2 prescaler set to 64:1, i get 0x98 at 1khz, and 0x30 at 100k with FOSC at 2mHz, and PR2 set at 255 (using a fixed freq clock generator right now) |
|
|
|
|
|
0x98=1kHz的152152个计数应取0.152秒fsif=2MHz,PR2=0xFF,预分频器=1∶64,它应该在2MHz/4/64/256=30.5Hz=0.0328 sSo下翻转,计数大约4.6倍太大。你确定这是一个很好的数字方波到达你的PIC输入引脚吗?如果它是以地面为中心的正弦波,或者是一个有很多振铃的方波,你就可以得到各种奇怪的效果。
以上来自于百度翻译 以下为原文 0x98 = 152 152 counts at 1kHz should take 0.152 seconds If Fosc = 2MHz, PR2 = 0xFF, Prescaler=1:64, it should roll over at 2MHz / 4 / 64 / 256 = 30.51Hz = 0.0328s So, the count is about 4.6 times too big. Something is seriously wrong. Are you sure it's a nice digital square wave reaching your PIC input pin? If it's a sine wave centred around ground, or a square wave with lots of ringing, you could get all sorts of weird effects. |
|
|
|
|
|
人力资源管理…我将仔细检查,以确保它运行在2MHz…MOVLW B’0110010’;比特7 N/A,6 3 1101=4MHz,2N/A,1-0 1X =内部振荡器,MOVWF OSCCON1100=2MHz。HRRM。应该在2MHz。我会把它推后,但要做到这一点,我必须重新调整我的所有时间回路的LCD显示器。它已经晚了…这就足够今晚。多谢帮忙!
以上来自于百度翻译 以下为原文 hrrm... i will double check to make sure it IS running at 2mHz.. MOVLW b'01100010' ;bit 7 n/a, 6-3 1101 = 4mHz, 2n/a, 1-0 1x = internal oscilator MOVWF OSCCON 1100 = 2mHz.. .hrrm. should be at 2mHz.. i will push it up later, but to do that I have to re-adjust all my timing loops for the LCD display. it's late..that's enough for tonight.. Thanks a BUNCH for the help! |
|
|
|
|
|
这个错误不是2的幂,所以我不认为FoCC选择是问题。我仍然怀疑你注入PIC中的是什么样的信号。如果它是一个SIGGEN,如果你没有专门设置一个DC偏移,它很可能是在地面周围。
以上来自于百度翻译 以下为原文 The error is not a power of two, so I don't think the Fosc selection is the problem. I'm still suspicious about what sort of signal you are injecting into the PIC to count. If it is a sig-gen, it's probably centred around ground if you have not specifically set a DC offset. |
|
|
|
|
|
迂回,“2MHz”是每两秒500毫秒,或一个时钟脉冲。
以上来自于百度翻译 以下为原文 Pedantic aside, "2mHz" is two milli-hertz, or one clock pulse every 500 seconds. Case matters a lot when using SI units. |
|
|
|
|
|
|
|
|
|
|
|
它是一个干净的,积极的只有方波。在1Hz,1kHz和100kHz之间的选择器开关是非常脏的tho。必须工作几次才能得到稳定的1KHz信号。是否有一个最小的电压必须被满足,被认为是一个正向脉冲?即使我的WaveTek SigGen只能产生1.5-2V P2P
以上来自于百度翻译 以下为原文 it is a clean, positive-going only square wave. the selector switch between 1hz, 1khz, and 100khz was very dirty tho.. had to work it a few times to get a stable 1khz signal out of it. is there a minimum voltage that has to be met to be considered a positive going pulse? even my WaveTek SigGen can only generate 1.5-2v p2p |
|
|
|
|
|
好吧…我想我把它钉牢了。用我好的WaveTek SigGe集只为正方形方波…IKOT:2kHz - 1计数4kHz - 2计数6kHz - 3计数8kHz - 4计数10kHz - 5计数12kHz - 6计数1/2K=5E-4(1 /4K)* 2计数=5E-4(1/6K)* 3计数=5E-4SO…FRIQ计数器的周期显然是5E-4或100个有趣的足够…2MHZ/4/256=1953.125Hz或5.12E-4…所以看起来问题是Time2预缩放器没有做我想做的事情。
以上来自于百度翻译 以下为原文 alright.. i think I nailed it down.. using my good WavTek SigGen set for positve only square wave... igot this: 2Khz - 1 count 4KHz - 2 counts 6khz - 3 counts 8KHz - 4 counts 10Khz - 5 counts 12KHZ - 6 counts 1/2K = 5E-4 (1/4k) * 2 counts = 5E-4 (1/6k) * 3 counts = 5E-4 so ... the period for the freq counter is obviously 5e-4 or 100uS interestingly enough... 2MHz / 4 / 256 = 1953.125hz or 5.12e-4.... so it looks like the problem is that the Timer2 pre-scaler isn't doing what I want it to.. |
|
|
|
|
|
*呻吟**脸棕榈* doh *我不知道如何或为什么…但是我已经启用了Time0的预分频器…为了…准备好了……1:64!!!!呸!!!!(我想我把预分频器关掉了,我可能把1放错了位置)现在预分频器被打开了。我得到一个数。你准备好了……0x1f= 31,或多或少是对的。因为这个Frq Gen是一个淡淡的FRQ(大约是900和变化)
以上来自于百度翻译 以下为原文 *GROAN* *FACE PALM* *DOH* i'm not sure how or why.. but I had the PreScaler on timer0 enabled... for.. ya ready...1:64!!! DOH!!!! (I thought I had the prescaler turned off, I may have put the 1 in the wrong bit) now that the prescaler is turned of.. I'm getting a count of.. ya ready..... 0x1F = 31 which is more or less right.. since this freq gen is a tad off freq (it's about 900 and change) |
|
|
|
|
|
好啊。。现在我需要掸掉OLE高中代数技能……因为…速度(在MPH)=((计* 4)/ 8×2.73 / 3.73×60 ^ 2)/76-即:计数* 4(因为我计数250秒)/ 8脉冲每传感器转速* 2.73(齿轮减速的SPEEDO驱动器)/3.73(齿轮减速后桥)* 60秒*分钟分钟,然后将整个混乱由我的后轮的离子/英里…这不是很有趣吗?英雄联盟
以上来自于百度翻译 以下为原文 ok.. now I need to dust off the 'ole high school algebra skills.. because.... Speed (in mph) = ((count * 4) / 8 * 2.73 / 3.73 * 60^2) / 746 that is: count * 4 (since I count for .250 seconds) / 8 pulses per rev of the sensor * 2.73 (gear reduction of the speedo drive) / 3.73 (gear reduction of the rear axle) * 60 seconds * 60 minutes then divide the whole mess by 746 revolutions / mile of my rear tires.. isn't this fun? LOL |
|
|
|
|
|
为了保证它能工作,它需要摆动到0.2×VDD=1Vand以上0.8×VDD=4V。这是一个3伏摆动。它最有可能工作于一个小得多的摆动,这只是你必须达到的电压,以确保它能起作用。
以上来自于百度翻译 以下为原文 To be guaranteed it will work, it needs to swing below 0.2 * VDD = 1V and above 0.8 * VDD = 4V. That is a 3 volt swing. It will most probably work for a much smaller swing too, that is just the voltages you must reach to sure it will work. |
|
|
|
|
|
我认为在它前面的比较器可能是一个好主意,信号调理。振幅随频率变化。它可能会出现低速问题。
以上来自于百度翻译 以下为原文 i'm thinking a compartor in front of it might be a good idea as signal conditioning. the amplitude varies as does the frequency ... it might have issues at low speed. |
|
|
|
|
|
找到了一个优雅的解决方案:“我把计数周期改为440秒。这意味着1计数=1 MPHBY,使用Time2后标器在1:14,并设置PR2在0xF6,i GET2E^ 6/4 / 64/246 / 14=2.268Hz或440832秒:
以上来自于百度翻译 以下为原文 found an elegant solution :) I changed the counting period to .440 seconds.. that means 1 count = 1 mph by using Timer2 POSTscaler at 1:14, and setting PR2 at 0xF6, I get 2e^6 /4/64/246/14 = 2.268hz or .440832 seconds :) |
|
|
|
|
只有小组成员才能发言,加入小组>>
MPLAB X IDE V6.25版本怎么对bootloader和应用程序进行烧录
473 浏览 0 评论
5793 浏览 9 评论
2334 浏览 8 评论
2224 浏览 10 评论
请问是否能把一个ADC值转换成两个字节用来设置PWM占空比?
3530 浏览 3 评论
1124浏览 1评论
有偿咨询,关于MPLAB X IPE烧录PIC32MX所遇到的问题
1095浏览 1评论
我是Microchip 的代理商,有PIC16F1829T-I/SS 技术问题可以咨询我,微信:A-chip-Ti
873浏览 1评论
MPLAB X IDE V6.25版本怎么对bootloader和应用程序进行烧录
475浏览 0评论
/9
小黑屋| 手机版| Archiver| 电子发烧友 ( 湘ICP备2023018690号 )
GMT+8, 2025-12-2 05:01 , Processed in 1.125799 second(s), Total 104, Slave 87 queries .
Powered by 电子发烧友网
© 2015 bbs.elecfans.com
关注我们的微信
下载发烧友APP
电子发烧友观察
版权所有 © 湖南华秋数字科技有限公司
电子发烧友 (电路图) 湘公网安备 43011202000918 号 电信与信息服务业务经营许可证:合字B2-20210191

淘帖
2429