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

Fast ADC code
Goto page Previous  1, 2
 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Tue Jan 11, 2005 3:22 pm     Reply with quote

Your question isn't really part of this thread, but the answer is
that if you don't specify the adc result, then it defaults to 8 bits.
future



Joined: 14 May 2004
Posts: 330

View user's profile Send private message

PostPosted: Tue Jan 11, 2005 3:33 pm     Reply with quote

Mine, the 452, defaults to 10bit.

You should look at the datasheet to see the default reg values.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Tue Jan 11, 2005 3:41 pm     Reply with quote

It doesn't matter what the PIC does (assuming it has 10-bit hardware).
The size of the value that's returned by the read_adc() function is
controlled by the compiler's generated code. If the compiler is in
8-bit mode, then it only returns the upper 8-bits of the 10-bit result.

I don't have the very latest version of PCH, but I tested it with vs. 3.188
and for the 18F452, the compiler defaults to 8-bits.

For the 16F88, I tested it with vs. 3.215 and it also defaults to returning
an 8-bit result.
future



Joined: 14 May 2004
Posts: 330

View user's profile Send private message

PostPosted: Tue Jan 11, 2005 4:02 pm     Reply with quote

The routines are reading ADRES directly... so the result must be left or right justified depending on what do you want, 10 or 8bit.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Tue Jan 11, 2005 4:28 pm     Reply with quote

I compiled a test program with PCH vs. 3.188, and the .LST file
shows that the compiler generates code to set or clear the ADFM bit,
based upon whether it needs to return an 8-bit or 10-bit result.
It does this because if you want 8-bits, it's more convenient if
the result is left justified. Then the compiler can simply read the
ADRESH register to get the upper 8-bits. It doesn't have to do
any shifting in that case. In the case where you want 10-bits,
most people want it to be right-justified, so the compiler sets
the ADFM bit = 1, and reads both ADRESH and ADRESL.
You don't have to manually put in code to control the ADFM bit.
The compiler does it for you.

In earlier versions of the compiler, this may not have worked
properly. But it works with PCH vs. 3.188 and the 18F452.
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Goto page Previous  1, 2
Page 2 of 2

 
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