0

I am creating a circuit for an automotive application which will take 3 buttons from the stalk as 3 inputs. Now I have measured these buttons and they are active low and output a constant 12v (ish) when not pressed.

I am using an STM32F4 MCU to read the button presses and I realise that I need to drop the voltage of the buttons to 5V max prior to the digital IO pins of the MCU. After looking online I came across the idea of using an opto-isolator and because of PCB constraints I wish to use one which comes ready made in a SOIC package with 3/4 channels.

Now I see there are many available and so far I have determined I will use a transistor based one as it is a good middle ground and I don't need to deal with fast switching.

But I am confused as to how to choose one exactly as there are so many available. My requirements are:

  1. relatively low cost (up to £2)
  2. SOIC package
  3. triple/quad channel
  4. suitable for automotive voltages, 12V (possibly fluctuating a bit)

I am considering using the Toshiba TLP290-4 opto-isolator, which has a min CTR of 50%.

So by following the advice here: https://electronics.stackexchange.com/a/43502/148565

And considering the schematic (Just the forward voltage scenario, if I am not mistaken, this opto-isolator can handle reverse also):

schematic

simulate this circuit – Schematic created using CircuitLab

I calculate that given a 10mA input current through R1 and D1, and the given 1.2V typical drop across D1 according to the datasheet, then R1 = VR1 / I = 1.08kΩ, so 1.2kΩ should do.

Then given the minimum CTR of 50%, at a 10mA input current, the output current would be 5mA. Therefore, assuming the 3.3V dropped across R2, R2 = VR2 / I = 330Ω.

So the question is, are my calculations correct and will the proposed circuit be safe for use under these conditions?

And as an aside, how would I go about inverting the output in terms of the switching, Do I just tie R2 to GND instead of 3.3V?

James Elder
  • 113
  • 4
  • 1
    As it stands, you're asking a "shopping" question, which isn't allowed. If you edit your question to just ask about parameters to look for instead, then it will be ok. – DoxyLover May 08 '17 at 19:53
  • 1
    You need to bear in mind that 12V in an automotive environment is nearer to 14V under normal running, and may spike much higher. That applies to driving the opto diode as well as supplying your 3.3V regulator. – Finbarr May 08 '17 at 20:42
  • As for inverting the output, why not just do it in your software? – Finbarr May 08 '17 at 20:43
  • Thanks, well actually I measured 12v at the stalk switches with the engine running and so I wonder whether the voltage is already regulated somewhere in the circuit from the switches. But yes, I realise that if not the voltage can spike up to 15v when the alternator is running etc. As for the inversion, I can do it in software, (and I probably will) but I just wanted to confirm how to do it in hardware for my own knowledge really... – James Elder May 08 '17 at 21:45
  • 1
    @JamesElder If for instance the driver switches to a low gear at high speed by mistake, the alternator running at 10000+ rpm will output much more that 15V. Do you want your device to survive common driving mistakes? – Dmitry Grigoryev May 10 '17 at 10:41
  • Well the supply voltage for the mcu is regulated and protected against over voltage, thermal overload and reverse polarity. However the stalk inputs are taken directly from the stalk buttons and I'm unsure whether they are indeed already regulated, but I think they are. Anyway, I will be using the opto-isolator circuit in the answer below which further ensures that the mcu will be protected in this scenario. – James Elder May 10 '17 at 17:29

1 Answers1

5

You need to start from the load you're trying to drive, then work backwards to what you need to take from the source, then adjust your results for the min/max limits of any of your components.

You don't specify your particular STM32F4 microcontroller (MCU), nor the maximum current you can take from your 12 V.

The load on your circuit is the input leakage current of an I/O pin when configured as an input. You need to find this in your MCU data sheet. A typical figure for these devices is +/- 1 uA. Your inputs need 0.7 x Vdd to Vdd to detect a logic high and GND to 0.3 x Vdd to detect logic low, again typical figures and being 0..1 V for a good low and 2.3..3.3 V for a good high.

You must also allow for the leakage current down the photo-transistor in your TLP290-4 opto-isolator when it's off, which you will find in the datasheet to be 0.1 uA max.

So your pull-up resistor can afford to drop 1 V across itself with 1.1 uA flowing through it and still be detected as logic high. That's about 909 K but with no margin for error and little resilience to noise.

Your Infra-Red LED (IRLED) has a transfer ratio of 50 % worst-case. Your datasheet also specifies the IRLED current, IF, with figures from 100 uA up in the graphs and example figures of 1 mA up in the tables for output saturated, with the max being 50 mA. In a noisy environment such as a car, you should draw a good-sized current from your signal source to be confident it is not triggered by noise. You had accepted 10 mA. Let's use 5 mA. This will drive the IRLED strongly but not hard. Transient overvoltages on your detection input can be almost 10x the normal 12 V before it'll get anywhere near the 50 mA max. so it's a well-protected input circuit.

So the IRLED series resistor is: (12 - 1.2) / 0.005 = 2160 (use 2K2)

With 5 mA through the IRLED, the photo-transistor Ice(max) can be taken as 2.5 mA. So the acceptable current range through the pull-up resistor is 1.1 uA to 2500 uA.

A 10 K resistor draws: (3.3 - 0.4) / 10000 = 290 uA

This is a good choice: a strong pull-up but still only 10%-odd of the maximum.

You can therefore also use the programmable internal pull-up resistors in your MCU, which the datasheet will tell you are equivalent to 30..50 K or 7..14 K.

In your calculations, you found the IRLED current stated as 10 mA in one place, worked out the current transfer ratio then tried to draw the maximum current you could from the output, rather than the current you need.

The other thing you need to observe is that the maximum reverse voltage that the IRLED in an opto-isolator can take is very often tiny by diode standards, something like -2..3 V being common. You would therefore need a diode connected across the IRLED that conducts when the IRLED is reverse-biased to protect it. The TLP290-4 has these built in so there is no need for an external diode.

schematic

simulate this circuit – Schematic created using CircuitLab

So: use R1 = 2K2 for 5 mA IRLED current and R2 = 10K and you'll be fine with your microcontroller input pins.

You can invert the active state of the signal in your software for free, as well as get the pull-up resistors in your software for free.

TonyM
  • 21,742
  • 4
  • 39
  • 62
  • Is there a reason you are suggesting 5mA IRLED current rather than 10mA? The datasheet suggests 10mA current through the diode in their test conditions, which gives rise to a 1.2V typical drop across the diode. I'm also intrigued as to how you came about the value of 10K for R2? – James Elder May 08 '17 at 21:28
  • This is a great answer and I follow it fully. After consulting the datasheet of my STM32F413ZH MCU, I can confirm the leakage current is +/-1uA and the pull up resistor range is 30-50K. Also the maximum current I can draw is very large as it is only drawn when the engine is on so there are no worries there. Thanks! – James Elder May 09 '17 at 09:13
  • You're welcome @JamesElder and good luck with it :-) – TonyM May 12 '17 at 06:09