PWM

General discussion about topics related to OpenMV.
lab
Posts: 18
Joined: Wed Mar 21, 2018 9:02 pm

PWM

Postby lab » Wed Jul 18, 2018 9:28 pm

We connected the motor for a drill to pin 6. I can turn the motor on or off by setting the pin high or low, but now we'd like to use PWM to control it. When I use the following example code, nothing happens:

from pyb import Pin, Timer

p = Pin('P6')
tim = Timer(2, freq=10)
ch = tim.channel(1, Timer.PWM, pin=p)
ch.pulse_width_percent(50)

Could you please let me know what is the issue?
User avatar
kwagyeman
Posts: 2313
Joined: Sun May 24, 2015 2:10 pm

Re: PWM

Postby kwagyeman » Wed Jul 18, 2018 9:29 pm

Have you tried this example code?

Code: Select all

# PWM Control Example
#
# This example shows how to do PWM with your OpenMV Cam.

import time
from pyb import Pin, Timer

tim = Timer(4, freq=1000) # Frequency in Hz
# Generate a 1KHz square wave on TIM4 with 50% and 75% duty cycles on channels 1 and 2, respectively.
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):
    time.sleep(1000)
Nyamekye,
User avatar
kwagyeman
Posts: 2313
Joined: Sun May 24, 2015 2:10 pm

Re: PWM

Postby kwagyeman » Wed Jul 18, 2018 9:30 pm

Note sure if PWM on PIN 6 works.
Nyamekye,

Return to “General Topics”

Who is online

Users browsing this forum: No registered users and 3 guests