Shop OBEX P1 Docs P2 Docs Learn Events
Source or Sink, Part 2 - the triac circuit — Parallax Forums

Source or Sink, Part 2 - the triac circuit

MJHanaganMJHanagan Posts: 189
edited 2012-04-26 20:57 in Propeller 1
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?
Basic Triac Circuit.jpg
726 x 798 - 161K

Comments

  • jmgjmg Posts: 15,173
    edited 2012-04-24 15:24
    MJHanagan wrote: »
    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...

    Nothing awkward about that, you want an open Drain output (source of sink) and so you control the Port OE.
  • Duane C. JohnsonDuane C. Johnson Posts: 955
    edited 2012-04-24 15:53
    Try this:

    All legal and no more parts.

    Opto.png


    Duane J
    446 x 322 - 6K
  • MJHanaganMJHanagan Posts: 189
    edited 2012-04-24 16:09
    Hmmm, you made simple work of that! I thought there was a simple way of doing it but just couldn't find it this afternoon.

    Thank you very much!
  • Duane C. JohnsonDuane C. Johnson Posts: 955
    edited 2012-04-24 16:25
    Please;

    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
  • MJHanaganMJHanagan Posts: 189
    edited 2012-04-24 17:59
    Yes, I will indeed follow up with a test circuit. Thank you!
  • jmgjmg Posts: 15,173
    edited 2012-04-24 18:48
    MJHanagan wrote: »
    Yes, I will indeed follow up with a test circuit. Thank you!

    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.
  • kwinnkwinn Posts: 8,697
    edited 2012-04-24 19:14
    You could get rid of one of the two resistors in Duane's circuit if you used a spdt pushbutton. The nc connection goes to P8, the no to +3.3V, and the common to the 150 ohm resistor and leds.
  • Peter JakackiPeter Jakacki Posts: 10,193
    edited 2012-04-25 16:23
    Can I chime in with jmg? Ditto for running from 5V (and not 3.3V in series mode) and ditto for sink mode. Red LEDs have a voltage drop of 1.6V at low currents and this climbs to around 1.8V whereas the IR LED will have a typical drop of 1.2V which leaves just 300mv of headroom (on a good day). While you can calculate optimal resistor values for 300mv @10ma = 30 ohms and assuming the I/O ESR is zero and constant (which it isn't) you will find that even a 150mv rise in combined voltage drops will reduce the current by half. Besides I think the typical ESR of the Prop's output stage is around 45 ohms or so if I remember correctly so 3.3V operation is a big NO-NO even if it appears to work. BTW, 5V operation in sink mode means that the Prop's pin never sees more than 5-1.6-1.2 = 2.2V max.
  • MJHanaganMJHanagan Posts: 189
    edited 2012-04-25 17:15
    If I use the sink approach with +5V as the source then what happens when I first change the pin from its boot-up state of input to output? Does the pin go low initially and thus activate the triac?
  • jmgjmg Posts: 15,173
    edited 2012-04-25 18:02
    MJHanagan wrote: »
    If I use the sink approach with +5V as the source then what happens when I first change the pin from its boot-up state of input to output? Does the pin go low initially and thus activate the triac?

    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.
  • MJHanaganMJHanagan Posts: 189
    edited 2012-04-26 06:31
    Oh, now that's something I didn't know! So let me see if I understand this correctly:

    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?
  • Peter JakackiPeter Jakacki Posts: 10,193
    edited 2012-04-26 20:57
    Yes, The I/O pin can only do what it's been told to do so when you "un-tristate" the output buffer (that is, make it an output) it will then pass the state of the output register (OUTA) to the pin. Never assume the OUTA register is high or low, always set it to what you will need and then make the pin an output. If you are familiar with logic diagrams then here is a simple I/O port diagram for a single pin.
    IO PORT STRUCTURE.png


    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?
    934 x 632 - 40K
Sign In or Register to comment.