Skip to content

Commit a076ca7

Browse files
committed
merge with dev
1 parent bd0e969 commit a076ca7

File tree

5 files changed

+40
-5
lines changed

5 files changed

+40
-5
lines changed

src/BLDCMotor.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -525,7 +525,7 @@ void BLDCMotor::setPhaseVoltage(float Uq, float Ud, float angle_el) {
525525
Ub -= Umin;
526526
Uc -= Umin;
527527
}
528-
528+
driver->setPhaseState(PhaseState::PHASE_ON, PhaseState::PHASE_ON, PhaseState::PHASE_ON);
529529
break;
530530

531531
case FOCModulationType::SpaceVectorPWM :
@@ -611,6 +611,7 @@ void BLDCMotor::setPhaseVoltage(float Uq, float Ud, float angle_el) {
611611
Ua = Ta*driver->voltage_limit;
612612
Ub = Tb*driver->voltage_limit;
613613
Uc = Tc*driver->voltage_limit;
614+
driver->setPhaseState(PhaseState::PHASE_ON, PhaseState::PHASE_ON, PhaseState::PHASE_ON);
614615
break;
615616

616617
}

src/drivers/hardware_api.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,4 +176,5 @@ void _writeDutyCycle4PWM(float dc_1a, float dc_1b, float dc_2a, float dc_2b, vo
176176
*/
177177
void _writeDutyCycle6PWM(float dc_a, float dc_b, float dc_c, PhaseState *phase_state, void* params);
178178

179+
179180
#endif

src/drivers/hardware_specific/generic_mcu.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,3 +122,13 @@ __attribute__((weak)) void _writeDutyCycle6PWM(float dc_a, float dc_b, float dc
122122
_UNUSED(phase_state);
123123
_UNUSED(params);
124124
}
125+
126+
// Function setting the phase state. i.e. active / disabled
127+
// - BLDC driver - 6PWM setting
128+
// - hardware specific
129+
__attribute__((weak)) void _setPhaseState(int sa, int sb, int sc, void* params){
130+
_UNUSED(sa);
131+
_UNUSED(sb);
132+
_UNUSED(sc);
133+
_UNUSED(params);
134+
}

src/drivers/hardware_specific/stm32/stm32_mcu.cpp

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -297,6 +297,9 @@ STM32DriverParams* _initHardware6PWMPair(long PWM_freq, float dead_zone, PinMap*
297297
LL_TIM_CC_EnableChannel(HT->getHandle()->Instance, getLLChannel(pinH) | getLLChannel(pinL));
298298
HT->pause();
299299

300+
// make sure timer output goes to LOW when timer channels are temporarily disabled
301+
LL_TIM_SetOffStates(HT->getHandle()->Instance, LL_TIM_OSSI_DISABLE, LL_TIM_OSSR_ENABLE);
302+
300303
params->timers[paramsPos] = HT;
301304
params->timers[paramsPos+1] = HT;
302305
params->channels[paramsPos] = channel1;
@@ -772,16 +775,38 @@ void* _configure6PWM(long pwm_frequency, float dead_zone, const int pinA_h, cons
772775

773776

774777

778+
void _setSinglePhaseState(PhaseState state, HardwareTimer *HT, int channel1,int channel2) {
779+
_UNUSED(channel2);
780+
switch (state) {
781+
case PhaseState::PHASE_OFF:
782+
// Due to a weird quirk in the arduino timer API, pauseChannel only disables the complementary channel (e.g. CC1NE).
783+
// To actually make the phase floating, we must also set pwm to 0.
784+
HT->pauseChannel(channel1);
785+
break;
786+
default:
787+
HT->resumeChannel(channel1);
788+
break;
789+
}
790+
}
775791

776792

777793
// Function setting the duty cycle to the pwm pin (ex. analogWrite())
778794
// - BLDC driver - 6PWM setting
779795
// - hardware specific
780-
void _writeDutyCycle6PWM(float dc_a, float dc_b, float dc_c, PhaseState *phase_state, void* params){
796+
void _writeDutyCycle6PWM(float dc_a, float dc_b, float dc_c, PhaseState* phase_state, void* params){
781797
switch(((STM32DriverParams*)params)->interface_type){
782798
case _HARDWARE_6PWM:
799+
// phase a
800+
_setSinglePhaseState(phase_state[0], ((STM32DriverParams*)params)->timers[0], ((STM32DriverParams*)params)->channels[0], ((STM32DriverParams*)params)->channels[1]);
801+
if(phase_state[0] == PhaseState::PHASE_OFF) dc_a = 0.0f;
783802
_setPwm(((STM32DriverParams*)params)->timers[0], ((STM32DriverParams*)params)->channels[0], _PWM_RANGE*dc_a, _PWM_RESOLUTION);
803+
// phase b
804+
_setSinglePhaseState(phase_state[1], ((STM32DriverParams*)params)->timers[2], ((STM32DriverParams*)params)->channels[2], ((STM32DriverParams*)params)->channels[3]);
805+
if(phase_state[1] == PhaseState::PHASE_OFF) dc_b = 0.0f;
784806
_setPwm(((STM32DriverParams*)params)->timers[2], ((STM32DriverParams*)params)->channels[2], _PWM_RANGE*dc_b, _PWM_RESOLUTION);
807+
// phase c
808+
_setSinglePhaseState(phase_state[2], ((STM32DriverParams*)params)->timers[4], ((STM32DriverParams*)params)->channels[4], ((STM32DriverParams*)params)->channels[5]);
809+
if(phase_state[2] == PhaseState::PHASE_OFF) dc_c = 0.0f;
785810
_setPwm(((STM32DriverParams*)params)->timers[4], ((STM32DriverParams*)params)->channels[4], _PWM_RANGE*dc_c, _PWM_RESOLUTION);
786811
break;
787812
case _SOFTWARE_6PWM:
@@ -819,8 +844,6 @@ void _writeDutyCycle6PWM(float dc_a, float dc_b, float dc_c, PhaseState *phase_s
819844

820845

821846

822-
823-
824847
#ifdef SIMPLEFOC_STM32_DEBUG
825848

826849
int getTimerNumber(int timerIndex) {

src/drivers/hardware_specific/stm32/stm32_mcu.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
// default pwm parameters
88
#define _PWM_RESOLUTION 12 // 12bit
9-
#define _PWM_RANGE 4095.0 // 2^12 -1 = 4095
9+
#define _PWM_RANGE 4095.0f // 2^12 -1 = 4095
1010
#define _PWM_FREQUENCY 25000 // 25khz
1111
#define _PWM_FREQUENCY_MAX 50000 // 50khz
1212

0 commit comments

Comments
 (0)