Projet_voilier2/Projet_voile/Sources/CAP_voilier.c

52 lines
922 B
C

#include "CAP_voilier.h"
MyTimer_Struct_TypeDef timer1;
void Madirection_IT (void);
signed char direction ;
int duty_cap ;
MyGPIO_Struct_TypeDef PA8;
MyGPIO_Struct_TypeDef PB1;
char valeur =0;
extern char MyChar;
void My_cap_init(void)
{
PA8.GPIO=GPIOA;
PA8.GPIO_Conf=AltOut_Ppull;
PA8.GPIO_Pin=8;
MyGPIO_Init(&PA8);
PB1.GPIO=GPIOB;
PB1.GPIO_Conf=Out_Ppull;
PB1.GPIO_Pin=1;
MyGPIO_Init(&PB1);
timer1.Timer=TIM1;
timer1.ARR=100; //pour avoir 20Khz et un PWM a 100 positions
timer1.PSC=36;
MyTimer_Base_Init(&timer1);
MyTimer_Base_Start(timer1.Timer);
MyPWM_init(timer1.Timer,1);
MyUART_init();
MyUART_ActiveIT(1,&Madirection_IT);
}
void Madirection_IT (void)
{
direction = UART_receive();
if( direction <0 )
{
MyGPIO_Set(GPIOB,1);
valeur =-direction;
}
else
{
MyGPIO_Reset(GPIOB,1);
valeur = direction;
}
duty_cap=valeur;
MyPWM_Duty(timer1.Timer,1, duty_cap );
}