Hello,
I have designed my own PCB consisting of an STM32G431CBT6 and two DRV8874PWPR H-bridges, which I operate in PWM mode. I have already managed to get the stepper motor running in open-loop mode. The problem I am facing is that the two H-bridges get extremely hot at a relatively low current (500 mA total). However, when I drive the motor with the Arduino library Stepper.h
, I can operate the motor with 2-3A without significant heating. Therefore, I suspect the issue might be with the code or the library. Does anyone have an idea what this could be? I would really appreciate any help!
Here the Arduino-Code:
#include “stm32g4xx_hal.h”
#include “stm32g4xx_hal_rcc.h”
#include “usbd_cdc_if.h”
#include “usbd_cdc.h”
#include <SimpleFOC.h>
#undef HSE_VALUE
#define HSE_VALUE ((uint32_t)8000000) // set 8 MHz external ceramic resonator frequency
#define PHASE_A_PIN1 PA3
#define PHASE_A_PIN2 PA2
#define PHASE_B_PIN1 PA1
#define PHASE_B_PIN2 PA0
PCD_HandleTypeDef hpcd_USB_FS;
StepperMotor motor = StepperMotor(50);
StepperDriver4PWM driver = StepperDriver4PWM(PHASE_A_PIN1, PHASE_A_PIN2, PHASE_B_PIN1, PHASE_B_PIN2);
void SystemClock_Config(void);
static void MX_GPIO_Init(void);
static void MX_USB_PCD_Init(void);
void setup() {
// put your setup code here, to run once:
HAL_Init();
SystemClock_Config();
MX_GPIO_Init();
MX_USB_PCD_Init();
pinMode(PB11, OUTPUT);
pinMode(PA4, OUTPUT);
pinMode(PA5, OUTPUT);
pinMode(PA6, OUTPUT);
pinMode(PA7, OUTPUT);
digitalWrite(PA4, HIGH); // disable sleep mode of H-bridge 1
digitalWrite(PA6, HIGH); // disable sleep mode of H-bridge 2
digitalWrite(PA7, HIGH); // set mode to pwm-mode of H-bridge 1
digitalWrite(PA5, HIGH); // set mode to pwm-mode of H-bridge 2
driver.voltage_power_supply = 12;
driver.pwm_frequency = 25000;
driver.init();
motor.linkDriver(&driver);
motor.voltage_limit = 8;
motor.controller = MotionControlType::velocity_openloop;
motor.foc_modulation = FOCModulationType::SpaceVectorPWM;
motor.init();
motor.initFOC();
motor.target = 15;
}
void loop() {
motor.loopFOC();
motor.move();
}
void SystemClock_Config(void) {
RCC_OscInitTypeDef RCC_OscInitStruct = { 0 };
RCC_ClkInitTypeDef RCC_ClkInitStruct = { 0 };
/** Configure the main internal regulator output voltage */
HAL_PWREx_ControlVoltageScaling(PWR_REGULATOR_VOLTAGE_SCALE1);
/** Initializes the RCC Oscillators according to the specified parameters
- in the RCC_OscInitTypeDef structure.
*/
RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI | RCC_OSCILLATORTYPE_HSE;
RCC_OscInitStruct.HSEState = RCC_HSE_ON;
RCC_OscInitStruct.HSIState = RCC_HSI_ON;
RCC_OscInitStruct.HSICalibrationValue = RCC_HSICALIBRATION_DEFAULT;
RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSE;
RCC_OscInitStruct.PLL.PLLM = RCC_PLLM_DIV1;
RCC_OscInitStruct.PLL.PLLN = 12;
RCC_OscInitStruct.PLL.PLLP = RCC_PLLP_DIV2;
RCC_OscInitStruct.PLL.PLLQ = RCC_PLLQ_DIV2;
RCC_OscInitStruct.PLL.PLLR = RCC_PLLR_DIV2;
if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK) {
// Error_Handler();
}
/** Initializes the CPU, AHB and APB buses clocks */
RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK | RCC_CLOCKTYPE_SYSCLK
| RCC_CLOCKTYPE_PCLK1 | RCC_CLOCKTYPE_PCLK2;
RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_HSI;
RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV1;
RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV1;
if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_0) != HAL_OK) {
// Error_Handler();
}
}
static void MX_USB_PCD_Init(void)
{
/* USER CODE BEGIN USB_Init 0 */
/* USER CODE END USB_Init 0 */
/* USER CODE BEGIN USB_Init 1 */
/* USER CODE END USB_Init 1 /
hpcd_USB_FS.Instance = USB;
hpcd_USB_FS.Init.dev_endpoints = 8;
hpcd_USB_FS.Init.speed = PCD_SPEED_FULL;
hpcd_USB_FS.Init.phy_itface = PCD_PHY_EMBEDDED;
hpcd_USB_FS.Init.Sof_enable = DISABLE;
hpcd_USB_FS.Init.low_power_enable = DISABLE;
hpcd_USB_FS.Init.lpm_enable = DISABLE;
hpcd_USB_FS.Init.battery_charging_enable = DISABLE;
if (HAL_PCD_Init(&hpcd_USB_FS) != HAL_OK)
{
// Error_Handler();
}
/ USER CODE BEGIN USB_Init 2 /
HAL_PCD_Start(&hpcd_USB_FS);
/ USER CODE END USB_Init 2 */
}
static void MX_GPIO_Init(void)
{
__HAL_RCC_GPIOF_CLK_ENABLE();
__HAL_RCC_GPIOA_CLK_ENABLE();
}