Infineon Logo AIROC BTSDK v4.9 - Documentation
 
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups
Pulse Width Modulation (PCM)

Defines a driver to facilitate interfacing with the Pulse-Width Modulation (PWM) driver. More...

Data Structures

struct  wiced_pwm_config_t
 

Enumerations

enum  { PWM0 = 0, PWM1 = 1, PWM2 = 2, MAX_PWMS = 4 }
 PWM HW block has 6 PWM channels each with its own 16 bit counter. More...
 
enum  PwmClockType { LHL_CLK, PMU_CLK }
 Clock used for PWM. More...
 

Functions

uint32_t wiced_hal_pwm_start (uint8_t channel, PwmClockType clk, uint32_t toggleCount, uint32_t initCount, int invert)
 Configures, enables, and starts the PWM to be active on a preconfigured GPIO pin. More...
 
uint32_t wiced_hal_pwm_change_values (uint8_t channel, uint32_t toggleCount, uint32_t initCount)
 Changes the PWM settings after the PWM HW has already been started. More...
 
uint32_t wiced_hal_pwm_get_toggle_count (uint8_t channel)
 Returns the current toggle count setting for the corresponding PWM channel. More...
 
uint32_t wiced_hal_pwm_get_init_value (uint8_t channel)
 Returns the current initial count setting for the corresponding PWM channel. More...
 
void wiced_hal_pwm_disable (uint8_t channel)
 Disables the PWM channel. More...
 
void wiced_hal_pwm_enable (uint8_t channel)
 Enables the PWM channel which is already preconfigured. More...
 
void wiced_hal_pwm_configure_pin (uint8_t pin, uint8_t PWM)
 Configure any GPIO as any PWM port. More...
 
wiced_result_t wiced_hal_pwm_get_params (uint32_t clock_frequency_in, uint32_t duty_cycle, uint32_t pwm_frequency_out, wiced_pwm_config_t *params_out)
 Calculate PWM parameters. More...
 

Detailed Description

Defines a driver to facilitate interfacing with the Pulse-Width Modulation (PWM) driver.

Use this driver to output a PWM signal to a GPIO pin for external use. There are six, 16-bit hardware PWM channels avaliable (0-5). Typical use-cases include fine-control over small devices such as LEDs. Please reference the Kit Guide or HW User Manual for your device for more information.

Enumeration Type Documentation

anonymous enum

PWM HW block has 6 PWM channels each with its own 16 bit counter.

The first PWM channel is PWM0.

Clock used for PWM.

When LHL_CLK is set, 128 KHz is used. PMU_CLK requires aclk to be configured first.

Function Documentation

uint32_t wiced_hal_pwm_change_values ( uint8_t  channel,
uint32_t  toggleCount,
uint32_t  initCount 
)

Changes the PWM settings after the PWM HW has already been started.

(!) Note that the maximum width or period of the PWM is 0xFFFF (16-bits).

Parameters
channel- Desired PWM channel to set [0-5].
toggleCount- The number of ticks to wait before toggling the signal.
initCount- Initial value for the counter.
Returns
1 if PWM was successfully changed, 0 otherwise.
void wiced_hal_pwm_configure_pin ( uint8_t  pin,
uint8_t  PWM 
)

Configure any GPIO as any PWM port.

Parameters
pin: pin to configure as PWM
PWMwhich PWM channel to set the pin to (0 - 5)
Returns
VOID
void wiced_hal_pwm_disable ( uint8_t  channel)

Disables the PWM channel.

Parameters
channel- Desired PWM channel to stop/disable.
Returns
VOID
void wiced_hal_pwm_enable ( uint8_t  channel)

Enables the PWM channel which is already preconfigured.

Parameters
channel- Desired PWM channel to enable.
Returns
VOID
uint32_t wiced_hal_pwm_get_init_value ( uint8_t  channel)

Returns the current initial count setting for the corresponding PWM channel.

Parameters
channel- Desired PWM channel from which to obtain the initial count.
Returns
The initial count value of the PWM.
wiced_result_t wiced_hal_pwm_get_params ( uint32_t  clock_frequency_in,
uint32_t  duty_cycle,
uint32_t  pwm_frequency_out,
wiced_pwm_config_t params_out 
)

Calculate PWM parameters.

Parameters
[in]clock_frequency_in- in clock frequency
[in]duty_cycle- duty cycle in percentage (0 to 100)
[in]pwm_frequency_out- Desire PWM output frequency
[out]params_out- PWM params
Returns
wiced_result_t
uint32_t wiced_hal_pwm_get_toggle_count ( uint8_t  channel)

Returns the current toggle count setting for the corresponding PWM channel.

Parameters
channel- Desired PWM channel from which to obtain the toggle count.
Returns
The value at which the PWM is going to toggle.
uint32_t wiced_hal_pwm_start ( uint8_t  channel,
PwmClockType  clk,
uint32_t  toggleCount,
uint32_t  initCount,
int  invert 
)

Configures, enables, and starts the PWM to be active on a preconfigured GPIO pin.

(!) Note that the desired GPIO pin must have already been configured as output. See the HW muxing section in the Kit Guide or HW User Manual for your device for more information.

Parameters
channel- Desired PWM channel to use [0-5].
clk- PMU_CLK or LHL_CLK
toggleCount- The number of ticks to wait before toggling the signal.
initCount- Initial value for the counter.
invert- 1 to invert the signal.
Returns
1 if PWM was successfully started, 0 otherwise.

The following example outputs a signal on P28 using the PMU clock.

(!) Note that the maximum width or period of the PWM is 0xFFFF (16-bits).

(!) Note that if you use PMU_CLK instead of LHL_CLK, a call to wiced_hal_aclk_enable() is required. When configuring aclk, ACLK0 is not avaliable for use with PWM–only ACLK1.

(!) Note that each PWM<#> channel corresponds to a specific GPIO pin, and said pin must be configured for output before PWM may use it. Please reference the User Documentation for more information on which pins support PWM on your platform.

Parameters
channel- Desired PWM channel to use [0-5].
clk- PMU_CLK or LHL_CLK
toggleCount- The number of ticks to wait before toggling the signal.
initCount- Initial value for the counter.
invert- 1 to invert the signal.
Returns
1 if PWM was successfully started, 0 otherwise.