← Back to Lab Hub RP2040 JHS Lab

DC Motor & DRV8833 Simulator

H-Bridge Logic & PWM Duty Cycle Speed Control

DC MOTOR RUNNING: CLOCKWISE
PWM WAVEFORM (ACTIVE PIN)
PWM Duty Cycle: 50% (32768 duty_u16)
Estimated RPM: 150 RPM
IN1 (GP14): PWM 50% IN2 (GP15): LOW
🐍 Live MicroPython Code Execution
from machine import Pin, PWM
# DRV8833 Pins (GP14=IN1, GP15=IN2)
in1 = PWM(Pin(14), freq=1000)
in2 = PWM(Pin(15), freq=1000)

def drive_motor():
  if mode == "BRAKE":
    in1.duty_u16(65535) # HIGH
    in2.duty_u16(65535) # HIGH
  elif dir == "FORWARD":
    in1.duty_u16(32768)
    in2.duty_u16(0) # LOW
  elif dir == "REVERSE":
    in1.duty_u16(0) # LOW
    in2.duty_u16(32768)
📝 Concept Check Quiz
Why does setting both DRV8833 input pins to maximum PWM (IN1=HIGH, IN2=HIGH) trigger a "Short Brake" instead of driving the motor at 100% speed?