View previous topic :: View next topic |
Author |
Message |
CCS_student Guest
|
A/D conversion |
Posted: Fri Feb 18, 2005 2:19 am |
|
|
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
|
|
Posted: Fri Feb 18, 2005 11:40 am |
|
|
anybody????? |
|
|
Mark
Joined: 07 Sep 2003 Posts: 2838 Location: Atlanta, GA
|
|
Posted: Fri Feb 18, 2005 11:51 am |
|
|
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
|
|
Posted: Fri Feb 18, 2005 12:08 pm |
|
|
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
|
|
Posted: Fri Feb 18, 2005 12:12 pm |
|
|
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
|
|
Posted: Fri Feb 18, 2005 12:21 pm |
|
|
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
|
|
Posted: Fri Feb 18, 2005 12:28 pm |
|
|
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
|
|
Posted: Fri Feb 18, 2005 1:48 pm |
|
|
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
|
|
Posted: Fri Feb 18, 2005 1:58 pm |
|
|
Maybe thats it. I use a 21 inch monitor running 1600X1200 with Normal fonts. I like to see everything at once |
|
|
Guest
|
Re: A/D conversion |
Posted: Thu Jan 19, 2006 6:00 pm |
|
|
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
|
|
Posted: Fri Feb 03, 2006 10:21 am |
|
|
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
|
|
Posted: Fri Feb 03, 2006 1:02 pm |
|
|
This thread is a year old. Guest has come in again and did a phantom post. |
|
|
|