134 linhas
2,5 KiB
C
134 linhas
2,5 KiB
C
#include "stm32f10x.h"
|
|
#include "Driver_GPIO.h"
|
|
#include "Driver_Timer.h"
|
|
#include "Driver_UART.h"
|
|
//=======
|
|
#include "Driver_ADC.h"
|
|
#include "MySPI.h"
|
|
#include "Driver_IMU.h"
|
|
|
|
|
|
//Applications
|
|
|
|
MyGPIO_Struct_TypeDef TI1;
|
|
|
|
MyGPIO_Struct_TypeDef TI2;
|
|
|
|
|
|
MyTimer_Struct_TypeDef Encoder;
|
|
Encoder->Timer = TIM4;
|
|
MyTimer_Base_Init(&Encoder);
|
|
MyTimer_ConfigureEncoder(&Encoder);
|
|
MyTimer_Start(&Encoder);
|
|
|
|
// Application
|
|
#include "App_girouette.h"
|
|
|
|
int main() {
|
|
|
|
MyGPIO_Struct_TypeDef PWM_GPIO;
|
|
PWM_GPIO.GPIO_Pin = 1;
|
|
PWM_GPIO.GPIO_Conf = AltOut_Ppull;
|
|
PWM_GPIO.GPIO = GPIOA;
|
|
MyGPIO_Init(&PWM_GPIO);
|
|
|
|
PWM_GPIO.GPIO_Pin = 0;
|
|
PWM_GPIO.GPIO_Conf = AltOut_Ppull;
|
|
PWM_GPIO.GPIO = GPIOA;
|
|
MyGPIO_Init(&PWM_GPIO);
|
|
|
|
|
|
MyTimer_Struct_TypeDef PWM_VOILE;
|
|
PWM_VOILE.Timer = TIM2;
|
|
PWM_VOILE.PSC = 7200;
|
|
PWM_VOILE.ARR = 200;
|
|
PWM_VOILE.channel = 2;
|
|
MyTimer_Base_Init(&PWM_VOILE);
|
|
MyTimer_ConfigurePWM(&PWM_VOILE, 10);
|
|
MyTimer_Start(&PWM_VOILE);
|
|
|
|
|
|
// MyTimer_Struct_TypeDef PWM_PLATEAU;
|
|
// PWM_PLATEAU.Timer = TIM2;
|
|
// PWM_PLATEAU.PSC = 7200;
|
|
// PWM_PLATEAU.ARR = 200;
|
|
// PWM_PLATEAU.channel = 1;
|
|
// MyTimer_Base_Init(&PWM_PLATEAU);
|
|
// MyTimer_ConfigurePWM(&PWM_PLATEAU, 60);
|
|
// MyTimer_Start(&PWM_PLATEAU);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
MyGPIO_Struct_TypeDef UART_GPIO;
|
|
UART_GPIO.GPIO_Pin = 10; //TX
|
|
UART_GPIO.GPIO_Conf = AltOut_Ppull;
|
|
UART_GPIO.GPIO = GPIOB;
|
|
MyGPIO_Init(&UART_GPIO);
|
|
|
|
UART_GPIO.GPIO_Pin = 11; //RX
|
|
UART_GPIO.GPIO_Conf = In_Floating;
|
|
UART_GPIO.GPIO = GPIOB;
|
|
MyGPIO_Init(&UART_GPIO);
|
|
|
|
|
|
|
|
MyUART_Struct_TypeDef UART;
|
|
UART.baudrate = 9600;
|
|
UART.UART = USART3;
|
|
MyUART_Init(&UART);
|
|
|
|
// TX: PB10
|
|
// RX: PB11
|
|
|
|
|
|
// Initialisation
|
|
App_Girouette_Init();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
while(1) {
|
|
|
|
int dir = App_Girouette_GetDirection();
|
|
|
|
|
|
if ((dir >= 335) && (dir < 25)) { //Vent debout
|
|
MyTimer_SetPWMDutyCycle(&PWM_VOILE, 10);
|
|
} else if ((dir >= 160) && (dir < 200)) { //Vent arrière
|
|
MyTimer_SetPWMDutyCycle(&PWM_VOILE, 5);
|
|
} else if((dir >= 325) && (dir < 335)){ //Vent Près
|
|
MyTimer_SetPWMDutyCycle(&PWM_VOILE, 9);
|
|
} else if((dir >= 295) && (dir < 325)){ //Vent bon plein
|
|
MyTimer_SetPWMDutyCycle(&PWM_VOILE, 8);
|
|
} else if ((dir >= 245) && (dir < 295)) { //Vent largue
|
|
MyTimer_SetPWMDutyCycle(&PWM_VOILE, 7);
|
|
} else if((dir >= 200) && (dir < 245)){ //Vent Grand largue
|
|
MyTimer_SetPWMDutyCycle(&PWM_VOILE, 8);
|
|
}
|
|
else {
|
|
MyTimer_SetPWMDutyCycle(&PWM_VOILE, 10); //Reste
|
|
}
|
|
|
|
|
|
|
|
|
|
char str[32];
|
|
sprintf(str, "Dir: %f deg", (float)dir);
|
|
|
|
MyUART_SendString(&UART, str);
|
|
MyUART_SendByte(&UART, '\n');
|
|
|
|
}
|
|
}
|