Emlid OES Prime has two available PWM pins. In this example, we are using
which is the alternative function of
URX0 pin. By default, it is disabled.
To enable it you should apply special Device Tree overlay by editing “`/boot/Env.txt“`.
You need to add “`pwm“` to the “`overlays“` section:
Save this file and reboot your device. When your system finished booting,
you should get “`pwmchip0“` interface in sysfs.
root@OES Prime:~# ls /sys/class/pwm/pwmchip0
device export npwm power subsystem uevent unexport
Activate the PWM:
echo 0 > /sys/class/pwm/pwmchip0/export
Set period to 10ms:
echo 10000000 > /sys/class/pwm/pwmchip0/pwm0/period
It means that the signal is high for 10% of the period and low the other 90%.
Set normal polarity:
echo “normal” > /sys/class/pwm/pwmchip0/pwm0/polarity
Enable the PWM:
echo 1 > /sys/class/pwm/pwmchip0/pwm0/enable
Set duty cycle to 1ms:
echo 1000000 > /sys/class/pwm/pwmchip0/pwm0/duty_cycle
You can connect logic analyzer to “`PWM0“` pin and see the result: