View previous topic :: View next topic |
Author |
Message |
pilar
Joined: 30 Jan 2008 Posts: 197
|
Config the AN12 in Pic18f2550 |
Posted: Thu May 20, 2010 8:02 am |
|
|
Hi, I am use the Pic18F2550 and I need use only the AN12 (RB0) as a analog input and the others ports specifically the RB1 as digital inputs and all others ports as digital outputs, someone can tell me if this configuration is correct or should I change it?
Code: | void main(){
setup_adc_ports(PIN_B0);
setup_adc(ADC_CLOCK_DIV_64 );
set_adc_channel(12);
SET_TRIS_A (0b00000000);
SET_TRIS_B (0b00000001);
SET_TRIS_C (0b00000000);
..........
....... |
|
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19520
|
|
Posted: Thu May 20, 2010 8:58 am |
|
|
Not correct, and not possible....
You can only use the constants for any function, that are defined _for_ that function. If you look in the include file for the 2550, you will find a section of defines _for_ the setup_adc_ports function.
Now none exist that only configure AN12 as an ADC input. This is not a CCS limitation, but a _chip_ limitation. Read the data sheet.
The _only_ selection, that allows B0, to be used as an analog input, is the 'ALL_ANALOG' selection, enabling every analog input.
A pin that is programmed as an analog input, _can_ still be used for normal output, but at a 'cost'. There is a small amount of crosstalk through the ADC multiplexer, implying that you will find the accuracy of the ADC degraded.
realistically, if you want a single analog input, you _must_ make the connection to AN0.
Best Wishes |
|
|
pilar
Joined: 30 Jan 2008 Posts: 197
|
|
Posted: Thu May 20, 2010 2:45 pm |
|
|
Hi Ttelmah, thank by your help, but necessarily I can only use the RB0 as analog input.
In these lines of code first configure all analog channels and then just leave the analog channel that interests me and reconfigure all the others as digital outputs, this can work?
Code: |
void main(){
setup_adc_ports(ALL_ANALOG);
setup_adc(ADC_CLOCK_DIV_64 );
set_adc_channel(12);
SET_TRIS_A (0b00000000);
SET_TRIS_B (0b00000001);
SET_TRIS_C (0b00000000);
..........
.......
|
|
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19520
|
|
Posted: Fri May 21, 2010 2:36 am |
|
|
Yes, but with the caveat already given....
Best Wishes |
|
|
|