ME 507 Romi++
Cylindrical Differential Drive Robot created for ME 507 at Cal Poly in Spring 2025
|
Low-level motor control interface for STM32 using PWM. More...
#include <stdio.h>
#include <stdint.h>
#include <stm32f4xx_hal.h>
Go to the source code of this file.
Classes | |
struct | motor_t |
Struct representing a DC motor controlled by two PWM channels. More... |
Functions | |
void | motor_set_duty (motor_t *p_mot, int32_t duty) |
Sets the PWM duty cycle to control motor speed and direction. | |
void | motor_enable (motor_t *p_mot) |
Enables PWM output to the motor by starting both channels. | |
void | motor_disable (motor_t *p_mot) |
Disables PWM output to the motor. |
Low-level motor control interface for STM32 using PWM.
Defines the motor object and provides function prototypes to control motor direction and speed through timer-based PWM outputs.
void motor_disable | ( | motor_t * | p_mot | ) |
Disables PWM output to the motor.
p_mot | Pointer to motor object. |
Disables PWM output to the motor.
p_mot | Pointer to motor object to disable. |
Stops the timer's PWM outputs on the assigned motor channels.
void motor_enable | ( | motor_t * | p_mot | ) |
Enables PWM output to the motor by starting both channels.
p_mot | Pointer to motor object. |
Enables PWM output to the motor by starting both channels.
p_mot | Pointer to motor object to enable. |
Starts the timer's PWM outputs on the assigned motor channels.
void motor_set_duty | ( | motor_t * | p_mot, |
int32_t | duty ) |
Sets the PWM duty cycle to control motor speed and direction.
p_mot | Pointer to motor object. |
duty | Signed duty cycle (-timer period to +timer period). |
Sets the PWM duty cycle to control motor speed and direction.
p_mot | Pointer to motor object. |
duty | Signed value representing the duty cycle (positive = forward, negative = reverse). |
Saturates the input duty cycle to match the timer auto-reload (ARR) value. Enforces a deadzone below which effort is ignored. Uses two complementary PWM channels to drive H-bridge outputs.