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

how to config only port AN4 for A/D input (16F876A)

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



Joined: 07 May 2007
Posts: 69

View user's profile Send private message

how to config only port AN4 for A/D input (16F876A)
PostPosted: Fri Jan 25, 2008 1:57 am     Reply with quote

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

View user's profile Send private message

PostPosted: Fri Jan 25, 2008 2:24 am     Reply with quote

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







PostPosted: Fri Jan 25, 2008 4:33 am     Reply with quote

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

View user's profile Send private message

Thanks to Ttelmah .But I stiil have some problem.
PostPosted: Fri Jan 25, 2008 6:11 am     Reply with quote

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







PostPosted: Fri Jan 25, 2008 6:28 am     Reply with quote

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

View user's profile Send private message

Thanks to Ttelmah .Again please.
PostPosted: Fri Jan 25, 2008 6:34 pm     Reply with quote

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

View user's profile Send private message

PostPosted: Fri Jan 25, 2008 6:53 pm     Reply with quote

Look at the 16F886.
http://www.microchip.com/stellent/idcplgidcplg?IdcService=SS_GET_PAGE&nodeId=1335&dDocName=en026562

Also check the errata sheet on that page. The i2c modes have got
problems.
sorasit46



Joined: 07 May 2007
Posts: 69

View user's profile Send private message

I'm solve by open A/D amoment
PostPosted: Wed Jan 30, 2008 8:11 pm     Reply with quote

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
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