microsoft / microsoft/pxt-microbit
Default PWM frequency is very low, resulting flickering and noisy motor control
Nobody has claimed this yet.
- Dominant language
- TypeScript
- Stars
- 804
- Forks
- 721
- Avg merge
- 2d 9h
- Merged PRs (30d)
- 2
Description
Describe the bug
The default PWM frequency on the pin outputs is very low, resulting flickering and noisy motor operation when using analog write.
To Reproduce
In makecode:
basic.forever(function () {
pins.analogWritePin(AnalogPin.P0, 300)
})
Expected behavior
Led flickering can be seen with the bare eye. You can also see it as a "trail" when the led moves.
When using motor control via a FET transistor, the operation will become very noisy. Video: https://youtu.be/Fer2_VP-BQo
micro:bit version (please complete the following information):
V1 and V2
Additional context
Why not make default PWM 200 instead of 20000?
I have tested the following code with a cheap servo to see if the servo will get affected after changing the pwm frequency, and the servo still works like before.
pins.analogWritePin(AnalogPin.P1, 0)
pins.analogSetPeriod(AnalogPin.P1, 200)
basic.forever(function () {
pins.servoWritePin(AnalogPin.P1, 45)
basic.pause(1000)
pins.servoWritePin(AnalogPin.P1, 135)
basic.pause(1000)
})
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by tracing the pins.analogWritePin and pins.analogSetPeriod entry points for the default PWM period on micro:bit V1 and V2. Compare the current behavior with the proposed 200 setting, then verify that LED output is no longer visibly flickery and motor control is less noisy without breaking the servo example.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- typescript
- Domain
- embedded-iot
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 38/100