Voltage divider for reading motor encoders

As per my Logic Level Shifter for reading motor encoders post, I am using an Arduino Nano 33 IoT to drive a Pololu 30:1 Metal Gearmotor and read the encoder signals. The Arduino runs on 3.3V, but the minimum voltage to power the encoder is 3.5V, so I am using the 5V pin from the Arduino to power the encoder. I then need to convert the 5V encoder signal to 3.3V for the Arduino.

I used the level shifter ok, but I get variations in the encoder readings with a constant PWM signal. For example, with a PWM duty cycle of 7.8%, I get readings of 1623, 1618, 1604, 1580, 1579, 1590, and 1600 counts per second.

I use interrupts in the Arduino to read the encoder signals. I don’t have an oscilloscope to check, but I wondered if there might be some additional transients on the signals due to the level shifter, and this is responsible for the variance I’m seeing.

I figured I’d try switching to using a voltage divider as Patrick suggested in the other post. I tried a voltage divider with 1K and 2K resistors, but no signals were detected in the Arduino. I checked the voltages with a multimeter, and the voltage out of the encoder is around ~1V rather than ~5V. Is this low voltage due to the resistors I have chosen? If so, what would appropriate resistor values be?

Also, is it possible that the level shifter is the cause of the variance in encoder readings, or is this level of variance expected?

The count variation is not at all surprising. When counting processes subjected to random fluctuations, the expected standard deviation of N counts is sqrt(N).

Evidently, the encoder output cannot drive a 3Kohm load. I suspect you could get away with a 4.7K to 10K series resistor, placed between the encoder output and the Nano input, which would limit the current through the input protection diode to a safe value.

Thanks for your reply Jim. That answers all my questions. I think I’ll go back to using the level shifter and see if the variance causes any issue in my control loop. I was planning to add a low pass filter to the encoder reading anyway.

From what you’re saying though, I would likely see the same variance even if I used resistors instead of the level shifter.