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
Tagge



Joined: 23 Aug 2005
Posts: 93

View user's profile Send private message Visit poster's website

Analog pins
PostPosted: Sun Mar 15, 2009 2:07 am     Reply with quote

Hi, Im wondering how I can "mask" an An port?
Its on a PIC18F97J60, and I just want to use for example AN8-11 as analogs, the rest of portF and portA should be normal I/O?
There is no option in the project-set-up for that..
To make this I have to use AN0 to AN11
Code:

#define AN0_TO_AN11 0x03  // A0 A1 A2 A3 A5 F0 F1 F2 F3 F4 F5 F6

How will the rest of the ports and pins react when set as analogs at init?
(I know that I only use the actual channels when making the AD conversion)
Thanks
FvM



Joined: 27 Aug 2008
Posts: 2337
Location: Germany

View user's profile Send private message

PostPosted: Sun Mar 15, 2009 2:39 am     Reply with quote

Generally, the said device has no option for arbitrary analog pin configuration as some newer PIC18 have. As you said, configuring AN8-AN11 to analog implies that all AN pins must have analog configuration. As the datasheet clarifies, it's no necessary in any case, to use analog configuration for analog inputs. The purpose of this option is only in disabling the digital input buffer to reduce exessive current consumption with analog input voltages. On the other hand, pins configured to analog can still work as digital outputs.

Quote:
21.4 Configuring Analog Port Pins
The ADCON1, TRISA, TRISF and TRISH registers control the operation of the A/D port pins. The port pins needed as analog inputs must have their corresponding TRIS bits set (input). If the TRIS bit is cleared (output), the digital output level (VOH or VOL) will be converted.

The A/D operation is independent of the state of the CHS3:CHS0 bits and the TRIS bits.

Note 1: When reading the PORT register, all pins configured as analog input channels will read as cleared (a low level). Pins configured as digital inputs will convert an analog input. Analog levels on a digitally configured input will be accurately converted.

2: Analog levels on any pin defined as a digital input may cause the digital input buffer to consume current out of the device's specification limits.
electrogen



Joined: 24 Feb 2009
Posts: 15
Location: Addis

View user's profile Send private message

PostPosted: Sun Mar 15, 2009 5:02 am     Reply with quote

Look on the datasheet on the "analog to digital converter module" description for possible configuration of the analog port pins.

You can't just assign any pin on the port as digital or analog! There are possible set of configurations though, it's stated on the datasheet!
_________________
chips are forever
eskachig



Joined: 27 Mar 2009
Posts: 8

View user's profile Send private message

PostPosted: Wed Apr 29, 2009 11:57 pm     Reply with quote

Sorry to resurrect this thread, but I'm still a bit confused. What exactly happens to my digital inputs when I am forced to use setup_adc_ports(all_analog) to get access to analog channel 13? Are they all automatically low?

The project I'm working on has this bizarre setup where I have to sample input on channels 12 and 13, but still have to use pin A0 as a digital input.
bungee-



Joined: 27 Jun 2007
Posts: 206

View user's profile Send private message

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

eskachig wrote:
Are they all automatically low?

Any input regardless digital or analog on PIC is high-z.
eskachig



Joined: 27 Mar 2009
Posts: 8

View user's profile Send private message

PostPosted: Thu Apr 30, 2009 12:21 am     Reply with quote

bungee- wrote:
eskachig wrote:
Are they all automatically low?

Any input regardless digital or analog on PIC is high-z.


Ok, I meant cleared.

Quote:
all pins configured as analog input channels will read as cleared (a low level)


Does this mean that they're all going to read zero if I try to use them as digital inputs?
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