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

reading 16-bits registers

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



Joined: 01 Jun 2004
Posts: 39
Location: Trois-Rivi�res

View user's profile Send private message

reading 16-bits registers
PostPosted: Sun Feb 06, 2005 12:37 pm     Reply with quote

Hi all,

Does any1 would know how to do read a 16-bits register (TMR1H:TMR1L per example) without using the built-in make16 function?

I built one using pointers and it works, but it access the registers using an indirect addressing operation. What I would like to do is the equivalent of the make16 function, which directly stores the upper byte in the upper byte of the variable and samething for the lower byte.

The reason for all this is that I must produce portable code that doesn't rely on the built-in functions of a compiler.

Thanks,
_________________
Alex
ckielstra



Joined: 18 Mar 2004
Posts: 3680
Location: The Netherlands

View user's profile Send private message

PostPosted: Sun Feb 06, 2005 12:57 pm     Reply with quote

Have a look at the following thread: http://www.ccsinfo.com/forum/viewtopic.php?t=20793
Neutone



Joined: 08 Sep 2003
Posts: 839
Location: Houston

View user's profile Send private message

PostPosted: Mon Feb 07, 2005 12:16 pm     Reply with quote

If your really accessing the timer variables I suggest you use the built in functions.

GET_TIMER1()

At least compile using the built-in functions and observe the assembly created and emulate it. Reading from a 16-bit counter in bytes has a risk of reading incorrectly during a overflow/underflow of the upper or lower byte.
Hans Wedemeyer



Joined: 15 Sep 2003
Posts: 226

View user's profile Send private message

PostPosted: Mon Feb 07, 2005 12:46 pm     Reply with quote

Neutone wrote:
If your really accessing the timer variables I suggest you use the built in functions.

GET_TIMER1()

At least compile using the built-in functions and observe the assembly created and emulate it. Reading from a 16-bit counter in bytes has a risk of reading incorrectly during a overflow/underflow of the upper or lower byte.


This is true when using PIC16 parts.
There has been a change in the PIC18 parts, and CCS has not kept up to date when reading Timer registers.

This works for most PIC18xxxx (check address)

#byte T1LO = 0XFCE
#byte T1HI = 0XFCF

int8 T1L, T1H;

T1L = T1LO; // read low first, that latches the hi byte.
T1H = T1HI;

The data sheet explains why this works.

Quote:
11.5 Timer1 16-Bit Read/Write Mode
Timer1 can be configured for 16-bit reads and writes
(see Figure 11-2). When the RD16 control bit
(T1CON<7>) is set, the address for TMR1H is mapped
to a buffer register for the high byte of Timer1. A read
from TMR1L will load the contents of the high byte of
Timer1 into the Timer1 high byte buffer. This provides
the user with the ability to accurately read all 16-bits of
Timer1 without having to determine whether a read of
the high byte followed by a read of the low byte is valid,
due to a rollover between reads.
End Quote:


LST file for the above code shows it is a little fatser than Get_Timer1();

.................... T1lo = T1L;
0052: MOVFF FCE,09
.................... T1hi = T1H;
0056: MOVFF FCF,0A
It saves one cycle time and reduces code size.


Get_Timer1(); lst

.................... T1lo = Get_Timer1();
004A: MOVF FCE,W
004C: MOVFF FCF,03
0050: MOVWF 09


LST for reading PIC16 timers is horrible... !
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