Thanks for clarifying that. So as I originally suggested, with a 12f683 I can rely on the port latches being initialised to low and simply set the TRIS as appropriate. Jan - when I was suggesting doing a movlw, movwf TRIS, that was to switch one pin to low and another pin back to OC at the same time, though I could presumably just as well do bcf, bsf on the appropriate bits. I've not got a good idea what's going on the other end of the resistor - it is a current setting resistor in a boost constant current regulator. I guess thinking about it, it is more likely to be switched with a very low duty cycle when I'm measuring rather than a fixed low voltage - I shan't be relying on the value when it's switched anyway (though actually now slightly concerned it may go above VDD). On 11/17/06, Harold Hallikainen wrote: > > I really think the appropriate port bits can be set low once, during > initialization using a movwf. Then you can do bsf and bcf TRIS all you > want. The read/modify/write problem is only a problem when dealing with a > PORT, and is due to external loading keeping a pin from moving immediately > after a write. The TRIS register does not have this problem, so RMW on > TRIS all you want. The 18 series gets around this problem by having a > separate LATCH register for each port. When you read the LATCH, it will > read what you last wrote to it, no matter what state the actual pin is. > > Harold > > > > I was thinking more of the initial case on power up - though in fact I > > probably want to have them OC at that point anyway so it's not an issue. > > I've realised the problem with RMW cycles now anyway! I'll have multiple > > OC > > pins, but only want to set one low at a time, so it shouldn't be a > > problem, > > as I can just bo a bcf followed by a movlw, movf TRIS to switch the pin > > which is OC (and investigation shows the pull-up is only to ~0.2V > anyway!) > > > > On 11/17/06, Jan-Erik S=F6derholm wrote: > >> > >> Chris McSweeny wrote : > >> > I presume that if I use a 12f683 where the latches are > >> > set to low be default according to the datasheet, I will be > >> > safe in simply switching from input to output,... > >> > >> Not at all. Besides of never trusting "defaults", > >> the problem is this : > >> > >> Say you want pin-1 to be OC with an external pullup. > >> > >> You set pin-1 "low" and then "toggle" tris-1. > >> All is fine so far, if there wasn't any other pins used ! > >> > >> Now say you also have another pin-2 that is an output. > >> > >> What will happen is that when tris-1 is "input" the pin-1 > >> will be pulled high by the external pullup. As expected > >> and by design when using an "open collector bus". > >> > >> Now if you bcf/bsf to pin-2, you have an R-M-W operation. > >> The whole GPIO will be read (incl pin-1 that now will be > >> read as "high"), pin-2 is set according to the bcf/bsf and > >> finaly the whole GPIO is written back. This will now set > >> pin-1 "high" !!! > >> > >> So the solution ot to always set pin-1 "low" right before > >> setting tris-1 as an output. > >> > >> This gets a little more complicated if you have multiple > >> OC pins with external pullup's, but in general it=E4s the same. > >> > >> Jan-Erik. > >> > >> > >> -- > >> http://www.piclist.com PIC/SX FAQ & list archive > >> View/change your membership options at > >> http://mailman.mit.edu/mailman/listinfo/piclist > >> > > -- > > http://www.piclist.com PIC/SX FAQ & list archive > > View/change your membership options at > > http://mailman.mit.edu/mailman/listinfo/piclist > > > > > -- > FCC Rules Updated Daily at http://www.hallikainen.com - Advertising > opportunities available! > -- > http://www.piclist.com PIC/SX FAQ & list archive > View/change your membership options at > http://mailman.mit.edu/mailman/listinfo/piclist > -- = http://www.piclist.com PIC/SX FAQ & list archive View/change your membership options at http://mailman.mit.edu/mailman/listinfo/piclist