完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
大家好,因为我不能在任何真正的平台上测试我的代码,我所拥有的只是你的经验和数据表,所以让我提前感谢你的耐心和愿意分享,这意味着很多:回到我的问题,我想能够设置一个16位模式的计时器(时间)在此情况下R1),并在运行时更改溢出时间。我将溢出周期固定在0xFFFF上,并希望用TMR1寄存器来处理溢出时间。首先,这是改变TMR1寄存器或关闭和打开TMR1外围冗余的有效方式吗?其次,我想用PR1寄存器代替TMR1寄存器来改变溢出时间。当计时器溢出时,我必须清除TMR1中的值,所以它不一直计数,直到0xFFFF值再计数到PR1寄存器中的值为止吗?最后,在应用注意事项(DS70362,第10页)中有一段话:当出现以下任何一种情况时,预分频器计数器被清除:一个写入定时器寄存器(TMRX)或定时器控制(TXCON)寄存器:清除定时器控制中的定时器使能(Ton)位(TXCON & LT;15和GT)。任何设备ReSeSO都意味着,每当我更新TMR1寄存器或关机和外设时,我必须向TTKPS&LT 1:0GT:(定时器输入时钟预选择位)写入寄存器。
以上来自于百度翻译 以下为原文 Hello people , since I am not able to test my code on any real platform , all I have is your experience and the datasheets ,so let me thank you in advance for your patience and willingness to share , it means a lot :) Going back to my question , I want to be able to set a timer in 16 bit mode (Timer1 in this case) , and change the overflow time during the runtime . I fixed the overflow period at 0xFFFF and want to manipulate the overflow time with the TMR1 register . Firstly is this a valid way of changing TMR1 register or is closing & opening of the the TMR1 peripheral redundant ? void set_timer1(uint16_t period) { T1CONbits.TON = 0; TMR1 = period; T1CONbits.TON = 1; } And secondly let's say I want to change the overflow time with the PR1 register instead of TMR1 register . Do I have to clear the value in TMR1 when the timer overflows , so it doesnt keep counting until the 0xFFFF value then count up to the value in PR1 register ? And lastly there is a paragraph in application note (DS70362 , Page 10) that says : The prescaler counter is cleared when any of the following occurs: • A write to the Timer register (TMRx) or Timer Control (TxCON) register • Clearing the Timer Enable (TON) bit in the Timer Control (TxCON<15>) register • Any device Reset So does that mean I have to write to the TCKPS<1:0>: (Timer Input Clock Prescale Select bits ) register whenever I update the TMR1 register or when I turn off and on the peripheral ? |
|
相关推荐
4个回答
|
|
你可以做TMR1操作如所示,除了你需要“-周期”而不是“周期”。TMR1中的值越大,越快溢出。但是,如果你想要一个以上的镜头,你就失去了规律性——从溢出到设置定时器的那一点的时间就消失了。PR1操作也可以。与TMR1操作不同,这种方法让计时器在没有干扰的情况下一次又一次地运行。根据您所做的,您可能需要确保将PR1设置为TMR1.imHo之上的值,您不能真正编写一个没有真实硬件的程序。
以上来自于百度翻译 以下为原文 You can do TMR1 manipulation as shown, except you need "-period" instead of "period". The larger the value in TMR1 the sooner it is going to overflow. However, if you want more than one shot, you will lose the regularity - the time since the overflow to the point where you set the timer is lost. PR1 manipulation is also Ok. Unlike the TMR1 manipulation, this method lets the timer run over and over again forever without disturbances. Depending on what you're doing, you may need to make sure that you set PR1 to a value above TMR1. IMHO, you cannot really write a program without real hardware. |
|
|
|
谢谢NothGee,如果我选择做PR1操作,我是否清除TMR1寄存器,当它与PR1相等?还是用硬件清除?
以上来自于百度翻译 以下为原文 Thanks NorthGuy , If I choose to do PR1 manipulation, do I clear the TMR1 register when it equilizes with the PR1 ? Or is it cleared in hardware ? |
|
|
|
这是在硬件中清除的。这在家庭参考手册的“同步”和“异步”部分中都有说明:“经过一段时间的匹配后,TMRX寄存器在定时器时钟输入的随后上升沿复位。”
以上来自于百度翻译 以下为原文 It's cleared in hardware. This is stated in both "synchronous" and "asynchronous" sections of the family reference manual "After a period match, the TMRx register resets on the subsequent rising edge of the timer clock input." |
|
|
|
TMR1被重置为零(在QHB规定的1个额外时钟之后),然后继续计数。取决于速度,当你到达它时,它可能已经有一定数量的计数。如果你想要连续性,你需要让它继续计数。如果不想要连续性,则禁用定时器,将TMR1设置为零,然后再次启用定时器。
以上来自于百度翻译 以下为原文 TMR1 is reset to zero (after 1 extra clock as qhb stated) and then continue counting. Depending on the speed, when you get to it, it may have some number of counts on it already. If you want continuity, you need to let it continue counting. If you don't want continuity then you disable timer, set TMR1 to zero and then enable the timer when want to use it again. |
|
|
|
只有小组成员才能发言,加入小组>>
5238 浏览 9 评论
2028 浏览 8 评论
1950 浏览 10 评论
请问是否能把一个ADC值转换成两个字节用来设置PWM占空比?
3204 浏览 3 评论
请问电源和晶体值之间有什么关系吗?PIC在正常条件下运行4MHz需要多少电压?
2253 浏览 5 评论
778浏览 1评论
666浏览 1评论
有偿咨询,关于MPLAB X IPE烧录PIC32MX所遇到的问题
595浏览 1评论
PIC Kit3出现目标设备ID(00000000)与预期的设备ID(02c20000)不匹配。是什么原因
677浏览 0评论
576浏览 0评论
小黑屋| 手机版| Archiver| 电子发烧友 ( 湘ICP备2023018690号 )
GMT+8, 2024-12-23 06:30 , Processed in 1.911816 second(s), Total 84, Slave 68 queries .
Powered by 电子发烧友网
© 2015 bbs.elecfans.com
关注我们的微信
下载发烧友APP
电子发烧友观察
版权所有 © 湖南华秋数字科技有限公司
电子发烧友 (电路图) 湘公网安备 43011202000918 号 电信与信息服务业务经营许可证:合字B2-20210191 工商网监 湘ICP备2023018690号