MBot Software Library  v1.0
An API documentation to mbot_firmware repository
motor.h
1 
10 #ifndef MBOT_MOTOR_H
11 #define MBOT_MOTOR_H
12 
13 #include <mbot/defs/mbot_pins.h>
14 
15 #define PWM_SLICES 8
16 static uint16_t slice_frequencies[PWM_SLICES] = {0};
17 static uint16_t pwm_wraps[PWM_SLICES] = {0};
18 
19 typedef enum mbot_motor_state {OFF, ON} mbot_motor_state;
20 
21 // motor pin table
22 typedef enum mbot_motor_pins {
23  M0_EN = M0_PWM_PIN,
24  M0_PH = M0_DIR_PIN,
25  M1_EN = M1_PWM_PIN,
26  M1_PH = M1_DIR_PIN,
27  M2_EN = M2_PWM_PIN,
28  M2_PH = M2_DIR_PIN,
29  M3_EN = M3_PWM_PIN,
30  M3_PH = M3_DIR_PIN
31 } mbot_motor_pins;
32 
33 // lookup table for motor 0-3
34 static uint16_t motor_en[4] = {M0_EN, M1_EN, M2_EN, M3_EN}; //PWM
35 static uint16_t motor_ph[4] = {M0_PH, M1_PH, M2_PH, M3_PH}; //DIR
36 
44 int mbot_motor_init_freq(uint8_t ch, uint16_t freq);
45 
49 void mbot_motor_adc_init();
50 
57 int mbot_motor_init(uint8_t ch);
58 
65 int mbot_motor_cleanup(uint8_t ch);
66 
74 //int mbot_motor_set_duty_int16(uint8_t ch, int32_t duty);
75 
83 int mbot_motor_set_duty(uint8_t ch, float duty);
84 
91 
92 // These would require PMODE=HIGH on DRV8874
93 // int mbot_motor_free_spin(uint8_t motor_num);
94 // int mbot_motor_brake(uint8_t motor_num);
95 
96 #endif /* MBOT_MOTOR_H */
int mbot_motor_cleanup(uint8_t ch)
Cleanup motor settings.
Definition: motor.c:58
float mbot_motor_read_voltage()
Returns voltage for motor driver read from ADC3 on Pico+ boards.
Definition: motor.c:94
int mbot_motor_init(uint8_t ch)
Initialize motor with default frequency.
Definition: motor.c:47
void mbot_motor_adc_init()
Initialize ADC3 to read motor driver voltage. Must be called before mbot_motor_read_voltage.
Definition: motor.c:52
int mbot_motor_set_duty(uint8_t ch, float duty)
Set duty cycle for the motor using an int16_t value.
Definition: motor.c:67
int mbot_motor_init_freq(uint8_t ch, uint16_t freq)
Initialize motor with specific frequency.
Definition: motor.c:11