1. Home
  2. Docs
  3. How to use device tree overlays
  4. Enabling I2C, SPI, UART, ADC, and PWM
  5. Enable PWM

Enable PWM

The Giant Board has 4 PWM’s, 3 of which are independent of each other. PWM1, PWM2, and PWM3 are all independent channels. There is one PWM pin labeled as PWML1, which is apart of the same controller as PWM1 but outputs the mirrored signal of PWM1. PWM1 and PWML1 can be used independently as long as both pins are not set as PWM outputs. We have overlays setup to enable single PWM’s as well as all of the independent PWM’s.

The included file names are:
GB-PWM1.dtbo
GB-PWM2.dtbo
GB-PWM1-3.dtbo – Enables PWM1-PWM3

To enable a PWM1 we need to edit /boot/uboot/uEnv.txt to include the GB-PWM1.dtbo overlay. This will enable the PWM1 labeled pin. Once added, save and exit the editor, and reboot your Giant Board.

Make sure to uncomment the line enable_uboot_overlays=1 this allows overlays to load on boot:

# enable u-boot overlays
enable_uboot_overlays=1

Once rebooted you should see the new interface by typing the command below.

ls /sys/class/pwm/

You should now see pwmchip0

As a simple test, you can use Adafruits example code below with an LED attached to the PWM1 pin and GND

import time
import board
import pulseio
 
led = pulseio.PWMOut(board.PWM1, frequency=5000, duty_cycle=0)
 
while True:
    for i in range(100):
        # PWM LED up and down
        if i < 50:
            led.duty_cycle = int(i * 2 * 65535 / 100)  # Up
        else:
            led.duty_cycle = 65535 - int((i - 50) * 2 * 65535 / 100)  # Down
        time.sleep(0.01)