piclist 2003\02\23\042330a >
Thread: Pin won't turn off properly
face BY : Russell McMahon email (remove spam text)

> >With a correctly designed circuit, the BCF/BSF instructions are a
> >valid way to code. I'd rather code it as "BSF PORTA,LED" than use
> >a shadow register and do:
> >BSF             SHADOW,LED
> >MOVF            SHADOW,F
> You know, your choice of symbolic name for the bit in question really
detracts from your argument.
> If I wanted to make the point Russell was making, I wouldn't have picked
the direct-base-drive
> transistor example.  I'd have picked directly driving an LED.  And that's
exactly the sort of static
> load that will give you static RMW problems.  Try that with two or more
LEDs on a port, and you may
> well find that trying to turn one of them off or on affects the other.

The transistor base example was intended to be an extreme case in order to
demonstrate the problem very clearly. ie the base-emitter junction clamps at
about 0.6v so obviously it isn't going to be able to get up to near "usual"
logic levels. Both transistor base drive and LED drive can of course be
designed so that they will work properly. When things work as expected.

The overwhelmingly important point that I was hoping to make is that,

       the use of a shadow register means that your software is not at
       the mercy of your hardware.

Conversely, if you rely on RMW instructions and they don't work because of a
hardware problem, regardless of WHY the problem occurred,  then your
program's operation is wrested from your control and placed at the mercy of
whatever it is that is happening that you don't expect. This might be (as I
described in my FET drive example) a failed component, or an out of spec
component or a hardware change made without enough thought of the effect on
software or (importantly) by someone who doesn't know what the software is

Murphy and reality say that YMWV.

Use of a shadow register gives you added certainty and costs little.
Sometimes performance issues make it an unviable solution.
In all other cases its use is prudent.
However, as they used to say when I rode motorcyles long ago, "If you have a
$10 head then by all means buy a $10 helmet." if you're head, or the correct
operation of your program is valuable to you, its prudent to take
appropriate precautions.

           Russell McMahon

> >The BSF saves two instructions in this case. That may be important
> >in busy code running at less than blistering speeds. I've written heaps
> >of code that uses BCF/BSF and has/will always work just fine but I
> >also have written code that uses shadow registers when required.
> This looks to me like a classic case of laziness masquerading as premature
> Another one, which has come up here far too often, is trying to do a table
lookup without checking
> to see if a 256-byte boundary has been crossed.  I have a hard time
imagining how writing the extra
> *two* instructions needed to do this properly can be harder than trying to
keep your tables
> boundary-aligned.
> --
> http://www.piclist.com hint: The PICList is archived three different
> ways.  See http://www.piclist.com/#archives for details.

http://www.piclist.com hint: The PICList is archived three different
ways.  See http://www.piclist.com/#archives for details.
<035f01c2db1a$cc9bf240$2301a8c0@Paradise> 7bit

See also: www.piclist.com/techref/ubicom/devices.htm?key=sx
Reply You must be a member of the piclist mailing list (not only a www.piclist.com member) to post to the piclist. This form requires JavaScript and a browser/email client that can handle form mailto: posts.
Subject (change) Pin won't turn off properly

month overview.

new search...