完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
你好,论坛,我想对如何使用PIC16F87A单片机读取特定波形图提出建议/建议。我知道有2个CCP模块。我能用这些来捕获和比较脉冲持续时间吗?请参阅从EV1527解码器IC发送的附加图像。我想用MCU编码这一点。请建议我需要使用RB0/INT中断引脚或CCP1引脚并捕获每个脉冲的上升沿。
以上来自于百度翻译 以下为原文 Hello Forum, I would like to get advice/suggestion on how to read a specific waveform pattern using pic16f877a MCU. I know that there are 2 CCP modules. can i use those to capture and compare the pulse duration. Please refer the attached image of signal which is sent from ev1527 decoder IC. I want to encode this using MCU. Please suggest should i need to use RB0/INT interrupt pin or CCP1 Pin and capture the rising edge of each pulse. Thanks Kiran Attached Image(s) |
|
相关推荐
18个回答
|
|
|
|
|
|
设置CCP模块在每一个上升沿捕获。允许中断发生。在ISR存储器中,CCPRX寄存器的值在一对辅助寄存器中,然后将CCP模块设置为在每个下降沿上捕获。它会产生另一个中断。这一次,你必须计算CCPRX寄存器的新值与存储在辅助寄存器中的旧值之间的差值。计算值乘以Ty-WIL给出信号停留在高电平的时间。因此,您可以确定比特值是0还是1。
以上来自于百度翻译 以下为原文 Set the CCP module to capture on every rising edge. Allow for interrupts to occur. At the ISR store the value of the CCPRx register in a pair of auxiliary registers, then set the CCP module to capture on every falling edge. It will generate another interrupt. This time you have to calculate the difference between the new value of the CCPRx registers and the old value stored in the auxiliary registers. The calculated value multiplied by TCy wil give the time the signal stayed at the high level. So you can determine if the bit value is 0 or 1. |
|
|
|
你也可以使用两个CCP模块,一组在上升时触发,一个在下降。在从下降沿CCP中断(不使用上升沿上的Its)之后,计算两个捕获的计时器读数从CCP寄存器中的差值,即脉冲宽度(在定时器时钟周期中)。
以上来自于百度翻译 以下为原文 You can also use two CCP modules, one set to trigger on the rise and one on the fall. After the interrupt from the falling edge CCP (do not use ints on rising edge) then calculate the difference in the two captured timer readings from the CCP registers and that is the pulse width (in timer clock cycles). |
|
|
|
|
|
|
|
另外,你需要在定时器中断中有代码来检测它是否需要一个以上的完整的定时器周期来改变信号!
以上来自于百度翻译 以下为原文 Plus you need to have code in the timer interrupt to detect if it takes more than one complete timer cycle for the signal to change! |
|
|
|
定时器应该设置为在不到一个周期内完成。计时器溢出告诉您失败。可选地,如果CPU不忙,您可以在一个循环中进行RX数据。这取决于应用程序。
以上来自于百度翻译 以下为原文 The Timer should be set to do it in less than a cycle. The Timer overflow tells you it failed. Optionally if the CPU is not Busy, you can sit in a loop to RX the data. It depends on the application. |
|
|
|
您在图1中的图表显示两个脉冲宽度,大约200个美国和620个美国。如果你需要做的是决定脉冲是短(200 US)还是长(620 US),那么:1)在Ext INT.ISR启动中设置ExtEngE2的启动中断,在定时器ISR中检查一个输入电平,低是短脉冲高,是长脉冲。这很简单,但是E。在输入上被噪声绊倒了。
以上来自于百度翻译 以下为原文 Your diagram in post#1 shows two pulse widths, around 200 us and 620 us. If all you need to do is decide if the pulse is short (200 us) or long (620 us) then: 1) set the ext. interrupt to trigger on the rising edge 2) in the ext. int. ISR start a 400 us timer 3) in the timer ISR check the level of the input, low is a short pulse high is a long pulse. This is simple but is easily tripped up by noise on the input. |
|
|
|
|
|
|
|
从微芯片网站:PIC16F87A:不推荐用于新的设计。如果你使用现代PIC(PIC16F1XXX),你会发现奇数定时器TMR1,TMR3,…我曾经用它们来解码类似的信号(来自国家时间广播,例如WWVB)的PW信号。代码很简单,问题是:你是否需要使用旧的MCU?今天100美元的近似MUSER价格:'877A: 5美元,18855美元:1.25.GP
以上来自于百度翻译 以下为原文 From the Microchip Web Site: PIC16F877A: Not Recommended for New Designs. If you use a modern PIC (PIC16F1xxx), you'll find the odd timers TMR1, TMR3, ... have Gated Timers. I've used them to decode similar signals (PW Signals from National Time Broadcasts, e.g. WWVB). The code is quite simple. The question is: are you constrained to use the old MCU? Approximate Mouser Prices today (US$) for Qty 100: '877A: $5.00, '18855: $1.25. GP |
|
|
|
这有点太过分了。你必须从6英寸'GAP '.GP中找到框架。
以上来自于百度翻译 以下为原文 This is a bit more to it. You have to find the frame from the ~6 ms. 'gap'. GP. |
|
|
|
这有点太过分了。你必须从6英寸的GAP 'GP.GP中找到框架,因此我用“如果你需要做的一切”来开始评论。我只讨论了这个问题的一部分……这样的脉冲流的“解码”一般是非常基本的,但是它容易被许多因素复杂化:噪声、比特率的变化等。如果超过图中所示的两个脉冲宽度,那么它当然会变得更加复杂,并且必须使用更复杂的方法。“帧开始”条件的检测可以与脉冲宽度问题分开处理,或者通过使用一般的脉冲宽度测量例程和解码过程的状态机方法。
以上来自于百度翻译 以下为原文 This is a bit more to it. You have to find the frame from the ~6 ms. 'gap'. GP. Hence the reason I prefaced the comments with "If all you need to do". I was discussing only that part of the question.... The "decoding" of such a pulse stream is in general very basic however it is complicated easily by many factors: noise, variations in the bit rate, etc. Done it a bunch of times by a few different methods. If more than the two pulse widths shown in the diagram are present then it gets more complicated of course and a more sophisticated method must be used. The detection of the "frame start" condition can be handled separately from the pulse width issue or by using a general pulse width measurement routine and a state machine approach to the decode process. |
|
|
|
大家好,谢谢回复和建议。我使用PIC16F87A只是因为我有开发板,它使测试和开发变得简单。
以上来自于百度翻译 以下为原文 Hi all, Thanks for reply and suggestions. i am using PIC16F877a just because i have development board for it and it makes easy testing and devloping. Thanks Kiran |
|
|
|
不是那么容易。PIC16F87A只有一个硬件断点,并指出一个新的芯片具有更适合这个任务的周环,但是PIC16F87A将满足您的需要。
以上来自于百度翻译 以下为原文 Not that Easy. The PIC16F877A only has one Hardware Breakpoint. And as pointed out a new chip has periperials more suited to the Task. But the PIC16F877a will do what you need. |
|
|
|
再次,我将用下面的逻辑来测量时间/持续时间上的脉冲,当脉冲上升沿检测到让我进入ISR,然后启动定时器并启用CCP模式来检测下降沿。当ISR触发下降沿时,我将读出TMR寄存器并存储它并停止T。这是我下面的ISR代码,我能激活ISR内部的定时器吗?我的计时器代码是否正确?
以上来自于百度翻译 以下为原文 Hi Again, I will go with below logic to measure the pulse ON time/duration when the Pulse rising edge detects let me go into ISR and then start a timer and enable CCP mode to detect falling edge. Again when ISR triggers for falling edge i will read out the TMR register and store it an array and stop the timer. This is my below ISR code. void interrupt ISR() { if(CCP1IF) // Capture Interrupt Flag { if(!Edge_flg) { T1CON = 0x31; // TMR1 ON RD2 = ~RD2; // Toggling the bit Edge_flg=1; CCP1CON = 0x04; // Capture at Every falling edge } else { end_time[Num_Pulse]=TMR1; Num_Pulse++; T1CON = 0x00; // TMR1 OFF RD3 = ~RD3; Edge_flg=0; CCP1CON = 0x05; // Capture at Every rising edge TMR1=0x0000; // Clear the timer reg } CCP1IF = 0; } } Can i activate timer inside ISR. Is my timer code proper. Thanks Kiran |
|
|
|
|
|
|
|
再次感谢你的支持。现在我能正确地接收到数据并显示在LCD.when上,没有数据传输,我观察到一些小的噪声峰值出现,并且由于这个CCP中断被错误地激活。我把两个CRO图像都附加在适当的RF数据上,在第二个图像中,当没有数据被发送时,出现了噪声。软件中有什么逻辑可以忽略噪声。还是必须在硬件水平上进行。PIC比较器可以用于这个目的。伊桑克斯坦
以上来自于百度翻译 以下为原文 Hi Again, Thanks for your support. Now i am able to receive the data properly and displaying on LCD. when there is no data transmitted, i am observing some small spike of noise is appears and due to this CCP interrupt is falsely getting activated. How can i neglect the noise signals and only receive the proper data. I am attaching both the CRO images where there is proper RF data and in the 2nd image when no data is sent the noise appears. Is there any kind of logic in software where can i ignore noise. or it has to be done in hardware level. Is the PIC comparator can be used for this purpose. My codevoid interrupt ISR() { if(CCP1IF) // Capture Interrupt Flag { if(!Edge_flg) { T1CON = 0x31; // TMR1 ON RD2 = ~RD2; // Toggling the bit Edge_flg=1; CCP1CON = 0x04; // Capture at Every falling edge } else { end_time[Num_Pulse]=TMR1; Num_Pulse++; T1CON = 0x00; // TMR1 OFF RD3 = ~RD3; Edge_flg=0; CCP1CON = 0x05; // Capture at Every rising edge TMR1=0x0000; } CCP1IF = 0; } } // Main Function void main(void) { unsigned char ch,temp; unsigned int i; RD2 = 0; // As Output for checking the toggling RD3 = 0; // As Output for checking the toggling RD4 = 0; TRISD2=0; TRISD3=0; TRISD4=0; delay(100); OPTION_REG = 0x00; TRISC2 = 1; // As CCP1 to capture the input GIE=1; TMR1H = 0; // Timer value TMR1L = 0; INTCON=0xC0; // Interrupt enable InitLCD(); InitUART(); ClearLCDScreen(); while(1) { /* configure capture unit */ CCPR1H=0x00; CCPR1L=0x00; CCP1CON = 0x05; // Capture at Every rising edge CCP1IE = 1; //Capture interrupt enable Num_Pulse=0; INTCON=0xC0; while(Num_Pulse<26); // wait till 25 pulses receive { INTCON=0x00; // disable the interrupt Num_Pulse=0; for(i=0;i<=26;i++) { temp = (end_time/100)%10; tx0(temp+48); // Sending it to Hyper terminal temp = (end_time/10)%10; tx0(temp+48);// Sending it to Hyper terminal tx0(' '); delay(80); } } } Thanks Kiran Attached Image(s) |
|
|
|
它们比有效脉冲小,不能忽略某个宽度以下的脉冲吗?
以上来自于百度翻译 以下为原文 They are skinnier than the valid pulses. Can't you just ignore pulses below a certain width? |
|
|
|
也许一个简单的电容滤波器或铁氧体磁珠可能会阻塞窄带噪声信号。你能量化噪声脉冲的宽度,并显示更多的电路细节吗?
以上来自于百度翻译 以下为原文 Perhaps a simple capacitor filter or ferrite bead might block the narrow noise signal. Can you quantify the width of the noise pulses, and show more details of the circuitry? |
|
|
|
只有小组成员才能发言,加入小组>>
5160 浏览 9 评论
1998 浏览 8 评论
1927 浏览 10 评论
请问是否能把一个ADC值转换成两个字节用来设置PWM占空比?
3170 浏览 3 评论
请问电源和晶体值之间有什么关系吗?PIC在正常条件下运行4MHz需要多少电压?
2225 浏览 5 评论
727浏览 1评论
612浏览 1评论
有偿咨询,关于MPLAB X IPE烧录PIC32MX所遇到的问题
501浏览 1评论
PIC Kit3出现目标设备ID(00000000)与预期的设备ID(02c20000)不匹配。是什么原因
626浏览 0评论
524浏览 0评论
小黑屋| 手机版| Archiver| 电子发烧友 ( 湘ICP备2023018690号 )
GMT+8, 2024-11-22 02:39 , Processed in 1.542315 second(s), Total 113, Slave 95 queries .
Powered by 电子发烧友网
© 2015 bbs.elecfans.com
关注我们的微信
下载发烧友APP
电子发烧友观察
版权所有 © 湖南华秋数字科技有限公司
电子发烧友 (电路图) 湘公网安备 43011202000918 号 电信与信息服务业务经营许可证:合字B2-20210191 工商网监 湘ICP备2023018690号