Control One Servo and Two DC Motors

I have both the OpenMV H7 and H7 plus. Though I have the motor shield and servo shields, I can’t use them due to weight constraints for my project. To control my motors, I am using the DRV8838 motor driver. My pin assignments are:
P0: I/O for motor driver 1
P1: I/O for motor driver 2
P7: PWM for motor driver 1
P8: PWM for motor driver 2
P9: PWM for servo

To control signals for P0 and P1, I use the pin_control.py example code. To control the PWM signals for P7 and P8, I use the pwm_control.py example code. To control the PWM signal for P9, I use the servo_control.py code.

I can control the PWM signal on P7 and P8 and it works for the dc motors. I can also control the PWM signal on P9 and it works for the servo motor. However, I can’t control P7, P8, and P9 at the same time . The code I’m running is:

import time
import sensor
from pyb import Pin, Timer, Servo

s3 = Servo(3) # P9

tim = Timer(4, freq=1000) 

pin0 = Pin('P0', Pin.OUT_PP, Pin.PULL_NONE)
pin1 = Pin('P1', Pin.OUT_PP, Pin.PULL_NONE)
ch1 = tim.channel(1, Timer.PWM, pin=Pin("P7"), pulse_width_percent=50)
ch2 = tim.channel(2, Timer.PWM, pin=Pin("P8"), pulse_width_percent=75)

while True:
    pin0.value(1)
    pin1.value(1)
    s3.pulse_width(1200)
    time.sleep(5)

If the servo definition is at the top, the servo does not turn. If the servo definition is at the bottom, the dc motors buzz and turn extremely slowly (are P7 and P8 somehow redefined as servo PWM signals?). The PWM signal in servo_control.py does not work for the motor driver, and the PWM signal in pwm_control.py does not work for the servo. How can I control one servo and two DC motors?

The same timer module is used for PWM and servo control. As such, they are mutually exclusive. You may use Servo output or PWM. Not both.