Skip to content

Add tour to explain PWM #454

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: dev
Choose a base branch
from
Open

Add tour to explain PWM #454

wants to merge 3 commits into from

Conversation

aykevl
Copy link
Member

@aykevl aykevl commented May 1, 2025

This tour explains how to do the following:

  • Blink an LED (on supported hardware, this is mostly just SAMD21)
  • Fade an LED
  • Control servos (directly, and using the servo driver).

aykevl added 3 commits May 1, 2025 17:45
I forgot this, this should not have been committed.
This update includes a few new features:

  * Better error reporting for type errors (they now include a range).
  * PWM support.
  * LED blink/fade support when connected to a PWM.
  * New part: a servo motor (using PWM)
This tour includes blinking LEDs, fading LEDs, and controlling servos.

We get a channel number back. One PWM peripheral typically has 2-4 channels, which can be connected to certain pins. Which pins can be used depends a lot on the hardware, which we'll [get to later](../multiple/#finding-the-correct-pwm-peripheral-and-pins). For now, all you need to know is that the PWM channel is now connected to a single GPIO pin.

To actually make the LED blink, we will set the duty cycle to half the "top" value of the LED:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps define "duty cycle" here.

weight: 10
---

Servos are controlled using a form of pulse-width modification (PWM) to control their position. Every 20ms or so (the precise interval doesn't matter too much) a pulse of 1ms to 2ms is sent that indicates the target position for the motor. The pulse width is what matters here: 1.5ms indicates the center position, 1ms all the way to the right, and 2ms all the way to the left.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tell us what a servo is, please.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants