How to calculate exactly resistors values of opto coupler

Optocupler: FAIRCHILD MOCD207M

According to the data sheet with If=1mA minimum CTR is 34%. Using series resistor of 1.5k at 3.3V gives If= (3.3-1.2) / 1.5k = 1.4mA.

The collector is connected to a 30k pull up resistor. It is directly connected to a controller input. Is the value of the pull up resistor adequate?

• Without knowing what toggle rates you are expecting to work with via the opto, it's difficult to say if 30k is too big or not. I suspect it might be. Commented Mar 14, 2014 at 13:05
• If the driver has a 0.4V output, the actual current might be more like 1.1mA. The CTR gives you (reliably) maybe 200uA from that, so it's okay. I would not go much lower. Commented Mar 14, 2014 at 13:28

The current transfer ratio (CTR) defines how much of the forward current in the LED is optically transferred to the BJT as its collector current.

From your description, I am assuming it's wired as follows:

simulate this circuit – Schematic created using CircuitLab

So $1.4$mA in the LED $\times 0.34 = 476\mu$A of current in the collector, according to the CTR.

The current through the Rpullup caused by the voltage drop across the Rpullup will be: $$\mathrm{I} = {\mathrm{V} \over \mathrm{R}} = {3.3 \over 30000} = {110\mu\mathrm{A}}$$

so $110\mu$A will flow through Rpullup and the remaining $476 - 110 = 366 \mu$A would (under ideal conditions) be available to charge the P1 port of the microcontroller and sink it to logic 0. However, the rise time of the transistor is $1.6\mu$s and assuming a P1 gate capacitance of $5$pF worst case, and an internal $10$k pullup in parallel with the external $30$K pullup is $7.5$K, so the RC time constant is: $$7500 \times 5\times 10^{-12} = 37.5\mathrm{ns}$$

This means that the gate capacitance will be charged up in just $5$ of those time constants, or $187.5$ns, well before the transistor is fully turned on and in saturation. After this, the transistor just continues to rise for the remaining rise time less the charging time, or

$$1.6\mu\mathrm{s} - 187.5\mathrm{ns} = 1.4125 \mu\mathrm{s}$$

at which point it just saturates at $110\mu$A

So this seems like enough current to pull down the micro's input port to logic LOW, but you need to look at your data sheet for the micro to determine what the actual input capacitance and pullups are.

When the optocoupler is switched off, the $30$K pullup will then be used in parallel with an internal pullup (I assumed $10$K internal) for $7500\Omega$ to charge the gate capacitor to the opposite logic level. Again, you will have $110\mu$A available (or even more if you include an internal pullup in parallel). So it seems like $30$K is fine here (because all the previously calculated time constants for logic LOW still apply here for switching to logic HIGH.)

You can easily avoid all these calculations if you use a reasonable current to begin with and middle of the road pullup like $10$K, at the expense of higher quiescent current draw. That optocoupler you are using can have $60$mA forward current in the LED, so give it $5$ to $10$mA, not $1$mA. $1$mA is also the minimum from the datasheet, and I like to stay away from minimums like that.

• The remaining 366uA WON'T come from the P1 port of the microcontroller - how can it? In fact, the transistor will be in saturation. Commented Mar 14, 2014 at 13:03
• yes it's in saturation, after it charges up the Cgs of the port pin. The collector current is initially limited by the CTR of the device, not by the Rpullup. Initially it limits the collector current to 476uA, of which 366uA is available to charge the Cgs internally on the P1 port to pull it down to 0..After P1(Cgs) is charged up, the collector current is now limited by Rpullup at just 110uA and it's in saturation. The P1 gate mosfet (Cgs) is small and the charging current doesn't last long, but it's there, and it is indeed a bandwidth limiter of the system. Commented Mar 15, 2014 at 0:12
• I see what I've done. I got caught thinking ideally, but it's not. I just simulated the circuit and I was surprised to see that the charging current for the P1 gate capacitance was just a few nA.. not at all the available 366uA that I calculated. The transistor's turn on rise time was way too slow, and this limited the turn on current. In simulation, I swapped out the optocoupler for a 2n2222 which is faster and it shoots up to 600uA charging current at Cgs, which is what I expected to happen here, but alas the Opto is too slow for that to happen, but I didn't think it would be THAT slow. Commented Mar 15, 2014 at 1:26
• The OPTO is not fast enough to even get to 476uA available before the Cgs of the P1 Gate is charged up already and needs no more current. After that, yes, it saturates at 110uA as we've both said. Commented Mar 15, 2014 at 1:30
• edited the answer to include the new information.. Thanks Andy.. please check and comment Commented Mar 15, 2014 at 2:07

The value of the pull-up resistor is uncritical. Typically you want to choose a value that sufficiently limits the current while not being to weak to properly "pull-up" the voltage to the desired value. Common values are in the 10-100k Ohm range.

Many micro controllers have internal pull-up resistors that can be optionally activated and are adequate in most cases. Check the data sheet.

The CTR is uncritical as well, because you only require a very low collector current. You already pointed out that the data sheet states that CTR is >34% at If=1mA. However, I would increase If to about 5mA to avoid driving the OC on the lower boundary.