cancel
Showing results for 
Search instead for 
Did you mean: 

DC Motor PID control with Hall efect sensor for position

MAvet.1
Associate II

Hi everyone please help for creat project ,

I'm new here and this area. I have stm32f103c8 and i want to control dc motor

can anyone help me to write code for control dc motor with hall encoder (PID control) thank's

1 ACCEPTED SOLUTION

Accepted Solutions
PBo
Associate III

​@MAvet.1​ 

Hello,

FYI, the actual MCSDK 5.4.4 release provides a Position Control using a Maxon Motor as an example project into it. Unfortunately, it is not your targeted MCU, as it is a STM32F303 MCU used, but you may find inspiration from this example to serve your application as it uses HALL sensors and Encoder.

Best Regards,

PBo

View solution in original post

10 REPLIES 10
Luca1
Senior

Hi,

i don't have much experience in the STM32 enviroments, but i know very well the control system world.

Basically you need to implements a control loop. You need a module to acquire the sensor signal (the hall effect sensor), a module to apply the control signal (the input of your motor driver, that is not the output of the PID) and a module to implement the PID control law. You may also need a module to implemente the reference position..

All this module need to run in an hard realtime enviroment, so you need also a RTOS or other hard realtime enviroment (like interrupts) to implements the control loop.

The most problematic thing in the control loop is the controller, i hope that you know how it is done mathematically and how you find the parameters, the sampling time...

How you write the code? This is the pseudo code for the control loop:

while(1){

acquireReferenceSignal()

acquireSensorSignal() // hall sensor

calculateError()

calculateControlSignal() // PID

applyControlSignal()

while(!sampleTime) ;

}

This is all!

PS

Are you sure that the hall effect sensor measure the position of the DC motor? I think that the hall effect sensor measure the speed and not the position. If you need to control the position you need to integrate the speed and this is not a good idea..

yes i already control the motor position with hall sensor, but its code for arduino, i want to convert my code in stm32, controller can read signal from Hall sensor and have matematics function its will make signal compare , through which the desired result is obtained

my problems its a convert and PID architecture for stm32 if have example or more please send me

thanks for answer and info

for code i use stmcube ide (C++)

without PID control motor does not stand smoothly after rotation

Hi!

i'm sorry but i can't help you with the stm32 code because i'm new of stm32 enviroments.

okay thanks ))

Laurent Ca...
Lead II

Dear @MAvet.1​ 

Do you have still this problem to solve?

Best regards

Laurent Ca...

PBo
Associate III

​@MAvet.1​ 

Please, could you confirm if you start from our Position Control algorithm example ?

Best Regards,

PBo

Laurent Ca...
Lead II

Dear @MAvet.1​ 

Any news?

Best regards

Laurent Ca...

MAvet.1
Associate II

not resolved yet