diff --git a/stm32-stepper-root/stepper_h7/CM7/Core/Inc/Spindle/spindel.h b/stm32-stepper-root/stepper_h7/CM7/Core/Inc/Spindle/spindel.h index 243ec5f..c00e03b 100644 --- a/stm32-stepper-root/stepper_h7/CM7/Core/Inc/Spindle/spindel.h +++ b/stm32-stepper-root/stepper_h7/CM7/Core/Inc/Spindle/spindel.h @@ -2,6 +2,7 @@ #include "Spindle.h" #include "main.h" #include "FreeRTOS.h" +#include "openamp.h" #include SpindleHandle_t init_spindle(ConsoleHandle_t c, float maxRPM, float minRPM, float absMinRPM); diff --git a/stm32-stepper-root/stepper_h7/CM7/Core/Inc/main.h b/stm32-stepper-root/stepper_h7/CM7/Core/Inc/main.h index f2794cb..a22a4c1 100644 --- a/stm32-stepper-root/stepper_h7/CM7/Core/Inc/main.h +++ b/stm32-stepper-root/stepper_h7/CM7/Core/Inc/main.h @@ -108,6 +108,8 @@ void Error_Handler(void); /* USER CODE END Private defines */ +extern TIM_HandleTypeDef htim2; + #ifdef __cplusplus } #endif diff --git a/stm32-stepper-root/stepper_h7/CM7/Core/Src/Spindle/spindel.c b/stm32-stepper-root/stepper_h7/CM7/Core/Src/Spindle/spindel.c index a246947..7c1ac6d 100644 --- a/stm32-stepper-root/stepper_h7/CM7/Core/Src/Spindle/spindel.c +++ b/stm32-stepper-root/stepper_h7/CM7/Core/Src/Spindle/spindel.c @@ -17,25 +17,30 @@ SpindleHandle_t init_spindle(ConsoleHandle_t c, float maxRPM, float minRPM, floa static void SPINDLE_SetDutyCycle(SpindleHandle_t h, void* context, int backwards, float dutyCycle){ - //TODO: Herausfinden welcher Timer und diesen einstellen backwards beachten! + uint32_t period = __HAL_TIM_GET_AUTORELOAD(&htim2); // Gets ARR value + uint32_t pulse = (period + 1) * dutyCycle / 100; + + __HAL_TIM_SET_COMPARE(&htim2, TIM_CHANNEL_3, pulse); + __HAL_TIM_SET_COMPARE(&htim2, TIM_CHANNEL_4, pulse); } static void SPINDLE_EnaPWM(SpindleHandle_t h, void* context, int ena){ //ena = 1 enable PWM / ena = 0 disable PWM - //TODO: if(ena == 1){ HAL_GPIO_WritePin(SPINDLE_ENA_L_GPIO_Port, SPINDLE_ENA_L_Pin, GPIO_PIN_SET); HAL_GPIO_WritePin(SPINDLE_ENA_R_GPIO_Port, SPINDLE_ENA_R_Pin, GPIO_PIN_SET); - //TODO: PWM aktivieren + HAL_TIM_PWM_Start(&htim2, TIM_CHANNEL_3); + HAL_TIM_PWM_Start(&htim2, TIM_CHANNEL_4); }else if(ena == 0){ HAL_GPIO_WritePin(SPINDLE_ENA_L_GPIO_Port, SPINDLE_ENA_L_Pin, GPIO_PIN_RESET); HAL_GPIO_WritePin(SPINDLE_ENA_R_GPIO_Port, SPINDLE_ENA_R_Pin, GPIO_PIN_RESET); - //TODO: PWM deaktivieren + HAL_TIM_PWM_Stop(&htim2, TIM_CHANNEL_3); + HAL_TIM_PWM_Stop(&htim2, TIM_CHANNEL_4); }