soft_start_stop_profile.py

M5Stack Encoder Motor Driver Unit (DRV8837DSGR) · File : soft_start_stop_profile.py · Language : MicroPython · Use case : Démarrage et arrêt progressifs pour éviter les chocs mécaniques et les pics de courant.

Generation of PWM ramp-up and ramp-down for smooth motor operation.

Modifies the PWM value in regular increments to increase or decrease speed. This reduces mechanical stress on gears and current spikes at startup. The steps and delay parameters allow adjusting the acceleration duration.

soft_start_stop_profile.py

import time
from m5stack import i2c

ADDR = 0x2F
bus = i2c.I2C(1)

def set_pwm(val):
    bus.writeto_mem(ADDR, 0x01, bytes([val]))

def soft_start(target_pwm=200, steps=50, delay=0.02):
    for i in range(steps):
        pwm = int((target_pwm / steps) * (i + 1))
        set_pwm(pwm)
        time.sleep(delay)

def soft_stop(steps=50, delay=0.02):
    current = 200 # Valeur actuelle supposée
    for i in range(steps, 0, -1):
        pwm = int((current / steps) * i)
        set_pwm(pwm)
        time.sleep(delay)
    set_pwm(0)

print("Démarrage progressif...")
soft_start()
print("Fonctionnement...")
time.sleep(3)
print("Arrêt progressif...")
soft_stop()

← Back to the board