Searching \ for '[PIC]: State of output drivers after a tris change' 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=output
Search entire site for: 'State of output drivers after a tris change'.

Exact match. Not showing close matches.
PICList Thread
'[PIC]: State of output drivers after a tris change'
2002\05\21@184551 by Jon Baker

flavicon
face
If I ran the following pseudo-code:

TRISB = 0
PORTB = 0xAA

TRISB = 255
TEMP = PORTB

TRISB = 0

After to port is set back to output what will be the state of the pins?
Does the contents of the output driver get destroyed when changing TRIS, or when performing a read operation on the port? I'm hoping that my original value ( AA ) is presented on the pins when I switch back to output mode.

Thanks muchly.

Jon Baker

--
http://www.piclist.com hint: To leave the PICList
spam_OUTpiclist-unsubscribe-requestTakeThisOuTspammitvma.mit.edu


2002\05\21@192418 by Bob Ammerman

picon face
Yes, when you switch back to output mode, the last value written to the port
will still be in the output latch.

However, there is a gotcha.... if you use any read-modify-write instructions
(including BCF, BSF and any others) on the port then the latch will be
overwritten. This is usually only a problem if the port is mixed between
inputs and outputs, as opposed to all inputs or all outputs.

Bob Ammerman
RAm Systems



{Original Message removed}

2002\05\21@200459 by Tony Nixon

flavicon
picon face
Jon Baker wrote:
>
> If I ran the following pseudo-code:
>
> TRISB = 0
> PORTB = 0xAA
>
> TRISB = 255
> TEMP = PORTB
>
> TRISB = 0
>
> After to port is set back to output what will be the state of the pins?
> Does the contents of the output driver get destroyed when changing TRIS, or when performing a read operation on the port? I'm hoping that my original value ( AA ) is presented on the pins when I switch back to output mode.

It should still be 0xAA because you did nothing to change the PORTB
output value.

--
Best regards

Tony

mICros
http://www.bubblesoftonline.com
.....salesKILLspamspam@spam@bubblesoftonline.com

--
http://www.piclist.com hint: To leave the PICList
piclist-unsubscribe-requestspamKILLspammitvma.mit.edu


2002\05\22@013605 by Jon Baker

flavicon
face
From: "Bob Ammerman"

> Yes, when you switch back to output mode, the last value written to the
port
> will still be in the output latch.
>
> However, there is a gotcha.... if you use any read-modify-write
instructions
> (including BCF, BSF and any others) on the port then the latch will be
> overwritten. This is usually only a problem if the port is mixed between
> inputs and outputs, as opposed to all inputs or all outputs.

Excellent, thats just what I wanted to hear. I knew there was some good
reason behind the port architecture. Thanks Bob and Tony.

Jon Baker

--
http://www.piclist.com hint: PICList Posts must start with ONE topic:
[PIC]:,[SX]:,[AVR]: ->uP ONLY! [EE]:,[OT]: ->Other [BUY]:,[AD]: ->Ads


2002\05\22@074346 by Olin Lathrop

face picon face
>>
If I ran the following pseudo-code:

TRISB = 0
PORTB = 0xAA

TRISB = 255
TEMP = PORTB

TRISB = 0

After to port is set back to output what will be the state of the pins?
Does the contents of the output driver get destroyed when changing TRIS, or
when performing a read operation on the port? I'm hoping that my original
value ( AA ) is presented on the pins when I switch back to output mode.
<<

On all but the 18 family PICs, any read of a port sets the output latches to
the value that was read.  This has been beaten to death here many times and
is described in the manual.  Search the archives.


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

--
http://www.piclist.com hint: PICList Posts must start with ONE topic:
[PIC]:,[SX]:,[AVR]: ->uP ONLY! [EE]:,[OT]: ->Other [BUY]:,[AD]: ->Ads


2002\05\22@074909 by Olin Lathrop

face picon face
> > TRISB = 0
> > PORTB = 0xAA
> >
> > TRISB = 255
> > TEMP = PORTB
> >
> > TRISB = 0
> >
> > After to port is set back to output what will be the state of the pins?
> > Does the contents of the output driver get destroyed when changing TRIS,
or when performing a read operation on the port? I'm hoping that my original
value ( AA ) is presented on the pins when I switch back to output mode.
>
> It should still be 0xAA because you did nothing to change the PORTB
> output value.

Actually he did, so it won't be.  TEMP = PORTB (assuming I interpret his
pseudo code correctly) reads port B while all bits are set as inputs.  This
will essentially copy the input values to the output latches.  The resulting
port B value therefore depends on the external circuit.


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

--
http://www.piclist.com hint: PICList Posts must start with ONE topic:
[PIC]:,[SX]:,[AVR]: ->uP ONLY! [EE]:,[OT]: ->Other [BUY]:,[AD]: ->Ads


2002\05\22@081553 by Bob Ammerman

picon face
I am quite sure Olin is incorrect here. The statement "TEMP = PORTB" would
almost certainly become "MOVF PORTB,W" and "MOVWF TEMP". The "MOVF"
instruction will not affect the PORTB latch because it is NOT
read-modify-write (although MOVF PORTB,F would be).

Bob Ammerman
RAm Systems

{Original Message removed}

2002\05\22@102518 by Jon Baker

flavicon
face
I wrote:
> After to port is set back to output what will be the state of the pins?
> Does the contents of the output driver get destroyed when changing TRIS,
or
> when performing a read operation on the port? I'm hoping that my original
> value ( AA ) is presented on the pins when I switch back to output mode.
> <<

Olin wrote:
> On all but the 18 family PICs, any read of a port sets the output latches
to
> the value that was read.  This has been beaten to death here many times
and
> is described in the manual.  Search the archives.

1) I don't remember seeing the question about whether reading a port affects
the data in the output latches before. If I had, and I had also seen the
answer, then I would not have asked. If I had not seen the answer I would
have looked for it in the archives.

2) I searched for the phrases "output and latch" "port and latch" and "read
and modify and write" in the archives, at least one of which I would have
expected to appear in any question similar to mine, and subsequent answer.-
so perhaps you could suggest alternative search terms which would have come
up with all the questions and answers that have aparently been beaten to
death behind my back.

3) As for searching the manual, I have this quote from the I/O PORTS, PORTA
section of the 16F877 datasheet (DS30292C) regarding PORTA:

"Reading the PORTA register reads the state of the pins, whereas writing to
it will write to the port latch. All write operations are read-modify-write
operations. Therefore, a write to a port implies that the port pins are
read, the value is modified and written to the port data latch."

Although my question was regarding PORTB, the block diagrams of RA3:RA0 and
RA5 pins (Figure 3-1), RB7:RB4 pins (Figure 3-4) and RB3:RB0 pins all show
similar functionality in that the "RD Port" control line does not trigger
the CK input of the port latch, therefore not over writing the data latch
with the value presented on the pins.

However, the pic could very easily assert both the RD Port and WR Port
control lines at the same time in a deliberate attempt to set the output
latch to the most recent value read from the port pins. I can not find any
reference to the existence (or not) of this functionality in the datasheet
which is why, in the hope that somebody with experience of this could give a
definitive answer, I posted the original question.

Perhaps if you ever get receive any of the consultants fees with which you
threaten people who email you directly, you can spend it on getting some
manners, and if you have any left after that, getting the size of your head
reduced.

--
Jon Baker

--
http://www.piclist.com hint: PICList Posts must start with ONE topic:
[PIC]:,[SX]:,[AVR]: ->uP ONLY! [EE]:,[OT]: ->Other [BUY]:,[AD]: ->Ads


2002\05\22@103516 by =?iso-8859-1?Q?F=E1bio_Pereira?=

flavicon
face
----- Original Message -----
From: "Olin Lathrop" <.....olin_piclistKILLspamspam.....EMBEDINC.COM>
To: <EraseMEPICLISTspam_OUTspamTakeThisOuTMITVMA.MIT.EDU>
Sent: Wednesday, May 22, 2002 8:48 AM
Subject: Re: [PIC]: State of output drivers after a tris change


> > > TRISB = 0
> > > PORTB = 0xAA
> > >
> > > TRISB = 255
> > > TEMP = PORTB
> > >
> > > TRISB = 0
> > >
> > > After to port is set back to output what will be the state of the
pins?
> > > Does the contents of the output driver get destroyed when changing
TRIS,
> or when performing a read operation on the port? I'm hoping that my
original
> value ( AA ) is presented on the pins when I switch back to output mode.
> >
> > It should still be 0xAA because you did nothing to change the PORTB
> > output value.
>
> Actually he did, so it won't be.  TEMP = PORTB (assuming I interpret his
> pseudo code correctly) reads port B while all bits are set as inputs.
This
> will essentially copy the input values to the output latches.  The
resulting
> port B value therefore depends on the external circuit.
>

I don't think so ... As far I can see, this attribution line will be
compilled as:

MOVF     PORTB,W
MOVWF TEMP

Note that the MOVF instruction isn't a RMW one. So it will only read the
PORTB pins. There will not be any writes to the PORTB latches.

My opinion is that after the TRISB=0, the output state of PORTB will be 0xAA
again.

Note that if there were any RMW instructions in the code, this wouldn't be
true as the RMW instructions actually do a read before the write operation.

Fabio

--
http://www.piclist.com hint: PICList Posts must start with ONE topic:
[PIC]:,[SX]:,[AVR]: ->uP ONLY! [EE]:,[OT]: ->Other [BUY]:,[AD]: ->Ads


2002\05\22@104944 by Byron A Jeff

face picon face
On Wed, May 22, 2002 at 03:22:04PM +0100, Jon Baker wrote:
{Quote hidden}

Which archive are you searching? Here's a post I wrote on the subject that
was easily found in the jkeyzer archive:

NOTE!!! that the site is passworded. The login and password are 'piclist'.

http://www.infosite.com/~jkeyzer/piclist/2002/Jan/1069.html

{Quote hidden}

The read and write are two separate operations that occurs at different
subclocks. The read happens on the Q1 subclock and the write on the Q4
subclock. So even if the schematic doesn't show the RD and CK tied together
(and it probably won't) RMW operations on a port will exhibit this behavior.
And not only for the port pin that's being modified, but for the whole port.

>
> However, the pic could very easily assert both the RD Port and WR Port
> control lines at the same time in a deliberate attempt to set the output
> latch to the most recent value read from the port pins. I can not find any
> reference to the existence (or not) of this functionality in the datasheet

See above. It doesn't happen simulteaneously. First the read, and then a
separate write later on in the instruction cycle.

> which is why, in the hope that somebody with experience of this could give a
> definitive answer, I posted the original question.

Olin kind of dropped the ball on this one. The behavior of transferring the
state of the input pins to the latches only occurs on a read/modify/write
instruction. Simply reading the port doesn't change the state of the output
latches because no write to the port's output latches occurs. Jon quoted the
relavent section above. A write transfers the current state of the pins to
the output latches, a read by itself does not.


>
> Perhaps if you ever get receive any of the consultants fees with which you
> threaten people who email you directly, you can spend it on getting some
> manners, and if you have any left after that, getting the size of your head
> reduced.

That's a bit harsh. We see so many folks come through here asking questions
without a lick of consultation with the datasheet and/or the archive that
it becomes a natural defense mechanism. It was unclear if you had done so.

Olin is a good, helpful guy. His advise given the information present at the
time was correct. This topic has been hashed to death.

BAJ

--
http://www.piclist.com hint: PICList Posts must start with ONE topic:
[PIC]:,[SX]:,[AVR]: ->uP ONLY! [EE]:,[OT]: ->Other [BUY]:,[AD]: ->Ads


2002\05\22@105551 by Drew Vassallo

picon face
>1) I don't remember seeing the question about whether reading a port
>affects
>the data in the output latches before. If I had, and I had also seen the
>answer, then I would not have asked. If I had not seen the answer I would
>have looked for it in the archives.

It *has* been beaten to death over the course of several years.  Maybe
you've just missed the posts.  Try searching for "RMW" or "R-M-W".

>3) As for searching the manual, I have this quote from the I/O PORTS, PORTA
>section of the 16F877 datasheet (DS30292C) regarding PORTA:

Many of the datasheets fail to describe this problem in its entirety.
You'll have to check around through the various datasheets if you want to
find out exactly which ones DO cover it.

The 16C71 datasheet covers this problem briefly in the I/O Port section.
It's on DS30272A-page 30.

However, to be fair, Microchip does recommend researching the I/O ports
further (from the 16F877 datasheet):

"Additional information on I/O ports may be found in the
PICmicro  Mid-Range Reference Manual, (DS33023)."

--Andrew

_________________________________________________________________
Chat with friends online, try MSN Messenger: http://messenger.msn.com

--
http://www.piclist.com hint: PICList Posts must start with ONE topic:
[PIC]:,[SX]:,[AVR]: ->uP ONLY! [EE]:,[OT]: ->Other [BUY]:,[AD]: ->Ads


2002\05\22@120502 by Jon Baker

flavicon
face
First things first:  Olin, I apologize for the un necessary personal
criticism.

BAJ> Which archive are you searching? Here's a post I wrote on the subject
that
BAJ> was easily found in the jkeyzer archive:
BAJ> http://www.infosite.com/~jkeyzer/piclist/2002/Jan/1069.html

I wasn't asking about RMW operations.

<insult snipped>

BAJ> That's a bit harsh.

Yes. It was. See apology above. I won't go into my bad day excuses.. but be
aware they exist :)

BAJ> We see so many folks come through here asking questions
BAJ> without a lick of consultation with the datasheet and/or the archive
that
BAJ> it becomes a natural defense mechanism. It was unclear if you had done
so.

I know, I see them too, but I thought I had explained my original question
well enough to avoid it being mis interpreted as a r-m-w question.

Drew>It *has* been beaten to death over the course of several years.  Maybe
Drew>you've just missed the posts.  Try searching for "RMW" or "R-M-W".

RMW has been beaten to death. I was refering to whether or not a READ ONLY
operation on a port destroyed the data held in the output latches.

Drew>The 16C71 datasheet covers this problem briefly in the I/O Port
section.
Drew>It's on DS30272A-page 30.
Drew>However, to be fair, Microchip does recommend researching the I/O ports
Drew>further (from the 16F877 datasheet):

Drew>"Additional information on I/O ports may be found in the
Drew>PICmicro  Mid-Range Reference Manual, (DS33023)."

I have just read the IO sections of the data sheet, it does go into RMW
quite nicely including :

"The PORT register is the latch for the data to be output. When the PORT is
read, the device reads the levels present on the I/O pins (not the latch).
This means that care should be taken with read-modify-write commands on the
ports and changing the direction of a pin from an input to an output."

I was assuming that a read only operation would not affect the data in the
port latch- although it doesnt say that specifically- but the last bit "care
should be taken ... changing the direction from an input to an output" just
confuses things further- or do they mean doing a RMW operation and then
changing TRIS, in which case the caution doesnt really apply?

--
Jon Baker

--
http://www.piclist.com hint: PICList Posts must start with ONE topic:
[PIC]:,[SX]:,[AVR]: ->uP ONLY! [EE]:,[OT]: ->Other [BUY]:,[AD]: ->Ads


2002\05\22@123622 by Harold M Hallikainen

picon face
       The output latch is unchanged by writes to the TRIS register. Thus the
comments inserted below.

Harold

On Tue, 21 May 2002 23:44:07 +0100 Jon Baker <jonspamspam_OUTHAYSEED.NET> writes:
> If I ran the following pseudo-code:
>
> TRISB = 0                     // All portb lines output
> PORTB = 0xAA          // Output 0xaa to portb (held in latb)
>
> TRISB = 255           // All portb lines input
> TEMP = PORTB          // Reads state of portb pins
>
> TRISB = 0                     // All portb lines output. They now reflect the 0xaa
written to portb (actually written to latb in the chip)
                               // above.

 temp=portb                    // This will read the state of the portb pins. If the pins
are not heavily loaded, this will be the
                               // 0xaa previously written to latb. If the pins are heavily loaded,
something else may be read back.
                               // If the loading is capacitive, the read back value may be different
from 0xaa right now, but
                               // a few cycles from now would be 0xaa, once the pins can move to
their final voltage.
{Quote hidden}

FCC Rules Online at http://hallikainen.com/FccRules
Lighting control for theatre and television at http://www.dovesystems.com


________________________________________________________________
GET INTERNET ACCESS FROM JUNO!
Juno offers FREE or PREMIUM Internet access for less!
Join Juno today!  For your FREE software, visit:
dl.http://www.juno.com/get/web/.

--
http://www.piclist.com hint: PICList Posts must start with ONE topic:
[PIC]:,[SX]:,[AVR]: ->uP ONLY! [EE]:,[OT]: ->Other [BUY]:,[AD]: ->Ads


2002\05\22@125149 by Drew Vassallo

picon face
>I was assuming that a read only operation would not affect the data in the
>port latch- although it doesnt say that specifically- but the last bit
>"care
>should be taken ... changing the direction from an input to an output" just
>confuses things further- or do they mean doing a RMW operation and then
>changing TRIS, in which case the caution doesnt really apply?

I guess I missed the original question.  But I can give an example of how
this can cause problems:

Pretend you're using passive I2C communication where the SCL and SDA lines
are being pulled up.  You load "0" into the latches for your SDA and SCL
pins.  Now you want to set the SCL line high, so you TRIS the pin to an
INPUT.  Now it's being pulled HIGH, even though your latch is still a "0".
Now you want to set the SCL line low, so you TRIS the pin back to an OUTPUT.
 Everything's fine.

Now, pretend you have an interrupt set and it goes off BETWEEN the two steps
described above (i.e., you're still in an INPUT mode).  Now somewhere in the
ISR, you happen to use a "BCF" on another pin of the same port.  This will
redefine your SCL latch to a "1" because of the RMW operation on the other
pin.  So, you have to "use caution when changing from an input to an output"
because of the possible unknown state of the port latches.  Note that it's
not a "READ" operation, per se, but a "BCF".  A pure READ operation will do
nothing to the port pin values itself, but it WILL redefine the port
latches.

Note that this is just one example of how things can go bad.  But I think
you can draw a parallel to your specific situation, assuming that your
application has any problems at all with these operations.

--Andrew

_________________________________________________________________
MSN Photos is the easiest way to share and print your photos:
http://photos.msn.com/support/worldwide.aspx

--
http://www.piclist.com hint: PICList Posts must start with ONE topic:
[PIC]:,[SX]:,[AVR]: ->uP ONLY! [EE]:,[OT]: ->Other [BUY]:,[AD]: ->Ads


2002\05\22@141708 by Olin Lathrop

face picon face
> I am quite sure Olin is incorrect here. The statement "TEMP = PORTB" would
> almost certainly become "MOVF PORTB,W" and "MOVWF TEMP". The "MOVF"
> instruction will not affect the PORTB latch because it is NOT
> read-modify-write (although MOVF PORTB,F would be).

Yes, Bob is right.  Somehow I was thinking that the mere READ of port B
would also write the value that was read to the port latches, but that is
not true.


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

--
http://www.piclist.com hint: PICList Posts must start with ONE topic:
[PIC]:,[SX]:,[AVR]: ->uP ONLY! [EE]:,[OT]: ->Other [BUY]:,[AD]: ->Ads


2002\05\22@203848 by Byron A Jeff

face picon face
On Wed, May 22, 2002 at 05:02:43PM +0100, Jon Baker wrote:
> First things first:  Olin, I apologize for the un necessary personal
> criticism.
>
> BAJ> Which archive are you searching? Here's a post I wrote on the subject
> that
> BAJ> was easily found in the jkeyzer archive:
> BAJ> http://www.infosite.com/~jkeyzer/piclist/2002/Jan/1069.html
>
> I wasn't asking about RMW operations.

I know. However the post explains the process. From it you can ascertain that
nothing would write the latches, therefore they would have their same value
when the corresponding TRIS bit is set back to an output.

{Quote hidden}

Not just a RMW question. A question where it was unclear how much digging
you had done before.

>
> Drew>It *has* been beaten to death over the course of several years.  Maybe
> Drew>you've just missed the posts.  Try searching for "RMW" or "R-M-W".
>
> RMW has been beaten to death. I was refering to whether or not a READ ONLY
> operation on a port destroyed the data held in the output latches.

The answer is no. A read only has no effect on the output latches.

{Quote hidden}

Actually caution does apply. The Midrange manual has a clarification in
section 9.10.1 (EMPHESIS MINE)
---------------------------------------------------------------
Any instruction which performs a write operation actually does a read followed
by a write operation. The BCF and BSF instructions, for example, read the
register into the CPU, execute the bit operation, and write the result back
to the register. Caution must be used when these instructions are applied to
a port with both inputs and outputs defined. For example, a BSF operation on
bit5 of PORTB will cause all eight bits of PORTB to be read into the CPU. Then
the BSF operation takes place on bit5 and PORTB is written to the output
latches. IF ANOTHER BIT OF PORTB IS USED AS A BI-DIRECTIONAL I/O PIN (E.G.,
BIT0) AND IT IS DEFINED AS AN INPUT AT THIS TIME, THE INPUT SIGNAL PRESENT ON
THE PIN ITSELF WOULD BE READ INTO THE CPU AND REWRITTEN TO THE DATA LATCH OF
THIS PARTICULAR PIN, OVERWRITING THE PREVIOUS CONTENT. aS LONG AS THE PIN
STAYS IN THE INPUT MODE, NO PROBLEM OCCURS. hOWEVER, IF BIT0 IS SWITCHED TO
AN OUTPUT, THE CONTENT OF THE DATA LATCH MAY NOW BE UNKNOWN.
--------------------------------------------------

But again it's a version of RMW. You didn't do that, so you should be safe.
The above passage describes the issues of transisioning from an input to
an output on a port that has had a RMW done on it.

BAJ

--
http://www.piclist.com hint: PICList Posts must start with ONE topic:
[PIC]:,[SX]:,[AVR]: ->uP ONLY! [EE]:,[OT]: ->Other [BUY]:,[AD]: ->Ads


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