cancel
Showing results for 
Search instead for 
Did you mean: 

Determining Motor Position using one Hall Signal

sanctified
Associate II

Hello,

I am using the stm32f042k6t6 to control a Motor which has one Hall Signal. The motor is connected to a Jack which I drive in clockwise and anticlockwise direction, so in and out. The jacks start at a specific position and I want that when I drive the jacks back in after they have been driven out, it stops excatly at the start position.

In order to achieve this, the Hall Signal is connected to a GPIO pin configured in external interrupt mode. I therefore count the number of rising edges by incrementing a counter variable until i stop the motor.This represents tthe number of steps the motor has taken. When driving the jacks back in, I decrement the counter variable based on the number of rising edges. But this is clearly not the best approach because if i play around with starting and stopping the motor, and then drive the jacks back in until the counter gets to zero, the Jacks do not stop at the position it started from.

I configured a timer in input capture mode, to capture every rising edge, but i got the same result.

Could anyone give me a suggestion on the best approach? A link is also perfect, i dont mind reading.

I have attached the Information about the Hal signal. If more information is needed, please let me know

Thank you!

2 REPLIES 2
Jaroslav JANOS
ST Employee

Hello @sanctified,

the timers TIM1/2/3 have encoder mode for this purpose, with additional input filters to filter out noise, refer to chapters 17.3.16 and 18.3.12 in the reference manual for F042 (link).

BR,
Jaroslav

To give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.

######
Senior

" I want that when I drive the jacks back in after they have been driven out, it stops exactly at the start position"

What is your specification on this? Capturing rising edges only means that even with precise counting your position may be anywhere within one motor rotation, as you only get one pulse per rotation.

What type of motor & motor control are you using? Do you have PID or control system? Usually for really tight position control you would need a better motor position sensor (such as an optical encoder or resolver) or a large effective gear ratio between motor and screw, and then a cascaded multi-loop control system controlling motor drive, speed and final position,

Off the top of my head I would guess that because of the inertia of the system (mostly motor rotor?) decelerating, once you've counted your full count of steps, the motion is then carrying on as it decelerates, and overshoots from where it originally started. Can you setup a test that verifies the count from the Hall effect sensor is equal going out and then in?

Best of luck with it.