Pulse-width modulation (PWM) is a technique that modifies the duty cycle of a pulsing signal to encode information or to control the amount of energy provided to a charge. The MCA implements pulse-width modulation in its firmware.

The MCA on the ConnectCore 8M Nano system-on-module provides one PWM controller. The controller has several channels and each channel maps to one MCA IO pin:

PWM controller Number of channels Channel IO

PWM0

6

0

MCA_IO0

1

MCA_IO12

2

MCA_IO15

3

MCA_IO16

4

MCA_IO17

5

MCA_IO18

On the ConnectCore 8M Nano:

  • All MCA PWM channels are available on the LGA pads.

  • PWM0 channel 0 is available on the castellated pads.

On the ConnectCore 8M Nano Development Kit: Most of the MCA pins with PWM capability are connected to different peripherals on the base board; make sure the pin is not in use for other functionality when evaluating it as PWM:

  • PWM0 channel 0 is available on J22-2 as SWD_DIO.

  • PWM0 channel 1 is connected to USER_LED1.

  • PWM0 channel 2 is available on J39-5 as XBEE1_RESET_N.

  • PWM0 channel 3 is available on J40-8 as XBEE1_ON/SLEEP_N.

  • PWM0 channel 4 is available on J32-16 as LVDS_PWM_OUT.

  • PWM0 channel 5 is connected to USER_LED2.

See MCA I/O pads for a list of all available MCA IOs and their capabilities.

Kernel configuration

You can manage the ConnectCore 8M Nano MCA PWM driver support through the following kernel configuration option:

  • Digi MCA PWM support (CONFIG_PWM_MCA)

This option is enabled as built-in on the default ConnectCore 8M Nano kernel configuration file.

Kernel driver

The driver for the ConnectCore 8M Nano MCA PWM is located at:

File Description

drivers/pwm/pwm-mca.c

MCA PWM driver

Device tree bindings and customization

The ConnectCore 8M Nano MCA PWM interface is documented at Documentation/devicetree/bindings/pwm/digi,mca-pwm.txt.

ConnectCore 8M Nano MCA PWM interfaces

The common ConnectCore 8M Nano device tree file contains entries for all the MCA PWM controllers:

ConnectCore 8M Nano device tree
mca_cc8m: mca@63 {
	pwms {
		compatible = "digi,mca-pwm";
		#address-cells = <1>;
		#size-cells = <0>;

		mca_pwm0: pwm@0 {
			reg = <0>;
			pwm-channels = <6>;
			#pwm-cells = <3>;
		};
	};
};

Using the MCA PWM channels

From sysfs

Each PWM interface is registered in the system as a standalone PWM controller.

The PWM interfaces appear under /sys/class/pwm:

~# ls -l /sys/class/pwm/
lrwxrwxrwx    1 root     root             0 Jan  9 11:00 pwmchip0 -> ../../devices/platform/30a20000.i2c/i2c-0/0-0063/mca-pwm/pwm/pwmchip0

The PWM interfaces begin numbering with an index of 0. The indexes are calculated using the number of channels of the previous interface. On the example above (DVK):

  • MCA PWM0 (6 channels) is pwmchip0

Check the number of channels of an interface by printing the value of npwm:

~# cat /sys/class/pwm/pwmchip0/npwm
6

To access one channel of a PWM interface, export the channel index. For example, for accessing channel 0 of MCA PWM0:

~# echo 0 > /sys/class/pwm/pwmchip0/export

Now you can access the PWM channel and configure its settings:

~# ls /sys/class/pwm/pwmchip0/pwm0/
capture     duty_cycle  enable      period      polarity    power       uevent

Period and duty cycle must be given in nanoseconds.

The maximum frequency of the MCA PWM is 1MHz (period = 1000ns). The minimum frequency of the MCA PWM is 100Hz (period = 10000000ns).

For example, to configure a 100kHz signal with 20% duty cycle:

~# echo 10000 > /sys/class/pwm/pwmchip0/pwm0/period
~# echo 2000 > /sys/class/pwm/pwmchip0/pwm0/duty_cycle

Each MCA PWM controller can only have one frequency for all its channels. Changing the period for one channel affects the period of all the channels in that MCA PWM controller.

You can only change the period of a channel if all the channels in that PWM controller are disabled.

To enable the PWM signal:

~# echo 1 > /sys/class/pwm/pwmchip0/pwm0/enable

The default polarity is normal (active high for the duty cycle). To invert the polarity:

~# echo inversed > /sys/class/pwm/pwmchip0/pwm0/polarity

Using Digi APIx library from a C application

An example application called apix-pwm-example is included in the dey-examples-digiapix recipe (part of dey-examples package) of meta-digi layer. This application shows how to generate a PWM signal using Digi APIx library on the ConnectCore 8M Nano platform.

Go to GitHub to see the application instructions and source code.

See PWM API for more information about the PWM APIx.

See also