Searching \ for '[PIC] Open drain output from conventional output p' in subject line. ()
Make payments with PayPal - it's fast, free and secure! Help us get a faster server
FAQ page: massmind.org/techref/microchip/ios.htm?key=output
Search entire site for: 'Open drain output from conventional output p'.

Exact match. Not showing close matches.
PICList Thread
'[PIC] Open drain output from conventional output p'
2006\11\17@091219 by Chris McSweeny

picon face
In my circuit I need a couple of open drain outputs (for varying the
resistance to ground of a certain point by connecting resistors). However
the PIC I'm using (12f675) has no open drain outputs, so I was wondering
whether it would be possible to simulate this by switching the pin between a
high impedance input and a low output? Are there any flaws I've missed in
this idea? (yes I could use external FETs, but given the reasons for using
an 8-pin PIC, I'm also trying to keep component count down).

2006\11\17@092948 by Paul James E.

picon face


Yes, this works well.   It is done every day to do that very thing.

                                                Jim



> In my circuit I need a couple of open drain outputs (for varying the
> resistance to ground of a certain point by connecting resistors).
> However the PIC I'm using (12f675) has no open drain outputs, so I was
> wondering whether it would be possible to simulate this by switching
> the pin between a high impedance input and a low output? Are there any
> flaws I've missed in this idea? (yes I could use external FETs, but
> given the reasons for using an 8-pin PIC, I'm also trying to keep
> component count down).
> --

2006\11\17@094201 by Kevin Timmerman

flavicon
face
Yes, you can do that. Be aware that any Read-Modify-Write operation
on the port - such as bcf & bsf - will update the output latch. So
you must make sure the output latch for that pin is set to 0 before
setting the TRIS for that pin to 0.


At 09:12 AM 11/17/2006, you wrote:
>In my circuit I need a couple of open drain outputs (for varying the
>resistance to ground of a certain point by connecting resistors). However
>the PIC I'm using (12f675) has no open drain outputs, so I was wondering
>whether it would be possible to simulate this by switching the pin between a
>high impedance input and a low output? Are there any flaws I've missed in
>this idea? (yes I could use external FETs, but given the reasons for using
>an 8-pin PIC, I'm also trying to keep component count down).

2006\11\17@094312 by Alan B. Pearce

face picon face
>so I was wondering whether it would be possible to simulate this by
>switching the pin between a high impedance input and a low output?

This is a perfectly valid way to do it.

2006\11\17@095203 by Gerhard Fiedler
picon face
Chris McSweeny wrote:

> In my circuit I need a couple of open drain outputs (for varying the
> resistance to ground of a certain point by connecting resistors).
> However the PIC I'm using (12f675) has no open drain outputs, so I was
> wondering whether it would be possible to simulate this by switching the
> pin between a high impedance input and a low output? Are there any flaws
> I've missed in this idea?

I don't think you'll have a problem. As you can see in the circuits of the
port pins, a normal port differs from the open drain port basically in the
added p-channel FET to Vdd. As long as you don't activate this FET (by
setting the port to "high"), it should behave in the same way as the open
drain output.

I didn't check your PIC's data sheet, but one difference may be that the
open drain output can handle higher voltages. As long as you stay below
Vdd, this shouldn't make any difference, though.

Gerhard

2006\11\17@095554 by Mike Harrison

flavicon
face
On Fri, 17 Nov 2006 14:12:13 +0000, you wrote:

>In my circuit I need a couple of open drain outputs (for varying the
>resistance to ground of a certain point by connecting resistors). However
>the PIC I'm using (12f675) has no open drain outputs, so I was wondering
>whether it would be possible to simulate this by switching the pin between a
>high impedance input and a low output? Are there any flaws I've missed in
>this idea? (yes I could use external FETs, but given the reasons for using
>an 8-pin PIC, I'm also trying to keep component count down).

Yes - this will work fine, the only proviso being that the pin can't swing above Vdd

2006\11\17@100053 by Wouter van Ooijen

face picon face
> However
> the PIC I'm using (12f675) has no open drain outputs, so I
> was wondering
> whether it would be possible to simulate this by switching
> the pin between a
> high impedance input and a low output? Are there any flaws
> I've missed in
> this idea? (yes I could use external FETs, but given the
> reasons for using
> an 8-pin PIC, I'm also trying to keep component count down).

This is standard practice, used for instance for I2C. Keep in mind that
the voltage on the 'open drain' output must not be higher than your
PIC's Vdd.

Wouter van Ooijen

-- -------------------------------------------
Van Ooijen Technische Informatica: http://www.voti.nl
consultancy, development, PICmicro products
docent Hogeschool van Utrecht: http://www.voti.nl/hvu


2006\11\17@103416 by Chris McSweeny

picon face
Thanks for the reminder - an easy thing to forget (and to the others for
confirming it's a valid thing to do). 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, but with a 12f675 where they
are undefined I should make sure by doing a write first. Does a write
actually force the data latches in this case, so I simply need to do bcf on
GPIO immediately before doing a bcf on TRIS, and that will override any
input value read?

On 11/17/06, Kevin Timmerman <spam_OUTlistsTakeThisOuTspampcmx.net> wrote:
{Quote hidden}

> -

2006\11\17@104202 by Chris McSweeny

picon face
Actually having done another search, I've realised all the info I needed was
already available (just need to search for the right terms), and that bcf on
GPIO is generally a bad thing to do anyway! Sorry for being such a newbie
(well actually I've been working with PICs for years, but not really doing
anything very complicated).

On 11/17/06, Chris McSweeny <.....cpmcsweenyKILLspamspam@spam@gmail.com> wrote:
{Quote hidden}

2006\11\17@120044 by Jan-Erik Söderholm

face picon face
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äs the same.

Jan-Erik.

2006\11\17@125440 by Chris McSweeny

picon face
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öderholm <.....jan-erik.soderholmKILLspamspam.....telia.com> wrote:
{Quote hidden}

>

2006\11\17@134250 by Jan-Erik Söderholm

face picon face
Chris McSweeny wrote :

> as I can just bo a bcf followed by a movlw, movf TRIS
> to switch the pin which is OC

Or simply do :

bcf gpio, the-pin
bcf trisio, the-pin

Note that there is *no* RMW issue with the TRIS register !

> (and investigation shows the pull-up is only to ~0.2V anyway!)

Hm, is there anything else pulling the "line" low ?
Normaly the pullup should keep the line "idle"
at close to the supply voltage (5 V or whatever).

Jan-Erik.

2006\11\17@135725 by peter green

flavicon
face

> So the solution ot to always set pin-1 "low" right before
> setting tris-1 as an output.
alternatively always do your set/clears on a variable and then copy the whole byte to the register.


2006\11\17@140420 by Harold Hallikainen

face
flavicon
face
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


{Quote hidden}

>> -

2006\11\17@141613 by Orin Eman

picon face
On 11/17/06, peter green <plugwashspamspam_OUTp10link.net> wrote:
>
> > So the solution ot to always set pin-1 "low" right before
> > setting tris-1 as an output.
> alternatively always do your set/clears on a variable and then copy the whole byte to the register.

...but be careful of race conditions if you do it that way and change
the variable in an interrupt routine as well.

It's also a useful technique to avoid reads on a port when you are
using the bit changed interrupt.

Orin.

2006\11\17@143032 by Chris McSweeny

picon face
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 <@spam@haroldKILLspamspamhallikainen.org> wrote:
{Quote hidden}

2006\11\17@144540 by peter green

flavicon
face

> I really think the appropriate port bits can be set low once, during
> initialization using a movwf.
that depends on what your app is doing with the rest of the port

> 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.
that is one situation in which it occours yes

the problem that is relavent to this discussion comes when you are using some outputs on a port as open collector ans some as normal outputs.

lets say there is a normal output on A1 and a pin being driven as open collector by use of tris on A0 which is pulled high

#init, all of port A as an output driving low
CLRF PORTA
CLRF TRISA

#make A0 an input allowing it to float high
BSF TRISA,0

#make A1 high,
#unfortunately due to RMW this also makes bit 0 of PORTA high
BSF PORTA,1

#make A0 an output again, we throught we would be making
#it drive low but in fact we end up making it drive high
BSF TRISA,0

of course if we used LATA rather than PORTA this code would be fine but unfortunately only the 18 series have LAT.


2006\11\17@160631 by Harold Hallikainen

face
flavicon
face

{Quote hidden}

I agree completely! Another way around this is to keep a mirror of the
PORT in RAM. Do the bsf and bcf on the mirror, then copy it to the port.

Harold

--
FCC Rules Updated Daily at http://www.hallikainen.com - Advertising
opportunities available!

2006\11\17@170415 by Jan-Erik Söderholm

face picon face
Harold Hallikainen wrote :

> I really think the appropriate port bits can be set low once, during
> initialization using a movwf.

Not if you're modifing *other* pins while the OC pin is Hi-Z.
(Just as I wrote...)

> Then you can do bsf and bcf TRIS all you want.

Correct.

>The read/modify/write problem is only a problem when dealing
> with a PORT,...

Or (as with the 12F's) the GPIO register.

Jan-Erik.

2006\11\17@171007 by Jan-Erik Söderholm

face picon face
Chris McSweeny wrote :

> 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.

No no no, that's not *generaly* so. It depends on what you "do"
with the other pins on GPIO.

I thought my description of the case where RMW will bite you
was clear enough.

And there is *no* difference between 12F629/675/683 in this case
(besides of some default, but...)

Or *any* other PIC16 or PIC18 (as long as we are talking about
the PORTx registers).

> 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.

Depends on your timing requirements. I just thought you where changing
*one* bit in TRISIO, and thought there was no need to mess with W in that
case.

> 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).

OK, I though it was a "normal" pullup...

Jan-Erik.

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