Hi Rob,

Iirc, the 'read_modify_write' (rmw) issue is that you can set a output
pin high, but when you read that same pin, you get the actual status.
This means that if you have a capacitor (or short) on an output pin
and you change that pin from low to high and read it back afterwards,
you might see low. The problem occurs when you interpret this that the
pin should be driven low.

Example:
pin 0 and 1 are low
Step1: set pin0 to high. that is: read port, set bit 0 and write it
back. okay so far.
Step2: set pin 1 to high too. Assume that pin0 is rising but not high
enough. So you read the port, where pin0 reads 0. You set bit1 and
then write back. This means from now on, the port will drive pin1 high
and pin0 low.

This is why the shadow register is introduced. It contains the value
that all pins of a port should be driven to when they are on output.
It is important that this register is never 'contaminated' with values
acually read from the port (and it is also important that the shadow
register is updated by all changes in desired port values - bit,
nibble and byte).

So I think Stef is right: for driving outputs, you should use the
shadow register and there is no harm done when you also use the high
byte of the shadow register while updating the lower one. The shadow
register contains the values that are set by the program.
I think your suggestion intruduces the rmw issue for the nibble you do
not change.

Joep

PS I do not know how likely it is you run into the rmw issue in real
life. The only tho situations I can think of are quick changes &
capacitor load and output pins that are also driven (not good
practice, but possible).

PPS I saw this code:
var volatile bit    LATB_LATB5           shared at LATB : 5
var volatile bit pin_B5 shared at LATB : 5
procedure pin_B5'put(bit in x at LATB : 5) is
   pragma inline
end procedure

Does this mean that LATB is actually an output-only register so there
is no such thing as an RMW problem on 18f chips?


2009/3/12 Rob Hamerling <[email protected]>:
>
>
> Albert (and others)
>
> While thinking about the LAT/PORT issue for the 18Fs I had a look at the
> shadowing for the lower ranges. Take for example:
>
>> procedure PORTA_high'put(byte in x) is
>>    _PORTA_shadow = (_PORTA_shadow & 0x0F) | (x << 4)
>>    _PORTA_flush()
>> end procedure
>> function PORTA_high'get() return byte is
>>    return (PORTA >> 4)
>> end function
>
> Shouldn't the second line better be
>
>  _PORTA_shadow = (PORTA & 0x0F) | (x << 4)
>
> because the flush() writes the whole register, while only the higher
> part should really be changed.
>
> BTW: The current construction in from Stef, so I have my doubts that I'm
> right!
>
> Regards, Rob.
>
> --
> Rob Hamerling, Vianen, NL (http://www.robh.nl/)
>
> >
>

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"jallib" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/jallib?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to