cancel
Showing results for 
Search instead for 
Did you mean: 

[STSPIN32G4] How to individually drive gate driver outputs (for testing purposes)

ALedi.1
Associate III

Hello, I want to flash a FW to my STSPIN32G4 custom boards that tests each phase FET individually by switching through the different high- and lowside FETs one per one. Is there an easy way to do this? Any help is appreciated.

PS:

All I found is a function to turn on all lowsidefets:

0693W00000QONq2QAH.png 

For the highside switches I know its more complicated because the bootstrap caps first need to be charged.

I also found this init function:

0693W00000QONqqQAH.pngAll I need is a code snippet to change the output state of those 6 pins from low to high and vice versa. Thanks! 🙂

1 ACCEPTED SOLUTION

Accepted Solutions
Fred V.
ST Employee

Hello,

There is an easy way to do what you want to do provided that it is only for testing purposes and not for actually driving a motor: you need to reconfigure the 6 pins that drive the 6 FETs as pure GPIOs. Doing this will allow you to individually drive each of them, as GPIOs.

Beware! This can be dangerous if you have a motor (or another power equipment) plugged to your hardware, after your FETs: if one or more high side FET is driving for too long or if you close both the high and the low side FET of a phase at the same time, you may experience high currents flowing through your system that may damage or even destroy it. Also, this kind of situation can be dangerous for anyone physically near to the hardware setup.

The code extracts that you highlight in your question do not directly control the FETs. They actually interface an Advanced Timer (most probably TIM1, but it depends on what timer is referenced by the TIMx variable) that does control the FETs. Advanced Timers on STM32 devices can handle both the High and the Low sides for driving a motor phase. They feature at least three channels that allow for handling the three phases of a motor.

When configured to do so, each of the three channels of an Advanced Timer is assigned a duty cycle (on each PWM period) and will toggle the high and low side switches according to this duty cycle.

This is done by the calls to the LL_TIM_OC_SetCompareCh*() functions visible in your code extracts. When setting the duty cycle to 0 for all phases (as in the first code extract), you make sure that the three low sides are closed, while the three high sides are open. Controlling the FETs through the timer means controlling both the high and the low side FETs of a phase at the same time. This prevents hazardous short circuits from happening.

A dead time is configured in the timer to prevent short circuits that can occur when switching a phase from Bus to Ground and vice versa. Also, the BREAKIN2 Timer input can be used to stop energizing the phases when an over current (or over voltage, or any other fault) occurs.

All this information is detailed in the Reference Manual of the STM32G4 devices which is available here: https://www.st.com/resource/en/reference_manual/rm0440-stm32g4-series-advanced-armbased-32bit-mcus-stmicroelectronics.pdf. Aim for chapter 28 - Advanced-control timers, from page 1084 onwards, for a complete description of the features of these timers.

In the hope it will help you.

Best Regards,

Fred.

View solution in original post

5 REPLIES 5
Fred V.
ST Employee

Hello,

There is an easy way to do what you want to do provided that it is only for testing purposes and not for actually driving a motor: you need to reconfigure the 6 pins that drive the 6 FETs as pure GPIOs. Doing this will allow you to individually drive each of them, as GPIOs.

Beware! This can be dangerous if you have a motor (or another power equipment) plugged to your hardware, after your FETs: if one or more high side FET is driving for too long or if you close both the high and the low side FET of a phase at the same time, you may experience high currents flowing through your system that may damage or even destroy it. Also, this kind of situation can be dangerous for anyone physically near to the hardware setup.

The code extracts that you highlight in your question do not directly control the FETs. They actually interface an Advanced Timer (most probably TIM1, but it depends on what timer is referenced by the TIMx variable) that does control the FETs. Advanced Timers on STM32 devices can handle both the High and the Low sides for driving a motor phase. They feature at least three channels that allow for handling the three phases of a motor.

When configured to do so, each of the three channels of an Advanced Timer is assigned a duty cycle (on each PWM period) and will toggle the high and low side switches according to this duty cycle.

This is done by the calls to the LL_TIM_OC_SetCompareCh*() functions visible in your code extracts. When setting the duty cycle to 0 for all phases (as in the first code extract), you make sure that the three low sides are closed, while the three high sides are open. Controlling the FETs through the timer means controlling both the high and the low side FETs of a phase at the same time. This prevents hazardous short circuits from happening.

A dead time is configured in the timer to prevent short circuits that can occur when switching a phase from Bus to Ground and vice versa. Also, the BREAKIN2 Timer input can be used to stop energizing the phases when an over current (or over voltage, or any other fault) occurs.

All this information is detailed in the Reference Manual of the STM32G4 devices which is available here: https://www.st.com/resource/en/reference_manual/rm0440-stm32g4-series-advanced-armbased-32bit-mcus-stmicroelectronics.pdf. Aim for chapter 28 - Advanced-control timers, from page 1084 onwards, for a complete description of the features of these timers.

In the hope it will help you.

Best Regards,

Fred.

thank you for the answer! Now before I destroy anything on my board, I would double check that I did everything right. I started from the generated code from the workbench, opened the .IOC file, removed the motor control middleware and changed the 6 pins for the driver output to GPIO outputs as pulldown.

0693W00000StexZQAR.pngThen I generate code and just do like this?

0693W00000Stf4uQAB.pngHow about the bootstrap capacitors, for the high side I need to charge them and I dont know how long they can store the voltage after the lowside is turned off again. I need a few seconds to place the probes of the oscilloscope between the different FETs.

thanks!

Fred V.
ST Employee

You're welcome.

I do not have any details on your hardware design (and as a firmware person I would probably not understand all the subtleties of it), but I would like to warn you again against hazardous short circuits, especially with the pull-down configuration of all you FET driving GPIOs. Just make sure that pull-down will indeed ensure that the corresponding FETs will be open by default.

Now, if this is confirmed, then your code (second image) looks ok, in principle.

About the boot strap caps, I cannot help you. Knowing their capacity (µF), and the resistance (Ω) on the line, you need to compute their charging time/their charge. Then, you'll know how much time you have to make your measurements.

Best Regards,

Fred

ALedi.1
Associate III

just a quick update: I modified the code to activate the 3 lowside FETs simultaneously first, to charge the bootstraps while I am measuring, then the lowsides are turned off and after a delay off 100 µs the highsides are all 3 turned on. I only have a small time window of approx. 10 ms to measure the highside FETs because thats the time the bootstraps need to fully discharge, then the highside FETs are switching off again.

But the main function I wanted to implement is working and I consider this thread closed. Thanks again!

Szhen.11
Associate II

@Fred V.​  Hello, can you help me look at this problem. I also want to test the gate drive of STSpin32g4. I created an empty project through cubemx instead of mcsdk. I initialize the IO port of the gate as GPIO push-pull output, and then copy the stspin32g4. c. h generated by the MCSDK into my project. After initializing the gate drive, I control the IO of the gate, but the gate has not changed. The high side gate is always fully open, and the low side gate is fully closed.

Here is the initialization code for my grid driver.

  /*************************************************/
 
  /*  STSPIN32G4 driver component initialization */
 
  /*************************************************/
 
  STSPIN32G4_init( &HdlSTSPING4 );
 
  STSPIN32G4_reset( &HdlSTSPING4 );
 
  STSPIN32G4_setVCC( &HdlSTSPING4, (STSPIN32G4_confVCC){ .voltage = _12V,
 
                              .useNFAULT = true,
 
                              .useREADY = false } );
 
  STSPIN32G4_setVDSP( &HdlSTSPING4, (STSPIN32G4_confVDSP){ .deglitchTime = _4us,
 
                               .useNFAULT = true } );
 
  STSPIN32G4_clearFaults( &HdlSTSPING4 );
     while (1)
    {
                 /* Any combination */
		HAL_GPIO_WritePin(M1_PWM_UH_GPIO_Port, M1_PWM_UH_Pin, GPIO_PIN_RESET);
		HAL_GPIO_WritePin(M1_PWM_UL_GPIO_Port, M1_PWM_UL_Pin, GPIO_PIN_RESET);
		HAL_GPIO_WritePin(M1_PWM_VH_GPIO_Port, M1_PWM_VH_Pin, GPIO_PIN_RESET);
		HAL_GPIO_WritePin(M1_PWM_VL_GPIO_Port, M1_PWM_VL_Pin, GPIO_PIN_RESET);
		HAL_GPIO_WritePin(M1_PWM_WH_GPIO_Port, M1_PWM_WH_Pin, GPIO_PIN_RESET);
		HAL_GPIO_WritePin(M1_PWM_WL_GPIO_Port, M1_PWM_WL_Pin, GPIO_PIN_RESET);
		
    }