@@ -297,6 +297,9 @@ STM32DriverParams* _initHardware6PWMPair(long PWM_freq, float dead_zone, PinMap*
297
297
LL_TIM_CC_EnableChannel (HT->getHandle ()->Instance , getLLChannel (pinH) | getLLChannel (pinL));
298
298
HT->pause ();
299
299
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
+
300
303
params->timers [paramsPos] = HT;
301
304
params->timers [paramsPos+1 ] = HT;
302
305
params->channels [paramsPos] = channel1;
@@ -772,16 +775,38 @@ void* _configure6PWM(long pwm_frequency, float dead_zone, const int pinA_h, cons
772
775
773
776
774
777
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
+ }
775
791
776
792
777
793
// Function setting the duty cycle to the pwm pin (ex. analogWrite())
778
794
// - BLDC driver - 6PWM setting
779
795
// - 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){
781
797
switch (((STM32DriverParams*)params)->interface_type ){
782
798
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 ;
783
802
_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 ;
784
806
_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 ;
785
810
_setPwm (((STM32DriverParams*)params)->timers [4 ], ((STM32DriverParams*)params)->channels [4 ], _PWM_RANGE*dc_c, _PWM_RESOLUTION);
786
811
break ;
787
812
case _SOFTWARE_6PWM:
@@ -819,8 +844,6 @@ void _writeDutyCycle6PWM(float dc_a, float dc_b, float dc_c, PhaseState *phase_s
819
844
820
845
821
846
822
-
823
-
824
847
#ifdef SIMPLEFOC_STM32_DEBUG
825
848
826
849
int getTimerNumber (int timerIndex) {
0 commit comments