Hi,
Still kind of new to working we motor drivers.
Code is at the bottom
Background:
I’m using a pi pico 2 w - https://www.raspberrypi.com/documentation/microcontrollers/pico-series.html#pico-2-family - powered over USB
along side with the DRV8835 - Pololu - DRV8835 Dual Motor Driver Carrier - VIN and GND are connected to a supply at 3.7v and limited at 2.5amps
I’ve connected the pi pico 2 to the drv8835 as described the documentation.
Problem(s):
- If the power supply is on before the micro controller the program fails - I hear an audible buzzing from the micro controller but the motor does not spin. There is a small draw of current.
- The program works initially when the microcontroller is turned on before the power supply. The motor spins and I see a nominal draw of current. After setting SPEED_OFF, when SPEED_SLOW is set - I hear an audible buzzing from the micro controller but the motor does not spin. There is a small draw of current.
I would expect to be able to set pwm to 0 and be able to then > 0 value later on. I’ve also tested this with the DRV8833 and I’m experiencing the same issue. I’ve successfully tested this on the MP6550 and it does just fine.
Let me know if I can elaborate anywhere. Appreciate any help and feedback.
#include "pico/stdlib.h"
#include "hardware/pwm.h"
#define MOTOR_GPIO 0 // GPIO pin connected to motor PWM input
// PWM duty cycle values (0-65535 for 16-bit resolution)
#define SPEED_OFF 0
#define SPEED_SLOW (65535 / 4) // 25% duty cycle
#define SPEED_FAST (65535 * 3 / 4) // 75% duty cycle
void setup_motor_pwm(uint gpio) {
gpio_set_function(gpio, GPIO_FUNC_PWM);
uint slice_num = pwm_gpio_to_slice_num(gpio);
pwm_set_wrap(slice_num, 65535); // Set top of PWM counter
pwm_set_enabled(slice_num, true);
}
void set_motor_speed(uint gpio, uint16_t duty_cycle) {
uint slice_num = pwm_gpio_to_slice_num(gpio);
pwm_set_chan_level(slice_num, pwm_gpio_to_channel(gpio), duty_cycle);
}
int main() {
stdio_init_all();
setup_motor_pwm(MOTOR_GPIO);
while (true) {
set_motor_speed(MOTOR_GPIO, SPEED_SLOW);
sleep_ms(5000);
set_motor_speed(MOTOR_GPIO, SPEED_FAST);
sleep_ms(5000);
set_motor_speed(MOTOR_GPIO, SPEED_OFF);
sleep_ms(5000);
}
return 0;
}```