I'm planning on using the LPC1768's QEI module for reading a motor's encoder (which has a high resolution - http://encoder.com/literature/datasheet-770.pdf).

I've read some people have hooked up their encoders to the module using pull down resistors [https://os.mbed.com/users/hexley/notebook/qei_hw-interface-implementation-notes/, however, apparently this is only suitable for reading panel encoders turned by humans because the pull down is too slow for high-speed application.

If this is the case, what would be an alternative to using a pull down/up resistor?

Ultimately I'd like to know the best way to hook up an encoder without losing counts.


closed as unclear what you're asking by Oldfart, Voltage Spike, Harry Svensson, Finbarr, mkeith May 7 '18 at 1:35

Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.

  • \$\begingroup\$ Ah the standard resistor that only comes with one value. \$\endgroup\$ – Harry Svensson May 2 '18 at 7:15
  • \$\begingroup\$ Link to datasheet? (Put it in the question - not in the comments.) \$\endgroup\$ – Transistor May 2 '18 at 7:20
  • \$\begingroup\$ See update... :) \$\endgroup\$ – M-R May 2 '18 at 7:48
  • \$\begingroup\$ Should work now - the square bracket found its way into the link. \$\endgroup\$ – M-R May 2 '18 at 8:05
  • 1
    \$\begingroup\$ So, what part of "we need the datasheet" don't you understand? Or do you think that you actually linked to one? \$\endgroup\$ – WhatRoughBeast May 2 '18 at 11:51

The first thing to do is to figure what the fastest toggling speed of any of the lines will be. Find the fastest shaft speed you need to handle, then figure out the toggle frequency out of the encoder for that.

Once you know the fastest response time you need, this problem no longer has anything to do with a encoder. It's really about how stiff a pullup or pulldown needs to be to float the line to the released state when it is no longer actively driven to the opposite state. This is mostly a RC time constant calculation.

Let's say you decide that there will be no more than 100 pF of parasitic capacitance on a line, and that the fastest toggle rate is 10 kHz. Each cycle is 100 µs long, so each level is 50 µs long. If you need to decode two of these lines in quadrature, one should be well settled before the other starts to change. Let's say you therefore decide you want each line to settle to 90% within 10 µs.

90% settling happens in 2.3 time constants. One time constant is therefore (10 µs)/2.3 = 4.35 µs. The minimum pullup or pulldown resistance is therefore (4.35 µs)/(100 pF) = 43.5 kΩ. That's actually rather high. Unless this is a particularly low power application where you need to conserve 10s of µA, I'd just use 10 kΩ in this case.

Note that most of these devices have open drain or open collector outputs with a common ground. You would therefore need pullup, not pulldown, resistors. Check the datasheet to make sure you are using the correct polarity. High speed devices usually drive both ways and don't need pullups/pulldowns at all. Again, check the datasheet.

  • \$\begingroup\$ So the encoder I'm using has an optional TTL output. So I'm assuming I don't need a pull up/down at all? \$\endgroup\$ – M-R May 2 '18 at 16:22
  • \$\begingroup\$ @M-R: A true TTL output needs no pullup or pulldown if it is driving something TTL-compatible. \$\endgroup\$ – Olin Lathrop May 2 '18 at 18:54
  • \$\begingroup\$ I imagine most MCUs such as the LPC1768 are TTL compatible? What do you mean by a true TTL output? \$\endgroup\$ – M-R May 3 '18 at 3:33
  • \$\begingroup\$ @M-R: Don't imagine, read the datasheet. Check the guaranteed high and low levels of the output, and compare that to the minimum required high and low levels of the input. \$\endgroup\$ – Olin Lathrop May 3 '18 at 11:50
  • \$\begingroup\$ The datasheet for this encoder isn't entirely clear on the guaranteed output levels. It only mentions that a Differential Line Driver Output can be chosen. Am I to assume that makes it TTL-compatible? ecatalog.dynapar.com/downloads/E23_DS_701949_2.pdf \$\endgroup\$ – M-R May 3 '18 at 12:45

You can specify the push-pull output, then you don't need pull-up or pull-down resistors, except maybe to establish a known state with the encoder disconnected. That's because the push-pull outputs should be able to drive tens of mA and easily switch at such a relatively low frequency (200kHz max).

Using open-collector or drain outputs, the time constant will be R*C where C is the sum of the cable capacitance and input capacitance. If you want it to work at 200kHz, the time on and off is 1/400,000 second or 2.5usec. If you allow four time constants (two time constants in quadrature) then you'll want the time constant to be less than 630nsec. With a resistor of 2.2K you'd have to have capacitance less than 280pF. If your cable is 40pF/foot that's about 7' of cable. You can go as low as 1/10 of that (20mA, assuming the logic levels hold) and that means 10x the cable length, all other things being equal.

So I don't think you will have a problem on that account unless you try to do something silly like using 100K or 10K resistors with a cable.

The QEI interface, being hardware, should easily respond at 200kHz but you may have insufficient resolution to read the velocity accurately, check the datasheet.


If there is quite a big distance (more than a foot) you really should use a voltage at least 1/2 way in its operational range. Because, over time, the photo transistors are going to lose gain. As far as counter accuracy, you will want to use the balanced signal lines (they call it differential or push-pull) into an op-amp that you level shift back to TTL. Because it will have the best noise immunity (about 40 dB over the open collector or unbalanced configuration).


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