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

A/D resolution problem

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



Joined: 10 Oct 2005
Posts: 4

View user's profile Send private message

A/D resolution problem
PostPosted: Tue Feb 14, 2006 3:27 am     Reply with quote

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

View user's profile Send private message

PostPosted: Tue Feb 14, 2006 3:55 am     Reply with quote

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:
Code:
#DEVICE ADC=16
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Tue Feb 14, 2006 1:21 pm     Reply with quote

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
PostPosted: Wed Mar 15, 2006 12:22 am     Reply with quote

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

View user's profile Send private message

PostPosted: Wed Mar 15, 2006 12:25 am     Reply with quote

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 ?
PostPosted: Mon Oct 23, 2006 2:41 am     Reply with quote

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







PostPosted: Mon Oct 23, 2006 4:20 am     Reply with quote

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
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