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 support@ccsinfo.com

Analog pins

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







PostPosted: Thu Apr 30, 2009 3:14 am     Reply with quote

Let me summarise:

The possible 'layouts' are:
1) Pin set as 'pure' digital input.
2) Pin set as 'pure' digital output.
3) Pin set as analog input, used as analog input.
4) Pin set as analog input, used as digital output.
5) Pin set as analog input, used as digital input.

Now, '3' is the preferred route for analog, but the first question is can you use 4 and 5, and what happens if you do?.

'4', works fine, but with two caveats:
A) There is slightly more tendency to crosstalk from this digital pin to the analog circuitry.
B) The Vref, then must be up close to Vss (or use Vss). A pin connected to the analog multiplexer, must not go more than 0.6v above the Vref level. So you can't (for instance), use 2.5v Vref, or you will get the digital signal tending to modulate the Vref...

The remaining question, is can '5' be used?.
Generally, no.
Selecting the analog input mode, disables the logic input buffer.
This has to be done, since otherwise excessive current can be drawn in this, if the input signal sits in the 'transition' region.

If you try to use them as digital inputs, what you read, will depend on the logic in the 'disable' circuitry, but on most of the older chips, the input is built using an 'OR' gate, with the 'analog enabled' signal, inverted, and fed into the other input of the gate. So when analog is enabled on a pin, it reads as '0' if you try to use the logic input.

On latter chips like the 18 series, this is described quite well in the data sheet, where the 'I/O pins' table, lists what happens for each pin, according to the settings on TRIS, and the analog input setting.

A 'classic' section in this (f just one pin), reads:
Code:

RA1/AN1 RA1 0 O DIG LATA<1> data output; not affected by analog input.
                     1 I TTL PORTA<1> data input; disabled when analog input enabled.
              AN1 1 I ANA A/D input channel 1. Default input configuration on POR; does not affect digital output

Note the critical line, where the TTL input is 'disabled when analog input enabled'.

So, you cannot use analog inputs as digital inputs. You need to layout your wiring, and pin choices, to avoid this.

Best Wishes
libor



Joined: 14 Dec 2004
Posts: 288
Location: Hungary

View user's profile Send private message

PostPosted: Thu Apr 30, 2009 6:55 am     Reply with quote

What is your application doing with the analog inputs ?
If you can afford measuring their value not too often, you can switch your port configuration to all-analog only just before the ADC process (allow some time for the ports to settle) and then go back to the digital configuration during runtime for the rest of your operations.
Ttelmah
Guest







PostPosted: Thu Apr 30, 2009 10:16 am     Reply with quote

The downside of this approach, is that then the pins with analog signals attached, will run into the excessive current in the input buffer problem....

Alternatively, just read the ADC value on the pin, and convert this to a logic level. Use an arbitary level (like half the input range), and if it is above this, return a '1', or below, return a '0'.
Doenside is it takes a fw uSec to read the pin, but no problems then with configuration.

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