View previous topic :: View next topic |
Author |
Message |
JamesW
Joined: 23 Apr 2007 Posts: 93 Location: Rochester, England
|
PIC18F46K80 #device ADC=16 compiles OK, with a 12-bit ADC |
Posted: Wed Sep 03, 2025 2:51 am |
|
|
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
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
|
|
Posted: Wed Sep 03, 2025 5:59 am |
|
|
ADC=16 just left justifies the result. It does not change the resolution. |
|
 |
Ttelmah
Joined: 11 Mar 2010 Posts: 19940
|
|
Posted: Wed Sep 03, 2025 11:05 am |
|
|
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
|
|
Posted: Tue Sep 09, 2025 2:36 am |
|
|
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 |
|
 |
|