41 lines
802 B
C
41 lines
802 B
C
#include "motoreducteur.h"
|
|
#include "timer.h"
|
|
#include "gpio.h"
|
|
|
|
void MyMotor_Init()
|
|
{
|
|
MyTimer_Struct_Typedef Timer;
|
|
MyGPIO_Struct_TypeDef Pin_Direction;
|
|
|
|
//F de 50kHz
|
|
Timer.Timer = TIM3;
|
|
Timer.ARR = 3599; //72Mhz / 50kHz = 1440 et 1440*1 = 1440
|
|
Timer.PSC = 0;
|
|
|
|
Pin_Direction.GPIO = GPIOB;
|
|
Pin_Direction.GPIO_Pin = 1;
|
|
Pin_Direction.GPIO_Conf = Out_PullUp;
|
|
|
|
MyTimer_Base_Init(&Timer);
|
|
MyGPIO_Init(&Pin_Direction);
|
|
|
|
//Pin Timer 3 Channel 3 PB0
|
|
MyTimer_PWM(TIM3, 3);
|
|
MyTimer_DutyCycle(TIM3, 3, 0);
|
|
|
|
MyTimer_Base_Start(Timer);
|
|
MyMotor_ChangeDirection(ANTIHOR);
|
|
}
|
|
|
|
void MyMotor_ChangeSpeed(unsigned int DC)
|
|
{
|
|
MyTimer_DutyCycle(TIM3, 3, DC);
|
|
}
|
|
|
|
void MyMotor_ChangeDirection(uint8_t Sens)
|
|
{
|
|
if (Sens == HORAIRE)
|
|
MyGPIO_Set(GPIOB, 1);
|
|
if (Sens == ANTIHOR)
|
|
MyGPIO_Reset(GPIOB, 1);
|
|
}
|