Microchip
直播中

张琪

7年用户 228经验值
私信 关注
[问答]

Timer0溢出周期有办法绕过吗

嗨,PIC16F1937中的time0模块是一个8位的计数器。这意味着要发生溢出,需要2 ^ 8(256)个指令周期。有没有办法绕过这256个指令周期?改为200个周期。谢谢

以上来自于百度翻译


      以下为原文

    Hi, the Timer0 module in pic16f1937 is an 8bit when used as a counter. That means it will take 2^8 (256) instruction cycles for an overflow to happen. Is there any way to bypass this 256 instruction cycle? Make it 200 cycles instead. Thanks

回帖(13)

杨玲

2018-10-29 11:45:41
最好的方法是不使用TMR0,而是使用TMR2/4等,这些寄存器具有周期寄存器,可以实现你想要的。

以上来自于百度翻译


      以下为原文

    The best way to do that is to not use TMR0, but use TMR2/4/etc. which have period register that does exactly what you want.
举报

薄坤坤

2018-10-29 12:00:58
受到警告
提示: 作者被禁止或删除 内容自动屏蔽
举报

王桂荣

2018-10-29 12:09:57
谢谢你的回复。另一个NOOB问题,如何将Time0的计数从0到255设置为中断?我怎么知道这个计数的持续时间?

以上来自于百度翻译


      以下为原文

    Thanks for the replies. Another noob question, how can I set the count of timer0 from 0 - 255 to enable the interrupt? How would I also know the duration of this count? 
举报

王焕树

2018-10-29 12:16:44
注意,“每个指令循环一个计数”不是一个给定的值。如果预分频器没有启用,这是唯一正确的。您只是通过写入TMR0寄存器预先设置计数值。如果您向寄存器写入56,那么它将溢出256 - 56=200个计数。如果您希望它中断每200个。计数,然后你的中断服务例程必须立即重新加载TMR0寄存器。如果你不使用预分频器,那么你需要抵消由多少个指令写的值进入中断服务例程和写一个新的值到寄存器。这就是为什么使用硬件在定时器2/4/6中做它是一个更好的解决方案。为什么你坚持使用TMR0?

以上来自于百度翻译


      以下为原文

    Note, the "one count per instruction cycle" is not a given.
That is only true if the prescaler is not enabled.
 

You are just pre-setting the count value by writing to the TMR0 register.
If you write 56 to the register, then it will overflow in 256 - 56 = 200 counts.
If you want it to interrupt every 200 counts, then your interrupt service routine must immediately reload the TMR0 register.
If you are not using the prescaler, then you need to offset the value written by how many instructions it takes to enter the interrupt service routine and write a new value to the register. That is why using the hardware to do it in timer 2/4/6 is a much better solution.
Why are you insisting on using TMR0 ?
 
举报

更多回帖

发帖
×
20
完善资料,
赚取积分