Searching \ for 'PORTA problem' in subject line. ()
Make payments with PayPal - it's fast, free and secure! Help us get a faster server
FAQ page: techref.massmind.org/techref/ios.htm?key=port
Search entire site for: 'PORTA problem'.

Truncated match.
PICList Thread
'PORTA problem'
1998\05\08@051121 by nanthan Paramananthan

flavicon
face
Hi,

I've had lot more trouble with PORTA of PIC16C73A/JW. I used RA4:RA0 of
PORTA as test out puts and RA5 as a jumper pin which is pull-up to 5V via
resistor. When I set 1 of the bits or clear one of the bits (bsf, bcf) all
other bits which were set are now cleared!  I couldn't figure out why. Then
I read through the part which says every write to i/o port is read modify
write operation. However, this will affect only if I use the pins as both
inputs and outputs but not when they are fixed as either input or output.

The solution was to use a temporary variable to and set or clear bits in it
and write the whole register back to port and use the register as a copy of
port of outputs. Problem with with this method is instead of one
instruction, we need three instruction for every single bsf, bcf operation
on a port.

    bsf          PORTA,3

becomes:

    bsf         TEMPA,3
    movf      TEMPA,W
    movwf    PORTA


The other problem is I used RA5 as an input connected to a jumper pin which
is pulled up to 5V via resistor. Only when we insert the jumper pin, RA5
will be pulled to GROUND.

     btfss    PORTA,5
     goto    PROGRAM
     ...................
     rest of the code
     .............................

However, the program always went into the PROGRAM mode even though I checked
the voltage at the pin and found it to be 5V. I could not understand why.  I
tried with different PIC16C73A/JW and even older PIC16C73/JW.

Finally I tried with RA4. It worked!!!

Could any body explain me the reasons for the peculiar behaviour, please.

Thanks
Saba

1998\05\08@055558 by Marco DI LEO

flavicon
face
Sabananthan Paramananthan wrote:
>
> Hi,
>
> I've had lot more trouble with PORTA of PIC16C73A/JW. I used RA4:RA0 of
> PORTA as test out puts and RA5 as a jumper pin which is pull-up to 5V via
> resistor. When I set 1 of the bits or clear one of the bits (bsf, bcf) all
> other bits which were set are now cleared!  I couldn't figure out why. Then
> I read through the part which says every write to i/o port is read modify
> write operation. However, this will affect only if I use the pins as both
> inputs and outputs but not when they are fixed as either input or output.

Not true, the problem you have noticed is also if the port pin are all
outputs and you don't change direction. You are correct to say that
write to port is actually read/modify/write but the read part gets the
value _directly_ form the output pins. So if your program drives bit 3
high but the corresponding pin is tied to ground the read operation gets
a '0' for that bit. When the PIC writes back the modifyed value to the
port the bit 3 is written as '0'.

{Quote hidden}

Yes, this is a solution if you have this kind of problem.

Ciao
 Marco

----
Marco DI LEO                  email: spam_OUTm.dileoTakeThisOuTspamsistinf.it
Sistemi Informativi S.p.A.    tel:   +39 6 50292 300
V. Elio Vittorini, 129        fax:   +39 6 5015991
I-00144 Roma
Italy

1998\05\08@083245 by Sean Breheny

face picon face
At 11:53 AM 5/8/98 +0200, you wrote:
>
>Not true, the problem you have noticed is also if the port pin are all
>outputs and you don't change direction. You are correct to say that
>write to port is actually read/modify/write but the read part gets the
>value _directly_ form the output pins. So if your program drives bit 3
>high but the corresponding pin is tied to ground the read operation gets
>a '0' for that bit. When the PIC writes back the modifyed value to the
>port the bit 3 is written as '0'.

I have often heard this mentioned as a caveat about the PIC, but why should
one expect the PIC to even work at all with one of its pins shorted to low?
Under this condition, the PIC would probably be outputting full IO pin
current, maybe over-spec. I don't see why one wouldn't just check their
hardware for shorts and other mistakes, instead of using this register
shadowing technique in a final design.


Sean


+--------------------------------+
| Sean Breheny                   |
| Amateur Radio Callsign: KA3YXM |
| Electrical Engineering Student |
+--------------------------------+
Save lives, please look at
http://www.all.org

Personal page: http://www.people.cornell.edu/pages/shb7
.....shb7KILLspamspam@spam@cornell.edu
Phone(USA): (607) 253-0315

1998\05\08@090126 by Keith Howell

flavicon
face
Sean Breheny wrote:
>
> >So if your program drives bit 3 high but the corresponding pin is
> >tied to ground the read operation gets a '0' for that bit.
> >When the PIC writes back the modified value to the
> >port the bit 3 is written as '0'.
>
> I don't see why one wouldn't just check their hardware for shorts
> and other mistakes, instead of using this register
> shadowing technique in a final design.
>
> Sean

I think he meant the pin being pulled low either by say a link or
a logic gate, and the pin being used as an input. i.e. it is tristated.
This does not involve shorts.
Register shadowing is needed, because what you read from mixed In/Out
ports is partly incoming data, and thus not the byte you last wrote to
the outgoing data buffer. This can cause screw ups when you re-enable
an input pin as an output pin (for example, as part of a bidirectional
data path).

1998\05\08@103011 by Sean Breheny

face picon face
At 01:56 PM 5/8/98 +0100, you wrote:
>I think he meant the pin being pulled low either by say a link or
>a logic gate, and the pin being used as an input. i.e. it is tristated.
>This does not involve shorts.
>Register shadowing is needed, because what you read from mixed In/Out
>ports is partly incoming data, and thus not the byte you last wrote to
>the outgoing data buffer. This can cause screw ups when you re-enable
>an input pin as an output pin (for example, as part of a bidirectional
>data path).
>

Well, I understand and agree with you that this is necessary with
bi-directional ports, but the whole point of that last message to which I
responded was that it was not only necessary in the bi-directional case,
but even when a pin remained as just an output! It was that assertion that
I was questioning.

Sean


+--------------------------------+
| Sean Breheny                   |
| Amateur Radio Callsign: KA3YXM |
| Electrical Engineering Student |
+--------------------------------+
Save lives, please look at
http://www.all.org

Personal page: http://www.people.cornell.edu/pages/shb7
shb7spamKILLspamcornell.edu
Phone(USA): (607) 253-0315

1998\05\08@112226 by Mike Keitz

picon face
On Fri, 8 May 1998 10:10:01 +0100 Sabananthan Paramananthan
<.....sabananthanKILLspamspam.....dial.pipex.com> writes:
>Hi,
>
>I've had lot more trouble with PORTA of PIC16C73A/JW. I used RA4:RA0
>of
>PORTA as test out puts and RA5 as a jumper pin which is pull-up to 5V
>via
>resistor. When I set 1 of the bits or clear one of the bits (bsf, bcf)
>all
>other bits which were set are now cleared!

Be sure to configure these pins for digital service with the ADCON
register.  When set for analog, they will still function as digital
outputs by clearing the TRIS bits, but the PORTA register will always
read zero on these pins.  Thus the bsf/bcf operations will misbehave as
you describe.

It is still good practice to do only writes to the port by saving an
image in RAM as you have.  Heavy DC or capacitive loads on the port pins
can cause them to read improperly.  If your hardware allows, the extra
instructions to copy RAM to port can be minimized by not updating the
port after changing each bit.  For example, turning LEDs on and off can
wait until the top of the main loop.  At that time, the RAM image would
be copied to the port, changing all bits at once.


_____________________________________________________________________
You don't need to buy Internet access to use free Internet e-mail.
Get completely free e-mail from Juno at http://www.juno.com
Or call Juno at (800) 654-JUNO [654-5866]

1998\05\08@112434 by Marco DI LEO

flavicon
face
Sean Breheny wrote:
> Well, I understand and agree with you that this is necessary with
> bi-directional ports, but the whole point of that last message to which I
> responded was that it was not only necessary in the bi-directional case,
> but even when a pin remained as just an output! It was that assertion that
> I was questioning.

I agree with you that the original described behavior is (probably) a
symptom of an electrical problem. I had something similar when I
mistakenly connect the katode of a protection diodes to Vss instead Vdd.
This sort of connection didn't hurt the PIC (they are quite resistant: I
put them backward from time to time) but I am sure that reading the pin
should give a '0' and not the value written on the port register (this
is less dangerous if you use the OC pin, of course).

Thinking again on the problem I recall that if you set the I/O pin for
analog conversion (using ADCON1 register) you can make them digital
output (just set the TRIS bits accordingly) but if you read them, you
always get '0' (check the 16C73 data sheet 'I/O ports' and 'A/D
converter module'). Could this be the case? If so, check ADCON1 or, if
you need A/D, use the shadow register. Otherwise double check the
wiring.

Ciao
 Marco

----
Marco DI LEO                  email: EraseMEm.dileospam_OUTspamTakeThisOuTsistinf.it
Sistemi Informativi S.p.A.    tel:   +39 6 50292 300
V. Elio Vittorini, 129        fax:   +39 6 5015991
I-00144 Roma
Italy

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