Quantcast
Viewing all articles
Browse latest Browse all 4883

General • How the brushed motor rotates continuously via PWM

I'm using a Raspberry Pi pico w with the following code:

Code:

from machine import Pinfrom machine import PWMpwmPin = Pin(15)pwmOutput = PWM(pwmPin)while True:    frequency = float(input("Enter pwm frequency in Hz : "))    if frequency >= 0:        pwmOutput.freq(int(frequency))        break    else:        print("frequency cannot be negative. Enter again ")        continuedef duty():    duty_cycle = float(input("Enter duty_cycle in percentage : "))    duty_cycle = int(duty_cycle * 65535/ 100)    print("duty_cycle = ", duty_cycle)    return duty_cyclewhile True:    duty_cycle = duty()    if 0 <= duty_cycle <= 65535:        pwmOutput.duty_u16(duty_cycle)    else:        print("Unsuitable range, please enter again")        continue
When I set the frequency to 250hz, about 30% of the motor starts to spin slightly, about 35% stops, > 35% starts to spin in the opposite direction.
During the rotation process, the motor keeps spinning and stopping.

How do I change this to ensure that the motor continues to run?
Image may be NSFW.
Clik here to view.
a1a33bac810a6b491ba405280c0d8ce7.png

Image may be NSFW.
Clik here to view.
abb6c57b8db7dd559eb37c67413381b7.png

Statistics: Posted by 1417766861 — Thu May 16, 2024 2:50 am



Viewing all articles
Browse latest Browse all 4883

Trending Articles