ME 507 Romi++
Cylindrical Differential Drive Robot created for ME 507 at Cal Poly in Spring 2025
Loading...
Searching...
No Matches
motor_driver.h File Reference

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.

Detailed Description

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.

Function Documentation

◆ motor_disable()

void motor_disable ( motor_t * p_mot)

Disables PWM output to the motor.

Parameters
p_motPointer to motor object.

Disables PWM output to the motor.

Parameters
p_motPointer to motor object to disable.

Stops the timer's PWM outputs on the assigned motor channels.

◆ motor_enable()

void motor_enable ( motor_t * p_mot)

Enables PWM output to the motor by starting both channels.

Parameters
p_motPointer to motor object.

Enables PWM output to the motor by starting both channels.

Parameters
p_motPointer to motor object to enable.

Starts the timer's PWM outputs on the assigned motor channels.

◆ motor_set_duty()

void motor_set_duty ( motor_t * p_mot,
int32_t duty )

Sets the PWM duty cycle to control motor speed and direction.

Parameters
p_motPointer to motor object.
dutySigned duty cycle (-timer period to +timer period).

Sets the PWM duty cycle to control motor speed and direction.

Parameters
p_motPointer to motor object.
dutySigned 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.