0
\$\begingroup\$

I am counting the pulse edges from a quadrature encoder with an FPGA and using opto-couplers as the encoder is powered with 12V and the FPGA inputs are 3.3V. The encoder is 1000ppr with 2 channels and I count both the rising and falling edges.

The opto-couplers are ILD74 (Link to ILD74 datasheet) and the inputs to the FPGA are pulled up with 10K resistors, like in the image at the bottom of the question. The FPGA inputs go through inverters to match up with the encoder outputs, as an encoder pulse pulls the FPGA input to ground.

So I am unsure if these opto-couplers switch fast enough. The encoder will run at max 4500rpm, so per channel this is an output frequency of roughly 75kHz (1000ppr * 4500rpm) / 60 = 75,000.

The ILD datasheet has a ton-toff switching times of typically 3us which is over 300kHz, so I think these opto-couplers should be ok?

Also I'm interested to hear if anyone has any recommendations to this circuit or any advice as to how encoder outputs are connected to microcontrollers / FPGAs in general.

Thanks everyone.

Encoder circuitry

EDIT 1

I have added the output of my encoder at approx 5000rpm. The output frequency is around 85kHz.

Encoder output image

EDIT 2

I am waiting for parts to arrive and I will get back if I have anymore questions. I will close the post when I get the problem working. Thanks everyone!

\$\endgroup\$
2
  • 1
    \$\begingroup\$ Getting high speed out of a diode + BJT opto requires crafted design of both the LED driver/transmitter as well as the BJT transistor receiver section. They should be designed hand-in-hand for each other. It's not a "throw resistors at it" kind of thing. Besides, you also need to take into account what the receiver is driving (the FPGA input.) Also, encoders can be mechanical or optical and should also be accounted, too. Have you run the encoder at full speed and scoped A and B together in the same plot, yet, both directions? \$\endgroup\$
    – jonk
    Apr 2, 2021 at 19:52
  • 1
    \$\begingroup\$ @jonk Yeah, I have added the encoder output image to my question, please have a look at it. The max encoder frequency is around 85kHz \$\endgroup\$
    – David777
    Apr 2, 2021 at 20:17

3 Answers 3

4
\$\begingroup\$

No, this will not work with the 10kohm load resistor.

Look at datasheet diagram 13, at 10kohm load resistor, it takes about 50us for the signal rising edge to propagate from input to output, while falling edge propagation is below 2us.

As 75kHz is about 13us period, you need signal rising edge propagation time much faster than that, and you can go down to 10us with about 470 ohm resistor.

If this resistance is too low, then you need another optocoupler.

\$\endgroup\$
1
  • \$\begingroup\$ Thanks, I didn't know there was such a chart. Obvious this isn't going to work. I will use of of the advised opto-couplers mentioned above. \$\endgroup\$
    – David777
    Apr 2, 2021 at 20:26
3
\$\begingroup\$

Get an optocoupler which is designed for high enough speed. Its receiving end is a complex amplifier circuit instead of pull-up with a resistor.

For high speed an ordinary opto-coupler could be used if there's very low resistance pull-up resistor and an amplifier or a cascode amp is used to prevent Vce voltage changes of the opto transistor during the state transitions.

Here's one. The internals are not revealed in the datasheet but the speed should be enough:

https://www.vishay.com/docs/84131/6n137a.pdf

It's Vishay 6N137A. It needs a pull-up resistor like an usual opto-coupler. It needs also +5V operating voltage. Read the datasheet carefully!

Vishay has published also an application note for high speed optocoupler. I guess it's both interesting and useful: https://www.vishay.com/docs/83747/appnote71.pdf

There's a comment which says that also the LED drive must be crafted for speed. If one simply opens the switch which feeds DC to the led through a resistor the led glow decays slowly because there's plenty of minority carriers which must vanish and they make light as they vanish. The charge must be at least shorted or preferably have a reverse feed.

Also switching the led ON fast needs attention. The same carrier cloud must be formed without too long charging time. Here's one old idea to get the speed with discrete components and with one switch (=M1)

enter image description here

C1 is classical speeding capacitor which causes current peak when M1 starts to conduct. L1 pushes current through led to reverse direction when M1 stops conducting. Do not attempt anything like this if you cannot calculate the needed boost pulses. Too big C1 and L1 can destroy M1 and LED. Try at first how the system works without a circuit like this.

Totem pole output can make the needed boost to both directions with no inductor. It's the next thing to try if some speeding is needed.

\$\endgroup\$
15
  • 1
    \$\begingroup\$ That's nothing new. You'll find plenty of writings about that level shifting. To keep it fast and not making it noise-sensitive need a little design. \$\endgroup\$
    – user136077
    Apr 2, 2021 at 21:11
  • 1
    \$\begingroup\$ BJT inverter becomes tricky if it must be fast - speeding circuits are needed. Passive resistor voltage divider can work well enough if your inputs do not pull nor push substantial currents and they have low enough capacitance To keep the 5V good for the opto output insert a 2N3904 emitter follower between the voltage divider and the opto output (which has the pull-up resistor).. \$\endgroup\$
    – user136077
    Apr 2, 2021 at 21:31
  • 1
    \$\begingroup\$ Please note that the optocoupler has open-collector output so it does not ouput 5V. It needs a pull-up resistor. Don't pull it to 5V then, pull it to 3.3V, and you are done - no level shifting needed. \$\endgroup\$
    – Justme
    Apr 2, 2021 at 22:32
  • 1
    \$\begingroup\$ The pull to 3.3V can work but it's not specified to work. Nobody of us knows without testing does the opto-coupler output something unacceptable during power-up. @David777 BSS138 fet + a resistor, say 1kOhm between the drain and +3.3V should work. \$\endgroup\$
    – user136077
    Apr 2, 2021 at 22:36
  • 1
    \$\begingroup\$ @user287001 The question of pulling 6N137 output to 3V3 has been answered here on ee.se already. Another options include getting a 6N137 that operates at 3.3V, at least one manufacturer makes those. Or select another 3.3V optocoupler as 6N137 is getting obsoleted by many manufacturers. David777 1k sounds good. Anything low which does not exceed max current. \$\endgroup\$
    – Justme
    Apr 2, 2021 at 23:12
1
\$\begingroup\$

The opto-transistor is fast when switching from OFF to ON that is from FPGA input 1 to FPGA input 0.

The problem here is that R has the responsibility to pull from 0 to 1 the FPGA input and it's really slow.


You need either:

  1. A totem pole optocoupler like this:

https://uk.rs-online.com/web/p/optocoupler-ics/6258413/

or

  1. To review your design and possibly design a totem pole yourself.
\$\endgroup\$
2
  • \$\begingroup\$ So this IC will bring the correct phase between encoder output and opto-coupler output. This will then just require a logic level shifter from 12V down to 3.3V? \$\endgroup\$
    – David777
    Apr 2, 2021 at 21:55
  • 1
    \$\begingroup\$ That IC will make rising and falling times equal. If you could attach that resistor to a local +3.3 V then just set R to 270 Ohm and you are all set. \$\endgroup\$ Apr 3, 2021 at 7:46

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.