Skip to content

Commit 5c32484

Browse files
aykevldeadprogram
authored andcommitted
tutorials: improve PWM tutorial slightly
Most importantly, I have explained how to look up the PWM peripheral for a given pin.
1 parent b7c8b2a commit 5c32484

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

content/docs/tutorials/pwm.md

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,9 +80,17 @@ pwm := machine.PWM4
8080
```
8181
Now things start to look quite different to the blinky example. This code creates a variable which references a PWM peripheral.
8282

83-
A _peripheral_ refers to any on-board integrated circuit which interfaces directly with the microprocessor and has I/O capabilities. Some other tasks which different peripherals may manage are communications ([I2C](https://en.wikipedia.org/wiki/I%C2%B2C), [SPI](https://en.wikipedia.org/wiki/Serial_Peripheral_Interface), UART, etc.) and [ADC](https://en.wikipedia.org/wiki/Analog-to-digital_converter)/[DAC](https://en.wikipedia.org/wiki/Digital-to-analog_converter).
83+
If you don't know which PWM peripheral to use for a pin, you can look it up in the documentation for your board. For example, for the [Raspberry Pi Pico](../../reference/microcontrollers/pico/) you can find a table with pins:
8484

85-
In the case of a PWM peripheral, there is the additional idea of a channel which can be used to control more than one pin at the same time with a single PWM peripheral.
85+
| Pin | Hardware pin | PWM |
86+
| ----------------- | ------------ | -------------------- |
87+
| `LED` | `GPIO25` | `PWM4` (channel B) |
88+
89+
Here, you can see the LED pin can be controlled by `PWM4`. (The table is a lot larger than this, but this is the relevant part).
90+
91+
A _peripheral_ refers to any on-chip piece of hardware that runs independently of the CPU core but which interfaces directly with the CPU. They are used for things that are difficult or impossible to do in software. Some other tasks which different peripherals may manage are communications ([I2C](https://en.wikipedia.org/wiki/I%C2%B2C), [SPI](https://en.wikipedia.org/wiki/Serial_Peripheral_Interface), UART, etc.) and [ADC](https://en.wikipedia.org/wiki/Analog-to-digital_converter)/[DAC](https://en.wikipedia.org/wiki/Digital-to-analog_converter).
92+
93+
In the case of a PWM peripheral, there is the additional idea of a channel which can be used to control more than one pin at the same time with a single PWM peripheral. All channels of a PWM peripheral have the same period (or frequency), but they can have a different duty cycle (or "on" time).
8694

8795
```go
8896
var period uint64 = 1e9 / 500

0 commit comments

Comments
 (0)