Skip to main content
MAvet.1
Associate II
June 22, 2020
Solved

DC Motor PID control with Hall efect sensor for position

  • June 22, 2020
  • 10 replies
  • 5277 views

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

This topic has been closed for replies.
Best answer by PBo

​@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

10 replies

Luca1
Associate III
June 22, 2020

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..

MAvet.1
MAvet.1Author
Associate II
June 22, 2020

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++)

Luca1
Associate III
June 22, 2020

Hi!

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

Laurent Ca...
Senior III
October 14, 2020

Dear @MAvet.1​ 

Do you have still this problem to solve?

Best regards

Laurent Ca...

PBo
Visitor II
October 22, 2020

​@MAvet.1​ 

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

Best Regards,

PBo

Laurent Ca...
Senior III
October 26, 2020

Dear @MAvet.1​ 

Any news?

Best regards

Laurent Ca...

MAvet.1
MAvet.1Author
Associate II
October 27, 2020

not resolved yet

PBo
PBoBest answer
Visitor II
October 27, 2020

​@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