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

PIC18F46K80 #device ADC=16 compiles OK, with a 12-bit ADC

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



Joined: 23 Apr 2007
Posts: 93
Location: Rochester, England

View user's profile Send private message Visit poster's website

PIC18F46K80 #device ADC=16 compiles OK, with a 12-bit ADC
PostPosted: Wed Sep 03, 2025 2:51 am     Reply with quote

Hi Folks,

Interesting question here - I'm going through a bit of code that was written 8 years ago by someone else - to look at a completely different issue.

I have just noticed in the header file, the settings for the A/D converter are set as follows

Code:
#device ADC=16


However the processor only has a 12-bit A/D converter - and to confuse things even further, the units have been working perfectly - even to the extent that there is a definition in the code for the number of Volts/Bit for incoming analogues, that matches up perfectly to 5V divided by 65535

Code:
#define ADC_VOLT_PER_BIT 0.0000762951094834821087


The irony is that this is reading a temperature and humity sensor, and the end result is rounded up to a whole value anyway - so a 12-bit A/D value would have been more than adequate!

Could someone please shed a bit of light onto what's going on here, and why this builds and works?

Thanks in advance

James[/code]
gaugeguy



Joined: 05 Apr 2011
Posts: 336

View user's profile Send private message

PostPosted: Wed Sep 03, 2025 5:59 am     Reply with quote

ADC=16 just left justifies the result. It does not change the resolution.
Ttelmah



Joined: 11 Mar 2010
Posts: 19940

View user's profile Send private message

PostPosted: Wed Sep 03, 2025 11:05 am     Reply with quote

It is perhaps worth understanding that the capability here comes from what
the chip offers.
All the PIC ADC's offer a configuration option for a left justified or right
justified result. ADC=16 enables the former.
The ADC's all also in left justified mode, have the top 8 bits in the upper
register. This is what ADC=8 returns. Single register read, so quicker.
ADC=12 on a chip with a 10bit ADC, will result in two extra bits being
read from the register, which depending on the chip may be meaningless,
or may contain status bits, so invalid in either case.
JamesW



Joined: 23 Apr 2007
Posts: 93
Location: Rochester, England

View user's profile Send private message Visit poster's website

PostPosted: Tue Sep 09, 2025 2:36 am     Reply with quote

Many thanks for the help - that makes sense.

Always thought it was a configuration command that helped set up the ADC itself.

Have "corrected" the original code, just so it makes sense to my inner pedant
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