Compare commits
6
Commits
728b978961
..
main
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
9b63d79ae5 | ||
|
|
296787e883 | ||
|
|
7ab20696f9 | ||
|
|
e68913e92b | ||
|
|
e2729d6e1e | ||
|
|
aba5e8809e |
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 */
|
||||
|
||||
extern TIM_HandleTypeDef htim2;
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#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 "Spindle.h"
|
||||
#include "Console.h"
|
||||
#include "Spindle/spindel.h"
|
||||
/* USER CODE END Includes */
|
||||
|
||||
/* Private typedef -----------------------------------------------------------*/
|
||||
@@ -100,18 +101,6 @@ QueueHandle_t uartRxQueue;
|
||||
/* Private user code ---------------------------------------------------------*/
|
||||
/* 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(){
|
||||
while(1){
|
||||
@@ -140,6 +129,7 @@ void blink_red_led(){
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// --------------------------------------------------------------------------------------------------------------------
|
||||
static int CapabilityFunc( int argc, char** argv, void* ctx )
|
||||
// --------------------------------------------------------------------------------------------------------------------
|
||||
@@ -180,6 +170,16 @@ static int CapabilityFunc( int argc, char** argv, void* ctx )
|
||||
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
|
||||
|
||||
typedef struct {
|
||||
@@ -310,9 +310,15 @@ int main(void)
|
||||
CONSOLE_RegisterCommand(c, "capability", "prints a specified string of capability bits",
|
||||
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_yellow_led, "blink_yellow_led", 1024, NULL, 1, NULL);
|
||||
xTaskCreate(blink_red_led, "blink_red_led", 1024, NULL, 1, NULL);
|
||||
|
||||
Reference in new issue
Block a user