Electronics > Projects, Designs, and Technical Stuff

Measuring Revolutions: Analog to digital conversion (Comparators?)

(1/6) > >>

paeion:
I am measuring the rotation of a shaft that will go from stationary to a few hundred RPM in both directions. To do so, I am using the AS5600 magnetic rotary encoder and I am trying to use the analog output to create a digital signal to hardware interrupt my MCU (polling via I2C is not fast enough to accurately detect each revolution and I don't want to hog the processor):



The AS5600 analog output switches 0–3.3V or 3.3V–0V depending on the rotation direction. To detect this change, my first thought was a comparator with hysteresis (schmitt trigger) so that with appropriate upper and lower thresholds close to 0 and 3.3V I can easily hardware interrupt the MCU on the rising/ falling edges of the comparator to indicate a revolution. To that extent, I got my hands on the LM319 because it is quite fast, however does not allow 0–3.3V input range on a single 5V rail (1-3V instead). I can also readily get the LM393 which is slower, but should be fast enough for the task at hand and I believe the input can swing to the ground/ 5V rail.

I am wondering if this is approach is sound and I haven't forgotten something critical... or even better yet, if there is a 'simpler' method to achieve what I am trying to do.

Kleinstein:
A comparator with hysteresis makes sense. The LM393 is fast enough, well faster than the sensor. If good performance at low speed is needed, one may consider 2 comparators for 2 (or 4) reference points per revolution.

Some µCs already include a comparator and some even incluce hysteresis. So one may be able to get away even without the external comparator.

With the relatively low speed it may also be an option to use a µC internal ADC and let the µC read the analog voltage.
Alternatively one could use the I2C interface for the lower speed range. The I2C part may even be fast enough up to 1000 RPM, at least if the µC supports a fast clock and there are not many other chips on the bus.

Directly triggering an interrupt may not be the best solution. Many µCs offer hardware for time measuring, like an input capture function of a HW timer. This could take case of most of the job and may even include some hardware debouncing.

paeion:
Thank you for your reply Kleinstein, it is reassuring to be on track!

For reference I am using the ESP32 micro, which unfortunately does not have a built-in comparator (as far as I know), but does feature a useful pulse counter for rising/falling edges. My idea for directly triggering interrupts was to determine the rotation direction (based on the time differences between the rising/falling edges) and using a hardware timer to determine the RPM directly.

My experimentation with I2C let me sample relatively quick (> 1000Hz), however I could not detect the 0<–>360° transition reliably in software. I will take on the idea of 2 comparators for low RPMs!

Kleinstein:
When sampling at 1000 Hz or faster, one should be able to get the 0 - 360 deg. transition, at least most of the time (except for a few points near the transition). The change in angle should be limited to relativelay small angles (e.g. 6 deg. at 1000 RPM).
So the 0 - 360 transition is in a way to make the change in angle smaller. For the µC program one could extend the angle by adding or subtracting 360 degree as needed to keep the steps < 180 degree.  From the than extended turn angle it is easy to calculate the speed, e.g. from linear regression or just difference over a window of maybe 100 readings.

Going to the comparator only makes things more complicated with getting the direction of close to a stand still and reversing the direction.

langwadt:

--- Quote from: paeion on May 14, 2022, 10:14:25 am ---Thank you for your reply Kleinstein, it is reassuring to be on track!

For reference I am using the ESP32 micro, which unfortunately does not have a built-in comparator (as far as I know), but does feature a useful pulse counter for rising/falling edges. My idea for directly triggering interrupts was to determine the rotation direction (based on the time differences between the rising/falling edges) and using a hardware timer to determine the RPM directly.

My experimentation with I2C let me sample relatively quick (> 1000Hz), however I could not detect the 0<–>360° transition reliably in software. I will take on the idea of 2 comparators for low RPMs!

--- End quote ---


do you need to get each transition or do you just need to keep an accurate count of the angle over multiple rations?

 you can add the difference between last and current angle to an angle variable and it'll be accurate as long long as you sample faster than 180deg can pass (so you can detect the wrap)

Navigation

[0] Message Index

[#] Next page

There was an error while thanking
Thanking...
Go to full version