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

8 or 10 bit A/D

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



Joined: 12 May 2004
Posts: 38

View user's profile Send private message

8 or 10 bit A/D
PostPosted: Wed Jan 26, 2005 3:08 am     Reply with quote

Hi

I'm using the 16F818 with it's 10 bit A/D.
I seem to remember from using 10 bit A/D a number of years ago that you had to force it into 10 bit mode as they default to 8 bit, is this still the case Question

If so I can't remember how to do this I've looked in my old manual and also in the new one but can't find it, can someone refresh my memory please.

TIA

JFK
Ttelmah
Guest







Re: 8 or 10 bit A/D
PostPosted: Wed Jan 26, 2005 5:30 am     Reply with quote

JohnKennedy wrote:
Hi

I'm using the 16F818 with it's 10 bit A/D.
I seem to remember from using 10 bit A/D a number of years ago that you had to force it into 10 bit mode as they default to 8 bit, is this still the case Question

If so I can't remember how to do this I've looked in my old manual and also in the new one but can't find it, can someone refresh my memory please.

TIA

JFK

#device ADC=10

There are quite a few other options too (whether you want left or right justified in the 16bit return for instance). Look in the reference for 'read_adc', to get the details.

Best Wishes
JohnKennedy



Joined: 12 May 2004
Posts: 38

View user's profile Send private message

Re: 8 or 10 bit A/D
PostPosted: Wed Jan 26, 2005 5:49 am     Reply with quote

Ttelmah wrote:
JohnKennedy wrote:
Hi

I'm using the 16F818 with it's 10 bit A/D.
I seem to remember from using 10 bit A/D a number of years ago that you had to force it into 10 bit mode as they default to 8 bit, is this still the case Question

If so I can't remember how to do this I've looked in my old manual and also in the new one but can't find it, can someone refresh my memory please.

TIA

JFK

#device ADC=10

There are quite a few other options too (whether you want left or right justified in the 16bit return for instance). Look in the reference for 'read_adc', to get the details.

Best Wishes


Hi
Thanks for the pointer found it in the manual now but when I put this into my code I get an error as below I have tried various places in my code like the first lline, with my variable declarations etc but always get this error. The manual doesn't show where it should be or shouldn't be placed.

Error 23 Can not change device type this far into the code.

I have even tried in the header file for the PIC where the #device declaration is but I still get the same error when I try to compile.

Where do I put this?

thanks

JFK
Ttelmah
Guest







PostPosted: Wed Jan 26, 2005 6:22 am     Reply with quote

It should work, if you put it as the first line after including the file defining the chip, so:
Code:

#INCLUDE   <16F818.H>
#DEVICE   *=16 ADC=10

As the first two lines of the main file (for a 16F818).
Critical thing, is that no statement that generates code, may appear above it. So #define statements (which only define macros), are OK.
Look carefully at the actual syntax of the line (no spaces inside the definitions), and make sure you have not modified anything in the #include file, that will result in code being generated.

Best Wishes
JohnKennedy



Joined: 12 May 2004
Posts: 38

View user's profile Send private message

PostPosted: Wed Jan 26, 2005 7:03 am     Reply with quote

Hi

Got it to work now thanks I had to put the #include #stlib.h command after the #device command (I had it before it), then it compiled fine.

I have one more question the compiler reports a few warnings on some do/while loops I have stating that the condition is always true or false.

I don't now how it can claim this as the expression is comparing a variable read on a adc pin (within the loop)to a constant, is this normal.

I have included an example below

Code:

do
   {
   vbatt = read_adc();
   }
   while(vbatt < vconnect);


I have used this in the past succesfully

Just to complete the picture yesterday I updated the compiler (my other was 2 years old) so I haven't seen a lot of the updates for a while so this may be something new I'm seeing that can be ignored.[/code]

thanks for your assistance much appreciated.

JFK
Ttelmah
Guest







PostPosted: Wed Jan 26, 2005 9:51 am     Reply with quote

JohnKennedy wrote:
Hi

Got it to work now thanks I had to put the #include #stlib.h command after the #device command (I had it before it), then it compiled fine.

I have one more question the compiler reports a few warnings on some do/while loops I have stating that the condition is always true or false.

I don't now how it can claim this as the expression is comparing a variable read on a adc pin (within the loop)to a constant, is this normal.

I have included an example below

Code:

do
   {
   vbatt = read_adc();
   }
   while(vbatt < vconnect);


I have used this in the past succesfully

Just to complete the picture yesterday I updated the compiler (my other was 2 years old) so I haven't seen a lot of the updates for a while so this may be something new I'm seeing that can be ignored.[/code]

thanks for your assistance much appreciated.

JFK

Glad it works.
How is 'vconnect' defined (presumably a #define)?.
How is 'vbatt' defined?. What type is the variable?.

Best Wishes
JohnKennedy



Joined: 12 May 2004
Posts: 38

View user's profile Send private message

PostPosted: Wed Jan 26, 2005 10:24 am     Reply with quote

Hi

I have it sorted now, I had declared them as Integers, changing them to long Integers has sorted it.

thanks again

John
Ttelmah
Guest







PostPosted: Wed Jan 26, 2005 11:15 am     Reply with quote

JohnKennedy wrote:
Hi

I have it sorted now, I had declared them as Integers, changing them to long Integers has sorted it.

thanks again

John

I suspected something of the sort, which is why I asked about the definitions. :-)
For your own future 'peace of mind', and given that the types exist in the more recent compilers, I'd suggest always using the 'explicit' size declarations (int8, int16, and int32). This way, it is a very useful reminder, of the values that can be held. It also increases portability, since it avoids the trap, of moving code with an 'int' declaration, to a compiler with a different size for this.

Best Wishes
Mark



Joined: 07 Sep 2003
Posts: 2838
Location: Atlanta, GA

View user's profile Send private message Send e-mail

PostPosted: Wed Jan 26, 2005 11:24 am     Reply with quote

Ttelmah wrote:
JohnKennedy wrote:
Hi

I have it sorted now, I had declared them as Integers, changing them to long Integers has sorted it.

thanks again

John

I suspected something of the sort, which is why I asked about the definitions. :-)
For your own future 'peace of mind', and given that the types exist in the more recent compilers, I'd suggest always using the 'explicit' size declarations (int8, int16, and int32). This way, it is a very useful reminder, of the values that can be held. It also increases portability, since it avoids the trap, of moving code with an 'int' declaration, to a compiler with a different size for this.

Best Wishes


I have a file called stdint.h that I include in my source:
Code:

typedef unsigned char       bool;
typedef unsigned char       uint8_t;   // 1 byte  0 to 255
typedef signed char         int8_t;    // 1 byte -127 to 127
typedef unsigned int        uint16_t;  // 2 bytes 0 to 65535
typedef signed int          int16_t;   // 2 bytes -32767 to 32767
typedef unsigned short long uint24_t;  // 3 bytes 0 to 16777215
typedef unsigned long       uint32_t;  // 4 bytes 0 to 4294967295
typedef signed long         int32_t;   // 4 bytes -2147483647 to 2147483647


If I switch compilers, I just have to change the typedefs. Note these definitions are for another compiler (C18) where an "int" is different than in CCS.
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