Drivers PWM and motors
Added comment to drivers and a clk prescaler to the pwm signal
This commit is contained in:
parent
b589ff8f1b
commit
ca351f536b
@ -8,20 +8,59 @@
|
||||
#ifndef DRIVERS_MOTORS_H_
|
||||
#define DRIVERS_MOTORS_H_
|
||||
|
||||
/**************************************************************************
|
||||
* BRIEF: Initializing a motor (maps a pwm signal to a certain pin) *
|
||||
* INFORMATION: The motor becomes active, Each motor configuration is changed in the "stm32f4xx_revo.h" file *
|
||||
* Example - pwmEnableMotor(MOTOR_1) *
|
||||
**************************************************************************/
|
||||
void pwmEnableMotor(uint8_t motor);
|
||||
|
||||
/**************************************************************************
|
||||
* BRIEF: Enables all motors (maps a pwm signal to all pins which will be connected to a motor) *
|
||||
* INFORMATION: All motors become active
|
||||
**************************************************************************/
|
||||
void pwmEnableAllMotors(void);
|
||||
|
||||
/**************************************************************************
|
||||
* BRIEF: Deactivates a motor (Disables the pwm signal for the motor pin )
|
||||
* INFORMATION:
|
||||
* Example - pwmDeactivateMotor(MOTOR_1)
|
||||
**************************************************************************/
|
||||
void pwmDeactivateMotor(uint8_t motor);
|
||||
|
||||
/**************************************************************************
|
||||
* BRIEF: If a motor is Deactivated (no pwm signal), this function will activate the motor to it's last state (the pwm signal will go back to is's last state) *
|
||||
* INFORMATION:
|
||||
* Example - pwmActivateMotor(MOTOR_1)
|
||||
**************************************************************************/
|
||||
void pwmActivateMotor(uint8_t motor);
|
||||
|
||||
/**************************************************************************
|
||||
* BRIEF: Deactivates all motors (Deactivate a pwm signal to all motor pins) *
|
||||
* INFORMATION: *
|
||||
* Example - pwmDeactivateAllMotors() *
|
||||
**************************************************************************/
|
||||
void pwmDeactivateAllMotors(void);
|
||||
|
||||
/**************************************************************************
|
||||
* BRIEF: Activates all motors (Activates a pwm signal to all motor pins to it's last state)* *
|
||||
* INFORMATION: *
|
||||
* Example - pwmActivateAllMotors() *
|
||||
**************************************************************************/
|
||||
void pwmActivateAllMotors(void);
|
||||
|
||||
/**************************************************************************
|
||||
* BRIEF: Change the speed of a certain motor if it's active *
|
||||
* INFORMATION: The speed is changes by switching the the pulse of a pwm signal *
|
||||
* Example - pwmAdjustSpeedOfMotor(MOTOR_2, 200) *
|
||||
**************************************************************************/
|
||||
void pwmAdjustSpeedOfMotor(uint8_t motor, uint16_t pulse);
|
||||
|
||||
/**************************************************************************
|
||||
* BRIEF: Change the speed of a certain motor if it's active *
|
||||
* INFORMATION: The speed is change by switching the the Duty Cycle of a pwm signal (The Duty Cycle may only take values between 0 - 100 %) *
|
||||
* Example - pwmAdjustSpeedOfMotor(MOTOR_2, 50); *
|
||||
**************************************************************************/
|
||||
void pwmAdjustSpeedOfMotorDutyCycle(uint8_t motor, uint16_t DutyCycle);
|
||||
|
||||
|
||||
|
@ -31,8 +31,18 @@ void pwmInit(GPIO_TypeDef * GPIO, uint16_t pin, TIM_TypeDef * tim, uint32_t Chan
|
||||
**************************************************************************/
|
||||
void setPwmPulse(uint32_t Channel, TIM_TypeDef * tim, uint16_t newPulse);
|
||||
|
||||
/**************************************************************************
|
||||
* BRIEF: startPwm Activates a pwm signal for a certain timer on a certain channel
|
||||
* INFORMATION:
|
||||
* Example - startPwm(TIM_CHANNEL_4, TIM3);
|
||||
**************************************************************************/
|
||||
void startPwm(uint32_t Channel, TIM_TypeDef * tim);
|
||||
|
||||
/**************************************************************************
|
||||
* BRIEF: stopPwm Deactivates a pwm signal for a certain timer on a certain channel
|
||||
* INFORMATION:
|
||||
* Example - stopPwm(TIM_CHANNEL_4, TIM3);
|
||||
**************************************************************************/
|
||||
void stopPwm(uint32_t Channel, TIM_TypeDef * tim);
|
||||
|
||||
#endif /* DRIVERS_PWM_H_ */
|
||||
|
@ -13,8 +13,8 @@
|
||||
#include "drivers/pwm.h"
|
||||
#include "drivers/motors.h"
|
||||
|
||||
#define MOTOR_PWM_INIT_PERIODE 2000
|
||||
#define MOTOR_PWM_INIT_PULSE 100
|
||||
#define MOTOR_PWM_INIT_PERIODE 65535
|
||||
#define MOTOR_PWM_INIT_PULSE MOTOR_PWM_INIT_PERIODE/2
|
||||
|
||||
/* A struct of a pwm motor profile */
|
||||
typedef struct
|
||||
@ -150,7 +150,7 @@ void pwmDeactivateMotor(uint8_t motor)
|
||||
}
|
||||
|
||||
/**************************************************************************
|
||||
* BRIEF: Activates all motors (Activates a pwm signal to all motor pins to it's last state) * *
|
||||
* BRIEF: Activates all motors (Activates a pwm signal to all motor pins to it's last state)* *
|
||||
* INFORMATION: *
|
||||
* Example - pwmActivateAllMotors() *
|
||||
**************************************************************************/
|
||||
|
@ -82,7 +82,7 @@ void pwmInit(GPIO_TypeDef * GPIO, uint16_t pin, TIM_TypeDef * tim, uint32_t Chan
|
||||
|
||||
TIM_HandleTypeDef TimHandle;
|
||||
|
||||
uint32_t uwPrescalerValue =0;
|
||||
uint32_t uwPrescalerValue =2;
|
||||
TimHandle.Instance = profile.tim; /* Sets timer */
|
||||
TimHandle.Init.Period = period; /* Sets period of pwm */
|
||||
TimHandle.Init.Prescaler = uwPrescalerValue;
|
||||
@ -91,6 +91,7 @@ void pwmInit(GPIO_TypeDef * GPIO, uint16_t pin, TIM_TypeDef * tim, uint32_t Chan
|
||||
|
||||
TIM_OC_InitTypeDef PWMConfig;
|
||||
|
||||
//PWMConfig.Pulse = 840;
|
||||
PWMConfig.Pulse = 840;
|
||||
PWMConfig.OCMode = TIM_OCMODE_PWM1;
|
||||
PWMConfig.OCPolarity = TIM_OCPOLARITY_HIGH;
|
||||
@ -141,10 +142,11 @@ void pwmInit(GPIO_TypeDef * GPIO, uint16_t pin, TIM_TypeDef * tim, uint32_t Chan
|
||||
}
|
||||
|
||||
/**************************************************************************
|
||||
* BRIEF: setPwmPulse changes a certain pulse for an initialized pwm signal *
|
||||
* BRIEF: setPwmPulse changes a certain pulse for an initialized pwm signal
|
||||
* INFORMATION: It's only possible to change the pwm output for a certain timer
|
||||
* on a certain channel, not a pin output
|
||||
* Example - setPwmPulse(TIM_CHANNEL_4, TIM3, 500); *
|
||||
* on a certain channel, not a pin output. This function will only run is a pwm is active.
|
||||
* The pwm is activated and deactivated at startPwm/stopPwm
|
||||
* Example - setPwmPulse(TIM_CHANNEL_4, TIM3, 500);
|
||||
**************************************************************************/
|
||||
void setPwmPulse(uint32_t Channel, TIM_TypeDef * tim, uint16_t newPulse)
|
||||
{
|
||||
@ -175,6 +177,11 @@ void setPwmPulse(uint32_t Channel, TIM_TypeDef * tim, uint16_t newPulse)
|
||||
}
|
||||
}
|
||||
|
||||
/**************************************************************************
|
||||
* BRIEF: startPwm Activates a pwm signal for a certain timer on a certain channel
|
||||
* INFORMATION:
|
||||
* Example - startPwm(TIM_CHANNEL_4, TIM3);
|
||||
**************************************************************************/
|
||||
void startPwm(uint32_t Channel, TIM_TypeDef * tim)
|
||||
{
|
||||
pwmOk = true;
|
||||
@ -184,6 +191,11 @@ void startPwm(uint32_t Channel, TIM_TypeDef * tim)
|
||||
HAL_TIM_PWM_Start(&TimHandle, Channel);
|
||||
}
|
||||
|
||||
/**************************************************************************
|
||||
* BRIEF: stopPwm Deactivates a pwm signal for a certain timer on a certain channel
|
||||
* INFORMATION:
|
||||
* Example - stopPwm(TIM_CHANNEL_4, TIM3);
|
||||
**************************************************************************/
|
||||
void stopPwm(uint32_t Channel, TIM_TypeDef * tim)
|
||||
{
|
||||
pwmOk = false;
|
||||
|
Reference in New Issue
Block a user