fixed code. spindle spins
This commit is contained in:
1 parent
7ab20696f9
commit
296787e883
2 files changed
+47
-31
No files matched your search
@@ -1,9 +1,52 @@
|
||||
#include "Spindle/spindel.h"
|
||||
|
||||
|
||||
|
||||
|
||||
static void SPINDLE_SetDutyCycle(SpindleHandle_t h, void* context, int backwards, float dutyCycle){
|
||||
|
||||
(void)h;
|
||||
(void)context;
|
||||
|
||||
uint32_t period = __HAL_TIM_GET_AUTORELOAD(&htim2); // Gets ARR value
|
||||
uint32_t pulse = (period + 1) * dutyCycle;
|
||||
|
||||
if(backwards==1){
|
||||
__HAL_TIM_SET_COMPARE(&htim2, TIM_CHANNEL_3, pulse);
|
||||
__HAL_TIM_SET_COMPARE(&htim2, TIM_CHANNEL_4, 0);
|
||||
}else{
|
||||
__HAL_TIM_SET_COMPARE(&htim2, TIM_CHANNEL_3, 0);
|
||||
__HAL_TIM_SET_COMPARE(&htim2, TIM_CHANNEL_4, pulse);
|
||||
}
|
||||
|
||||
printf("duty=%f backwards=%d pulse=%lu\r\n", dutyCycle, backwards, (unsigned long)pulse);
|
||||
|
||||
}
|
||||
|
||||
static void SPINDLE_EnaPWM(SpindleHandle_t h, void* context, int ena){
|
||||
//ena = 1 enable PWM / ena = 0 disable PWM
|
||||
(void)h;
|
||||
(void)context;
|
||||
|
||||
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);
|
||||
|
||||
}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);
|
||||
|
||||
}
|
||||
printf("ena=%d\r\n", ena);
|
||||
|
||||
}
|
||||
|
||||
|
||||
SpindleHandle_t init_spindle(ConsoleHandle_t c, float maxRPM, float minRPM, float absMinRPM){
|
||||
// set parameters for the physical system
|
||||
SpindlePhysicalParams_t s;
|
||||
static SpindlePhysicalParams_t s;
|
||||
s.maxRPM = maxRPM;
|
||||
s.minRPM = minRPM;
|
||||
s.absMinRPM = absMinRPM;
|
||||
@@ -11,37 +54,8 @@ SpindleHandle_t init_spindle(ConsoleHandle_t c, float maxRPM, float minRPM, floa
|
||||
s.enaPWM = SPINDLE_EnaPWM;
|
||||
s.context = NULL;
|
||||
|
||||
return SPINDLE_CreateInstance( 4*configMINIMAL_STACK_SIZE, configMAX_PRIORITIES - 3, c, &s);
|
||||
}
|
||||
|
||||
|
||||
static void SPINDLE_SetDutyCycle(SpindleHandle_t h, void* context, int backwards, float dutyCycle){
|
||||
|
||||
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
|
||||
|
||||
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);
|
||||
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);
|
||||
HAL_TIM_PWM_Stop(&htim2, TIM_CHANNEL_3);
|
||||
HAL_TIM_PWM_Stop(&htim2, TIM_CHANNEL_4);
|
||||
|
||||
}
|
||||
|
||||
return SPINDLE_CreateInstance( 4*configMINIMAL_STACK_SIZE, configMAX_PRIORITIES - 3, c, &s);
|
||||
}
|
||||
@@ -313,6 +313,8 @@ int main(void)
|
||||
CONSOLE_RegisterCommand(c, "fabi", "prints a hallo fabi",
|
||||
fabi, NULL);
|
||||
|
||||
//Spindle
|
||||
init_spindle(c, 9000, -9000, 1600);
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in new issue
Block a user