cancel
Showing results for 
Search instead for 
Did you mean: 

Help setting the comparator for the timer brake. Internal connection between the comp and TIM1 with complementary outputs

MGrod
Associate

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


_legacyfs_online_stmicro_images_0693W00000bid4IQAQ.png 


_legacyfs_online_stmicro_images_0693W00000bid4NQAQ.png 


_legacyfs_online_stmicro_images_0693W00000bid4SQAQ.png
_legacyfs_online_stmicro_images_0693W00000bid4XQAQ.png

1 ACCEPTED SOLUTION

Accepted Solutions
MGrod
Associate

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

View solution in original post

1 REPLY 1
MGrod
Associate

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