The dead zone of the magnetic encoder

Hi everybody. Yesterday I tried to get the position of the encoder using an analog signal. First I connected the arduino nano and with the help of an example determined the maximum and minimum position, they were 14- 1020. But when I connected this sensor to the esp32, the maximum and minimum values are 0- 4095. Moreover, the minimum and maximum values remain unchanged when the motor rotor rotates by about 10 degrees. It turns out I have two dead zones of 10 degrees each. I also noticed that the maximum value in the port monitor automatically reaches 4095. Although I have just started the microcontrollers and the actual position is much smaller, I have tried several times. Thanks

Its a bit hard to tell what is going on from this description…

Did you account for the fact that Nano is 5V while ESP32 is 3.3V?

What’s your circuit, what’s the code? Please provide some more details, then perhaps someone can see what’s going on…

Yes, of course I did. For arduino 5 volts, for ESP32 3.3.
I used this example, only changed the reading pin to 13

As you can see in the example, the code is very simple… its directly outputting the values returned by the ADC.

Using analog is a lot more difficult than digital interfaces. Small changes in the PCB design or components can make a difference to the output signal, even ambient temperature and humidity can affect sensitive ADCs.
The ESP32s ADC is not very good to begin with - check the ESP32 Datasheet on calibrating it.

While we offer the MagneticSensorAnalog class for users to experiment with, I don’t think many people use it, and if you look at the implementation, it doesn’t really do anything except call the Arduino analogRead() function.

Depending on the sensor IC used, and the circuit with which it is attached, I think considerably more work is probably needed to make it reliable - to give it a linear response, deal with noise, handle the 0-crossing reliably, compensate temperature and more… much of this stuff is normally handled for you by the chip when you choose a digital interface…

From the way you describe it the sensor’s output is outside of the ESP32s ADC input range. Presumably its an electrical problem in the way you connected them and their power sources.
To fix it you’ll have to add a circuit to shift the sensor’s output to lie within the ESP32s ADC range.

1 Like

Thank you for such a detailed answer. Today I replaced the controller with the stm32 f401 and everything worked. There is noise, possibly due to the sensor… Tomorrow I will try to connect the stepper motor and calibrate the encoder.
It is precisely because I cannot place the encoder exactly in the center that I use an analog signal. Since the library does not yet support sensor alignment in abz mode
Thanks

2 Likes