【Underwater Thruster Control】 How to control ESC by PWM with STM32?

Posted by Fengyukun on

A lot of researchers who want to control the operation of the thruster with a microcontroller to find a lot of information on the Internet, but found that a lot of them are not written very clearly, APISQUEEN roughly record how to solve.
I hope you can exchange experience in the comments section, can help more people.
We buy the ESC may be different, but the overall control idea is the same, so I believe you can certainly achieve your goal after reading this article.

PWM signal:
(1) PWM wave control (generally speaking ESCs are controlled by PWM wave at 50Hz, that is 20ms);
(2) Medium stop (here generally refers to the high level of the duty cycle) 1.5ms, actually between 1.475ms to 1.525ms are out of the medium stop;
(3) The control range is from 1ms to 2ms;
(4) 1.5ms to 2ms forward, 1.5ms to 1ms reverse.

Here is an Arduino based one for a brief reference:

Note: The ESC needs to be unlocked before it can be used! The ESC will beep 3 times when you connect it to the power supply, and then it will beep 2 times when it is successfully unlocked, for a total of 5 times. If you don't unlock the ESC successfully, you can't use it for control. Therefore, referring to the above code, we can conclude that the way to unlock the ESC is to set it to the neutral signal after initialisation, and wait for the signal to be received (two beeps) before you can start speed control.


Control and debugging method


We are using the STM32F7 development board, using the HAL library for programming and debugging, is actually a timer output PWM wave. But there are a lot of things to pay attention to, a lot of details are not clear really delayed time and energy, this side of the debugging experience to say a few words.

First of all, when configuring the PWM wave in the timer, be careful not to initialise it as your unlock signal, give him a random value, or either do not configure. Because the ESC is unlocked only after the timer as well as the PWM is initialised, take this one of mine as an example, the 1.5ms median stop signal is its unlock signal, then you can't configure the PWM to be 1.5ms from the start, otherwise the ESC will only be ringing once after three beeps of the power on and then your paddles still won't turn.

Secondly, pay attention to the use of delay. At the beginning, I did not use a delay, the result is that the ESC only beeped and then there is no response, and then when I observed the PWM wave with an oscilloscope, I found that my initialised PWM flashed directly, which needs to be given to the ESC to receive the unlock signal time. But this time is also to pay attention to, at first I was using the delay_us () configuration, the problem can not be solved, and then changed to delay_ms (1000), that is, configure the time of 1s, there is still a problem, and then the time to be adjusted again after the final heard two beeps, and then the motor began to rotate. So how to grasp the reception time of this unlock signal is very important.

And also take care to learn to work with an oscilloscope to check if there are any problems with the signals you have configured during use. Below is a PWM wave with 1.5ms duty cycle, 20ms period and 3.3V amplitude that I initialised at the beginning.

To summarise, the whole process should be noted:

(1) The ESC is generally controlled at a frequency of 50Hz, and the control range is roughly between 1ms and 2ms, depending on the circumstances of course.
(2) After connecting the power, the ESC will sound 3 times, and if you unlock it successfully, the ESC will sound 2 times after that. However, if the ESC only beeps once, it probably means that the ESC has received the signal you configured, but did not unlock the device successfully, so you need to double-check your unlocking code to see if there is any mistake. If the ESC doesn't sound, then it doesn't even receive the signal, check your wiring and code carefully.
(3) Pay attention to the use of delay function to give the ESC a certain amount of time to receive the unlock signal, each ESC is different, adjust this yourself.
(4) Pay attention to the ground, the ESC signal line to the signal output port of the control board, and then the signal line ground to the control board GND.
(5) Learn to use an oscilloscope to check the signals you have configured.
(6) Don't connect the wrong wire!


Share this post



← Older Post Newer Post →


0 comments

Leave a comment