A kernel module for generating bit banging PWM signals

Soft_pwm is a nice device driver written by Antonio Galea which can generate a bit banging PWM signal on any GPIO available on the FOX Board G20 or Aria G25 using an internal timer interrupt and a sysfs interface.

Assuming you have already read the basic using the sysfs interface, you might wonder how you can hook up something fancier than a LED a servo RC or stepper motor.

It turns out that the Acme boards are indeed capable of generating the required PWM (Pulse Width Modulation) signal, directly in hardware. There's a catch, though: you can only have a couple of pins for that (not enough for many applications - like making an hexapod walk, for instance). Worse still we didn't find a clear and easy way to understand Linux drivers (at least, not yet).

Quick-and-dirty test

Download soft_pwm.ko executable class='acmetable' Kernel module on your Acme board from this link:

Load it by typing:

insmod soft_pwm_xxxx.ko

Export the GPIO pin using it Kernel ID (82 for example):

echo 82 > /sys/class/soft_pwm/export

 Note:   Please note tha the Kernel id are changed starting from Kernel 3.5.

Set the wave period (for example 1000 microseconds) and the pulse width (in this case 500 microseconds to obtaint a duty cucle of 50%):

echo 1000 > /sys/class/soft_pwm/pwm82/period
echo 500 > /sys/class/soft_pwm/pwm82/pulse

Have a look at the running counter.

cat /sys/class/soft_pwm/pwm82/counter

Cross compile the module from sources:

Install the cross compiler toolchain on your PC and the kernel tree an explainen on these articles:

Clone the git repository on your Linux PC by typing:

git clone git://github.com/tanzilli/soft_pwm.git
cd soft_pwm

Edit KDIR with the path of your kernel tree then type:

make ARCH=arm CROSS_COMPILE=arm-linux-gnueabi- KDIR=/home/linux-3.xxxx

Copy the soft_pwm.ko on your acme board and load it:

insmod soft_pwm.ko

Related links