CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to support@ccsinfo.com

using tmr0 overflow for higher counts

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
anestho



Joined: 27 Dec 2006
Posts: 28

View user's profile Send private message

using tmr0 overflow for higher counts
PostPosted: Thu Jul 26, 2007 9:28 am     Reply with quote

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?
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Fri Jul 27, 2007 1:06 pm     Reply with quote

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);
}
anestho



Joined: 27 Dec 2006
Posts: 28

View user's profile Send private message

PostPosted: Fri Jul 27, 2007 2:42 pm     Reply with quote

Thank you!
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group