Projet_voilier2/Projet_DevDrivers/Sources/CAP_voilier.c
2023-04-11 15:34:44 +02:00

48 lines
865 B
C

#include "UART.h"
#include "TIMER.h"
#include "GPIO.h"
MyTimer_Struct_TypeDef timer1;
void Madirection_IT (void);
signed char direction ;
int duty_cap ;
MyGPIO_Struct_TypeDef PA9;
MyGPIO_Struct_TypeDef PB1;
void My_cap(void)
{
PA9.GPIO=GPIOA;
PA9.GPIO_Conf=AltOut_Ppull;
PA9.GPIO_Pin=9;
MyGPIO_Init(&PA9);
PB1.GPIO=GPIOB;
PB1.GPIO_Conf=Out_Ppull;
PB1.GPIO_Pin=1;
MyGPIO_Init(&PB1);
timer1.Timer=TIM1;
timer1.ARR=20000; //pour avoir 20Khz
timer1.PSC=3600;
MyTimer_Base_Init(&timer1);
MyTimer_Base_Start(timer1.Timer);
MyPWM_init(timer1.Timer,2);
MyUART_init();
MyUART_ActiveIT(2,&Madirection_IT);
}
void Madirection_IT (void)
{
direction = UART_receive();
if( direction <0 )
{
MyGPIO_Set(GPIOB,1);
}else
{
MyGPIO_Reset(GPIOB,1);
}
duty_cap=(20000*(int8_t) direction)/100 ;
MyPWM_Duty(timer1.Timer,2, duty_cap );
}