Name

Overview — eCos Support for PWM, the Inter IC Bus

Synopsis

#include <cyg/io/pwm.h>
        

cyg_pwm_device *cyg_pwm_find(char *name);

int cyg_pwm_set(cyg_pwm_device *device, cyg_uint32 channel, cyg_pwm_period period, cyg_pwm_period width);

int cyg_pwm_get(cyg_pwm_device *device, cyg_uint32 channel, cyg_pwm_period *period, cyg_pwm_period *width);

int cyg_pwm_polarity(cyg_pwm_device *device, cyg_uint32 channel, cyg_uint32 polarity);

int cyg_pwm_pin_enable(cyg_pwm_device *device, cyg_uint32 channel, cyg_uint32 pin);

int cyg_pwm_pin_disable(cyg_pwm_device *device, cyg_uint32 channel, cyg_uint32 pin);

int cyg_pwm_start(cyg_pwm_device *device, cyg_uint32 channel);

int cyg_pwm_stop(cyg_pwm_device *device, cyg_uint32 channel);

Description

This API provided access to very basic PWM (Pulse Width Modulation) functionality where supported by underlying hardware. The functionality simply allows one or more external pins to be programmed to generate a square wave of a fixed period with a fixed duty cycle. Features of more advanced PWM devices are not supported.

The model for PWM devices allows a single device to contain several independent channels which may be programmed separately. Each channel may have several output pins which may be enabled separately but which all generate the same signal programmed into the channel. Channels within a device, and pins within a channel are all numbered from zero.

The function cyg_pwm_find() looks for a PWM device by name and returns a pointer to it. The PWM device is typically defined in the platform HAL and may be given a platform specific name. Typical names may be "pwm0" or "pwm1".

The function cyg_pwm_set() sets the square wave parameters for the selected channel. Both period and width are specified in nanoseconds. For example setting period to 100000 and width to 25000 sets up a square wave with a 100us (10KHz) period and a 25% duty cycle. The function cyg_pwm_get() returns the current settings.

The function cyg_pwm_polarity() sets the polarity of the signal. By default the width defines the high portion of the wave. Setting polarity to CYG_PWM_POLARITY_INVERTED means it defines the low part.

The function cyg_pwm_pin_enable() enables the selected channel output pin and cyg_pwm_pin_disable() disables it. While is is unusual, it is permitted to enable any number of channel pins.

The function cyg_pwm_pin_start() starts the PWM channel generating the square wave and cyg_pwm_pin_stop() stops it. The channel configuration functions may all be called before starting the channel, they may also be called after it started and will immediately affect it. If none are called before starting the channel then default values, defined in the platform HAL will be used. There is no need to stop a channel to reconfigure it, unless this is required by the application or attached hardware.