2023-04-22 01:18 PM - edited 2023-11-20 07:25 AM
Hi, I'm setting up a custom board with STM32G431CBT6 to control a 6-step bldc motor. I want to use comparators to protect against overcurrent.
My problem I configured the bkin input and comparators. the bkin input works, the comparator also works separately (puts out an external signal).
But the PWM does not stop when the comparator is working. I can see the active output of the comparator, but it has no effect on the pwm.
I created a simple program to test this, no motor control, just complementary PWM.
I want it to work at the hardware level. Can someone tell me what I'm doing wrong?
I add screenshots and code.
MX_GPIO_Init();
MX_TIM1_Init();
MX_COMP1_Init();
MX_DAC1_Init();
/* USER CODE BEGIN 2 */
HAL_TIM_PWM_Start(&htim1, TIM_CHANNEL_1);
HAL_TIMEx_PWMN_Start( &htim1, TIM_CHANNEL_1 );
HAL_COMP_Start(&hcomp1);
HAL_DAC_SetValue(&hdac1, DAC_CHANNEL_2, DAC_ALIGN_12B_R, 4000);
HAL_DAC_Start(&hdac1, DAC1_CHANNEL_2);
HAL_DAC_SetValue(&hdac1, DAC_CHANNEL_1, DAC_ALIGN_12B_R, 4000);
HAL_DAC_Start(&hdac1, DAC1_CHANNEL_1);
Solved! Go to Solution.
2023-04-24 10:04 PM
I give the answer during tests of different polarities, there was a state that the PWM did not even start. no attention was paid to it. thinking that this is not the correct configuration.
instead, it was a correct configuration, but the comparator had an active state on restart, since it turned on in the code faster than the voltage reference from the DAC
2023-04-24 10:04 PM
I give the answer during tests of different polarities, there was a state that the PWM did not even start. no attention was paid to it. thinking that this is not the correct configuration.
instead, it was a correct configuration, but the comparator had an active state on restart, since it turned on in the code faster than the voltage reference from the DAC