| View previous topic :: View next topic |
| Author |
Message |
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Tue Jan 11, 2005 3:22 pm |
|
|
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
|
|
Posted: Tue Jan 11, 2005 3:33 pm |
|
|
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
|
|
Posted: Tue Jan 11, 2005 3:41 pm |
|
|
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
|
|
Posted: Tue Jan 11, 2005 4:02 pm |
|
|
| 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
|
|
Posted: Tue Jan 11, 2005 4:28 pm |
|
|
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. |
|
 |
|