Compare commits
No commits in common. "7c51dd43cfc95f5ea7a638900cfd17ee9fdb3337" and "8b95eeb0a500352ecf235513f9f28c07bcd827c2" have entirely different histories.
7c51dd43cf
...
8b95eeb0a5
17 changed files with 12 additions and 219 deletions
|
|
@ -1,8 +0,0 @@
|
||||||
#include <stm32f10x.h>
|
|
||||||
#include <stdint.h>
|
|
||||||
|
|
||||||
void initAccelo(void);
|
|
||||||
uint16_t * RecupAccelo(void);
|
|
||||||
void LacheVoile(uint16_t * DATA);
|
|
||||||
void initLacheur(void);
|
|
||||||
uint16_t * KattRecupAccelo(void);
|
|
||||||
0
Pilotes/Include/DriverGPIO.h
Executable file → Normal file
0
Pilotes/Include/DriverGPIO.h
Executable file → Normal file
0
Pilotes/Include/Girouette.h
Executable file → Normal file
0
Pilotes/Include/Girouette.h
Executable file → Normal file
|
|
@ -1,16 +0,0 @@
|
||||||
#include <stm32f10x.h>
|
|
||||||
#define PSC_VAL 624
|
|
||||||
#define ARR_VAL 0xE0FF
|
|
||||||
|
|
||||||
//DUTY CYCLE
|
|
||||||
#define DUTYC 70 //Chiffre entre 0 et 100, où 100 est 100% duty cycle
|
|
||||||
#define POWERMODE 1 // 1 vaut powermode 1, 0 vaut powermode 2 (Powermode pour le config de dutycycle)
|
|
||||||
//Powermode 1 reste sur la bonne polarité: cad. si DUTY_CYCLE vaut 60 alors le signal reste HIGH pour 60% du periode, inverse pour pwmd2
|
|
||||||
//Timer
|
|
||||||
void Timer_Init(TIM_TypeDef *Timer, unsigned short Autoreload, unsigned short Prescaler);
|
|
||||||
void MyTimer_ActiveIT(TIM_TypeDef * Timer, char Prio, void(*Interrupt_fonc)(void));
|
|
||||||
void TIM2_IRQHandler(void);
|
|
||||||
|
|
||||||
//PWM
|
|
||||||
void MyTimer_PWM(TIM_TypeDef * Timer , int Channel);
|
|
||||||
int Set_DutyCycle_PWM(TIM_TypeDef *Timer, int Channel, int DutyC);
|
|
||||||
0
Pilotes/Include/IT.h
Executable file → Normal file
0
Pilotes/Include/IT.h
Executable file → Normal file
0
Pilotes/Include/PWM.h
Executable file → Normal file
0
Pilotes/Include/PWM.h
Executable file → Normal file
0
Pilotes/Include/Servo.h
Executable file → Normal file
0
Pilotes/Include/Servo.h
Executable file → Normal file
0
Pilotes/Include/Timer.h
Executable file → Normal file
0
Pilotes/Include/Timer.h
Executable file → Normal file
|
|
@ -1,31 +0,0 @@
|
||||||
#include <stm32f10x.h>
|
|
||||||
#include <Horloge.h>
|
|
||||||
//#include <MYGPIO.h>
|
|
||||||
#include <stdlib.h>
|
|
||||||
|
|
||||||
#include <stdint.h>
|
|
||||||
|
|
||||||
|
|
||||||
void initLacheur(void){
|
|
||||||
GPIOB->CRH &= ~(0xF << (0 * 4));
|
|
||||||
GPIOB->CRH |= (0xA << (0 * 4)); //On met GPIOB.8 en mode output 2Mhz, alternate pp
|
|
||||||
Timer_Init(TIM4, 20000 - 1, 71); //Claire m'a aidé
|
|
||||||
}
|
|
||||||
|
|
||||||
//Recuperer le DATA en X, Z, Y
|
|
||||||
void LacheVoile(uint16_t * DATA){
|
|
||||||
//uint16_t X = DATA[0]; //Z le longe du mât (masten)
|
|
||||||
//uint16_t Z = DATA[2];// //X le long du sense de voilier
|
|
||||||
uint16_t Y = DATA[1]; ////Y vers les bords (Tribord/Babord)
|
|
||||||
if (Y>=0x007B){// exatement à 40 degrés, on lache le 40%. 0xFF*(40deg/90deg)
|
|
||||||
//Le PWM du moteur est gère par PB7
|
|
||||||
MyTimer_PWM(TIM4, 3); //TIM4 CH3 pour PB8
|
|
||||||
Set_DutyCycle_PWM(TIM4, 3, 2); //On met Duty cycle à 2% et il reste autour de 90 deg
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
5
Pilotes/Source/DriverGPIO.c
Executable file → Normal file
5
Pilotes/Source/DriverGPIO.c
Executable file → Normal file
|
|
@ -56,19 +56,16 @@ 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
Executable file → Normal file
21
Pilotes/Source/Girouette.c
Executable file → Normal file
|
|
@ -6,13 +6,9 @@
|
||||||
|
|
||||||
#include <stdlib.h> // Pour abs()
|
#include <stdlib.h> // Pour abs()
|
||||||
|
|
||||||
#define POSITIONS (360*4) //0x5A0
|
#define POSITIONS 4*360
|
||||||
|
|
||||||
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
|
||||||
|
|
@ -27,24 +23,19 @@ 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 8 in mode floating Index
|
MyGPIO_Init(GPIOA,8,In_PullDown ); // GPIOA pin 7 in mode floating Index
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int angleVent (TIM_TypeDef * Timer){ // Returner l'angle du vent
|
int angleVent (TIM_TypeDef * Timer){ // Returner l'angle du vent
|
||||||
int angle =(((Timer -> CNT*360)/POSITIONS ));
|
return((Timer -> CNT)/POSITIONS * 360);
|
||||||
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(angle < 45){
|
if(abs(angle) < 90){
|
||||||
return 0; // Les voiles restent immobiles
|
return 0;
|
||||||
}
|
}
|
||||||
else{
|
else{
|
||||||
return(2*(angle-45)/3); // Augmentation linéaire
|
return(abs(angle)-90);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,136 +0,0 @@
|
||||||
#include <stm32f10x.h>
|
|
||||||
#include <stdio.h>
|
|
||||||
#include <Horloge.h>
|
|
||||||
|
|
||||||
|
|
||||||
//Il faut trouver le signal
|
|
||||||
//On est à Timer 2
|
|
||||||
|
|
||||||
static void (*TIM2_Appel)(void) = 0;
|
|
||||||
|
|
||||||
void Timer_Init(TIM_TypeDef *Timer, unsigned short Autoreload, unsigned short Prescaler){
|
|
||||||
if (Timer == TIM1) {
|
|
||||||
RCC->APB2ENR |= RCC_APB2ENR_TIM1EN; //L'horloge est enabléd
|
|
||||||
} else if (Timer == TIM2) {
|
|
||||||
TIM2->CR1 |= TIM_CR1_CEN; //On enable l'horloge interne
|
|
||||||
RCC->APB1ENR |= RCC_APB1ENR_TIM2EN;
|
|
||||||
} else if (Timer == TIM3) {
|
|
||||||
RCC->APB1ENR |= RCC_APB1ENR_TIM3EN;
|
|
||||||
} else if (Timer == TIM4) {
|
|
||||||
RCC->APB1ENR |= RCC_APB1ENR_TIM4EN;
|
|
||||||
}
|
|
||||||
Timer->ARR |= Autoreload;
|
|
||||||
Timer->PSC |= Prescaler;
|
|
||||||
}
|
|
||||||
|
|
||||||
//La fonction TIM2_IRQHandler s'utilise dans le processeur, on l'a juste redifint, tel qu'à chaque overflow on met un bit 1 dans GPIOA_ODR
|
|
||||||
void TIM2_IRQHandler(void) { //On redefinit le IRQHandler qui est déjà ecrit dans le code source
|
|
||||||
if (TIM2->SR & TIM_SR_UIF) { //On met le bit de overflow à un dès qu'on a overflow
|
|
||||||
TIM2->SR &= ~TIM_SR_UIF; //Remise à zero
|
|
||||||
|
|
||||||
if (TIM2_Appel){TIM2_Appel();}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void MyTimer_ActiveIT(TIM_TypeDef * Timer, char Prio, void(*Interrupt_fonc)(void)){ //On veut créer une fonction qui envoie un signal au cas où il y a debordement, avec une prioritaire, 0 plus importante 15 moins importante
|
|
||||||
if (Timer == TIM2){
|
|
||||||
|
|
||||||
TIM2_Appel = Interrupt_fonc;
|
|
||||||
|
|
||||||
NVIC_EnableIRQ(TIM2_IRQn);
|
|
||||||
NVIC_SetPriority(TIM2_IRQn, Prio);
|
|
||||||
TIM2->DIER |= TIM_DIER_UIE; //Le registre DIER(Interrupt Enable Register) est mis au bit Update Interrupt, qui se commute lors d'un overflow
|
|
||||||
TIM2->CR1 |= TIM_CR1_CEN; //Clock Enable
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
//Fonction qui permet de clignoter le DEL à un pulse volue (Sinusoïdale)
|
|
||||||
//Si le sinus est haut(haute tension) le Duty Cicle est proche de 100%,
|
|
||||||
//si le sinus est bas (vers la tension la plus basse) le Duty Cycle est vers 0%
|
|
||||||
//On s'applique sur un plage de [0V; 3.3V]
|
|
||||||
|
|
||||||
|
|
||||||
void MyTimer_PWM(TIM_TypeDef * Timer , int Channel){
|
|
||||||
int pwrmd;
|
|
||||||
#if POWERMODE //Powermode 1
|
|
||||||
pwrmd = 0b110;
|
|
||||||
#else
|
|
||||||
pwrmd = 0b111; //Powermode 2
|
|
||||||
#endif
|
|
||||||
|
|
||||||
if (Channel == 1){
|
|
||||||
Timer->CCMR1 &= ~(0b111<<4); //On clear les trois bits qui sont de pwm
|
|
||||||
Timer->CCMR1 |= (pwrmd<<4); //On affecte le powermode au bits de lecture pour le µ-controlleur
|
|
||||||
Timer->CCMR1 |= TIM_CCMR1_OC1PE; //Update preload, il n'affecte pas le valeur avant que la prochaine cycle
|
|
||||||
Timer->CCER = TIM_CCER_CC1E; //Enable le pin voulu basculer
|
|
||||||
}
|
|
||||||
else if (Channel == 2){
|
|
||||||
Timer->CCMR1 &= ~(0b111<<12); //Le TIMx_CCMR1 configure deux channels, de bit [6:4] CH1, [14:12] CH2 (OC2M = Output Channel 2 )
|
|
||||||
Timer->CCMR1 |= (pwrmd<<12);
|
|
||||||
Timer->CCMR1 |= TIM_CCMR1_OC2PE;
|
|
||||||
Timer->CCER |= TIM_CCER_CC2E;
|
|
||||||
}
|
|
||||||
else if (Channel == 3){
|
|
||||||
Timer->CCMR1 &= ~(0b111<<4);
|
|
||||||
Timer->CCMR2 |= (pwrmd<<4);
|
|
||||||
Timer->CCMR2 |= TIM_CCMR2_OC3PE;
|
|
||||||
Timer->CCER |= TIM_CCER_CC3E;
|
|
||||||
}
|
|
||||||
else if (Channel == 4){
|
|
||||||
Timer->CCMR1 &= ~(0b111<<12);
|
|
||||||
Timer->CCMR2 |= (pwrmd<<12);
|
|
||||||
Timer->CCMR2 |= TIM_CCMR2_OC4PE;
|
|
||||||
Timer->CCER |= TIM_CCER_CC4E;
|
|
||||||
}
|
|
||||||
|
|
||||||
//En dessous d'ici, on a l'aide du plus gentil chat que je connais
|
|
||||||
// Enable auto-reload preload -- //Ensures that your initial configuration — PWM mode, duty cycle, period — actually takes effect before the timer starts counting.
|
|
||||||
Timer->CR1 |= TIM_CR1_ARPE;
|
|
||||||
// Force update event to load ARR and CCR values immediately
|
|
||||||
Timer->EGR |= TIM_EGR_UG;
|
|
||||||
// Start the timer
|
|
||||||
Timer->CR1 |= TIM_CR1_CEN;
|
|
||||||
|
|
||||||
switch (Channel) {
|
|
||||||
case 1:
|
|
||||||
if (Timer == TIM1){GPIOA->CRH &= ~(0xF<<0*4); GPIOA->CRH |= (0xA<<0*4); TIM1->BDTR |= 1<<15; }
|
|
||||||
if (Timer == TIM2){GPIOA->CRL &= ~(0xF<<0*4); GPIOA->CRL |= (0xA<<0*4);}
|
|
||||||
if (Timer == TIM3){GPIOA->CRL &= ~(0xF<<6*4); GPIOA->CRL |= (0xA<<6*4);}
|
|
||||||
if (Timer == TIM4){GPIOB->CRL &= ~(0xF<<5*4); GPIOB->CRL |= (0xA<<5*4);}
|
|
||||||
break;
|
|
||||||
case 2:
|
|
||||||
if (Timer == TIM1){GPIOA->CRH &= ~(0xF<<1*4); GPIOA->CRL |= (0xA<<1*4); TIM1->BDTR |= 1<<15;}
|
|
||||||
if (Timer == TIM2){GPIOA->CRL &= ~(0xF<<1*4); GPIOA->CRL |= (0xA<<1*4);}
|
|
||||||
if (Timer == TIM3){GPIOA->CRL &= ~(0xF<<7*4); GPIOA->CRL |= (0xA<<7*4);}
|
|
||||||
if (Timer == TIM4){GPIOB->CRL &= ~(0xF<<7*4); GPIOB->CRL |= (0xA<<7*4);}
|
|
||||||
break;
|
|
||||||
case 3:
|
|
||||||
if (Timer == TIM1){GPIOA->CRH &= ~(0xF<<2*4); GPIOA->CRH |= (0xA<<2*4); TIM1->BDTR |= 1<<15;}
|
|
||||||
if (Timer == TIM2){GPIOA->CRL &= ~(0xF<<2*4); GPIOA->CRL |= (0xA<<2*4);}
|
|
||||||
if (Timer == TIM3){GPIOB->CRL &= ~(0xF<<0*4); GPIOB->CRL |= (0xA<<0*4);}
|
|
||||||
if (Timer == TIM4){GPIOB->CRH &= ~(0xF<<0*4); GPIOB->CRH |= (0xA<<0*4);}
|
|
||||||
break;
|
|
||||||
case 4:
|
|
||||||
if (Timer == TIM1){GPIOA->CRH &= ~(0xF<<3*4); GPIOA->CRH |= (0xA<<3*4); TIM1->BDTR |= 1<<15;}
|
|
||||||
if (Timer == TIM2){GPIOA->CRL &= ~(0xF<<3*4); GPIOA->CRL |= (0xA<<3*4);}
|
|
||||||
if (Timer == TIM3){GPIOB->CRL &= ~(0xF<<1*4); GPIOB->CRL |= (0xA<<1*4);}
|
|
||||||
if (Timer == TIM4){GPIOB->CRH &= ~(0xF<<1*4); GPIOB->CRH |= (0xA<<1*4);}
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
//Une fonction qui met le bon PWM volue
|
|
||||||
int Set_DutyCycle_PWM(TIM_TypeDef *Timer, int Channel, int DutyC){
|
|
||||||
int CCR_VAL = (ARR_VAL + 1) * DutyC / 100; //ARR_VAL déjà definie
|
|
||||||
switch (Channel){
|
|
||||||
case 1: Timer->CCR1 = CCR_VAL;
|
|
||||||
case 2: Timer->CCR2 = CCR_VAL;
|
|
||||||
case 3: Timer->CCR3 = CCR_VAL;
|
|
||||||
case 4: Timer->CCR4 = CCR_VAL;
|
|
||||||
default: break;
|
|
||||||
}
|
|
||||||
return 0;
|
|
||||||
Timer->EGR |= TIM_EGR_UG;
|
|
||||||
}
|
|
||||||
0
Pilotes/Source/IT.c
Executable file → Normal file
0
Pilotes/Source/IT.c
Executable file → Normal file
0
Pilotes/Source/PWM.c
Executable file → Normal file
0
Pilotes/Source/PWM.c
Executable file → Normal file
12
Pilotes/Source/Servo.c
Executable file → Normal file
12
Pilotes/Source/Servo.c
Executable file → Normal file
|
|
@ -2,22 +2,18 @@
|
||||||
#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;
|
||||||
Set_DutyCycle_PWM(TIM4, 3, dutyCycle); //On met Duty cycle à 2% et il reste autour de 90 deg
|
PWM_Set_DutyCycle(Timer, Channel, dutyCycle);
|
||||||
}
|
}
|
||||||
|
|
||||||
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);
|
MyTimer_Base_Init(TIM4, 20000 - 1, 71); //Claire m'a
|
||||||
|
|
||||||
if (Channel == 3){
|
if (Channel == 3){
|
||||||
MyGPIO_Init(GPIOB, 8, AltOut_Ppull); // Outut push pull alternate
|
MyGPIO_Init(GPIOB, 8, AltOut_Ppull);
|
||||||
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
Executable file → Normal file
0
Pilotes/Source/Timer.c
Executable file → Normal 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, TIM4, 3); // Faire bouger le moteur servo
|
Servo_Moteur(angleVoileVar, TIM1, 1); // Faire bouger le moteur servo
|
||||||
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue