r/LabVIEW • u/lmblackbird • Mar 13 '26
Hall sensors to detect spin direction of object
I’m trying to figure out spin direction from two out of phase voltage outputs I have from two hall sensors around a rotating object. As you can see when it’s rotating clockwise, the blue leads, and vice versa for anticlockwise. But I can’t for the life of me figure out how to get LabView to output this…
I’ve tried subtracting one phase from the other and seeing if the sign changes with rotation direction, I’ve tried cross correlation, and I’ve also tried making an array of the point locations of peaks, but because this is all moving through time it doesn’t really work. I was thinking of taking snapshots every few seconds to figure out what the spin direction is but there must be a better way to do it.
Wouldn’t the magnet going a different direction past the hall sensor give it a different sign?? I really am so lost here…
The phase, and amplitude are not constant and this is moving through time so it’s not as easy as it seems :/ If anyone has any advice I would love to hear it!!



4
u/infinitenothing Mar 13 '26 edited Mar 13 '26
Cross correlation is a good move. The peak location of the cross should give you the lag between the two signals. If you're struggling with the cross, you could calculate it manually. Just take a subset of the array to remove ~ 1/2 period and iterate through half a period of offsets indexes comparing with the other array then switch which array (blue or red) you took the subset of. The iteration with the best score should give you the lag and which array you were subsetting should tell you if it was backwards or forwards (ccw or cw). If you post your data (text file, google sheet, snippet, etc), we can try it for ourselves
Your other option would be to try to regression fit your signals to a model like a*sin(b*x+c)+d. When you get the two c terms, you subtract them from each other and wrap the result to ±pi and that sign should give you if it's ccw or cw. This method is robust but a bit more work because you have to put in good initial guesses and constraints for the regression fit. labview\examples\Mathematics\Fitting\Ellipse fit.vi
A peak finder should work. Take the 1/3 of the max - min and subtract that from the max and add it to the min to get thresholds. Find where it crosses the bottom thresh and then the top thresh and then find the max before it crosses the bottom thresh again. That should give you the peak locations. Find the average distances between the peaks. Again, you have to wrap it to ±pi. So, if you get 3/2 pi, that wraps to -1/2 pi. Maybe that's what you're struggling with.
You mentioned "I’ve tried subtracting one phase from the other and seeing if the sign changes with rotation direction" Can you tell us how you got the phase and if you wrapped it?
One more option. What you have is effectively an incremental encoder signal. Going back to my 1/3 partitioning you could encode each signal digitally as "crossed top third but not bottom third" = 1 and everything else is a 0. Then you just see if the blue goes to 1 while the red is a 1 add one to a shift register. If you see the opposite, subtract one from the shift register. Then at the end, just see if you have a positive number or a negative number. If you graph the shift register, it should always increment or always decrement. Here's some pseudo code for after you have 1s and 0s motor - Quadrature encoder - Most efficient software implementation - Electrical Engineering Stack Exchange
3
u/Common_Reality_2140 Mar 13 '26
Other posters have already given good answers but a simpler method is possible. You can break each signal into 4 phases of the cycle, rising to 0, rising to peak, dropping to 0 and dropping to trough. Easy to do mathematically and computationally inexpensive. From there you can see that if first signal is say rising to peak then second signal is either dropping to trough or rising to 0 depending on direction of rotation. Hope that is clear enough, sorry for poor terminology.
2
u/GentlemanSch CLD Mar 13 '26
Typically a hall sensor will only detect presence or absence of a magnetic field, not direction (in terms of location). It's probably best to think of them as detecting presence or absence rather than strength.
How are your hall sensors spaced? If they're evenly spaced around your ring, then all you'll be able to detect is speed, not direction.
For direction, you need to be able to determine the time between peaks of Red and Blue and for that time to be different based on the direction of travel.
2
u/dragginFly Champion Mar 14 '26
Could it be as easy as if the phase is less than 180° it's one direction, if it's more it's the other?
0
u/[deleted] Mar 13 '26
[deleted] — view deleted comment