Séance 25/11
This commit is contained in:
parent
8b95eeb0a5
commit
b24d9812b4
13 changed files with 28 additions and 12 deletions
0
Pilotes/Include/DriverGPIO.h
Normal file → Executable file
0
Pilotes/Include/DriverGPIO.h
Normal file → Executable file
0
Pilotes/Include/Girouette.h
Normal file → Executable file
0
Pilotes/Include/Girouette.h
Normal file → Executable file
0
Pilotes/Include/IT.h
Normal file → Executable file
0
Pilotes/Include/IT.h
Normal file → Executable file
0
Pilotes/Include/PWM.h
Normal file → Executable file
0
Pilotes/Include/PWM.h
Normal file → Executable file
0
Pilotes/Include/Servo.h
Normal file → Executable file
0
Pilotes/Include/Servo.h
Normal file → Executable file
0
Pilotes/Include/Timer.h
Normal file → Executable file
0
Pilotes/Include/Timer.h
Normal file → Executable file
5
Pilotes/Source/DriverGPIO.c
Normal file → Executable file
5
Pilotes/Source/DriverGPIO.c
Normal file → Executable file
|
|
@ -56,16 +56,19 @@ GPIO -> CRH |= ( conf << shift_pin);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
int MyGPIO_Read(GPIO_TypeDef * GPIO, char GPIO_Pin){
|
|
||||||
|
|
||||||
|
int MyGPIO_Read(GPIO_TypeDef * GPIO, char GPIO_Pin){
|
||||||
return(GPIO -> IDR & (1 << GPIO_Pin));
|
return(GPIO -> IDR & (1 << GPIO_Pin));
|
||||||
}
|
}
|
||||||
|
|
||||||
void MyGPIO_Set(GPIO_TypeDef * GPIO, char GPIO_Pin){
|
void MyGPIO_Set(GPIO_TypeDef * GPIO, char GPIO_Pin){
|
||||||
GPIO -> BSRR = (1<<GPIO_Pin);//1 on set zone
|
GPIO -> BSRR = (1<<GPIO_Pin);//1 on set zone
|
||||||
}
|
}
|
||||||
|
|
||||||
void MyGPIO_Reset(GPIO_TypeDef * GPIO, char GPIO_Pin){
|
void MyGPIO_Reset(GPIO_TypeDef * GPIO, char GPIO_Pin){
|
||||||
GPIO -> BSRR = (1<<(GPIO_Pin+16));//1 on reset zone
|
GPIO -> BSRR = (1<<(GPIO_Pin+16));//1 on reset zone
|
||||||
}
|
}
|
||||||
|
|
||||||
void MyGPIO_Toggle(GPIO_TypeDef * GPIO, char GPIO_Pin){
|
void MyGPIO_Toggle(GPIO_TypeDef * GPIO, char GPIO_Pin){
|
||||||
GPIO -> ODR = GPIO -> ODR ^ (0x1 << GPIO_Pin);
|
GPIO -> ODR = GPIO -> ODR ^ (0x1 << GPIO_Pin);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
21
Pilotes/Source/Girouette.c
Normal file → Executable file
21
Pilotes/Source/Girouette.c
Normal file → Executable file
|
|
@ -6,9 +6,13 @@
|
||||||
|
|
||||||
#include <stdlib.h> // Pour abs()
|
#include <stdlib.h> // Pour abs()
|
||||||
|
|
||||||
#define POSITIONS 4*360
|
#define POSITIONS (360*4) //0x5A0
|
||||||
|
|
||||||
void configEncoder(TIM_TypeDef * Timer){
|
void configEncoder(TIM_TypeDef * Timer){
|
||||||
|
// Timer
|
||||||
|
EnableTimer(Timer);
|
||||||
|
|
||||||
|
// Settings
|
||||||
Timer -> CCMR1 |= TIM_CCMR1_CC1S; // TI1FP1 mapped on TI1
|
Timer -> CCMR1 |= TIM_CCMR1_CC1S; // TI1FP1 mapped on TI1
|
||||||
Timer -> CCMR1 |= TIM_CCMR1_CC2S; // TI1FP2 mapped on TI2
|
Timer -> CCMR1 |= TIM_CCMR1_CC2S; // TI1FP2 mapped on TI2
|
||||||
Timer -> CCER &= ~(TIM_CCER_CC1P | TIM_CCER_CC1NP); // TI1FP1 output non-inverted
|
Timer -> CCER &= ~(TIM_CCER_CC1P | TIM_CCER_CC1NP); // TI1FP1 output non-inverted
|
||||||
|
|
@ -23,19 +27,24 @@ void configEncoder(TIM_TypeDef * Timer){
|
||||||
// GPIO
|
// GPIO
|
||||||
MyGPIO_Init(GPIOA,0,In_Floating ); // GPIOA pin 0 in mode floating TIM2_CH1
|
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,1,In_Floating ); // GPIOA pin 1 in mode floating TIM2_CH2
|
||||||
MyGPIO_Init(GPIOA,8,In_PullDown ); // GPIOA pin 7 in mode floating Index
|
MyGPIO_Init(GPIOA,8,In_PullDown ); // GPIOA pin 8 in mode floating Index
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int angleVent (TIM_TypeDef * Timer){ // Returner l'angle du vent
|
int angleVent (TIM_TypeDef * Timer){ // Returner l'angle du vent
|
||||||
return((Timer -> CNT)/POSITIONS * 360);
|
int angle =(((Timer -> CNT*360)/POSITIONS ));
|
||||||
|
if (angle > 180){
|
||||||
|
angle = 360 - angle; // Pour que l'angle soit entre 0 et 180
|
||||||
|
}
|
||||||
|
return(angle);
|
||||||
}
|
}
|
||||||
|
|
||||||
int vent2voile(int angle){ // Conversion angle vent à angle voile
|
int vent2voile(int angle){ // Conversion angle vent à angle voile
|
||||||
if(abs(angle) < 90){
|
if(angle < 45){
|
||||||
return 0;
|
return 0; // Les voiles restent immobiles
|
||||||
}
|
}
|
||||||
else{
|
else{
|
||||||
return(abs(angle)-90);
|
return(2*(angle-45)/3); // Augmentation linéaire
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
0
Pilotes/Source/IT.c
Normal file → Executable file
0
Pilotes/Source/IT.c
Normal file → Executable file
0
Pilotes/Source/PWM.c
Normal file → Executable file
0
Pilotes/Source/PWM.c
Normal file → Executable file
12
Pilotes/Source/Servo.c
Normal file → Executable file
12
Pilotes/Source/Servo.c
Normal file → Executable file
|
|
@ -2,18 +2,22 @@
|
||||||
#include "DriverGPIO.h"
|
#include "DriverGPIO.h"
|
||||||
#include "PWM.h"
|
#include "PWM.h"
|
||||||
#include "Timer.h"
|
#include "Timer.h"
|
||||||
|
#include "Accelerometre.h"
|
||||||
|
#include "Horloge.h"
|
||||||
|
|
||||||
void Servo_Moteur(int angle, TIM_TypeDef * Timer, int Channel){ // Controle du moteur
|
void Servo_Moteur(int angle, TIM_TypeDef * Timer, int Channel){ // Controle du moteur
|
||||||
int dutyCycle = (5* angle + 5*90)/90;
|
int dutyCycle = (5* angle + 5*90)/90;
|
||||||
PWM_Set_DutyCycle(Timer, Channel, dutyCycle);
|
Set_DutyCycle_PWM(TIM4, 3, dutyCycle); //On met Duty cycle à 2% et il reste autour de 90 deg
|
||||||
}
|
}
|
||||||
|
|
||||||
void initServo(TIM_TypeDef * Timer, int Channel){ // Config du moteur servo
|
void initServo(TIM_TypeDef * Timer, int Channel){ // Config du moteur servo
|
||||||
if (Timer == TIM4) {
|
if (Timer == TIM4) {
|
||||||
EnableTimer(TIM4);
|
EnableTimer(TIM4);
|
||||||
MyTimer_Base_Init(TIM4, 20000 - 1, 71); //Claire m'a
|
MyTimer_Base_Init(TIM4, 20000 - 1, 71);
|
||||||
|
|
||||||
if (Channel == 3){
|
if (Channel == 3){
|
||||||
MyGPIO_Init(GPIOB, 8, AltOut_Ppull);
|
MyGPIO_Init(GPIOB, 8, AltOut_Ppull); // Outut push pull alternate
|
||||||
|
MyTimer_PWM(TIM4, 3); //TIM4 CH3 pour PB8
|
||||||
}
|
}
|
||||||
else{
|
else{
|
||||||
//printf("Cet pilôte n'existe pas");
|
//printf("Cet pilôte n'existe pas");
|
||||||
|
|
|
||||||
0
Pilotes/Source/Timer.c
Normal file → Executable file
0
Pilotes/Source/Timer.c
Normal file → Executable file
|
|
@ -27,7 +27,7 @@ int main ( void ){
|
||||||
while (1){
|
while (1){
|
||||||
angleVentVar = angleVent(TIM2); // Récupérer l'angle de girouette
|
angleVentVar = angleVent(TIM2); // Récupérer l'angle de girouette
|
||||||
angleVoileVar = vent2voile(angleVentVar); // Transformer l'angle de girouette au l'angle des voiles souhaités
|
angleVoileVar = vent2voile(angleVentVar); // Transformer l'angle de girouette au l'angle des voiles souhaités
|
||||||
Servo_Moteur(angleVoileVar, TIM1, 1); // Faire bouger le moteur servo
|
Servo_Moteur(angleVoileVar, TIM4, 3); // Faire bouger le moteur servo
|
||||||
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue