6 Commits
Author SHA1 Message Date
fewikay 9b63d79ae5 fix 2026-10-19 14:18:02 +02:00
fewikay 296787e883 fixed code. spindle spins 2026-10-19 13:45:17 +02:00
fewikay 7ab20696f9 added void SPINDLE_SetDutyCycle; built. 2026-10-19 10:44:10 +02:00
fewikay e68913e92b added HAL doc 2026-10-19 00:44:08 +02:00
fewikay e2729d6e1e added spindel.h and spindel.c 2026-10-19 00:40:30 +02:00
fewikay aba5e8809e implemented spindle - doesn't work 2026-10-16 16:58:11 +02:00
5 changed files with 95 additions and 13 deletions

No files matched your search

Binary file not shown.
@@ -0,0 +1,13 @@
#include "Console.h"
#include "Spindle.h"
#include "main.h"
#include "FreeRTOS.h"
#include "openamp.h"
#include <stddef.h>
SpindleHandle_t init_spindle(ConsoleHandle_t c, float maxRPM, float minRPM, float absMinRPM);
static void SPINDLE_SetDutyCycle(SpindleHandle_t h, void* context, int backwards, float dutyCycle);
static void SPINDLE_EnaPWM(SpindleHandle_t h, void* context, int ena);
@@ -108,6 +108,8 @@ void Error_Handler(void);
/* USER CODE END Private defines */ /* USER CODE END Private defines */
extern TIM_HandleTypeDef htim2;
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif #endif
@@ -0,0 +1,61 @@
#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\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\n", ena);
}
SpindleHandle_t init_spindle(ConsoleHandle_t c, float maxRPM, float minRPM, float absMinRPM){
// set parameters for the physical system
static SpindlePhysicalParams_t s;
s.maxRPM = maxRPM;
s.minRPM = minRPM;
s.absMinRPM = absMinRPM;
s.setDutyCycle = SPINDLE_SetDutyCycle;
s.enaPWM = SPINDLE_EnaPWM;
s.context = NULL;
HAL_TIM_PWM_Start(&htim2, TIM_CHANNEL_3);
HAL_TIM_PWM_Start(&htim2, TIM_CHANNEL_4);
return SPINDLE_CreateInstance( 4*configMINIMAL_STACK_SIZE, configMAX_PRIORITIES - 3, c, &s);
}
@@ -29,6 +29,7 @@
#include "assert.h" #include "assert.h"
#include "Spindle.h" #include "Spindle.h"
#include "Console.h" #include "Console.h"
#include "Spindle/spindel.h"
/* USER CODE END Includes */ /* USER CODE END Includes */
/* Private typedef -----------------------------------------------------------*/ /* Private typedef -----------------------------------------------------------*/
@@ -100,18 +101,6 @@ QueueHandle_t uartRxQueue;
/* Private user code ---------------------------------------------------------*/ /* Private user code ---------------------------------------------------------*/
/* USER CODE BEGIN 0 */ /* USER CODE BEGIN 0 */
// -------------------------------------------------------------------------------------------------------------------- // --------------------------------------------------------------------------------------------------------------------
static void playgroundTask(void* args)
// --------------------------------------------------------------------------------------------------------------------
{
(void)args;
while(1) {
printf("test \n");
vTaskDelay(pdMS_TO_TICKS(10));
}
vTaskDelete(xTaskGetCurrentTaskHandle());
}
void blink_green_led(){ void blink_green_led(){
while(1){ while(1){
@@ -140,6 +129,7 @@ void blink_red_led(){
} }
} }
// -------------------------------------------------------------------------------------------------------------------- // --------------------------------------------------------------------------------------------------------------------
static int CapabilityFunc( int argc, char** argv, void* ctx ) static int CapabilityFunc( int argc, char** argv, void* ctx )
// -------------------------------------------------------------------------------------------------------------------- // --------------------------------------------------------------------------------------------------------------------
@@ -180,6 +170,16 @@ static int CapabilityFunc( int argc, char** argv, void* ctx )
return 0; return 0;
} }
static int fabi(int argc, char** argv, void* ctx){
(void)argc;
(void)argv;
(void)ctx;
printf("Hallo Fabi");
return 0;
}
#define BKPSRAM_BASE 0x38800000UL #define BKPSRAM_BASE 0x38800000UL
typedef struct { typedef struct {
@@ -310,9 +310,15 @@ int main(void)
CONSOLE_RegisterCommand(c, "capability", "prints a specified string of capability bits", CONSOLE_RegisterCommand(c, "capability", "prints a specified string of capability bits",
CapabilityFunc, NULL); CapabilityFunc, NULL);
CONSOLE_RegisterCommand(c, "fabi", "prints a hallo fabi",
fabi, NULL);
//Spindle
init_spindle(c, 9000, -9000, 1600);
// create a playground task at the very beginning
// tasks
xTaskCreate(blink_green_led, "blink_green_led", 1024, NULL, 1, NULL); xTaskCreate(blink_green_led, "blink_green_led", 1024, NULL, 1, NULL);
xTaskCreate(blink_yellow_led, "blink_yellow_led", 1024, NULL, 1, NULL); xTaskCreate(blink_yellow_led, "blink_yellow_led", 1024, NULL, 1, NULL);
xTaskCreate(blink_red_led, "blink_red_led", 1024, NULL, 1, NULL); xTaskCreate(blink_red_led, "blink_red_led", 1024, NULL, 1, NULL);