There are three possible causes of RMW issues that may affect PICs: a) Due to capacitive loading: One instruction modifies a pin then another instruction reads the pin value and writes it back as a side effect of modifying another pin in the same port. Because of the capacitive loading, the first pin didn't have time to settle to the value set by the first instruction before the second instruction samples its value. Ex.: clrf PORTA . . ; some delay... . bsf PORTA,0 bsf PORTA,1 The 'bsf' instruction reads the entire port, modifies one bit and then writes the entire port back. The first 'bsf' reads the already stable value of PORTA and sets its bit 0. The second 'bsf' reads again the value of PORTA. The bit 0 voltage is raising but didn't reach the level '1' threshold, so it is read still as '0'. Then the instruction writes bit 0 as '0' and bit 1 as '1'. b) Due to a pin being input then changed to output: movlw 0x03 movwf PORTA ; here all bits of the latch of PORTA are initialized to a known value, even the ones that are inputs, because movwf doesn't have issues with RMW. banksel TRISA clrf TRISA ; bits 0 and 1 change to '1' correctly . . . bsf TRISA,1 ; bit 1 is changed to input. Here we assume that it is pulled down externally banksel PORTA bcf PORTA,0 ; we clear bit 0, that is still an output, and it works OK, but bit 1 is read also and as it is an input and pulled low externally, the value written back for bit 1 is '0' banksel TRISA bcf TRISA,1 ; change bit 1 back to output. Some would assume that it would output an '1', but due to RMW it will be a '0'. c) Due to a pin being an output but configured as analog: ; RA0 is configured as output but also as analog and RA1 is a digital output bsf PORTA,0 ; RA0 changes to '1' . . . ; some delay to avoid capacitive RMW . bsf PORTA,1 ; RA1 changes to '1', but RA0 changes to '0' because when the instruction reads the port value, RA0 is read as '0' because as it is configured as analog its digital input circuitry is turned off. Best regards, Isaac =20 Em 24/8/2012 19:48, Tamas Rudnai escreveu: > Actually, it would not be a big deal to detect RMW errors on the emulator= - > it is just checking when the last write happened to the actual port, and = if > X virtual time tick passed, then it is safe again to read that port, > otherwise log it as RMW error on the console. You may even can control th= is > by the simulator settings, so one can increase this minimum tick value fo= r > deeper test (sometimes a nop is inserted in between RMW instructions as a > quick fix and that might not enough in some case, so you can go even > further). For this kind of dummy tests you do not need a real SPICE > simulation... > > Tamas > > > On 24 August 2012 15:36, David Meiklejohn wrote: > >> John Coppens wrote: >>> Hello all... >>> >>> As mentioned in my mail, I submitted the strange behaviour I >>> experienced with mplab x to the Microchip bug list, and got as answer: >>> >>> >>> We believe that this is due to the read-modify-write nature of the bsf >>> instructions. You should keep an image and update the image >>> (...and closed the bug) >>> >>> If I understand the RMW behaviour, then the possible problems are due >>> to either capacitive (or other) loading of the outputs, or having some >>> internal peripheral enabled which could cause the same loading. >>> >>> Is there any way this could explain my problem? I even tried the >>> 'image' method to update port A, and the mplab X simulator _still_ >>> doesn't show any change to the port A output. >> Microchip's reply sounds like a cop-out to me. RMW potentially affects >> actual hardware, in ways that depend on the hardware. A simulator can't >> take that into account (ok, unless you're using something like Proteus w= ith >> a SPICE model of the attached hardware). RMW should not be the explanat= ion >> for what you see in the simulator. >> >> I suspect that Microchip didn't understand what you were getting at (or >> didn't take the time to understand...). >> >> >> Cheers, >> David Meiklejohn >> www.gooligum.com.au >> >> >> -- >> http://www.piclist.com PIC/SX FAQ & list archive >> View/change your membership options at >> http://mailman.mit.edu/mailman/listinfo/piclist >> > > --=20 http://www.piclist.com PIC/SX FAQ & list archive View/change your membership options at http://mailman.mit.edu/mailman/listinfo/piclist .