注意,“每个指令循环一个计数”不是一个给定的值。如果预分频器没有启用,这是唯一正确的。您只是通过写入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 ?
注意,“每个指令循环一个计数”不是一个给定的值。如果预分频器没有启用,这是唯一正确的。您只是通过写入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 ?
举报