Friends,
For my own entertainment, I'm working on a project that (may) partly involve turning a DC motor + a magnetometer into what I think could be called a servo motor? Here's my test setup:

The 3D printed apparatus holds three items: the magnetometer mentioned earlier, a magnet, and then a DC motor. The rest of the parts pictured here are a motor driver IC and an ESP32-C6.
In theory, the magnet is aligned with the magnetometer in an order that the datasheet says should allow rotation sensing (this is from the application note example for rotary encoding):

I seem to be able to get a pretty good angle signal out of this device, but when used to measure rotation speed, there appears to be a lot of jitter. When stationary, I get measurements within 1deg/sec of zero. However, when rotating the motor at a constant duty cycle, the apparent noise is significant -- on the order of +- 20deg/sec (sampling at a little less than 200hz).
There are a ton of possible sources of error -- bad firmware as written by me, a bad physical setup, maybe magnetic noise form the motor? Or maybe the motor's speed is really varying by the amounts I'm measuring (although visually it appears to run very smoothly). Assuming the motor is running at a nearly constant speed at a fixed duty cycle, then the measurements I'm seeing contain both high and low frequency noise. I know this because I've looked at plots of the noise both raw and smoothed with an EWMA (alpha=0.95) and I saw significant variance in the measured speed under both approaches.
My main question: I wanted to ask here to see if anyone would know if I have fundamentally misunderstood what is possible with this part. I'm wondering if this is just not a very good way of sensing rotation speed? I'm aware that there are other approaches, mostly encoder wheels combined with optical, physical, or magnetic sensors, as far as I'm aware. I would like to know if I just need to keep debugging, or if my princess is in another castle. If I should keep on pushing, I'd appreciate any sources you have for me to read that would help me work through the problems I'm grinding on.
If it's at all helpful, the reason why I thought I might be able to use this device is because I looked up how Lego does their servomotors. If you're not aware, their motors are also capable of both absolute position control and speed control. If you look at a teardown of their motors, they appear to use a similar IC on the motor output shaft, so I formed a belief that I could do something like what they do. My process for picking the parts for my design (if you can call it that) was to look for parts that do something similar to Lego's design and try to jam them together.
Here are links to the part datasheet and application notes.
Getting started guide: https://www.melexis.com/-/media/fil...n-notes/mlx90393-application-note-melexis.pdf
Datasheet: https://www.mouser.com/datasheet/2/734/MLX90393-Datasheet-Melexis-953267.pdf
Thank you in advance for any advice you have to offer.
For my own entertainment, I'm working on a project that (may) partly involve turning a DC motor + a magnetometer into what I think could be called a servo motor? Here's my test setup:

The 3D printed apparatus holds three items: the magnetometer mentioned earlier, a magnet, and then a DC motor. The rest of the parts pictured here are a motor driver IC and an ESP32-C6.
In theory, the magnet is aligned with the magnetometer in an order that the datasheet says should allow rotation sensing (this is from the application note example for rotary encoding):

I seem to be able to get a pretty good angle signal out of this device, but when used to measure rotation speed, there appears to be a lot of jitter. When stationary, I get measurements within 1deg/sec of zero. However, when rotating the motor at a constant duty cycle, the apparent noise is significant -- on the order of +- 20deg/sec (sampling at a little less than 200hz).
There are a ton of possible sources of error -- bad firmware as written by me, a bad physical setup, maybe magnetic noise form the motor? Or maybe the motor's speed is really varying by the amounts I'm measuring (although visually it appears to run very smoothly). Assuming the motor is running at a nearly constant speed at a fixed duty cycle, then the measurements I'm seeing contain both high and low frequency noise. I know this because I've looked at plots of the noise both raw and smoothed with an EWMA (alpha=0.95) and I saw significant variance in the measured speed under both approaches.
My main question: I wanted to ask here to see if anyone would know if I have fundamentally misunderstood what is possible with this part. I'm wondering if this is just not a very good way of sensing rotation speed? I'm aware that there are other approaches, mostly encoder wheels combined with optical, physical, or magnetic sensors, as far as I'm aware. I would like to know if I just need to keep debugging, or if my princess is in another castle. If I should keep on pushing, I'd appreciate any sources you have for me to read that would help me work through the problems I'm grinding on.
If it's at all helpful, the reason why I thought I might be able to use this device is because I looked up how Lego does their servomotors. If you're not aware, their motors are also capable of both absolute position control and speed control. If you look at a teardown of their motors, they appear to use a similar IC on the motor output shaft, so I formed a belief that I could do something like what they do. My process for picking the parts for my design (if you can call it that) was to look for parts that do something similar to Lego's design and try to jam them together.
Here are links to the part datasheet and application notes.
Getting started guide: https://www.melexis.com/-/media/fil...n-notes/mlx90393-application-note-melexis.pdf
Datasheet: https://www.mouser.com/datasheet/2/734/MLX90393-Datasheet-Melexis-953267.pdf
Thank you in advance for any advice you have to offer.