Difference between revisions of "PWM"

From ArmadeusWiki
Jump to: navigation, search
m (linux-menuconfig is not "buildroot standard")
m (Usage)
Line 27: Line 27:
 
== Usage ==
 
== Usage ==
 
* Load the module:
 
* Load the module:
 +
<pre class="apf">
 
  # modprobe imx-pwm
 
  # modprobe imx-pwm
 
  Initializing PWM class.
 
  Initializing PWM class.
Line 32: Line 33:
 
  PWM driver v0.6
 
  PWM driver v0.6
 
  done.
 
  done.
 +
</pre>
 
* If you plan to use sound, create ''/dev/pwm'' device file if not already existing (Major is dynamically allocated)
 
* If you plan to use sound, create ''/dev/pwm'' device file if not already existing (Major is dynamically allocated)
 +
<pre class="apf">
 
  # DEV=`cat /proc/devices | grep imx-pwm | cut -d " " -f 1`; mknod /dev/pwm c $DEV 0
 
  # DEV=`cat /proc/devices | grep imx-pwm | cut -d " " -f 1`; mknod /dev/pwm c $DEV 0
 +
</pre>
  
 
=== PWM Mode ===
 
=== PWM Mode ===
Line 42: Line 46:
 
After driver loading, you have access to ''/sys/class/pwm/...'' functionnalities:
 
After driver loading, you have access to ''/sys/class/pwm/...'' functionnalities:
 
* to change frequency (for example 500 Hz):
 
* to change frequency (for example 500 Hz):
 +
<pre class="apf">
 
  # echo 500 > /sys/class/pwm/pwm0/frequency
 
  # echo 500 > /sys/class/pwm/pwm0/frequency
 +
</pre>
 
* to change period (for example 100us):
 
* to change period (for example 100us):
 +
<pre class="apf">
 
  # echo 100 > /sys/class/pwm/pwm0/period
 
  # echo 100 > /sys/class/pwm/pwm0/period
 +
</pre>
 
* to change duty cycle (for example 50.0%)
 
* to change duty cycle (for example 50.0%)
 +
<pre class="apf">
 
  # echo 500 > /sys/class/pwm/pwm0/duty
 
  # echo 500 > /sys/class/pwm/pwm0/duty
 +
</pre>
 
* to activate PWM:
 
* to activate PWM:
 +
<pre class="apf">
 
  # echo 1 > /sys/class/pwm/pwm0/active
 
  # echo 1 > /sys/class/pwm/pwm0/active
 +
</pre>
 
* to de-activate PWM:
 
* to de-activate PWM:
 +
<pre class="apf">
 
  # echo 0 > /sys/class/pwm/pwm0/active
 
  # echo 0 > /sys/class/pwm/pwm0/active
 +
</pre>
  
 
=== Audio Mode ===
 
=== Audio Mode ===
Line 68: Line 82:
 
  [host:/.../armadeus]$ cp target/linux/modules/pwm/test/KDE_Startup_2.raw $NFS_DIR
 
  [host:/.../armadeus]$ cp target/linux/modules/pwm/test/KDE_Startup_2.raw $NFS_DIR
 
on target do:
 
on target do:
 +
<pre class="apf">
 
  # testplaymode
 
  # testplaymode
 +
</pre>
 
or
 
or
 +
<pre class="apf">
 
  # testplaymode KDE_Startup_2.raw
 
  # testplaymode KDE_Startup_2.raw
 +
</pre>
  
 
== Links ==
 
== Links ==

Revision as of 09:44, 1 April 2009

On this page, you will find usefull informations to configure and use the Pulse Width Modulation (PWM) capabilities of your APF9328 board.

The i.MXL processor is capable of driving 2 PWM signals:

  • one is linked to the LCD controller and allow to control the LCD backlight
  • the other can be used to generate a PWM signal in several mode:
    • audio playback
    • real PWM

Hardware

i.MXL PWM module is using PWMO (PortA 2) pin as ouput.

Linux driver installation

i.MXL PWM driver is now installed by default in standard Armadeus rootfs. Following instructions are only given as reference (to uninstall it at rootfs generation for example):

  • Launch Linux configuration:
 $ make linux26-menuconfig

And in Device Drivers ---> Armadeus specific drivers choose:
Linux config pwm.png

  • rebuild your system:
 $ make
  • then, either copy generated module target/linux/modules/pwm/imx-pwm.ko to your system with TFTP or NFS or reflash the generated rootfs. For more informations.

Usage

  • Load the module:
 # modprobe imx-pwm
 Initializing PWM class.
  Initializing PWM#0...PWM major number = 253
 PWM driver v0.6
 done.
  • If you plan to use sound, create /dev/pwm device file if not already existing (Major is dynamically allocated)
 # DEV=`cat /proc/devices | grep imx-pwm | cut -d " " -f 1`; mknod /dev/pwm c $DEV 0

PWM Mode

Remark:

  • The pwm has a resolution of 1uS

After driver loading, you have access to /sys/class/pwm/... functionnalities:

  • to change frequency (for example 500 Hz):
 # echo 500 > /sys/class/pwm/pwm0/frequency
  • to change period (for example 100us):
 # echo 100 > /sys/class/pwm/pwm0/period
  • to change duty cycle (for example 50.0%)
 # echo 500 > /sys/class/pwm/pwm0/duty
  • to activate PWM:
 # echo 1 > /sys/class/pwm/pwm0/active
  • to de-activate PWM:
 # echo 0 > /sys/class/pwm/pwm0/active

Audio Mode

Audio playback mode is working since v0.5 of PWM driver (thanks to User:SebastienR). You can play 8, 16 & 32 KHz 8bit linear RAW sound. It's recommended to play 8kHz one, as they use less CPU ressources. To convert a sound to the right format we recommend to use SoX (on Linux). For exemple:

[host]$ sox /usr/share/sounds/KDE_Chimes_1.ogg -r 8192 -b -u -c 1 Chimes.raw
-r -> sampling rate
-b -> byte/8bit signal
-u -> linear /not compressed
-c 1 -> Mono / 1 channel

Then you can test it using target/linux/modules/pwm/test/testplaymode:

[host:/.../armadeus]$ make -C target/linux/modules/pwm/test/
[host:/.../armadeus]$ cp target/linux/modules/pwm/test/testplaymode $NFS_DIR
[host:/.../armadeus]$ cp target/linux/modules/pwm/test/KDE_Startup_2.raw $NFS_DIR

on target do:

 # testplaymode

or

 # testplaymode KDE_Startup_2.raw

Links