Source or Sink, Part 2 - the triac circuit
MJHanagan
Posts: 189
Hi everyone - I need a little advice on how to design some circuitry. Attached below is a schematic of a triac control circuit. I want to use P8 of the Propeller to power the LED in the MOC3012 (need about 5 mA of current to trigger MOC3012 and another 5-10 mA for the external LED). I also want to be able to manually activate the triac via a switch (SW1 in the circuit). My concern is when a Prop pin is set as an output it will have two states: (1) high - sourcing, or (2) low - sinking. So if P8 is set to be an output and I set it high to power both LEDs thereby activating the triac, when low (i.e. not high) then it will sink any current that comes its way. So my concern is what happens when P8 is low and SW1 is pressed? If P8 acts a sink then I am likely to damage it by connecting it directly to the +3.3V source. Is this correct?
If that is the case then the second option is to use P8 as a sink to control the circuit (see Option 2 circuit). Setting P8 low causes it to sink the 5+(5-10) mA thus activating the circuit. When it is set high it sources +3.3V, so what happens when I activate SW1? Assuming P8 is now sourcing then the switch needs to sink the current from the LEDs and whatever come out of P8 (perhaps 40+ mA -ish?).
My final thought is go with the first option (P8 sourcing) and programmatically control it to only be an output when I want to activate the triac, and when not in use set the pin to be an input. Seems a bit awkward, but I cannot think of another way of incorporating direct "manual/harware" control.
The other possibility is to add diode protection between P8 and the +3.3V source (or P8 and ground) to prevent unwanted current flow - but then I will have to suffer 0.7V of voltage drop and so now I'm adding additional resistors or another diode to balance the current from each source (I'm very tight for board space too!). I'm thinking there must be a more simply way of doing this and I'm just not seeing it.
Ideas?
If that is the case then the second option is to use P8 as a sink to control the circuit (see Option 2 circuit). Setting P8 low causes it to sink the 5+(5-10) mA thus activating the circuit. When it is set high it sources +3.3V, so what happens when I activate SW1? Assuming P8 is now sourcing then the switch needs to sink the current from the LEDs and whatever come out of P8 (perhaps 40+ mA -ish?).
My final thought is go with the first option (P8 sourcing) and programmatically control it to only be an output when I want to activate the triac, and when not in use set the pin to be an input. Seems a bit awkward, but I cannot think of another way of incorporating direct "manual/harware" control.
The other possibility is to add diode protection between P8 and the +3.3V source (or P8 and ground) to prevent unwanted current flow - but then I will have to suffer 0.7V of voltage drop and so now I'm adding additional resistors or another diode to balance the current from each source (I'm very tight for board space too!). I'm thinking there must be a more simply way of doing this and I'm just not seeing it.
Ideas?
Comments
Nothing awkward about that, you want an open Drain output (source of sink) and so you control the Port OE.
All legal and no more parts.
Duane J
Thank you very much!
Do a bit of bread boarding to make sure your parts work correctly.
While I'm confident the circuit configuration is sound I don't have your opto-couplers nor LEDs.
You may need to adjust the resister values a bit. I don't think you can use blue LEDs though.
And of course there is the complement sinking circuit also.
Duane J
Just be wary that an LED _plus_ an opto coupler in series at 3.3V, has very little drop left for the resistor, so will be very component/temperature and Vcc sensitive. Might not work at all at the margins.
( and an LED failure == No triac drive )
Such a series connection could be more practical from a 5V rail, in Sink mode. - still use open collector mode.
Usually when doing Open Drain, you usually define the OUT register first, and _then_ define the direction register, and code drives the direction register. The output state never changes from low, as it does not need to.
Upon boot-up all pins are set to be inputs which is the high-Z state so they will neither sink or source. You can set a pin's direction to be either sink or source prior to switching it to be an output so when it changes from input to output it will be in this predefined state which prevents any unwanted sourcing or sinking activity of the pin.
Did I get that right?
This diagram is from an old 68HC05 manual as Parallax have not published such a diagram AFAIK and modern I/O tends to have lots of other functions tied in with it which include pull-up resistors and gating of peripheral functions. However in this diagram there are two latches which are since we are looking at a single port, the one-bit equivalent of the OUTA and DIRA registers. The top latch controls the output buffer in that when it is "0" the output is disconnected (tristated) from the pin. This is the power-up and reset state of the pin. Notice that even when it is set as an OUTPUT that you can still read the state of the pin itself. On some processors in this mode they read the state of the output register rather than the pin to guarantee that read-modify-write operations are not compromised by heavily loaded outputs that look low when they should be high etc.
Does anybody know if Parallax have published the I/O port structure?