Ajouter fonctinnalité comptage/décomptage
This commit is contained in:
parent
5175474912
commit
663bef108a
4 changed files with 44 additions and 17 deletions
|
|
@ -2,3 +2,5 @@
|
|||
extern void configEncoder(TIM_TypeDef * Timer);
|
||||
extern void configChannel();
|
||||
extern int returnAngle (TIM_TypeDef * Timer);
|
||||
extern int vent2voile(int angle);
|
||||
extern void Servo_Moteur(int angle, TIM_TypeDef * Timer, int Channel);
|
||||
|
|
@ -4,6 +4,9 @@
|
|||
#include "Timer.h"
|
||||
#include "DriverGPIO.h"
|
||||
#include "Girouette.h"
|
||||
#include "PWM.h"
|
||||
|
||||
#include <stdlib.h> // 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);
|
||||
}
|
||||
|
|
@ -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);
|
||||
}
|
||||
|
|
|
|||
25
principal.c
25
principal.c
|
|
@ -1,19 +1,22 @@
|
|||
#include "stm32f10x.h"
|
||||
#include <stdio.h> // 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();
|
||||
// Giroutte.c
|
||||
|
|
@ -24,12 +27,16 @@ int main ( void ){
|
|||
//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));
|
||||
|
||||
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue