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 CCS Technical Support

timer/counter3 issue

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



Joined: 23 Oct 2006
Posts: 4
Location: Aberdeen

View user's profile Send private message

timer/counter3 issue
PostPosted: Mon Oct 23, 2006 10:00 am     Reply with quote

Hi i'am trying to use timer 3 as a 16bit counter using timer1 external clock (pin RC0/T1OSC/T13CK1). The problem is that it only counts up to 255 before overflowing and resetting back to 0.

The device is a 18F8722.

Does anyone know why this is?

My code sets up timer 3 as follows:

setup_timer_3(T3_EXTERNAL);

set_timer3(0);

encoder_velocity = get_timer3();

If i use timer0 and its associated external clk pin it works but I need to counters running run to seperate sources.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Mon Oct 23, 2006 10:43 am     Reply with quote

Quote:
encoder_velocity = get_timer3();


How did you declare 'encoder_velocity' ?

Was it like this:
Code:
int encoder_velocity;

If so, you have declared it as an unsigned 8-bit integer.
That's what 'int' means in CCS.

To declare it as a 16-bit unsigned integer, do this:

int16 encoder_velocity;
or
long encoder_velocity;

To make those be signed values, put 'signed' in front of the data type.
David_Delph



Joined: 23 Oct 2006
Posts: 4
Location: Aberdeen

View user's profile Send private message

PostPosted: Tue Oct 24, 2006 2:19 am     Reply with quote

No it is declared as an int16.

The code I have works on timer/counter 0 but if I change to using timer/counter 1 it only counts to 255 before overflowing
badtzdizzy
Guest







I found it !!
PostPosted: Tue Jan 09, 2007 8:02 pm     Reply with quote

Hi

I found a solution, you have to clear bit 7 and bit 2 from T1CON register, I did it and I'm getting a 16 bit data.

Regards
eskimobob



Joined: 07 Feb 2009
Posts: 40

View user's profile Send private message

PostPosted: Tue Mar 30, 2010 8:22 am     Reply with quote

Hmmm - that solution did not work for me however I was able to use Timer0 instead and all works properly. The problem with Timer3 seems to be related to reading the two bytes as a 16 bit value - inspecting the RAM, the high byte is always 0.
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