View previous topic :: View next topic |
Author |
Message |
anestho
Joined: 27 Dec 2006 Posts: 28
|
using tmr0 overflow for higher counts |
Posted: Thu Jul 26, 2007 9:28 am |
|
|
Hi, I am using PIC 12F683 which has 3 timers. timer1 is 16 bit, but I am using it for another purpose. I am trying to use timer0 for higher than 255 counts prescaled at 1:8. Its okay if it overflows, because I check for overflow and add 256 to the count. The counter holds 16 bits.
QUestion... is there any faster way to increment the 16 bit variable than just adding the 256 to the total? |
|
![](templates/subSilver/images/spacer.gif) |
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Fri Jul 27, 2007 1:06 pm |
|
|
It is fast. To see this, make a test program and look at the .LST file.
The compiler doesn't do a full 16-bit add of 0x100. It just adds 1 to the MSB.
Here's the code from the .LST file:
Code: | ........... value += 256;
0015: MOVLW 01
0016: ADDWF value+1,F
|
Here's the test program:
Code: | #include <12F683.h>
#fuses INTRC_IO, NOWDT, PUT, BROWNOUT
#use delay(clock = 8000000)
//==========================
void main()
{
int16 value;
value += 256;
while(1);
} |
|
|
![](templates/subSilver/images/spacer.gif) |
anestho
Joined: 27 Dec 2006 Posts: 28
|
|
Posted: Fri Jul 27, 2007 2:42 pm |
|
|
Thank you! |
|
![](templates/subSilver/images/spacer.gif) |
|