Searching \ for '[PIC] : Quick question regarding PORTA digital out' in subject line. ()
Make payments with PayPal - it's fast, free and secure! Help us get a faster server
FAQ page: www.piclist.com/techref/microchip/ios.htm?key=port
Search entire site for: ': Quick question regarding PORTA digital out'.

Exact match. Not showing close matches.
PICList Thread
'[PIC] : Quick question regarding PORTA digital out'
2002\04\05@055300 by Adam

flavicon
face
Hi,

I'm using a PIC16f877

Is it possible to configure a pin as an analog input in ADCON1 yet use as an
digital output by setting the appropriate bits in TRISB?
I need two a/d lines but still want to use the other 4 lines as digital
outputs.

 bsf STATUS, RP0 ; Select bank 1
 movlw 0x021  ; RA5,0 inputs, 4-1 outputs,
 movwf TRISA
 movlw b'00000010'   ; set all of port E
 movwf ADCON1   ; to Digital I/O, port A to analog

--
http://www.piclist.com#nomail Going offline? Don't AutoReply us!
email spam_OUTlistservTakeThisOuTspammitvma.mit.edu with SET PICList DIGEST in the body


2002\04\05@062558 by Kevin Blain

flavicon
face
Page 116, section 11.3 of the data sheet for the device you are using
(DS30292)says:

"The ADCON1, and TRIS registers control the operation of the A/D port
pins. The port pins that are desired 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."

Page 23-9 of DS31023, The mid range reference manual says the same thing
as it happens.

This means that if TRIS it output for a pin, it will be outputting the
level you set (VOH or VOL).

Regards, Kevin


> {Original Message removed}

2002\04\05@064933 by Adam

flavicon
face
> Page 116, section 11.3 of the data sheet for the device you are using
> (DS30292)says:
>
> "The ADCON1, and TRIS registers control the operation of the A/D port
> pins. The port pins that are desired 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."

Yes, I read those notes and figured it was possible.  After a quick try (not
very thorough at all) I wasn't receiving the proper voltages on the pins.
MPLab simulator didn't set the pins when I steped through it.  ??

The line that puzzles me a bit is "will be converted" - does this mean if
the TRISA is set as output, the analog value will converted to a VOH or VOL
for the A/D converter, or does it mean what we both assumed?

Thanks.

Adam

--
http://www.piclist.com#nomail Going offline? Don't AutoReply us!
email .....listservKILLspamspam@spam@mitvma.mit.edu with SET PICList DIGEST in the body


2002\04\05@070124 by Kevin Blain

flavicon
face
> Yes, I read those notes and figured it was possible.  After a
> quick try (not very thorough at all) I wasn't receiving the
> proper voltages on the pins. MPLab simulator didn't set the
> pins when I steped through it.  ??

Any idea what sort of voltages you were getting? What was the supply
voltage?
It works for me. Note that outputs only show up if the pins are outputs.
Note also the problem with read modify write on the analog pins, i.e.
don't.

> The line that puzzles me a bit is "will be converted" - does
> this mean if the TRISA is set as output, the analog value
> will converted to a VOH or VOL for the A/D converter, or does
> it mean what we both assumed?

The analogue value (reading the pin) will read either the Voltage Output
High level or the Voltage Output Low level. I don't understand what you
mean.


Regards, Kevin

--
http://www.piclist.com#nomail Going offline? Don't AutoReply us!
email listservspamKILLspammitvma.mit.edu with SET PICList DIGEST in the body


2002\04\05@082351 by Olin Lathrop

face picon face
> Is it possible to configure a pin as an analog input in ADCON1 yet use as
an
> digital output by setting the appropriate bits in TRISB?
> I need two a/d lines but still want to use the other 4 lines as digital
> outputs.

No.


*****************************************************************
Embed Inc, embedded system specialists in Littleton Massachusetts
(978) 742-9014, http://www.embedinc.com

--
http://www.piclist.com#nomail Going offline? Don't AutoReply us!
email .....listservKILLspamspam.....mitvma.mit.edu with SET PICList DIGEST in the body


2002\04\05@082751 by Olin Lathrop

face picon face
> Page 116, section 11.3 of the data sheet for the device you are using
> (DS30292)says:
>
> "The ADCON1, and TRIS registers control the operation of the A/D port
> pins. The port pins that are desired 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."
>
> Page 23-9 of DS31023, The mid range reference manual says the same thing
> as it happens.
>
> This means that if TRIS it output for a pin, it will be outputting the
> level you set (VOH or VOL).

Hmm, this seems quite conclusive.  The reason I said "No" before is that a
common issue with PICs with A/Ds is that the A/D wakes up enabled and the
lines don't work for digital I/O.  I guess this means they only don't work
for digital input.  I thought I had run into this problem early on trying to
figure out why my output didn't wiggle as expected, but it was a long time
ago and I am apparently wrong.


*****************************************************************
Embed Inc, embedded system specialists in Littleton Massachusetts
(978) 742-9014, http://www.embedinc.com

--
http://www.piclist.com#nomail Going offline? Don't AutoReply us!
email EraseMElistservspam_OUTspamTakeThisOuTmitvma.mit.edu with SET PICList DIGEST in the body


2002\04\05@083856 by Kevin Blain

flavicon
face
It is a pain to do though, because when you do r-m-w instructions, it
reads the whole port, which will (as defined in the datasheet) read as
zeros. So whilst you can set all pins to 1 using movlw, and movwf you
cannot do it with a sequence of bsfs. A shadow register here would be
needed, unless you could always use w (say you only needed to control
one pin)

On the project I'm working on at the moment I'm using RA4 and RA5 as
outputs, with the rest as analog inputs, and aside from the problems
outlined, it works fine.

However Olin, to your defense, if you reread your post, you are correct
in what you said, as modifying TRISB won't help at all. TRISA is the one
required here :-)

Regards, Kevin

> Hmm, this seems quite conclusive.  The reason I said "No"
> before is that a common issue with PICs with A/Ds is that the
> A/D wakes up enabled and the lines don't work for digital
> I/O.  I guess this means they only don't work for digital
> input.  I thought I had run into this problem early on trying
> to figure out why my output didn't wiggle as expected, but it
> was a long time ago and I am apparently wrong.

--
http://www.piclist.com#nomail Going offline? Don't AutoReply us!
email listservspamspam_OUTmitvma.mit.edu with SET PICList DIGEST in the body


2002\04\05@123757 by Mike Mansheim

flavicon
face
>> Is it possible to configure a pin as an analog input in ADCON1 yet
>> use as an digital output by setting the appropriate bits in TRISB?
>> I need two a/d lines but still want to use the other 4 lines as
>> digital outputs.

> No.

I assumed you said no because of the TRISB reference!

Actually, there is an r-m-w implication here that, in my opinion, goes
beyond the normal caveat, because it WILL happen every time.

Say PORTA.0 and PORTA.1 are both configured as analog in ADCON1, but are
used as a digital outputs (this can be necessary because only certain
combinations of analog and digital pins are possible).  Both will always
READ as a low.  If PORTA.0 is set high, then (even a long time) later
PORTA.1 is changed, PORTA.0 WILL be set low because of the r-m-w fact
that the entire port is read and re-written when changing a single pin.

A shadow register solves this problem - but, as was stated recently, it's
better to understand why you need the shadow register rather than just
blindly using one.
This is a bigger implication to me because it does not require tris
changes, or successive bcf, bsf's which depend on pin capacitance - this
will always happen!
The mistake I made when first tracking down a problem caused by this was
not understanding the data sheet:
"When reading the port register, any pin configured as an analog input
channel will read as cleared (a low level)."
I focused on the word "input" - I thought I was ok because I had the pin
configured as an "output" with the tris register.  However, the key word
is "analog" - as configured by ADCON1.
So, I would have written that part of the data sheet:
"When reading the port register, any pin configured as analog by ADCON1
will read as cleared, regardless of the TRIS setting."

The original data sheet statement was probably obvious to most of you,
but perhaps this explanation will help the original poster.

--
http://www.piclist.com#nomail Going offline? Don't AutoReply us!
email @spam@listservKILLspamspammitvma.mit.edu with SET PICList DIGEST in the body


2002\04\06@180556 by Adam

flavicon
face
PORTA now works as digital out for me.   Thanks for everyones help.

The problem I encountered was the r-m-w issue.  I was not familiar with this
issue until now.  The shadow register cleared it all up.

Adam


{Original Message removed}

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