Skip to content

Commit f39e628

Browse files
committed
Update stm32_mcu.cpp
1 parent deba1dc commit f39e628

File tree

1 file changed

+16
-1
lines changed

1 file changed

+16
-1
lines changed

src/drivers/hardware_specific/stm32/stm32_mcu.cpp

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -680,7 +680,7 @@ void* _configure8PWM(long pwm_frequency, float dead_zone)
680680
// Enable clock for TIM1 and TIM8
681681
__HAL_RCC_TIM1_CLK_ENABLE();
682682
__HAL_RCC_TIM8_CLK_ENABLE();
683-
683+
__HAL_RCC_GPIOE_CLK_ENABLE();
684684
// Configure PE8, PE9, PE10, PE11, PE12, PE13 as TIM1 channels
685685
GPIO_InitStruct.Pin = GPIO_PIN_8 | GPIO_PIN_9 | GPIO_PIN_10 | GPIO_PIN_11 | GPIO_PIN_12 | GPIO_PIN_13;
686686
GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
@@ -730,6 +730,17 @@ void* _configure8PWM(long pwm_frequency, float dead_zone)
730730
{return (STM32DriverParams*)SIMPLEFOC_DRIVER_INIT_FAILED;
731731
}else{Serial.println("TIM8 INIT OK!");}
732732

733+
/*
734+
***************************************************
735+
Yes, those values should produce a 38kHz PWM signal.
736+
what should the value be for 50Khz PWM signal?
737+
The value for a 50kHz PWM signal would be: htim8.Init.Period = 3279;
738+
And 50Khz for this: TIM1->ARR = (168000000 / (38000 * 2)) - 1; // Set auto-reload value for 38kHz frequency is egual
739+
No, the equation should be changed to calculate the auto-reload value for a 50kHz frequency.
740+
The equation would be: TIM1->ARR = (168000000 / (50000 * 2)) - 1; // Set auto-reload value for 50kHz frequency
741+
*******************************************************************************************************************
742+
*/
743+
733744
sMasterConfig.MasterOutputTrigger = TIM_TRGO_RESET;
734745
sMasterConfig.MasterSlaveMode = TIM_MASTERSLAVEMODE_DISABLE;
735746
if (HAL_TIMEx_MasterConfigSynchronization(&htim1, &sMasterConfig)!= HAL_OK)
@@ -874,6 +885,7 @@ and they are used for driving push-pull outputs such as MOSFETs.
874885
TIM1->PSC = 0; // Set prescaler to 0
875886
TIM1->ARR = (168000000 / (38000 * 2)) - 1; // Set auto-reload value for 38kHz frequency
876887
TIM1->CCR1 = 0; // Set duty cycle to 0%
888+
TIM1->CCR2 = 0; // Set duty cycle to 0%
877889
TIM1->CCR3 = 0; // Set duty cycle to 0%
878890
TIM1->CCR4 = 0; // Set duty cycle to 0%
879891
TIM1->BDTR |= TIM_BDTR_MOE; // Main output enable
@@ -886,6 +898,9 @@ and they are used for driving push-pull outputs such as MOSFETs.
886898
TIM8->PSC = 0; // Set prescaler to 0
887899
TIM8->ARR = (168000000 / (38000 * 2)) - 1; // Set auto-reload value for 38kHz frequency
888900
TIM8->CCR1 = 0; // Set duty cycle to 0%
901+
TIM8->CCR2 = 0; // Set duty cycle to 0%
902+
TIM8->CCR3 = 0; // Set duty cycle to 0%
903+
TIM8->CCR4 = 0; // Set duty cycle to 0%
889904
TIM8->BDTR |= TIM_BDTR_MOE; // Main output enable
890905

891906
// Start TIM1 and TIM8 PWM outputs

0 commit comments

Comments
 (0)