View previous topic :: View next topic |
Author |
Message |
David_Delph
Joined: 23 Oct 2006 Posts: 4 Location: Aberdeen
|
timer/counter3 issue |
Posted: Mon Oct 23, 2006 10:00 am |
|
|
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
|
|
Posted: Mon Oct 23, 2006 10:43 am |
|
|
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
|
|
Posted: Tue Oct 24, 2006 2:19 am |
|
|
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 !! |
Posted: Tue Jan 09, 2007 8:02 pm |
|
|
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
|
|
Posted: Tue Mar 30, 2010 8:22 am |
|
|
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. |
|
|
|