完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
大家好,我正在做一个无线射频应用程序,我正在尝试了解一些基于PIC16F872架构的Microchip网站上的代码。我引用的文档是AN74。由于某种原因,我不能把它附在这个帖子上。接收机功能基本上在一个输入引脚上读取RF信号,并将数据放入缓冲器中进行描述。接收器功能是当timeR0溢出(溢出中断)时触发的中断例程。AN74的作者指出时基是138,这意味着这是他的中断期。我不确定的是,“选项”寄存器设置为0x0F,这意味着预分频器被分配给看门狗定时器(预分频因数变为128)。由于这也是一个8位定时器,时钟将翻转每256个计数(每个计数为1US)。使用4MHz时钟,这将给我:(4/4)* 128×256=327 68,这显然不符合公布的138个美国时基。我知道我错过了一些东西,但需要一些洞察力,因为我没有与图片在一段时间内。谢谢大家提前。
以上来自于百度翻译 以下为原文 Hi All, I am working on a wireless RF application, and I am trying to understand some code that I found on the Microchip website that is based on the PIC16F872 architecture. The document I am referencing is AN744. For some reason I am unable to attach it to this post. The receiver function basically reads in an RF signal on one of the input pins and places the data into a buffer for description. The receiver function is an interrupt routine that is triggered when Timer0 overflows (overflow interrupt). The author of AN744 states that the time base is 138 us which means that this is his interrupt period. What I am not sure of is the fact that the "OPTION" register is set to 0x0f which means that the prescaler is assigned to the watchdog timer (prescale factor becomes 128). Since this is also an 8 bit timer the clock will rollover every 256 counts (each count is 1us). Using a 4MHz clock this would give me: (4/4) * 128 * 256 = 32768us which obviously does not match the 138 us time base that is published. I know I am missing something but need some insight as I have not worked with PICs in a while. Thanks all in advance. |
|
相关推荐
10个回答
|
|
在AN74中,Time0设置为CPU时钟除以4(指令时钟)的增量。正如你所说的,预分频器不与Time0一起使用,而是与WDT一起使用,因此它不进入Time0周期计算。这些定义用于在每次溢出时为Time0建立重新加载值并导致中断:该值从ISR中的Time0的当前值减去(然后重写为Time0),以便为下一个周期重新加载Time0。这个值导致文本中描述的138US定时器周期。记住,这个代码中的Time0将在每4个振荡器时钟周期上增加(指令速率是FoCC/4,所以4 MHz / 4=1US)或每1个U。通过将Time0设置为上面定义的周期值,代码在Time0计数中产生大约138个指令周期或138个指令周期。记住计时器是一个计数器,从加载的值到255,然后溢出并导致中断。
以上来自于百度翻译 以下为原文 In AN744 Timer0 is setup to increment on the cpu clock divided by 4 (instruction clock). As you stated the prescaler is not used with timer0 but rather the wdt so it does not enter into the timer0 period calculation. These defines are used to establish the reload value for timer0 every time it overflows and causes an interrupt: #define CLOCK 4 // MHz #define TE 400 // us #define OVERSAMPLING 3 #define PERIOD TE/OVERSAMPLING*4/CLOCK This value is subtracted from the current value of timer0 (and then rewriten to timer0) in the ISR to reload the timer0 for the next period. This value results in the 138us timer period described in the text. Remember that timer0 in this code will increment on every 4 oscillator clock cycles (instruction rate is Fosc/4 so 4 Mhz/4= 1us) or every 1 us. By setting the timer0 to the PERIOD value defined above the code results in the timer0 counting approx. 138 instruction cycles or 138 us. Remember that the timer is an upcounter, counts from the loaded value up to 255 then overflows and results in the interrupt. |
|
|
|
好啊。真正让我失望的是我把WDT缩放因子分配给我的计算。因此,总结应用程序首先在微处理器上加电时,计时器计数为255,并在翻转时进入中断程序(因为最初138个未加载到TMR0)。在中断例程内,我们从当前定时器值减去138(最大值为255),并将所得值加载到TMR0中。计时器从138开始,然后再次翻转,在数据缓冲器填满的过程中重复该过程。对于他为什么会将预分频器分配给WDT的任何想法?我认为驱动因素是开发者在这种情况下不需要缩放因子,因为分配给TMR0时的最小缩放因子是1:2。本周早些时候,我花了好几个小时试图解决这个问题。
以上来自于百度翻译 以下为原文 Ok. What was really throwing me off was the fact I was assigning the WDT scaling factor to my calculation. So to summarize when the application is first powered up on the microprocessor the timer is counting to 255 and entering into the interrupt routine upon rollover (since initially the 138 us is not loaded into TMR0). Inside the interrupt routine we are subtracting the 138 from the current timer value (the max of 255) and loading the resulting value into TMR0. The timer then starts from 138 before rolling over once again and the process repeats while the data buffer fills up. Any thoughts as to why he would have assigned the prescaler to the WDT for this application? I would think that the driving factor is that the developer wants no scaling factor in this case as the min scaling factor when assigned to TMR0 is 1:2. I appreciate the help as spent hours trying to figure this out earlier this week. |
|
|
|
不,计时器加载(CurrnTimeTimeValue- 138)(大约为138的值被计算并且可能有点关闭)。CurrnTyTimeRoad值将是0(因为定时器正好从255溢出)+但是在读取值之前出现了许多溢出循环。这使定时器值设置为118(加减几个),并且从那里继续计数。第一次定时器将没有正确的超时周期,但是随着定时器连续运行,代码处理这个OK。预分频器被分配给WDT,因为它不需要与Time0一起使用,而这是唯一的另一个选项——分配给Time0或WDT。
以上来自于百度翻译 以下为原文 No, the timer is loaded with (current_timer_value - 138) (approximately as the value of 138 is calculated and may be a little off). The current_timer_value will be 0 (because the timer just overflowed from 255) + however many insruction cycles have occured since the overflow before the value is read. This sets the timer value at 118 (plus or minus a few) and it continues counting up from there. The very first time the timer will not have the correct time-out period however as the timer runs continuously the code handles this OK. The prescaler was assigned to the wdt because it was not needed to be used with timer0 and that is the only other option - assigned to timer0 or the wdt. |
|
|
|
准确地说,将预分频器分配给WDT意味着它没有连接到TMR0,所以没有发生缩放。
以上来自于百度翻译 以下为原文 Exactly. Assigning the prescaler to the WDT means that it is NOT connected to TMR0, so no scaling occurs. |
|
|
|
是的,我的坏,这是对的。当进入中断例程时,“当前定时器值”实际上为0,这意味着138将从0的定时器值减去,因为它刚刚翻转。由于TMR0是一个寄存器,从计时器值中减去138个计数将有效地将计时器计数翻转到118。我把这个运算和传统算法混淆了。感谢您对这段代码的澄清。
以上来自于百度翻译 以下为原文 Yes my bad, that is right. The "current timer value" will in fact be 0 upon entering the interrupt routine which would mean that the 138 would get subtracted from the timer value of ~0 since it just rolled over. Since TMR0 is a register, 'subtracting' 138 counts from the timer value would effectively roll the Timer count back to 118. I confused this operation with conventional arithmetic. Thanks both for the clarification of this code. |
|
|
|
这是传统的8位无符号算术。声明为“unChar char”的变量将完全相同。
以上来自于百度翻译 以下为原文 That is conventional 8 bit unsigned arithmetic. Any variable declared as "unsigned char" will behave exactly the same. |
|
|
|
Pedantic:周期等于400/3=133。一个指令周期更新TMR0,当写入时,两个指令周期的TMR0增量被抑制。因此,时基实际上是136美,而不是138美,只要时钟正好是4兆赫。;)
以上来自于百度翻译 以下为原文 Pedantic: PERIOD equals to 400/3 = 133. It takes one instruction cycle to update TMR0 and the increment of TMR0 is inhibited for two instruction cycles when written. So, the time base is actually 136 us, not 138 us, provided the clock is exactly 4 MHz. ;) |
|
|
|
在中断向量(在ISR例程开始)之后,您是否正在进行上下文保存和/或做其他任何测试????如果你的计算非常耗时,当计算TMR0值时,你应该包括这些丢失的时钟脉冲。当前的TMR0值包括每个时钟脉冲,包括ISR指令,直到复位或重新加载。
以上来自于百度翻译 以下为原文 Are you context saving and / or doing any other other tests, after the interrupt vector (at start of your ISR routine) ??? If your calculations are so time critical, you should include these lost clock pulses, when calculating TMR0 values. The current TMR0 value includes every clock pulse, including ISR instructions, until reset or re-loaded. Trevor |
|
|
|
正如杰克所说的,偏移量被加到定时器寄存器的当前值中,它自动地允许从中断触发器得到许多指令,直到修改定时器寄存器的指令。在计时器寄存器中添加新的值,而不是增加它。
以上来自于百度翻译 以下为原文 Irrelevant. As Jack has been saying, the offset is added to the CURRENT VALUE of the timer register. That automatically allows for however many instructions it takes from the interrupt trigger until the instruction that modifies the timer register. The effect you describe happens if you just blind write a new value into the timer register, rather than adding to it. |
|
|
|
正如杰克所说的,偏移量被加到定时器寄存器的当前值中,它自动地允许从中断触发器得到许多指令,直到修改定时器寄存器的指令。在计时器寄存器中增加一个新的值,而不是增加它。模运算的美。微笑:
以上来自于百度翻译 以下为原文 Irrelevant. As Jack has been saying, the offset is added to the CURRENT VALUE of the timer register. That automatically allows for however many instructions it takes from the interrupt trigger until the instruction that modifies the timer register. The effect you describe happens if you just blind write a new value into the timer register, rather than adding to it. The beauty of modulo arithmetic. Smile: |
|
|
|
只有小组成员才能发言,加入小组>>
5284 浏览 9 评论
2056 浏览 8 评论
1968 浏览 10 评论
请问是否能把一个ADC值转换成两个字节用来设置PWM占空比?
3231 浏览 3 评论
请问电源和晶体值之间有什么关系吗?PIC在正常条件下运行4MHz需要多少电压?
2277 浏览 5 评论
820浏览 1评论
709浏览 1评论
有偿咨询,关于MPLAB X IPE烧录PIC32MX所遇到的问题
652浏览 1评论
PIC Kit3出现目标设备ID(00000000)与预期的设备ID(02c20000)不匹配。是什么原因
710浏览 0评论
605浏览 0评论
小黑屋| 手机版| Archiver| 电子发烧友 ( 湘ICP备2023018690号 )
GMT+8, 2025-1-12 07:06 , Processed in 1.316653 second(s), Total 95, Slave 79 queries .
Powered by 电子发烧友网
© 2015 bbs.elecfans.com
关注我们的微信
下载发烧友APP
电子发烧友观察
版权所有 © 湖南华秋数字科技有限公司
电子发烧友 (电路图) 湘公网安备 43011202000918 号 电信与信息服务业务经营许可证:合字B2-20210191 工商网监 湘ICP备2023018690号