View previous topic :: View next topic |
Author |
Message |
sorasit46
Joined: 07 May 2007 Posts: 69
|
how to config only port AN4 for A/D input (16F876A) |
Posted: Fri Jan 25, 2008 1:57 am |
|
|
Please help! 16F876A.
How to direct config AN4 for A/D. I try 3 ways.
1. setup_adc_ports(RA5_Analog); compile error .
2. setup_adc_ports(AN4); compile error
3. setup_adc_ports(AN4_Analog); compile error
Can I use only AN4(RA5) for A/D and leave other pin for digital I/O?
Thanks
regards
Last edited by sorasit46 on Fri Jan 25, 2008 6:39 pm; edited 1 time in total |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Fri Jan 25, 2008 2:24 am |
|
|
Look in the 16F876A.H file, in the section on Setup_ADC_Ports.
It shows all the options that you can use to configure the A/D pins.
You can't select AN4 as an analog pin by itself. This is a limitation
of the PIC hardware design in the 16F876A. Some later PICs allow
individual selection of A/D pins, but not the 16F876A. |
|
|
Ttelmah Guest
|
|
Posted: Fri Jan 25, 2008 4:33 am |
|
|
However, it is worth 'remembering', that (with an increase in the 'noise' present on AD readings), you can use bits defined as 'ADC' inputs, as logic outputs. So (for instance), you setup:
Code: |
setup_adc_ports(ALL_ANALOG);
//This set to connect AN0 to AN4 to the ADC multiplexer, and chose
//the supply rails as the Vref+/-
set_adc_channel(4);
//Now switch the multiplexer to connect AN4 to the actual ADC
output_high(PIN_A0);
//This still works OK.
|
If you look at the pin diagram in the data sheet, you will see that the driver, and logic inputs, are still present, when the ADC is selected. It is just that if you _use_ them, you can no longer use the pin as an ADC pin, without turning the drivers back off.
However the _input_ gate, is disabled, when the ADC mode is selected. This is because it otherwise causes excessive current to be drawn, if the voltage sits in the 'transition' region for the logic input.
Best Wishes |
|
|
sorasit46
Joined: 07 May 2007 Posts: 69
|
Thanks to Ttelmah .But I stiil have some problem. |
Posted: Fri Jan 25, 2008 6:11 am |
|
|
In fact only Pin AN4 use A/D.Another port use normal I/O port,If I set :setup_adc_ports(All_ANALOG);I don't sure .It may be have problem on another ports.
regards |
|
|
Ttelmah Guest
|
|
Posted: Fri Jan 25, 2008 6:28 am |
|
|
PCM programmer has already answered this. It is _not_ possible on this chip, to only select AN4 as analog. Read the _data sheet_. However it _is_ possible to select all the pins (AN0 to AN4) as analog, and then still use the pins for digital output. When a pin is selected as 'analog', it turns off the logic input buffer, but the output drivers are still available, if enabled by clearing the TRIS bit. There are only four selections that enable AN4 as analog, the other three, use one of more of the Vref pins, and _all_the selections alowing analog input on AN4, also use all the lower pins as analog.
This is a real example, that you _must_ use the chip's data sheet, to make decisions about what to connect to pins, and even what chip to use.
Best Wishes |
|
|
sorasit46
Joined: 07 May 2007 Posts: 69
|
Thanks to Ttelmah .Again please. |
Posted: Fri Jan 25, 2008 6:34 pm |
|
|
Now I have big problem. Because I'm ready have pcb.If I can not config only pin_an4 for A/D input and leave other pin for digital I/O.Can you advice other chip which place all pin like 16F876A ( include portA,portB,portC).Except only pin_an4 (pin 7)for direct config A/D input.
regards |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
|
sorasit46
Joined: 07 May 2007 Posts: 69
|
I'm solve by open A/D amoment |
Posted: Wed Jan 30, 2008 8:11 pm |
|
|
In 16F876A I'm solve by open A/D a moment. When finish read A/D,
I cancel A/D back to normal I/O port.
.
.
set_tris_a(0b00101100);
.
.
setup_adc_ports(All_ANALOG); // All pin(AN0-AN4) for ADC
setup_adc(ADC_CLOCK_INTERNAL); // Clock RC
set_adc_channel(4); // Read Analog input RA5/AN4 (channel=4)
delay_us(10); // must let afew time for read analog input
Vread = Read_ADC();
setup_adc_ports(NO_ANALOGS); // Don't fix port for ADC
setup_adc(ADC_OFF); // Off A/D function
.
.
Please ! teach me .What mean off
1. #use fast_io(A). I don't understand.
2. #byte port_b=6. If not register port b .what happen or it's not stable ?
regards |
|
|
|