简体   繁体   中英

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

Here is aa 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM