aquarat wrote:Hi Gordon
I found your wiringPi library when I first started looking for PWM-related stuff. I was/am specifically after hardware PWM (which is available on GPIO18?) because I hoped that 1) it'd provide higher sampling rates 2) it'd be less prone to multi-tasking related timing error and 3) it'd use less cpu time. So far I can't find anything that demonstrates the use of GPIO18's hardware PWM functions, especially in a BASH format. The fact that the audio output can act as a pseudo-PWM output, especially at 44.1kHz will certainly suffice for my requirements. The triacs I've bought only require 0.5V to trigger them and Vmax from the audio output on the Pi is roughly 0.9V while outputting a 5:1 PWM output (5 on, 1 off).
Thanks for the effort though, your library is very cool and I found a diagram you made (that showed the wiringPi, GPIO number and header pin numbers) to be very useful when I first started experimenting with GPIOs.
If you want command-line stuff (ie. from bash or csh, etc.), then install wiringPi:
git clone git://git.drogon.net/wiringPi
cd wiringPi
./build
then:
gpio mode 1 pwm
gpio pwm 1 500
gpio -h
you can change the range and mode and frequency using the gpio command. (which is part of wiringPi) Default range is 1024. Default mode is 'balanced'. To get traditional mark:space ratio, then
gpio pwm-ms
change the range:
gpio range 512
change the clock divider:
gpio pwmc 16 #default is 32
If you want to use the other pin numbers, then:
gpio -g mode 18 pwm
gpio -g pwm 1 200
etc.
I'd not personally connect a triac directly to a Pi - but I would do it via an opto isolator. And remember you're switching something that's only running at 50Hz - you probably need to use a zero-crossing detector.
-Gordon