完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
我有一个问题我想描述一下,有人能帮我吗?问题如下。一个控制器18F45 K22,我想要测量来自连接到输入端的接收器的输入信号A(PWM)信号。PURS调制宽度A要有频率,并且一旦有频率,就必须在程序中进行选择。我无法测量我开始上市的频率,但似乎没有效果。整个星期和一个月,我都没办法解决这个问题。因此,如果测量频率超过该函数,那么如果测量的频率比其他函数执行的频率。我有一个程序,我怀疑是解决方案,但它不起作用。
TXT(0.98 KB)-下载32次频率。TXT(0.98 KB)-下载30次频率。TXT(0.98 KB)-下载26次 以上来自于百度翻译 以下为原文 I Have a problem what i want to describe, is there someone who can help my?. The problem is as following. A controller a 18f45k22 i want to measure a incoming signal a (pwm) signal from a receiver that is connecting to a input. puls modulation width a want to have the frequency and once i have the frequency there must be a selection in the program. I can't measure the frequency i have a listing where i was beginning with but it didn't seem to work. All week and month i tried no solution for the problem. thus if a measure the frequency than that function will do that and if a measure another frequency than that other function will executed. i have a program what i suspected must be the solution but it doesn't work. Attachment(s) frequency.txt (0.98 KB) - downloaded 36 times frequency.txt (0.98 KB) - downloaded 32 times frequency.txt (0.98 KB) - downloaded 30 times frequency.txt (0.98 KB) - downloaded 26 times |
|
相关推荐
11个回答
|
|
这是行不通的:你需要浮点,或者类似于频率=100000
以上来自于百度翻译 以下为原文 This won't work: unsigned long period; // declare variable periode unsigned long frequency; frequency = 1 / period; You need floating point, or maybe something like frequency = 1000000000L/period |
|
|
|
嗨,至少有2个其他线程在这个论坛在过去的几个星期里,关于实验的脉冲长度或频率计数。迈西尔
以上来自于百度翻译 以下为原文 Hi, There have been at least 2 other threads in this forum during the last few weeks, about experimenting with pulse length or frequency counting. With example code, and/or corrections. Mysil |
|
|
|
|
|
|
|
你是如何使用频率=100000万升/周期的?
以上来自于百度翻译 以下为原文 How do you come there by to use frequency = 1000000000L/period ? |
|
|
|
|
|
|
|
它是整数缩放的一种形式。你的代码做两个整数的除法,分子是1。在整数值1除以任何数字格雷特然后0(1,2,3,…等)将导致零的结果。因此,将分子量放大到一个大数,然后得到一个可能有意义的结果。我相信,建议的代码将导致频率为千赫兹(kHz)假设周期为纳秒(ns)。我可能会离开这里,因为它还很早……或者使用浮点变量和数学。可以是慢的并且会使用更多的代码空间。
以上来自于百度翻译 以下为原文 It is a form of integer scaling. Your code does a division of two integer quantities, the numerator being a 1. In integer values 1 divided by any number greate then 0 (1,2,3,... etc) will result in a zero result. So scale the numerator up to a large number and then get a result that might be meaningful. I beleive the suggested code will result in a frequency in kilohertz (Khz) assuming the period is in nanoseconds(ns). I might be off here as it is early still.... Or use floating point variables and math. Can be slow and will use more code space. |
|
|
|
分子是1E9,所以如果分母是NS,它将给出HZ。如果是微秒,那么结果是KHZ/1000000,所以你可以把十进制转换成六位小数。因此,10 kHz是100 USEC,结果是10000000或10千赫。如果它是100000纳秒,结果将是10000赫兹,或10千赫。最好使用1000000作为分子,而USEC用于分母,这将给出一个16位无符号整数结果,达到62500赫兹(16 USEC)。
以上来自于百度翻译 以下为原文 The numerator is 1e9, so it will give Hz if the denominator is nS. If it is microseconds, then the result is kHz/1000000, so you can shift the decimal to get a result to six decimal places. So, 10 kHz is 100 uSec, and the result is 10000000 or 10.000000 KHz. If it is 100,000 nSec, the result would be 10,000 Hz, or 10.000 kHz. It is probably better to use 1000000 as the numerator, and uSec for denominator, which will give a 16 bit unsigned integer result up to 62500 Hz (16 uSec). |
|
|
|
谢谢你,保罗,我担心我匆匆忙忙地读了索引,想把文章做完。欣赏修正和细节,也许OP也会!
以上来自于百度翻译 以下为原文 Thank you Paul, I was afraid I had mis-read the exponents in my haste to get the post done. Appreciate the corrections and detail, maybe the OP will too! |
|
|
|
我尝试另一个程序来测量频率是正确的还是有错误?
以上来自于百度翻译 以下为原文 i try another program to measure the frequency is it correct or are there mistakes? Attachment(s) frequencymeasure2.txt (1.44 KB) - downloaded 29 times |
|
|
|
Heredid你的意思是
以上来自于百度翻译 以下为原文 Here while (count=! 2){ did you mean while (count != 2){ |
|
|
|
有太多的错误需要纠正,而不能完全重写。但我会指出一些明显的:
以上来自于百度翻译 以下为原文 There are really too many errors to correct without completely rewriting. But I'll point out some glaring ones: // LCD module connections // frequency measure void main(void) { int count=0; float rise1=0,rise2=0,frequency,period; OSCCON = 0b11111010; // clear the interrupts at beginning that way we are sure that our calculations will be exact no previous interrupt present PIR1bits.CCP1IF=0; PIE1bits.CCP1IE=0; // output ANSELC = 0; TRISCbits.TRISC2 = 1; // set it to input // configure CCP1 CCP1CONbits.CCP1M = 0x05; // set it to Capture mode; on every rising edge #define delay_us //*********** does nothing while (count=! 2){ //************* should be != count +=1; // increment the value of count // configure Timer 1 //*********** Don't configure peripherals in a loop T1CONbits.TMR1CS = 0; //set the timer 1 clock to instruction clock Fosc/4 as mentioned in page300 T1CONbits.TMR1ON = 1; // set Timer 1 on delay_us(10); //aquisition time T1GCONbits.T1GGO =1; // aquisition is ready wait for a rising edge while (T1GCONbits.T1GGO =1); //wait untill the aquisition is complete if (count==1) { //************ Converting unsigned int to float rise1=CCPR1; } //capture the first rising edge and store that value in rise1 if (count ==2) { rise2=CCPR1; } // capture the second rising edge and store the value in rise2 } period = rise2-rise1; // subtracte both values to get the period of the signal //*************** What happens if Timer1 rolls over? frequency=1/period; //********* period always > 1, so frequency < 1 // clear any interrupts that are set PIR1bits.CCP1IF=0; PIE1bits.CCP1IE=0; } //************** End of main(), processor resets |
|
|
|
只有小组成员才能发言,加入小组>>
5183 浏览 9 评论
2005 浏览 8 评论
1932 浏览 10 评论
请问是否能把一个ADC值转换成两个字节用来设置PWM占空比?
3178 浏览 3 评论
请问电源和晶体值之间有什么关系吗?PIC在正常条件下运行4MHz需要多少电压?
2229 浏览 5 评论
739浏览 1评论
626浏览 1评论
有偿咨询,关于MPLAB X IPE烧录PIC32MX所遇到的问题
510浏览 1评论
PIC Kit3出现目标设备ID(00000000)与预期的设备ID(02c20000)不匹配。是什么原因
637浏览 0评论
535浏览 0评论
小黑屋| 手机版| Archiver| 电子发烧友 ( 湘ICP备2023018690号 )
GMT+8, 2024-11-27 22:06 , Processed in 1.354583 second(s), Total 96, Slave 80 queries .
Powered by 电子发烧友网
© 2015 bbs.elecfans.com
关注我们的微信
下载发烧友APP
电子发烧友观察
版权所有 © 湖南华秋数字科技有限公司
电子发烧友 (电路图) 湘公网安备 43011202000918 号 电信与信息服务业务经营许可证:合字B2-20210191 工商网监 湘ICP备2023018690号