Skip to content

Commit ef7fc75

Browse files
Merge pull request #72 from Moddingear/stspin32_startup
stspin32g4: Add bootstrap capacitor charge mode on enable to avoid high side UVLO error on enable
2 parents c3b7306 + 28242ce commit ef7fc75

2 files changed

Lines changed: 41 additions & 1 deletion

File tree

src/drivers/stspin32g4/STSPIN32G4.cpp

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,45 @@ int STSPIN32G4::init(){
3737

3838
// TODO init fault monitor
3939

40+
bootstrap_charge();
41+
4042
return isReady() ? 1 : 0;
4143
};
4244

43-
45+
void STSPIN32G4::enable()
46+
{
47+
bootstrap_charge();
48+
BLDCDriver6PWM::enable();
49+
}
50+
51+
52+
void STSPIN32G4::bootstrap_charge()
53+
{
54+
//store phase states, enable low side drive
55+
static const int num_phases = sizeof(phase_state)/sizeof(phase_state[0]);
56+
PhaseState phase_state_before[num_phases];
57+
bool none_disabled = true;
58+
for (size_t i = 0; i < num_phases; i++)
59+
{
60+
phase_state_before[i] = phase_state[i];
61+
if (phase_state[i] == PHASE_HI || phase_state[i] == PHASE_OFF)
62+
{
63+
none_disabled = false;
64+
}
65+
}
66+
if (none_disabled)
67+
{
68+
return;
69+
}
70+
setPhaseState(PHASE_LO, PHASE_LO, PHASE_LO);
71+
setPwm(0,0,0);
72+
_delay(bootstrap_capacitor_charge_time);
73+
//restore phase states
74+
for (size_t i = 0; i < num_phases; i++)
75+
{
76+
phase_state[i] = phase_state_before[i];
77+
}
78+
}
4479

4580
void STSPIN32G4::wake() {
4681
digitalWrite(STSPIN32G4_PIN_WAKE, HIGH);

src/drivers/stspin32g4/STSPIN32G4.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,8 +116,13 @@ class STSPIN32G4 : public BLDCDriver6PWM {
116116
STSPIN32G4();
117117
~STSPIN32G4();
118118

119+
unsigned int bootstrap_capacitor_charge_time = 10; //time to let the bootstrap capacitors charge for, in ms. During his time, brakes are applied. This is not necessary if the motor is rotating, as the BEMF allows the caps to charge.
120+
119121
int init() override;
120122

123+
void enable() override;
124+
125+
void bootstrap_charge();
121126
void wake();
122127
void sleep();
123128
bool isReady();

0 commit comments

Comments
 (0)