I have a 24V DC motor with a magnetic rotary encoder. The encoder has a 5V supply voltage. The datasheet states that it has an output voltage of 300-700mV. I have also measured it, and it gives around 0.5V. I want to interface this encoder with an STM32 microcontroller, so I want to convert it (reliably) to 3.3V. But I don't really know how. Since the datasheet states a 300mV minimum voltage, I want to build a circuit, that "turns on" at 0.25V, it is "off" below and "on" above, and gives me a clean square signal.

My first though was a transistor operated as a switch, but 0.3V is not enough for a BJT transistor's operation. Then I was thinking about a MOSFET circuit like this one, with an N-channel enhancement MOSFET:

enter image description here

But I have no experience with such circuits. Could this work with just 0.25V threshold? Or do I have to amplify it? What MOSFET and resistor values do I choose?

Or what other solution would be better in this situation?

Thanks for the answers!

Datasheet: https://www.power-tronic.com/wp-content/uploads/2019/11/Type-Magnetic-Incremental-2019-01-08.pdf

MCU: STM32F101R8T6 (GPIO PC8, PC9)

  • 1
    \$\begingroup\$ @Marcell Juhász, Ah there is some misunderstanding. The specified output voltage of 300-700mV, and you measured 0.5V is the "active" or "triggered" signal. When not active or not triggered, the output voltage is roughly Vcc. If you use Vcc = 5V at the output side, the signal is 5V not active, 0.3 to 0.7V (or 0.5V in your case). What you might not be aware, that the the 20mA current loop protocol is used in your encoder. You might like to google "20mA" to learn more. Eg, 4-20mA Current Loop Primer - DMS murata.com/-/media/webrenewal/products/power/appnote/… \$\endgroup\$
    – tlfong01
    Commented Mar 5, 2021 at 12:14
  • \$\begingroup\$ The output low voltage is actually the Vce(sat) voltage of the NPN BJT switch in the datesheet. The output high voltage is your Vcc, can be as high as 15V. If you mcu/sbc is 5V, then us 5V Vcc. \$\endgroup\$
    – tlfong01
    Commented Mar 5, 2021 at 12:16
  • \$\begingroup\$ ohh okay, thank you very much, I will look up what you wrote! \$\endgroup\$ Commented Mar 5, 2021 at 12:17

1 Answer 1


You need to add what's called a pull-up resistor to the encoder's output pin [from OP's data sheet]:
pullup resistor schematic
The pull-up resistor should go to the processor's +3.6V Vdd. Your processor may have GPIO pins that are 5V-tolerant. If so, you can pull-up to +5v DC.

What value? The transistor pulls down to GND, but the spec is ambiguous...suggesting that when the transistor is ON (pulling 20 mA current down to GND), you'll have 0.3V -to- 0.7V at the output pin.

If you use a large-value pull-up resistor to the processor's 3.3V Vdd, this "low" voltage will likely be closer to GND than 0.3V. You might try a 10k pull-up resistor to start. With such a large value, when the motor turns quickly, pulses may disappear because switching time is too slow. If so, try a smaller value pull-up resistor.


Your Answer

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

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