#A kernel module for generating bit banging PWM signals

<span class="abstract">
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.
</span>

Assuming you have already read the basic @article='gpio_sysfs' 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 Kernel module on your Acme board from this link:

* [soft_pwm_2_6_38.ko for the FOX Board G20 with Kernel 2.6.38](./soft_pwm_2_6_38.ko)
* [soft_pwm_3_11_0.ko for the ARIA/FOX with Kernel 3.11.0](./soft_pwm_3_11_0.ko)

Load it by typing:

<pre class="minicom">
insmod soft_pwm_xxxx.ko
</pre>

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

<pre class="minicom">
echo 82 > /sys/class/soft_pwm/export
</pre>

@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%):
 
<pre class="minicom">
echo 1000 > /sys/class/soft_pwm/pwm82/period
echo 500 > /sys/class/soft_pwm/pwm82/pulse
</pre>


Have a look at the running counter.

<pre class="minicom">
cat /sys/class/soft_pwm/pwm82/counter
</pre>

##Cross compile the module from sources:

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

* @article='arm9_toolchain'
* @article='compile_linux_2_6_38'
* @article='compile_linux'

Clone the git repository on your Linux PC by typing:

<pre class="minicom">
git clone git://github.com/tanzilli/soft_pwm.git
cd soft_pwm
</pre>

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

<pre class="minicom">
make ARCH=arm CROSS_COMPILE=arm-linux-gnueabi- KDIR=/home/linux-3.xxxx
</pre>
 
Copy the soft_pwm.ko on your acme board and load it: 

<pre class="minicom">
insmod soft_pwm.ko
</pre>

# Related links

* [Antonio Galea original source repository of soft_pwm](https://github.com/ant9000/soft_pwm) 
* [Sergio Tanzilli fork used to write this article](https://github.com/tanzilli/soft_pwm) 

