Projet_voilier2/Projet_voile/Sources/Pwm_voile.c

54 lines
942 B
C

# include "Pwm_voile.h"
MyTimer_Struct_TypeDef Timer2, Timer3;
MyGPIO_Struct_TypeDef PB0;
XYZ mesures;
void write_pwm(void)
{
int val_pwm;
float cnt;
rouli_GetAccel(&mesures);
if((mesures.gY <= (-0.7)) || (mesures.gY >= 0.7))
{
val_pwm = 720;//0.985ms
}
else
{
cnt=Read_CNT();
if(cnt>=360)
{
cnt=cnt-360;
val_pwm=(Timer3.ARR/20)+((Timer3.ARR/20)*(cnt/360.0));
}
else
{
val_pwm=2*(Timer3.ARR/20)-((Timer3.ARR/20)*(cnt/360.0));
}
}
MyPWM_Duty(Timer3.Timer,3,val_pwm);
}
void init_pwm_voile(void)
{
Timer2.Timer=TIM2;
Timer2.ARR=18000;
Timer2.PSC=1000;
MyTimer_Base_Init(&Timer2);
MyTimer_ActiveIT(Timer2.Timer,2,&write_pwm);
MyTimer_Base_Start(Timer2.Timer);
PB0.GPIO=GPIOB;
PB0.GPIO_Conf=AltOut_Ppull;
PB0.GPIO_Pin=0;
MyGPIO_Init(&PB0);
Timer3.Timer=TIM3;
Timer3.ARR=14400;
Timer3.PSC=100;
MyTimer_Base_Init(&Timer3);
MyPWM_init(Timer3.Timer,3);
MyTimer_Base_Start(Timer3.Timer);
}