I'm trying to design a circuit to connect this quadrature encoder AMT11 output signal to my microcontroller STM32L4R5ZIT6P that's running on 3.3V. Since the output from the encoder is 5V, if I directly connect the output signal to the 5V tolerant pin on the micro (eg. pin 18,19), will it damage the microcontroller in the long run if the pins are receiving 5V constantly? Do I need any protection on the pin?
The absolute maximum input voltage is min(VDD, VDDA, VDDIO2, VDDUSB) + 4.0 with some notes.
It does not appear to me that it's safe to apply 5V to the pin if min(VDD, VDDA, VDDIO2, VDDUSB) < 1V.
In other words, supply sequencing may be necessary to ensure that the 3.3V supply is not absent with the 5V supply present. (Or, you could just use a level translator that has two Vdd pins and is designed for this kind of application).
What you need is a bi-directional voltage level converter between 3.3V and 5V. You can find additional information in this stackexchange post: Is there any bidirectional 5v-3.3v level shifter? If you search the internet for “3.3V to 5V level shifter bidirectional IC” you will find several companies with integrated circuits that do the job.
Basically the circuit works like this:
• On one side you have the 3.3V from the power supply of the microcontroller feeding its 3.3V level signal.
• On the other side you have the 5V from the power supply of the quadrature encoder feeding the level 5V signal.
• In the middle you have a transistor (BJT or MOSFET) to isolate them and provide the correct voltage to the other side.
• The ground of both power supplies (3.3V and 5V) are common.
• Here is the final circuit. Please note the substrate diode direction. You want it to be forward biased from the 3.3V to 5V and in reversed biased from the 5V to 3.3V.
• When the signal from the microcontroller is high (3.3V) the MOSFET is OFF and the signal on the quadrature encoder is pulled-up (5V) by the Rhigh resistor.
• When the signal from the microcontroller is low (0V) the MOSFET is ON and the signal on the quadrature encoder is pulled-down (0V) by the MOSFET.
• When the signal from the quadrature encoder is low (0V) the substrate diode pulls the signal from the microcontroller low (0V) ) turning the MOSFET ON.
• When the signal quadrature encoder is (5V) the MOSFET source pin is pulled up by the 3.3V and the MOSFET is OFF.
• Note: This works for open collector type of gates.
If all you want to do is convert the 5V quadrature signals to 3.3V for the microcontroller, then a few resistors connected as voltage dividers should work fine. In general, this will degrade the rise time a little, but full featured encoders like this usually have muscular output drivers, so it might not even be noticeable unless you're trying to spin the encoder at its maximum speed.