Searching \ for '[PIC] Analog input assignment question' in subject line. ()
Make payments with PayPal - it's fast, free and secure! Help us get a faster server
FAQ page: massmind.org/techref/microchip/ios.htm?key=analog
Search entire site for: 'Analog input assignment question'.

Exact match. Not showing close matches.
PICList Thread
'[PIC] Analog input assignment question'
2010\02\12@153453 by MCH

flavicon
face
Am I reading the PIC 18F4520 docs correctly that you can only assign
analog inputs in ascending order? IOW, if I want only three analog
inputs, I have to use pins AN0, AN1, and AN2 and I cannot make the
selection based on open pins such as AN3, AN8, and AN9?

Put another way, if I want AN5 to be analog, AN4-AN0 has to be analog as
well.

Do I have this correct?

Joe M.

2010\02\12@160514 by ivp

face picon face
> Am I reading the PIC 18F4520 docs correctly that you can only
> assign analog inputs in ascending order?

Yes. Some are not like that, and you can assign any individual pin as
an analogue input on its own

Depending on the circuit, you should be able to temporarily switch
from outputs to inputs if the pin is not left floating. For example if
you want AN5 to be the analogue input and PORTA <4:0> are in
use as outputs, you set PORTA <5:0> as inputs in TRISA and
ADCON1 <3:0> = 1001 to configure AN <5:0> whilst you select
and read AN5 (ADCON0 <5:2> = 0101)

wbr

2010\02\12@162837 by ivp

face picon face
> Am I reading the PIC 18F4520 docs correctly that you can only
> assign analog inputs in ascending order?

Some of what I wrote previously is not correct. A couple of points -

In your example, any pins below AN5 that are set as digital I/O do
not need changing to analogue inputs, so you can leave TRISA as
you need it. However, if AN5 is selected as a digital I/O then you
might get a problem if it has an analogue voltage on it

IOW, it's OK to have digital signals on a pin configured as an
analogue input or potential analogue input but it's not always OK to
have analogue voltage on a pin configured as a digital I/O. A series
current-limiting should prevent excessive power consumption

In that case, if you want to use AN5 as the analogue input, set
ADCON1 <PCFG3:PCFG0> to 1001, TRISA <5> = 1 and
ADCON0 <CH3:CHS0> to 0101

Sorry for the mistake, was kind of thinking of something else

wbr

2010\02\12@170040 by MCH

flavicon
face
I've become quite adept at pin sharing. :-)

Thanks for the confirmation.

The basic premise is what I was asking about - whether having AN5 used
means I have to set AN4-0 as analog as well (even temporarily in the
subroutine).

Pin sharing aside, I think you confirmed that is true.

So, getting into sharing, not only would I have to consider what is
connected to AN5, but also perhaps AN4-0 if the circuit cannot be left
floating while AN0-4 are defined as analog inputs.

Joe M.

ivp wrote:
{Quote hidden}

2010\02\12@173930 by peter green

flavicon
face
MCH wrote:
> Am I reading the PIC 18F4520 docs correctly that you can only assign
> analog inputs in ascending order? IOW, if I want only three analog
> inputs, I have to use pins AN0, AN1, and AN2 and I cannot make the
> selection based on open pins such as AN3, AN8, and AN9?
>
> Put another way, if I want AN5 to be analog, AN4-AN0 has to be analog as
> well.
>  
Yes and no

Yes you can only put pins into analog mode in order. However afaict the
only thing that putting a pin in analog input mode does is disable the
digitial input buffers.

So you can still use a pin as a digital output when it's set as analog
(this was very useful when I had to drive a resistive touchscreen) and
if you are prepared to put up with the extra power consumption caused by
having a digital input floating between the rails you can use a pin as
an analog input when it's set as digitial.

2010\02\12@232057 by Bob Ammerman

picon face
> IOW, it's OK to have digital signals on a pin configured as an
> analogue input or potential analogue input but it's not always OK to
> have analogue voltage on a pin configured as a digital I/O. A series
> current-limiting should prevent excessive power consumption

A series current-limiting resistor is *not* going to help the power
consumption issue. The power consumption occurs inside the PIC when the
input is neither a valid 0 nor a valid 1 value. The current is *not* drawn
thru the input, but rather between the power and ground rails in thePIC
itself. The series resistor is not going to change the voltage seen by the
PIC input and thus will be no help.

-- Bob Ammerman
RAm Systems

2010\02\13@002828 by MCH

flavicon
face
So, you can only assign analog inputs in ascending order, but the only
thing that will 'affect' is when the 'lower' pins are inputs.

IOW, if the lower pins are all outputs, you can assign ANx as an analog
input and only that pin will be treated as such and the only one you
will have to worry about.

Put a third way, the digital I/O assignments for outputs override the
analog input settings.

Joe M.

peter green wrote:
{Quote hidden}

2010\02\13@030312 by ivp

face picon face
> The series resistor is not going to change the voltage seen by the
> PIC input and thus will be no help.

Yes, my bad. There will be a range of analogue voltage which causes
the input FETs to not commit to a '0' or '1' value and even try to turn
on together, making a short between the rails

wbr

2010\02\13@091254 by Marechiare

picon face
ivp wrote:
>> The series resistor is not going to change the voltage
>> seen by the PIC input and thus will be no help.
>
> Yes, my bad. There will be a range of analogue voltage
> which causes the input FETs to not commit to a '0' or '1'
> value and even try to turn on together, making a short
> between the rails

Except for Schmitt Trigger inputs that are likely to be discussed in
this thread. Input wires within the package are of some resistance, so
the Schmitt trigger feedback would not let the input to stay stably at
that intermediate level.

2010\02\15@150625 by Gerhard Fiedler

picon face
MCH wrote:

> So, you can only assign analog inputs in ascending order, but the only
> thing that will 'affect' is when the 'lower' pins are inputs.

Almost, but not quite.

> IOW, if the lower pins are all outputs, you can assign ANx as an
> analog input and only that pin will be treated as such and the only
> one you will have to worry about.
>
> Put a third way, the digital I/O assignments for outputs override the
> analog input settings.

The input of the digital input latch that is associated with the output
(and that is functional even when a pin is set as an output) is also
affected.

Check out the port block diagrams in the data sheet. They are quite
helpful for understanding how this works together. There is no way to
disable the input circuitry; there is only a way to disable the output
drivers (the TRIS bits). Configuring a pin as analog makes the digital
input latch always read 0, and that's it, basically. If you don't read
it while it is set to analog, there shouldn't be any other consequences.

Gerhard

2010\02\15@162913 by Wouter van Ooijen

face picon face
>> Put a third way, the digital I/O assignments for outputs override the
>> analog input settings.

That is misleading. When ANx is enabled and TRISxn low (digital output),
you can write to the pin *and then read the actual (analog) level using
the ADC*.

--

Wouter van Ooijen

-- -------------------------------------------
Van Ooijen Technische Informatica: http://www.voti.nl
consultancy, development, PICmicro products
docent Hogeschool van Utrecht: http://www.voti.nl/hvu

2010\02\16@223317 by MCH

flavicon
face
But if you write to that pin, the analog voltage present from what
you're reading would interfere with the output, wouldn't it?

Joe M.

Wouter van Ooijen wrote:
{Quote hidden}

2010\02\17@012714 by Wouter van Ooijen

face picon face
>> When ANx is enabled and TRISxn low (digital output),
>> you can write to the pin *and then read the actual (analog) level using
>> the ADC*.

> But if you write to that pin, the analog voltage present from what
> you're reading would interfere with the output, wouldn't it?

You can't successfully present analog voltage to a pin that is an
output. What you are reading with the ADC is how well the digital output
drivers are doing their work against the load.

--

Wouter van Ooijen

-- -------------------------------------------
Van Ooijen Technische Informatica: http://www.voti.nl
consultancy, development, PICmicro products
docent Hogeschool van Utrecht: http://www.voti.nl/hvu

More... (looser matching)
- Last day of these posts
- In 2010 , 2011 only
- Today
- New search...