cancel
Showing results for 
Search instead for 
Did you mean: 

Hi. I have a STM32F3Discovery card, from that i try to control a Blue Robotics Basic ESC and a M100 motor. I set it up using STM32CudeIDE for a 50Hz PWM signal on PA15. The problem is to send a 1500 microseconds initzialization signal. How do i do this?

MHelg.1
Associate II

Below are example code for Arduino provided in the Basic Esc documentation

#include <Servo.h>

byte servoPin = 9;

Servo servo;

void setup() {

servo.attach(servoPin);

servo.writeMicroseconds(1500); // send "stop" signal to ESC.

delay(7000); // delay to allow the ESC to recognize the stopped signal

}

void loop() {

int signal = 1700; // Set signal value, which should be between 1100 and 1900

servo.writeMicroseconds(signal); // Send signal to ESC.

}

This discussion is locked. Please start a new topic to ask your question.
7 REPLIES 7
KnarfB
Super User

__HAL_TIM_SET_COMPARE(&htim1, TIM_CHANNEL_1, pulse_width);

The pulse width depends on the timer prescaler and period. You might set the prescaler such that timer clock is 1MHz. Then a 50 Hz period corresponds to a period length of 20000 (µs). Note that everything counts from 0. So you set the upper limit to 20000-1 and the prescaler to e.g. 48-1 if the SysClock is 48 MHz.

hth

KnarfB

MHelg.1
Associate II

Thank you. I`ve set it up using 48MHz, Prescaler 47, Counter Period 19999 and Pulse 10000. I got a 50 Hz signal with period length 20000 µs.

Below are my code. I get a 1500 µs pulse (Initzialization signal) but i want a delay for 2 seconds and then give a 1700 µs to run the motor. This does not happen?

 /* USER CODE BEGIN 2 */

 HAL_TIM_PWM_Start(&htim2, TIM_CHANNEL_1); // Starter PWM

 /* USER CODE END 2 */

 /* Infinite loop */

 /* USER CODE BEGIN WHILE */

 while (1)

 {

 __HAL_TIM_SET_COMPARE(&htim2, TIM_CHANNEL_1, 1500);

 HAL_Delay(2000);

 __HAL_TIM_SET_COMPARE(&htim2, TIM_CHANNEL_1, 1700);

  /* USER CODE END WHILE */

Attached are oscilloscope print and motor diagram if needed.0693W000007CW3YQAW.png0693W000007CW3TQAW.png

Do you delay after the second setting? Should this be in a loop?

Scope isn't showing multiple seconds, diagram the waveform you actually want to see.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
MHelg.1
Associate II

I initialize a 1500 µs pulse and then delay for 2 seconds. I tried to move it outside the loop (see code below).

 /* USER CODE BEGIN 2 */

 HAL_TIM_PWM_Start(&htim2, TIM_CHANNEL_1); // Start PWM

 /* USER CODE END 2 */

 __HAL_TIM_SET_COMPARE(&htim2, TIM_CHANNEL_1, 1500); // Initialization signal

 HAL_Delay(2000); // Delay 2 seconds

 __HAL_TIM_SET_COMPARE(&htim2, TIM_CHANNEL_1, 1700); // Run motor

Still doesent change after 2 seconds to a 1700 µs pulse. Is it possible that i have reset the timer before sending a new signal?

No, you don't have to reset. The __HAL macro results in a single register write and that's fine.

Your code should work. Are you sure that the last line is reached, i.e. HAL_Delay is working okay (needs SysTick running, not in interrupt).

MHelg.1
Associate II

I tried to make a new prosject since i have change a lot of configurations during my troubleshooting.

Verifed the HAL_Delay on my oscilloscope, and now it changes to 1700 µs after 2 seconds!

Fantastic, but my motor wont run. If you guys cant fint anything wrong with my code i suspect the ESC to be defect..

Anyway thanks for your help

2 seconds delay 1700 µs0693W000007CWYMQA4.pngSTM32CubeIDE setup0693W000007CWYCQA4.png

KnarfB
Super User

ESC has typically a dead-zone around the neutral value (although your diagram doesn't show one). You could carefully try larger values or put the scope at the ESC output.

Announcement

We’re moving the ST Community to a new platform to give you a better and more reliable community experience.