@@ -680,7 +680,7 @@ void* _configure8PWM(long pwm_frequency, float dead_zone)
680
680
// Enable clock for TIM1 and TIM8
681
681
__HAL_RCC_TIM1_CLK_ENABLE ();
682
682
__HAL_RCC_TIM8_CLK_ENABLE ();
683
-
683
+ __HAL_RCC_GPIOE_CLK_ENABLE ();
684
684
// Configure PE8, PE9, PE10, PE11, PE12, PE13 as TIM1 channels
685
685
GPIO_InitStruct.Pin = GPIO_PIN_8 | GPIO_PIN_9 | GPIO_PIN_10 | GPIO_PIN_11 | GPIO_PIN_12 | GPIO_PIN_13;
686
686
GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
@@ -730,6 +730,17 @@ void* _configure8PWM(long pwm_frequency, float dead_zone)
730
730
{return (STM32DriverParams*)SIMPLEFOC_DRIVER_INIT_FAILED;
731
731
}else {Serial.println (" TIM8 INIT OK!" );}
732
732
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
+
733
744
sMasterConfig .MasterOutputTrigger = TIM_TRGO_RESET;
734
745
sMasterConfig .MasterSlaveMode = TIM_MASTERSLAVEMODE_DISABLE;
735
746
if (HAL_TIMEx_MasterConfigSynchronization (&htim1, &sMasterConfig )!= HAL_OK)
@@ -874,6 +885,7 @@ and they are used for driving push-pull outputs such as MOSFETs.
874
885
TIM1->PSC = 0 ; // Set prescaler to 0
875
886
TIM1->ARR = (168000000 / (38000 * 2 )) - 1 ; // Set auto-reload value for 38kHz frequency
876
887
TIM1->CCR1 = 0 ; // Set duty cycle to 0%
888
+ TIM1->CCR2 = 0 ; // Set duty cycle to 0%
877
889
TIM1->CCR3 = 0 ; // Set duty cycle to 0%
878
890
TIM1->CCR4 = 0 ; // Set duty cycle to 0%
879
891
TIM1->BDTR |= TIM_BDTR_MOE; // Main output enable
@@ -886,6 +898,9 @@ and they are used for driving push-pull outputs such as MOSFETs.
886
898
TIM8->PSC = 0 ; // Set prescaler to 0
887
899
TIM8->ARR = (168000000 / (38000 * 2 )) - 1 ; // Set auto-reload value for 38kHz frequency
888
900
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%
889
904
TIM8->BDTR |= TIM_BDTR_MOE; // Main output enable
890
905
891
906
// Start TIM1 and TIM8 PWM outputs
0 commit comments