|
|
|
|
|
|
|
|
/* Private define ------------------------------------------------------------*/ |
|
|
/* Private define ------------------------------------------------------------*/ |
|
|
/* Private macro -------------------------------------------------------------*/ |
|
|
/* Private macro -------------------------------------------------------------*/ |
|
|
/* Private variables ---------------------------------------------------------*/ |
|
|
/* Private variables ---------------------------------------------------------*/ |
|
|
|
|
|
UART_HandleTypeDef huart2; |
|
|
static volatile uint16_t gLastError; |
|
|
static volatile uint16_t gLastError; |
|
|
static volatile bool gButtonPressed = FALSE; |
|
|
static volatile bool gButtonPressed = FALSE; |
|
|
|
|
|
static volatile float sunWindow; |
|
|
|
|
|
|
|
|
/* Initialization parameters. */ |
|
|
/* Initialization parameters. */ |
|
|
l6208_Init_t initDeviceParameters = |
|
|
l6208_Init_t initDeviceParameters = |
|
|
|
|
|
|
|
|
*/ |
|
|
*/ |
|
|
int main(void) |
|
|
int main(void) |
|
|
{ |
|
|
{ |
|
|
int32_t pos; |
|
|
|
|
|
uint32_t freqPwm; |
|
|
|
|
|
|
|
|
int32_t pos; |
|
|
|
|
|
uint32_t freqPwm, timeToNextStep; |
|
|
|
|
|
|
|
|
/* STM32xx HAL library initialization */ |
|
|
|
|
|
HAL_Init(); |
|
|
|
|
|
|
|
|
|
|
|
/* Configure the system clock */ |
|
|
|
|
|
SystemClock_Config(); |
|
|
|
|
|
|
|
|
|
|
|
//----- Init of the Motor control library |
|
|
|
|
|
/* Set the L6208 library to use 1 device */ |
|
|
|
|
|
BSP_MotorControl_SetNbDevices(BSP_MOTOR_CONTROL_BOARD_ID_L6208, 1); |
|
|
|
|
|
/* When BSP_MotorControl_Init is called with NULL pointer, */ |
|
|
|
|
|
/* the L6208 parameters are set with the predefined values from file */ |
|
|
|
|
|
/* l6208_target_config.h, otherwise the parameters are set using the */ |
|
|
|
|
|
/* initDeviceParameters structure values. */ |
|
|
|
|
|
BSP_MotorControl_Init(BSP_MOTOR_CONTROL_BOARD_ID_L6208, NULL); |
|
|
|
|
|
//BSP_MotorControl_Init(BSP_MOTOR_CONTROL_BOARD_ID_L6208, &initDeviceParameters); |
|
|
|
|
|
|
|
|
|
|
|
/* Attach the function MyFlagInterruptHandler (defined below) to the flag interrupt */ |
|
|
|
|
|
BSP_MotorControl_AttachFlagInterrupt(MyFlagInterruptHandler); |
|
|
|
|
|
|
|
|
/* STM32xx HAL library initialization */ |
|
|
|
|
|
HAL_Init(); |
|
|
|
|
|
|
|
|
/* Attach the function MyErrorHandler (defined below) to the error Handler*/ |
|
|
|
|
|
BSP_MotorControl_AttachErrorHandler(MyErrorHandler); |
|
|
|
|
|
|
|
|
/* Configure the system clock */ |
|
|
|
|
|
SystemClock_Config(); |
|
|
|
|
|
|
|
|
//----- Configure Button for user interaction |
|
|
|
|
|
|
|
|
//----- Init of the Motor control library |
|
|
|
|
|
/* Set the L6208 library to use 1 device */ |
|
|
|
|
|
BSP_MotorControl_SetNbDevices(BSP_MOTOR_CONTROL_BOARD_ID_L6208, 1); |
|
|
|
|
|
/* When BSP_MotorControl_Init is called with NULL pointer, */ |
|
|
|
|
|
/* the L6208 parameters are set with the predefined values from file */ |
|
|
|
|
|
/* l6208_target_config.h, otherwise the parameters are set using the */ |
|
|
|
|
|
/* initDeviceParameters structure values. */ |
|
|
|
|
|
BSP_MotorControl_Init(BSP_MOTOR_CONTROL_BOARD_ID_L6208, NULL); |
|
|
|
|
|
//BSP_MotorControl_Init(BSP_MOTOR_CONTROL_BOARD_ID_L6208, &initDeviceParameters); |
|
|
|
|
|
|
|
|
/* Set Systick Interrupt priority highest to ensure no lock by using HAL_Delay */ |
|
|
|
|
|
HAL_NVIC_SetPriority(SysTick_IRQn, 0x0, 0x0); |
|
|
|
|
|
|
|
|
|
|
|
/* Configure KEY Button */ |
|
|
|
|
|
BSP_PB_Init(BUTTON_KEY, BUTTON_MODE_EXTI); |
|
|
|
|
|
|
|
|
|
|
|
//----- Disable the power bridges after initialization of the L6208 device |
|
|
|
|
|
|
|
|
|
|
|
/* Disable the power bridges after initialization */ |
|
|
|
|
|
BSP_MotorControl_CmdDisable(0); |
|
|
|
|
|
|
|
|
|
|
|
/* Wait for 2 seconds */ |
|
|
|
|
|
HAL_Delay(2000); |
|
|
|
|
|
|
|
|
/* Attach the function MyFlagInterruptHandler (defined below) to the flag interrupt */ |
|
|
|
|
|
BSP_MotorControl_AttachFlagInterrupt(MyFlagInterruptHandler); |
|
|
|
|
|
|
|
|
//----- Get the PWM frequency used for the VREFA and VREFB voltage generation |
|
|
|
|
|
|
|
|
|
|
|
freqPwm = BSP_MotorControl_GetBridgeInputPwmFreq(0); |
|
|
|
|
|
|
|
|
/* Attach the function MyErrorHandler (defined below) to the error Handler*/ |
|
|
|
|
|
BSP_MotorControl_AttachErrorHandler(MyErrorHandler); |
|
|
|
|
|
|
|
|
//----- Set the PWM frequency used for the VREFA and VREFB voltage generation |
|
|
|
|
|
|
|
|
|
|
|
BSP_MotorControl_SetBridgeInputPwmFreq(0, freqPwm>>1); |
|
|
|
|
|
|
|
|
//----- Configure Button for user interaction |
|
|
|
|
|
|
|
|
pos = BSP_MotorControl_GetPosition(0); |
|
|
|
|
|
|
|
|
/* Set Systick Interrupt priority highest to ensure no lock by using HAL_Delay */ |
|
|
|
|
|
HAL_NVIC_SetPriority(SysTick_IRQn, 0x0, 0x0); |
|
|
|
|
|
|
|
|
BSP_MotorControl_SetHome(0, pos); |
|
|
|
|
|
|
|
|
/* Configure KEY Button */ |
|
|
|
|
|
BSP_PB_Init(BUTTON_KEY, BUTTON_MODE_EXTI); |
|
|
|
|
|
|
|
|
//BSP_MotorControl_Move(0, FORWARD, 4000); |
|
|
|
|
|
|
|
|
|
|
|
//BSP_MotorControl_WaitWhileActive(0); |
|
|
|
|
|
|
|
|
|
|
|
//HAL_Delay(2000); |
|
|
|
|
|
|
|
|
|
|
|
//BSP_MotorControl_Move(0, BACKWARD, 4000); |
|
|
|
|
|
|
|
|
|
|
|
//BSP_MotorControl_WaitWhileActive(0); |
|
|
|
|
|
|
|
|
//----- Disable the power bridges after initialization of the L6208 device |
|
|
|
|
|
|
|
|
//BSP_MotorControl_SoftStop(0); |
|
|
|
|
|
|
|
|
/* Disable the power bridges after initialization */ |
|
|
|
|
|
BSP_MotorControl_CmdDisable(0); |
|
|
|
|
|
|
|
|
BSP_MotorControl_SelectStepMode(0, STEP_MODE_FULL); |
|
|
|
|
|
|
|
|
/* Wait for 2 seconds */ |
|
|
|
|
|
HAL_Delay(2000); |
|
|
|
|
|
|
|
|
/* Infinite loop */ |
|
|
|
|
|
|
|
|
//----- Get the PWM frequency used for the VREFA and VREFB voltage generation |
|
|
|
|
|
|
|
|
|
|
|
freqPwm = BSP_MotorControl_GetBridgeInputPwmFreq(0); |
|
|
|
|
|
|
|
|
|
|
|
//----- Set the PWM frequency used for the VREFA and VREFB voltage generation |
|
|
|
|
|
|
|
|
|
|
|
BSP_MotorControl_SetBridgeInputPwmFreq(0, freqPwm>>1); |
|
|
|
|
|
|
|
|
|
|
|
pos = BSP_MotorControl_GetPosition(0); |
|
|
|
|
|
|
|
|
|
|
|
BSP_MotorControl_SetHome(0, pos); |
|
|
|
|
|
|
|
|
|
|
|
timeToNextStep = (float)(sunWindow / 100) * 60 * 60 * 1000; |
|
|
|
|
|
|
|
|
|
|
|
BSP_MotorControl_SelectStepMode(0, STEP_MODE_FULL); |
|
|
|
|
|
|
|
|
|
|
|
//BSP_MotorControl_Move(0, FORWARD, 25); |
|
|
|
|
|
//BSP_MotorControl_WaitWhileActive(0); |
|
|
|
|
|
|
|
|
|
|
|
/* Infinite loop */ |
|
|
while(1) |
|
|
while(1) |
|
|
{ |
|
|
{ |
|
|
if (gButtonPressed) |
|
|
if (gButtonPressed) |
|
|
{ |
|
|
{ |
|
|
gButtonPressed = FALSE; |
|
|
gButtonPressed = FALSE; |
|
|
BSP_MotorControl_Move(0, FORWARD, 25); |
|
|
|
|
|
BSP_MotorControl_WaitWhileActive(0); |
|
|
|
|
|
BSP_MotorControl_Move(0, FORWARD, 25); |
|
|
|
|
|
BSP_MotorControl_WaitWhileActive(0); |
|
|
|
|
|
BSP_MotorControl_Move(0, FORWARD, 25); |
|
|
|
|
|
BSP_MotorControl_WaitWhileActive(0); |
|
|
|
|
|
BSP_MotorControl_Move(0, FORWARD, 25); |
|
|
|
|
|
BSP_MotorControl_WaitWhileActive(0); |
|
|
|
|
|
HAL_Delay(2000); |
|
|
|
|
|
|
|
|
// Sleep for timeToNextStep |
|
|
|
|
|
// Shut down motor for timeToNextStep |
|
|
|
|
|
// Wake up F401RE and motor after timeToNextStep |
|
|
|
|
|
// Make the Step |
|
|
} |
|
|
} |
|
|
BSP_MotorControl_GoHome(0); |
|
|
BSP_MotorControl_GoHome(0); |
|
|
BSP_MotorControl_WaitWhileActive(0); |
|
|
BSP_MotorControl_WaitWhileActive(0); |
|
|
|
|
|
|
|
|
HAL_NVIC_ClearPendingIRQ(KEY_BUTTON_EXTI_IRQn); |
|
|
HAL_NVIC_ClearPendingIRQ(KEY_BUTTON_EXTI_IRQn); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void transmit_uart(char *string){ |
|
|
|
|
|
uint8_t len = strlen(string); |
|
|
|
|
|
HAL_UART_Transmit(&huart2, (uint8_t*) string, len, 200); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#ifdef USE_FULL_ASSERT |
|
|
#ifdef USE_FULL_ASSERT |
|
|
|
|
|
|
|
|
/** |
|
|
/** |