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 conversion

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







A/D conversion
PostPosted: Fri Feb 18, 2005 2:19 am     Reply with quote

Hi all,
I have a quick question. How do I configure a PIC18F452's A/D converter to be left justified? I read somewhere that I need to do a

#device adc= 16

but don't know if that is correct. Is there anything else that I need to do?

This is what I currently have for my A/D converter:

#device adc= 16
.
.
.

setup_adc_ports(RA0_RA1_RA3_ANALOG);
setup_adc(ADC_CLOCK_DIV_32);
.
.
set_adc_channel(0);
.
.
result = read_adc(ADC_START_AND_READ)


will this give me a valid result (int)? how do I just copy ADRESH into result, instead of a 10 bit answer?
any help is appreciated
thank you
Guest








PostPosted: Fri Feb 18, 2005 11:40 am     Reply with quote

anybody?????
Mark



Joined: 07 Sep 2003
Posts: 2838
Location: Atlanta, GA

View user's profile Send private message Send e-mail

PostPosted: Fri Feb 18, 2005 11:51 am     Reply with quote

ADC is either 8 or 10 and not 16 for the 452. If you set it to 8, you should an int that is 8 bits. This would be the 8 MSB's or left justified. If you set adc to 10 then you read a 16bit integer (which is only 10 bits) which would be right justified.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Fri Feb 18, 2005 12:08 pm     Reply with quote

Also, to learn about this for yourself, download the compiler manual here:
http://www.ccsinfo.com/ccscmanual.zip
Then go to page 153 in the Acrobat reader. This is the page for
the read_adc() function. You'll see a table which shows the format of
the A/D results, based on the A/D resolution of the PIC, and on the
setting of the #device adc statement. In your case, you have a 10-bit
A/D, so use that column.

Also remember that in CCS an "int" is only 8-bits. If you want a 16-bit
variable you have to declare it as int16 or "long". (Same thing in CCS,
but int16 is more descriptive).
Mark



Joined: 07 Sep 2003
Posts: 2838
Location: Atlanta, GA

View user's profile Send private message Send e-mail

PostPosted: Fri Feb 18, 2005 12:12 pm     Reply with quote

I like using the help file that comes with the compiler. It seems to be more up to date than the manuals.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Fri Feb 18, 2005 12:21 pm     Reply with quote

I did look at the help file first and was going to point him to that,
but the table that I wanted to show him is poorly formatted in the
help file.
Mark



Joined: 07 Sep 2003
Posts: 2838
Location: Atlanta, GA

View user's profile Send private message Send e-mail

PostPosted: Fri Feb 18, 2005 12:28 pm     Reply with quote

Are you looking at the ccsc.chm file? It is the same as the one in the manual on my computer. The one I am using is dated from Sep04 as well. My maintenance expired last week so I haven't downloaded the latest. Not sure if it is different.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Fri Feb 18, 2005 1:48 pm     Reply with quote

Yes, ccsc.chm is the one with the poorly formatted A/D settings table.
The table in CCSC.HLP looks nice, though. I admit that my system
is set for Large Fonts. That might have something to do with it.
Mark



Joined: 07 Sep 2003
Posts: 2838
Location: Atlanta, GA

View user's profile Send private message Send e-mail

PostPosted: Fri Feb 18, 2005 1:58 pm     Reply with quote

Maybe thats it. I use a 21 inch monitor running 1600X1200 with Normal fonts. Very Happy I like to see everything at once Wink
Guest








Re: A/D conversion
PostPosted: Thu Jan 19, 2006 6:00 pm     Reply with quote

CCS_student wrote:
Hi all,
I have a quick question. How do I configure a PIC18F452's A/D converter to be left justified? I read somewhere that I need to do a

#device adc= 16

but don't know if that is correct. Is there anything else that I need to do?

This is what I currently have for my A/D converter:

#device adc= 16
.
.
.

setup_adc_ports(RA0_RA1_RA3_ANALOG);
setup_adc(ADC_CLOCK_DIV_32);
.
.
set_adc_channel(0);
.
.
result = read_adc(ADC_START_AND_READ)


will this give me a valid result (int)? how do I just copy ADRESH into result, instead of a 10 bit answer?
any help is appreciated
thank you
bernardinim



Joined: 07 Dec 2005
Posts: 10
Location: Italy

View user's profile Send private message

PostPosted: Fri Feb 03, 2006 10:21 am     Reply with quote

I am using a PIC18F2525 at 32MHz and i'm trying to read from adc...
but i have a problem: i set #device adc=10 , but i read the result at 8bit only (0-255) ..why?
I show my code:

#device adc=10


int16 ADC_Channel_0_int;
int16 ADC_Channel_1_int;


#task(rate=1000ms,max=100ms)
void task_2_ADC_INTERNAL();

void task_2_ADC_INTERNAL()
{
float constant=5/1025;
set_adc_channel( 0 );
delay_us(10);
ADC_Channel_0_int=Read_ADC();
set_adc_channel( 1 );
delay_us(10);
ADC_Channel_1_int=Read_ADC();
output_high(TX_ENABLE);
printf("%lu %lu\r",ADC_Channel_0_int,ADC_Channel_1_int);
delay_ms(10);
output_low(TX_ENABLE);
}


//main
void main()
{


setup_adc_ports(AN0_TO_AN1|VSS_VDD);
setup_adc(ADC_CLOCK_INTERNAL);

setup_wdt(WDT_OFF);
setup_timer_0(RTCC_INTERNAL);
setup_timer_1(T1_DISABLED);
setup_timer_2(T2_DISABLED,0,1);
setup_timer_3(T3_DISABLED|T3_DIV_BY_1);
setup_comparator(NC_NC_NC_NC);
setup_vref(FALSE);
setup_low_volt_detect(FALSE);
setup_oscillator(OSC_NORMAL);
enable_interrupts(INT_RDA);
enable_interrupts(GLOBAL);

rtos_run();


}
rnielsen



Joined: 23 Sep 2003
Posts: 852
Location: Utah

View user's profile Send private message

PostPosted: Fri Feb 03, 2006 1:02 pm     Reply with quote

This thread is a year old. Guest has come in again and did a phantom post.
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