|
|
View previous topic :: View next topic |
Author |
Message |
ElectroNick
Joined: 10 Oct 2005 Posts: 4
|
A/D resolution problem |
Posted: Tue Feb 14, 2006 3:27 am |
|
|
Hello,
I'm using PIC16F946 and trying to use ADC.
My problem is the ADC result is 8 bit instead of 10 bit.
Code: | unsigned int16 value = 0;
.
.
.
while (TRUE)
{
setup_adc(ADC_CLOCK_INTERNAL);
setup_adc_ports(sAN3 | sAN4 | sAN5 | sAN6 | sAN7 | VSS_VDD); // A3, A5, E0, E1, E2 -> ANALOG
set_adc_channel(3);
delay_ms(100);
value = read_adc();
} |
I'm using Microchip ICD2 as a debugger and I see that value is always ADRESH value, that is 8 bit. I couldn't see a value larger than 0xFF even the analog valtage is almost the same of the reference voltage.
What do you think about this, what is the problem?
I use:
MPLAB IDE v7.30
PCWH Compiler
IDE Version 3.233
PCB Version 3.233
PCM Version 3.233
PCH Version 3.233 |
|
|
ckielstra
Joined: 18 Mar 2004 Posts: 3680 Location: The Netherlands
|
|
Posted: Tue Feb 14, 2006 3:55 am |
|
|
From the PICC manual for the Read_ADC() function:
Quote: | Returns: Either a 8 or 16 bit int depending on #DEVICE ADC= directive. |
We can't tell from the small code sample you gave us, but very likely the following is missing in your program: |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Tue Feb 14, 2006 1:21 pm |
|
|
For a 10-bit A/D, if you use #device adc=16, the compiler
will left-justify the result. i.e., the max reading will be
formated as 0xFFC0. Most people want a right-justified
result, to format it as 0x03FF. To do this, you should use
#device adc=10. The manual has the following chart
in the read_adc() section:
Code: |
A/D type
#device 8-bit 10-bit 11-bit 16-bit
adc=8 00-FF 00-FF 00-FF 00-FF
adc=10 x 0-3FF x x
adc=11 x x 0-7FF x
adc=16 0-FF00 0-FFC0 0-FFE0 0-FFFF
|
|
|
|
raj Guest
|
ADC resolution |
Posted: Wed Mar 15, 2006 12:22 am |
|
|
I am seeing the posts on 10 bit ADc problems but no solutions.
I had configured
#device adc=10
and i am using 16 bit variable
int16 reading
still i get the maximum value as 255.
How do I get 10 bit value? |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Wed Mar 15, 2006 12:25 am |
|
|
1. What PIC are you using ?
2. What is your compiler version ?
The compiler version is given at the top of the .LST file, which is
in your project folder. It will be a number like 3.191, 3.245, etc. |
|
|
kj Guest
|
data type ? |
Posted: Mon Oct 23, 2006 2:41 am |
|
|
Hello,
I'm using PIC16F946
My problem is the data type compilling.
#include "16f946.h"
//#include "16f877.h"
#FUSES HS,WDT,BROWNOUT,NOPROTECT,PUT,NODEBUG,CPD,MCLR,NOFCMEN
#ZERO_RAM
#use delay(clock=20000000,restart_wdt)
.
.
bit run_chk_flag,sec_chk_flag,key_chk_flag;
if include 16f877 file ; not problem
if include 16f946 file ; "expeciting a ( "message appeared at bit position
What do you think about this, what is the problem?
I use:
MPLAB IDE v7.30
PCWH Compiler
IDE Version 3.249
PCB Version 3.249
PCM Version 3.249
PCH Version 3.249 |
|
|
Ttelmah Guest
|
|
Posted: Mon Oct 23, 2006 4:20 am |
|
|
There is no inherent 'bit' datatype in CCS. There is an 'int1', which is a single bit, and the '#bit' directive, which allows a int1, to be mapped to a fixed location. This is why the compile fails.
The reason it works for the 877, is that your version of the include file for this, contains a line like:
#define bit int1
This is not standard (there is normally one for 'boolean', as int1, and one for 'byte' as int8), but somehow the version you have has had this line included.
Best Wishes |
|
|
|
|
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
|