59 lines
1.3 KiB
C
59 lines
1.3 KiB
C
#include "MyTimer.h"
|
|
#include "stm32f10x.h"
|
|
#include "Driver_GPIO.h"
|
|
#include "Plateau.h"
|
|
|
|
/* Declarations */
|
|
|
|
char channel = 1 ;
|
|
MyTimer_Struct_TypeDef TIM;
|
|
MyTimer_Struct_TypeDef * Data = &TIM;
|
|
MyGPIO_Struct_TypeDef GPIOA5; // pin direction
|
|
MyGPIO_Struct_TypeDef GPIOA6; // pin moteur
|
|
|
|
void Init_Plateau (void) {
|
|
|
|
/* Configuration du Timer */
|
|
Data->Timer = TIM3;
|
|
Data->ARR = 300;
|
|
Data->PSC = 11;
|
|
|
|
MyTimer_Base_Init(Data);
|
|
|
|
/* Configuration des GPIOs */
|
|
GPIOA5.GPIO = GPIOA;
|
|
GPIOA5.GPIO_Pin = 5;
|
|
GPIOA5.GPIO_Conf = Out_Ppull;
|
|
MyGPIO_Init(&GPIOA5);
|
|
|
|
GPIOA6.GPIO = GPIOA;
|
|
GPIOA6.GPIO_Pin = 6;
|
|
GPIOA6.GPIO_Conf = AltOut_Ppull;
|
|
MyGPIO_Init(&GPIOA6);
|
|
|
|
MyTimer_Base_Start(TIM3);
|
|
MyTimer_PWM(Data->Timer,channel);
|
|
}
|
|
|
|
void Set_Direction (char sens) {
|
|
/* Rotation */
|
|
if (sens == ANTI_HORRAIRE){
|
|
MyGPIO_Reset(GPIOA5.GPIO, GPIOA5.GPIO_Pin); // on met à 0
|
|
}
|
|
else if (sens == HORRAIRE) {
|
|
MyGPIO_Set(GPIOA5.GPIO, GPIOA5.GPIO_Pin); // on met à 1
|
|
}
|
|
}
|
|
|
|
void Set_Vitesse (char vitesse) {
|
|
|
|
Set_PWM_PRCT(Data->Timer, channel, vitesse);
|
|
|
|
}
|
|
/* Permet de diriger le plateau du voilier */
|
|
void Set_Moteur_Plateau(char sens, char vitesse){ // -1 gauche et 1 droite
|
|
Init_Plateau();
|
|
Set_Direction(sens);
|
|
Set_Vitesse(vitesse);
|
|
|
|
}
|