Hi,
I still think it WAS a RMW write issue but the cause wasn't heavy loading of the output and/or speed as I initially suspected. The cause was, as Steve noticed, the ANSEL register.
A pin configured for analog input will, when read, return '0'. The SEROUT2 statement, doing RMW operations, will read the port, flip a bit and re-write the port. What's happening then is that the port is read and since the RLY-pin is configured as analog it will (always) read '0', the STX pin/bit will then be modified and the port will be re-written - this time with the RLY-bit/pin as 0 because that is what was read.
With ANSEL correctly setup (RLY-bit/pin as digital) the RMW process of the SEROUT2 statement will read the correct state of the RLY-pin so when the port byte is re-written it will keep the '1'-state previously set.
Steves suggestion of using LAT instead of PORT is great, however in this particular case I don't think it would have made any difference because I don't think (I'm not sure though) SEROUT2 actually targets the LAT registers so the result would have been the same anyway. However, for manual 'bit-flipping' using the LAT register would prevent RMW-issues caused by capacitive loading of the pin etc.
(Actually it's not the SEROUT2 statement per se that performs the RMW operation, it's just the way the PIC works internally.)
/Henrik.
Bookmarks