vlado
vlado

Reputation: 51

raspberry pi B+ hardware PWM

Raspberry pi B+ has four hardware PWM. How to use them in C/C++. The less complicated solution - the better.

I found one working solution with WiringPi

gpio mode 1 pwm  
gpio pwm-bal  
gpio pwmr 1024  
gpio pwm 1 500  

This solution works only for one PWM output (GPIO18). I thinks it is because WiringPi is designed for previous version of raspberry pi (Model B+ has new PWMs on GPIO12, GPIO13 and GPIO19).

For controlling regular GPIO I found solution:

pi@auto:~$ sudo -i  
root@auto:~# echo "16" > /sys/class/gpio/export  
root@auto:~# echo "out" > /sys/class/gpio/gpio16/direction  
root@auto:~# echo "1" > /sys/class/gpio/gpio16/value  
root@auto:~# echo "0" > /sys/class/gpio/gpio16/value  

But there is no way how to control hardware PWM.

Product https://www.pololu.com/product/2753 has reference to python library - that do exactly what I want.

Please no software PWM suggestions.

Thanks

Vlado

Upvotes: 3

Views: 2985

Answers (1)

Thomas Hsieh
Thomas Hsieh

Reputation: 731

Here is a a distro that can hopefully fit your need. It provides PWM and Servo kernel modules. You can simply modify the kernel files under /sys/class/rpi-pwm/ to create custom PWM output.
Here is the download link.

Upvotes: 1

Related Questions