55 lines
1.2 KiB
C
55 lines
1.2 KiB
C
#include "Driver_GPIO.h"
|
|
#include "MyTimer.h"
|
|
#include "stm32f10x.h"
|
|
#include "bordage.h"
|
|
|
|
/********** PWM **********/
|
|
#define TIMER_PWM (TIM3)
|
|
#define CANAL_PWM (4)
|
|
#define GPIO_PWM (GPIOB)
|
|
#define GPIO_PIN_PWM (1)
|
|
/*************************/
|
|
|
|
|
|
#define TIMER_CI (TIM2) // Timer codeur incrémental
|
|
#define GIROUETTE_PHA (PA1)
|
|
#define GIROUETTE_PHB (PA4)
|
|
#define GIROUETTE_INDEX (PB0)
|
|
#define SERVO_VOILE_PWM (PA4)
|
|
|
|
|
|
int bordage ( int angle ) {
|
|
// l'angle se comprends entre 0 et 90
|
|
MyGPIO_Struct_TypeDef GPIO_Struct;
|
|
|
|
float angle_servo = 90.0 - angle;
|
|
|
|
float duty_cycle = angle_servo/18.0 + 5.0; // convertit l'angle en rapport cyclique pour la commande du servo moteur
|
|
|
|
// Configuration du timer avec une période de 20ms
|
|
MyTimer_Struct_TypeDef TIM;
|
|
TIM.Timer = TIMER_PWM;
|
|
TIM.ARR = 59999;
|
|
TIM.PSC = 23;
|
|
MyTimer_Base_Init(&TIM);
|
|
|
|
// Configuration du GPIO sur lequel sort la PWM
|
|
GPIO_Struct.GPIO = GPIO_PWM;
|
|
GPIO_Struct.GPIO_Pin = GPIO_PIN_PWM;
|
|
GPIO_Struct.GPIO_Conf = AltOut_Ppull;
|
|
MyGPIO_Init(&GPIO_Struct);
|
|
|
|
// Génération de la PWM
|
|
MyTimer_PWM (TIMER_PWM, CANAL_PWM);
|
|
Set_Duty_Cycle(TIMER_PWM, CANAL_PWM, duty_cycle);
|
|
|
|
return 0;
|
|
}
|
|
|
|
|
|
|
|
|
|
void Roulis_Handler ( void )
|
|
{
|
|
bordage(0);
|
|
}
|