Close

Hardware PWM

A project log for Raspberry Pi EVSE Hat

Use a Raspberry Pi to build an EV charging station

Nick SayerNick Sayer 09/26/2019 at 22:590 Comments

The good news is that hardware PWM works and the jitter observed with RPi.GPIO is nowhere to be seen.

The bad news is that it doesn't appear to be supported by Python directly so far as I can see.

The other good news, though, is that it's fairly easy to do. It's like doing manual GPIO manipulation via /sys/class. You write a "0" to /sys/class/pwm/pwmchip0/export and in response you'll see /sys/class/pwm/pwmchip0/pwm0/ show up. Inside pwm0 you'll find "period", "duty_cycle" and "enable". Write a cycle period in nanoseconds (1000000 for 1 kHz) into "period", write the number of nanoseconds you want it to be high (e.g. 100000 for 10%) into "duty_cycle" and a "1" into "enable".

Discussions