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

adc resolution setup 16f88

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



Joined: 02 Oct 2009
Posts: 123
Location: Denmark

View user's profile Send private message

adc resolution setup 16f88
PostPosted: Mon Oct 19, 2009 5:55 am     Reply with quote

16F88 have a 10 bit ADC, so, 1023 must be the maximum value.

I have a program with this instructions, that do adc and lcd update each second (through interrupt):
Code:

int16 adc_value;

setup_adc_ports(sAN0);
setup_adc(ADC_CLOCK_DIV_8);
set_adc_channel(0);
delay_us(20);

adc_value = read_adc();
printf(lcd_putc, "volt=%lu", adc_value);

But when I give +5V to the ADC input, I read just "volt=250" on the lcd.
Maybe the adc is working at 8 bit, so the maximum value is 255.

How can I change the ADC bit resolution?
dyeatman



Joined: 06 Sep 2003
Posts: 1938
Location: Norman, OK

View user's profile Send private message

PostPosted: Mon Oct 19, 2009 6:11 am     Reply with quote

#DEVICE ADC=10
_________________
Google and Forum Search are some of your best tools!!!!
webgiorgio



Joined: 02 Oct 2009
Posts: 123
Location: Denmark

View user's profile Send private message

PostPosted: Mon Oct 19, 2009 1:22 pm     Reply with quote

I imagined that was something simple.

Now the higher value is 65472.... like 2^16.
adc_value is an int16 variable.

why I get 2^16 as max?... Confused How can I get 2^10=1023 as max?

I observe also that the lcd can show just some values, for example from 21632 go directly to 21760. I supose because there are 2^10 levels, but into 2^16 range.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Mon Oct 19, 2009 2:29 pm     Reply with quote

That's because vs. 3.160 is buggy with the 16F88. Normally, the compiler
sets the ADFM bit = 1, to right-justify the 10-bit A/D result. But it doesn't
do that in your version. To fix it, you need to do it manually with code.
Add the lines shown in bold below:
Quote:
#include <16F88.h>
#device ADC=10
#fuses XT, NOWDT, NOLVP
#use delay(clock=4000000)

#byte ADCON1 = 0x9F
#bit ADFM_BIT = ADCON1.7

//=====================================
void main(void)
{
int16 result;

// Put A/D setup code here.

ADFM_BIT = 1; // Right-justify 10-bit A/D result

result = read_adc();

while(1);
}

I didn't show the A/D setup code. I only showed how to set the ADFM
bit.
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