Skip to content

Commit a522127

Browse files
Added PWM info for GIGA
1 parent 8d60adb commit a522127

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

content/micropython/01.basics/05.digital-analog-pins/digital-analog-pins.md

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,3 +134,31 @@ pwm.freq(1000)
134134
while True:
135135
pwm.duty_u16(duty)
136136
```
137+
138+
### PWM on GIGA (STM32)
139+
140+
On STM32 boards like the GIGA R1, the PWM setup is slightly different. You need to use the `Timer` module along with the `Pin` module to configure PWM.
141+
142+
Here's how you can set up PWM on STM32 boards:
143+
144+
```python
145+
from machine import Pin, Timer
146+
147+
pin1 = Pin("PC6", Pin.OUT_PP, Pin.PULL_NONE)
148+
timer1 = Timer(3, freq=1000)
149+
channel1 = timer1.channel(1, Timer.PWM, pin=pin1, pulse_width=0)
150+
151+
duty = 50 # Duty cycle percentage (0-100)
152+
153+
while True:
154+
channel1.pulse_width_percent(duty)
155+
```
156+
157+
In this example:
158+
159+
- `pin1` is configured as an output pin with no pull-up or pull-down resistors.
160+
- `timer1` is initialized with a frequency of 1000 Hz.
161+
- `channel1` is created on timer 3, channel 1, and is set to PWM mode.
162+
- `channel1.pulse_width_percent(duty)` sets the duty cycle of the PWM
163+
164+
***Note: Always refer to your board's documentation for the correct pin names and timer configurations specific to the GIGA. For more information, check out the [GIGA R1 MicroPython Guide](https://docs.arduino.cc/tutorials/giga-r1-wifi/giga-micropython/).***

0 commit comments

Comments
 (0)