diff --git a/Pilotes/Include/Girouette.h b/Pilotes/Include/Girouette.h index c5f8961..10e3205 100644 --- a/Pilotes/Include/Girouette.h +++ b/Pilotes/Include/Girouette.h @@ -1,4 +1,6 @@ #include "stm32f10x.h" extern void configEncoder(TIM_TypeDef * Timer); extern void configChannel(); -extern int returnAngle (TIM_TypeDef * Timer); \ No newline at end of file +extern int returnAngle (TIM_TypeDef * Timer); +extern int vent2voile(int angle); +extern void Servo_Moteur(int angle, TIM_TypeDef * Timer, int Channel); \ No newline at end of file diff --git a/Pilotes/Source/Girouette.c b/Pilotes/Source/Girouette.c index 18ebe8b..255c993 100644 --- a/Pilotes/Source/Girouette.c +++ b/Pilotes/Source/Girouette.c @@ -4,6 +4,9 @@ #include "Timer.h" #include "DriverGPIO.h" #include "Girouette.h" +#include "PWM.h" + +#include // Pour abs() #define POSITIONS 4*360 @@ -21,10 +24,25 @@ void configEncoder(TIM_TypeDef * Timer){ } void configChannel(){ MyGPIO_Init(GPIOA,0,In_Floating ); // GPIOA pin 0 in mode floating TIM2_CH1 - MyGPIO_Init(GPIOA,1,In_Floating ); // GPIOA pin 1 in mode floating TIM2_CH2 - MyGPIO_Init(GPIOA,8,In_Floating ); // GPIOA pin 7 in mode floating Index + MyGPIO_Init(GPIOA,1,In_Floating ); // GPIOA pin 1 in mode floating TIM2_CH2 + MyGPIO_Init(GPIOA,2,In_Floating); + MyGPIO_Init(GPIOA,8,In_PullDown ); // GPIOA pin 7 in mode floating Index } int returnAngle (TIM_TypeDef * Timer){ - return(Timer -> CNT / POSITIONS * 360); + return((Timer -> CNT % POSITIONS)/POSITIONS * 360); } +// Reste à coder une fonction de reset des degrés et une fonction qui retourne correctement l'angle +int vent2voile(int angle){ // Conversion angle vent à angle voile + if(abs(angle) < 90){ + return 0; + } + else{ + return(abs(angle)-90); + } +} + +void Servo_Moteur(int angle, TIM_TypeDef * Timer, int Channel){ // Controle du moteur + int dutyCycle = (5* angle + 5*90)/90; + MyTimer_Set_DutyCycle(Timer, Channel, dutyCycle); +} \ No newline at end of file diff --git a/Pilotes/Source/MyTimer.c b/Pilotes/Source/MyTimer.c index bf5be8a..e84a38f 100644 --- a/Pilotes/Source/MyTimer.c +++ b/Pilotes/Source/MyTimer.c @@ -34,6 +34,6 @@ void ConfigureIT(){ // Activate general interuption with a function and priority MyTimer_ActiveIT(TIM3, 4, Test); //start interruption with priority 4 } void ConfigurePWM(){ // Set dutycycle with timer -MyTimer_PWM(TIM1, 1); +MyTimer_PWM(TIM1, 1); // Utiliser timer1 avec channel 1 MyTimer_Set_DutyCycle(TIM1, 1, 20.0); } diff --git a/principal.c b/principal.c index 4b7941e..33733ad 100755 --- a/principal.c +++ b/principal.c @@ -1,35 +1,42 @@ #include "stm32f10x.h" +#include // Pour print #include "MyTimer.h" #include "Nucleo.h" #include "Girouette.h" #include "DriverGPIO.h" -volatile int Angle; - +int test=0; +volatile int angleVent; +volatile int angleVoile; int main ( void ){ + // ---- Setup ------ //Nucleo.c - //ConfigHorloge(); - ConfigBroche(); + ConfigHorloge(); + //ConfigBroche(); //MyTimer.c ConfigureTimers(); - ConfigureIT(); + //ConfigureIT(); //PWM. - ConfigurePWM(); + ConfigurePWM(); // Giroutte.c configEncoder(TIM2); - configChannel(); - + configChannel(); + //MyTimer_Base_Start (TIM2); //MyTimer_Base_Start (TIM1); //MyTimer_Base_Start (TIM3); - // ----- Opérations ----- + // ----- Opération ----- while (1){ - //Angle = returnAngle(TIM2); - MyGPIO_Toggle(GPIOA, 0); - MyGPIO_Toggle(GPIOA, 1); + if(MyGPIO_Read(GPIOA,8)){ // Index + TIM2 -> CNT = 0x0; // Remet angle à zero + } + angleVent = returnAngle(TIM2); // Récupérer l'angle de girouette + angleVoile = vent2voile(angleVent); // Transformer l'angle de girouette au l'angle des voiles souhaités + Servo_Moteur(angleVoile, TIM1, 1); // Faire bouger le moteur servo + //printf("L'angle est %d ", returnAngle(TIM2)); }