Searching \ for '[PIC]: incf PORTB,F a bad idea ?' 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: 'incf PORTB,F a bad idea ?'.

Exact match. Not showing close matches.
PICList Thread
'[PIC]: incf PORTB,F a bad idea ?'
2002\01\09@104547 by Peter Onion

flavicon
face
I've seen several postings that say that read-modify-write instructions on IO
ports is a bad idea.

Is this only the case when the TRIS bits are a mixture of inputs and outputs ?
I've been using "incf PORT[BC},F" and "addwf PORT[BC],F instructions on ports
with DACs connected to control the position of the dot on a scope screen and I
havn't seen any problems.....

Peter.

----------------------------------
E-Mail: Peter Onion <spam_OUTponionTakeThisOuTspamsrd.bt.co.uk>
Date: 09-Jan-02
Time: 15:30:07

This message was sent by XFMail
----------------------------------

--
http://www.piclist.com hint: The PICList is archived three different
ways.  See http://www.piclist.com/#archives for details.


2002\01\09@110408 by Robert Rolf

picon face
That depends on whether you're using PORTB 'interrupt on change'.
ALL PIC I/O instructions are R/M/W (look at the tech doc on the instruction set).
Moves & clears just throw away the read data.

Peter Onion wrote:
{Quote hidden}

--
http://www.piclist.com hint: The PICList is archived three different
ways.  See http://www.piclist.com/#archives for details.


2002\01\09@111419 by Peter Onion

flavicon
face
On 09-Jan-02 Robert Rolf wrote:
> That depends on whether you're using PORTB 'interrupt on change'.

Oh No !!  I wasted a lot of time trying to use "PORTB interrupt on change"
a few weeks ago....  Looks like its only good for waking up a sleeping PIC.

> ALL PIC I/O instructions are R/M/W (look at the tech doc on the instruction
> set).
> Moves & clears just throw away the read data.

Yes I understand that, which is why I am slightly unsure as to when it
is/isn't safe to use real R/M/W instructions like "incf  PORTC,F"

Peter.


----------------------------------
E-Mail: Peter Onion <.....ponionKILLspamspam@spam@srd.bt.co.uk>
Date: 09-Jan-02
Time: 16:14:40

This message was sent by XFMail
----------------------------------

--
http://www.piclist.com hint: The PICList is archived three different
ways.  See http://www.piclist.com/#archives for details.


2002\01\09@111854 by Shawn Yates

flavicon
face
As long as the things connected to the ports are not pulling the pins high
or low then it should work ok.  Some of the biggest problems come in with
pins that are open collector type outputs.



{Original Message removed}

2002\01\09@114032 by Alan B. Pearce

face picon face
>Yes I understand that, which is why I am slightly unsure as to when it
>is/isn't safe to use real R/M/W instructions like "incf  PORTC,F"

You may be all right and you may not. The problem depends on the load the
port is connected to.

If you have a transistor without a base protection resistor, to drive a high
current load, the read part of the instruction will detect a 0, and rewrite
it as a 0 if the instruction did not modify that bit. This applies to any
load on the port that may hold the output down at a 0 level during the read
part of the cycle.

The second part of the problem occurs when driving a load that has enough
capacitance associated with it to form a significantly long time constant at
the fastest speed you access the port. This could be due to the input
capacitance of a power FET, or wiring to some remote part of the hardware.
This is usually only a problem if you use consecutive instructions to do BSF
on separate bits of the port, for example. Imagine that you have set bit 1
of the port, and this pin has a high capacitance on it, so it takes a
significant time for the voltage on the output pin to reach a '1' state. The
next instruction does a BSF on bit 2, but this is a R/M/W instruction so it
reads bit 1, and finds it is not yet at a '1' state because of the rise time
due to the capacitance on the pin load, so reads it as a '0'. It then gets
written back as a '0' as the whole port is written, not just the bit being
modified. For this reason it is generally recommended to have at least one
instruction between consecutive port writes, or between a write, and a read
that uses modified bits.

As for the interrupt on port B change, this is another problem again, in
that others have shown that even a write (without a read) to a port is
actually executed as a read/modify/write operation. This upsets the input
bits on port B because the read portion of the instruction modifies the
shadow register where the previous state of the port is held, to do the
compare that finds if it has been changed. This write can then remove the
interrupt state, so it gets missed. For a better explanation, and a code
example that illustrates the problem search the PICList archives.

--
http://www.piclist.com hint: The PICList is archived three different
ways.  See http://www.piclist.com/#archives for details.


2002\01\09@115046 by Peter Onion

flavicon
face
On 09-Jan-02 Alan B. Pearce wrote:
>>Yes I understand that, which is why I am slightly unsure as to when it
>>is/isn't safe to use real R/M/W instructions like "incf  PORTC,F"
>
> You may be all right and you may not. The problem depends on the load the
> port is connected to.

[SNIP of R/M/W explanation]

Alan,

Thanks for that detailed description.  I understand the issues now :-)

[PORTB interrupt on change stuff SNIPPED]

Yes, I found useful stuff in the archive AFTER I've spent a couple of days
trying to get it to work :-(

Peter.


----------------------------------
E-Mail: Peter Onion <ponionspamKILLspamsrd.bt.co.uk>
Date: 09-Jan-02
Time: 16:52:54

This message was sent by XFMail
----------------------------------

--
http://www.piclist.com hint: The PICList is archived three different
ways.  See http://www.piclist.com/#archives for details.


2002\01\09@142548 by Lawrence Lile

flavicon
face
Unless you are trying to do something very fast, I would use a mirror byte
like this,

incf mirrorB, f
movf mirror, w
movwf portB

I pretty much always use a mirror byte when operating on PIC ports, unless I
am really strapped for resources or need to change the port really fast.  I
believe the above code is immune to the read-modify-write "feature" (aka
BUG).  I have seen the RMW bug a couple of times, and found it to be
intermittent in some cases, a scary situation.

--Lawrence Lile


{Original Message removed}

2002\01\10@024249 by Vasile Surducan

flavicon
face
On Wed, 9 Jan 2002, Alan B. Pearce wrote:

>
> If you have a transistor without a base protection resistor, to drive a high
> current load, the read part of the instruction will detect a 0, and rewrite
> it as a 0 if the instruction did not modify that bit. This applies to any
> load on the port that may hold the output down at a 0 level during the read
> part of the cycle.
>
 I'm just curious, have you used a bipolar transistor driven by a pic pin
without any serial resistor ( just internal pic limited output current ).
If yes, why ?

regards, Vasile

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


2002\01\10@045226 by Peter Onion

flavicon
face
On 09-Jan-02 Lawrence Lile wrote:
> Unless you are trying to do something very fast, I would use a mirror byte
> like this,
>
> incf mirrorB, f
> movf mirror, w
> movwf portB

I'm drawing lines and vectors in real time on a scope using 8bit DACs and
driving the X,Y and Z inputs.  So minimum cycle count is important when using
lowish frequency xtals.  I'm currently using 3.2768Mhz Xtal as I need a 100Hz
time base for frequency counting purposes.

Peter.

----------------------------------
E-Mail: Peter Onion <EraseMEponionspam_OUTspamTakeThisOuTsrd.bt.co.uk>
Date: 10-Jan-02
Time: 09:47:36

This message was sent by XFMail
----------------------------------

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


2002\01\10@052012 by Alan B. Pearce

face picon face
>  I'm just curious, have you used a bipolar transistor driven by a pic pin
>without any serial resistor ( just internal pic limited output current ).
>If yes, why ?

No, I was using that as an example of something that may stop the voltage on
the pin going high enough to be sensed as a '1' state. But I might do it
with a Darlington transistor and a small series resistor if wanting to drive
a lamp or relay. This may still be enough to stop the pin voltage going high
enough to be detected as a '1' on a R/M/W instruction.

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


2002\01\11@051947 by Andrei B.

picon face
--- "Alan B. Pearce" <KILLspamA.B.PearceKILLspamspamRL.AC.UK> wrote:

Although this will increase the cost and many may not like it, but
here's the idea:
Please tell me if in your opinion these will work.

> If you have a transistor without a base protection resistor, to drive
> a high
> current load, the read part of the instruction will detect a 0, and
> rewrite
> it as a 0 if the instruction did not modify that bit. This applies to
> any
> load on the port that may hold the output down at a 0 level during
> the read
> part of the cycle.

Add a buffer between the PIC port and the load  : an inverting or non
inverting buffer/gate. AFAIK there are some high current capable
buffers in CMOS technology for such interfacing and they will take the
burden of supplying adequate drive for the transistor.

{Quote hidden}

An idea with be to use a D latch on the pins that are sensitive that
would latch data on the falling edge of the clock during the Q1 period
only.
This is the only moment when one can sync data with the clock and not
affect a read or write in progress.
Additional circuitry is required to separate this falling edge though.

Please tell me if it makes sense.


=====
ing. Andrei Boros
Centrul pt. Tehnologia Informatiei
Societatea Romana de Radiodifuziune

__________________________________________________
Do You Yahoo!?
Send FREE video emails in Yahoo! Mail!
http://promo.yahoo.com/videomail/

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


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