Merge pull request #4 from MDHSweden/pwmDriver
Drivers approved by Lennart
This commit is contained in:
commit
c0e4f39d86
@ -13,7 +13,7 @@
|
||||
#include "drivers/pwm.h"
|
||||
#include "drivers/motors.h"
|
||||
|
||||
#define MOTOR_PWM_INIT_PERIODE 65535
|
||||
#define MOTOR_PWM_INIT_PERIODE 2000
|
||||
#define MOTOR_PWM_INIT_PULSE MOTOR_PWM_INIT_PERIODE/2
|
||||
|
||||
/* A struct of a pwm motor profile */
|
||||
@ -25,6 +25,16 @@ typedef struct
|
||||
uint32_t channel; //TIM_CHANNEL_1/TIM_CHANNEL_1/..
|
||||
}motorProfile;
|
||||
|
||||
/**************************************************************************
|
||||
* BRIEF: Returns the final pulse of a motor driver call
|
||||
* INFORMATION: The pulse is not allowed to be higher then 94 % of the total periode of the pwm signal, otherwise the pwm won't perform correctly
|
||||
* Example - pwmEnableMotor(MOTOR_1)
|
||||
**************************************************************************/
|
||||
uint16_t checkPulse(uint16_t pulse)
|
||||
{
|
||||
return ((pulse/MOTOR_PWM_INIT_PERIODE)*100 < 94)? pulse: MOTOR_PWM_INIT_PERIODE*0.94;
|
||||
}
|
||||
|
||||
/**************************************************************************
|
||||
* BRIEF: Returns a profile of a certain motor
|
||||
* INFORMATION: Each Motor has a certain profile which includes a pin, port, timer and a timer channel
|
||||
@ -152,7 +162,6 @@ void pwmDeactivateMotor(uint8_t motor)
|
||||
/**************************************************************************
|
||||
* BRIEF: Activates all motors (Activates a pwm signal to all motor pins to it's last state)* *
|
||||
* INFORMATION: *
|
||||
* Example - pwmActivateAllMotors() *
|
||||
**************************************************************************/
|
||||
void pwmActivateAllMotors(void)
|
||||
{
|
||||
@ -178,7 +187,7 @@ void pwmAdjustSpeedOfMotor(uint8_t motor, uint16_t pulse)
|
||||
{
|
||||
motorProfile profile = getMotorProfile(motor);
|
||||
|
||||
setPwmPulse(profile.channel, profile.tim, pulse);
|
||||
setPwmPulse(profile.channel, profile.tim, checkPulse(pulse));
|
||||
}
|
||||
|
||||
/**************************************************************************
|
||||
@ -191,5 +200,5 @@ void pwmAdjustSpeedOfMotorDutyCycle(uint8_t motor, uint16_t DutyCycle)
|
||||
uint16_t pulse = (DutyCycle*MOTOR_PWM_INIT_PERIODE)/100; /* Converts the DutyCycle to a pulse */
|
||||
motorProfile profile = getMotorProfile(motor);
|
||||
|
||||
setPwmPulse(profile.channel, profile.tim, pulse);
|
||||
setPwmPulse(profile.channel, profile.tim, checkPulse(pulse));
|
||||
}
|
||||
|
@ -81,10 +81,9 @@ void pwmInit(GPIO_TypeDef * GPIO, uint16_t pin, TIM_TypeDef * tim, uint32_t Chan
|
||||
|
||||
TIM_HandleTypeDef TimHandle;
|
||||
|
||||
uint32_t uwPrescalerValue =2;
|
||||
TimHandle.Instance = profile.tim; /* Sets timer */
|
||||
TimHandle.Init.Period = period; /* Sets period of pwm */
|
||||
TimHandle.Init.Prescaler = uwPrescalerValue;
|
||||
TimHandle.Init.Prescaler = 88; /* pwm prescaler of clk */
|
||||
TimHandle.Init.ClockDivision = 0;
|
||||
TimHandle.Init.CounterMode = TIM_COUNTERMODE_UP;
|
||||
|
||||
|
Reference in New Issue
Block a user