ChibiOS/RT Logo ChibiOS/RT

Architecture - Reference Manual - Guides

Data Structures | Modules | Defines | Typedefs | Enumerations | Functions

PWM Driver
[HAL]

Generic PWM Driver. More...

Collaboration diagram for PWM Driver:


Description

Generic PWM Driver.

This module implements a generic PWM driver. The driver implements a state machine internally:

inline_dotgraph_18.dot

Data Structures

struct  PWMChannelConfig
 PWM driver channel configuration structure. More...
struct  PWMConfig
 Driver configuration structure. More...
struct  PWMDriver
 Structure representing an PWM driver. More...

Modules

 PWM Low Level Driver
 

PWM Driver low level driver template.


Defines

#define pwmEnableChannelI(pwmp, channel, width)   pwm_lld_enable_channel(pwmp, channel, width)
 Enables a PWM channel.
#define pwmDisableChannelI(pwmp, channel)   pwm_lld_disable_channel(pwmp, channel)
 Disables a PWM channel.
#define PWM_CHANNELS   4
 Number of PWM channels per PWM driver.
#define USE_STM32_PWM1   TRUE
 PWM1 driver enable switch.
#define USE_STM32_PWM2   TRUE
 PWM2 driver enable switch.
#define USE_STM32_PWM3   TRUE
 PWM3 driver enable switch.
#define USE_STM32_PWM4   TRUE
 PWM4 driver enable switch.
#define STM32_PWM1_IRQ_PRIORITY   7
 PWM1 interrupt priority level setting.
#define STM32_PWM2_IRQ_PRIORITY   7
 PWM2 interrupt priority level setting.
#define STM32_PWM3_IRQ_PRIORITY   7
 PWM3 interrupt priority level setting.
#define STM32_PWM4_IRQ_PRIORITY   7
 PWM4 interrupt priority level setting.
#define PWM_COMPUTE_PSC(clksrc, pwmclk)   ((uint16_t)(((clksrc) / (pwmclk)) - 1))
 PWM clock prescaler initialization utility.
#define PWM_COMPUTE_ARR(pwmclk, pwmperiod)   ((uint16_t)(((pwmclk) / (1000000000 / (pwmperiod))) - 1))
 PWM cycle period initialization utility.
#define PWM_FRACTION_TO_WIDTH(pwmp, numerator, denominator)
 Converts from fraction to pulse width.
#define PWM_DEGREES_TO_WIDTH(pwmp, degrees)   PWM_FRACTION_TO_WIDTH(pwmp, 36000, degrees)
 Converts from degrees to pulse width.
#define PWM_PERCENTAGE_TO_WIDTH(pwmp, percentage)   PWM_FRACTION_TO_WIDTH(pwmp, 10000, percentage)
 Converts from percentage to pulse width.

Typedefs

typedef uint8_t pwmchannel_t
 PWM channel type.
typedef uint16_t pwmcnt_t
 PWM counter type.
typedef struct PWMDriver PWMDriver
 Type of a structure representing an PWM driver.
typedef void(* pwmcallback_t )(PWMDriver *pwmp)
 PWM notification callback type.

Enumerations

enum  pwmstate_t { PWM_UNINIT = 0, PWM_STOP = 1, PWM_READY = 2 }
 

Driver state machine possible states.

More...
enum  pwmmode_t { PWM_OUTPUT_DISABLED = 0, PWM_OUTPUT_ACTIVE_HIGH = 1, PWM_OUTPUT_ACTIVE_LOW = 2 }
 

PWM logic mode.

More...

Functions

void pwmInit (void)
 PWM Driver initialization.
void pwmObjectInit (PWMDriver *pwmp)
 Initializes the standard part of a PWMDriver structure.
void pwmStart (PWMDriver *pwmp, const PWMConfig *config)
 Configures and activates the PWM peripheral.
void pwmStop (PWMDriver *pwmp)
 Deactivates the PWM peripheral.
void pwmEnableChannel (PWMDriver *pwmp, pwmchannel_t channel, pwmcnt_t width)
 Enables a PWM channel.
void pwmDisableChannel (PWMDriver *pwmp, pwmchannel_t channel)
 Disables a PWM channel.
void pwm_lld_init (void)
 Low level PWM driver initialization.
void pwm_lld_start (PWMDriver *pwmp)
 Configures and activates the PWM peripheral.
void pwm_lld_stop (PWMDriver *pwmp)
 Deactivates the PWM peripheral.
void pwm_lld_enable_channel (PWMDriver *pwmp, pwmchannel_t channel, pwmcnt_t width)
 Enables a PWM channel.
void pwm_lld_disable_channel (PWMDriver *pwmp, pwmchannel_t channel)
 Disables a PWM channel.

Define Documentation

#define pwmEnableChannelI (   pwmp,
  channel,
  width 
)    pwm_lld_enable_channel(pwmp, channel, width)

Enables a PWM channel.

Programs (or reprograms) a PWM channel.

Note:
This function has to be invoked from a lock zone.
Parameters:
[in] pwmp pointer to a PWMDriver object
[in] channel PWM channel identifier
[in] width PWM pulse width as clock pulses number

Definition at line 89 of file pwm.h.

#define pwmDisableChannelI (   pwmp,
  channel 
)    pwm_lld_disable_channel(pwmp, channel)

Disables a PWM channel.

The channel is disabled and its output line returned to the idle state.

Note:
This function has to be invoked from a lock zone.
Parameters:
[in] pwmp pointer to a PWMDriver object
[in] channel PWM channel identifier

Definition at line 101 of file pwm.h.

#define PWM_CHANNELS   4

Number of PWM channels per PWM driver.

Definition at line 40 of file platforms/STM32/pwm_lld.h.

#define USE_STM32_PWM1   TRUE

PWM1 driver enable switch.

If set to TRUE the support for PWM1 is included.

Note:
The default is TRUE.

Definition at line 52 of file platforms/STM32/pwm_lld.h.

#define USE_STM32_PWM2   TRUE

PWM2 driver enable switch.

If set to TRUE the support for PWM2 is included.

Note:
The default is TRUE.

Definition at line 61 of file platforms/STM32/pwm_lld.h.

#define USE_STM32_PWM3   TRUE

PWM3 driver enable switch.

If set to TRUE the support for PWM3 is included.

Note:
The default is TRUE.

Definition at line 70 of file platforms/STM32/pwm_lld.h.

#define USE_STM32_PWM4   TRUE

PWM4 driver enable switch.

If set to TRUE the support for PWM4 is included.

Note:
The default is TRUE.

Definition at line 79 of file platforms/STM32/pwm_lld.h.

#define STM32_PWM1_IRQ_PRIORITY   7

PWM1 interrupt priority level setting.

Definition at line 86 of file platforms/STM32/pwm_lld.h.

Referenced by pwm_lld_start().

#define STM32_PWM2_IRQ_PRIORITY   7

PWM2 interrupt priority level setting.

Definition at line 93 of file platforms/STM32/pwm_lld.h.

Referenced by pwm_lld_start().

#define STM32_PWM3_IRQ_PRIORITY   7

PWM3 interrupt priority level setting.

Definition at line 100 of file platforms/STM32/pwm_lld.h.

Referenced by pwm_lld_start().

#define STM32_PWM4_IRQ_PRIORITY   7

PWM4 interrupt priority level setting.

Definition at line 107 of file platforms/STM32/pwm_lld.h.

Referenced by pwm_lld_start().

#define PWM_COMPUTE_PSC (   clksrc,
  pwmclk 
)    ((uint16_t)(((clksrc) / (pwmclk)) - 1))

PWM clock prescaler initialization utility.

Note:
The real clock value is rounded to the lower valid value, please make sure that the source clock frequency is a multiple of the requested PWM clock frequency.
The calculated value must fit into an unsigned 16 bits integer.
Parameters:
[in] clksrc clock source frequency, depending on the target timer cell it can be one of:

  • STM32_TIMCLK1
  • STM32_TIMCLK2

Please refer to the STM32 HAL driver documentation and/or the STM32 Reference Manual for the right clock source.

[in] pwmclk PWM clock frequency in cycles
Returns:
The value to be stored in the pc_psc field of the PWMConfig structure.

Definition at line 245 of file platforms/STM32/pwm_lld.h.

#define PWM_COMPUTE_ARR (   pwmclk,
  pwmperiod 
)    ((uint16_t)(((pwmclk) / (1000000000 / (pwmperiod))) - 1))

PWM cycle period initialization utility.

Note:
The calculated value must fit into an unsigned 16 bits integer.
Parameters:
[in] pwmclk PWM clock frequency in cycles
[in] pwmperiod PWM cycle period in nanoseconds
Returns:
The value to be stored in the pc_arr field of the PWMConfig structure.

Definition at line 257 of file platforms/STM32/pwm_lld.h.

#define PWM_FRACTION_TO_WIDTH (   pwmp,
  numerator,
  denominator 
)
Value:
((uint16_t)((((uint32_t)(pwmp)->pd_config->pc_arr + 1UL) *                \
               (uint32_t)(denominator)) / (uint32_t)(numerator)))

Converts from fraction to pulse width.

Note:
Be careful with rounding errors, this is integer math not magic. You can specify tenths of thousandth but make sure you have the proper hardware resolution by carefully choosing the clock source and prescaler settings, see PWM_COMPUTE_PSC.
Parameters:
[in] numerator numerator of the fraction
[in] denominator percentage as an integer between 0 and numerator
Returns:
The pulse width to be passed to pwmEnableChannel().

Definition at line 273 of file platforms/STM32/pwm_lld.h.

#define PWM_DEGREES_TO_WIDTH (   pwmp,
  degrees 
)    PWM_FRACTION_TO_WIDTH(pwmp, 36000, degrees)

Converts from degrees to pulse width.

Note:
Be careful with rounding errors, this is integer math not magic. You can specify hundredths of degrees but make sure you have the proper hardware resolution by carefully choosing the clock source and prescaler settings, see PWM_COMPUTE_PSC.
Parameters:
[in] pwmp pointer to a PWMDriver object
[in] degrees degrees as an integer between 0 and 36000
Returns:
The pulse width to be passed to pwmEnableChannel().

Definition at line 290 of file platforms/STM32/pwm_lld.h.

#define PWM_PERCENTAGE_TO_WIDTH (   pwmp,
  percentage 
)    PWM_FRACTION_TO_WIDTH(pwmp, 10000, percentage)

Converts from percentage to pulse width.

Note:
Be careful with rounding errors, this is integer math not magic. You can specify tenths of thousandth but make sure you have the proper hardware resolution by carefully choosing the clock source and prescaler settings, see PWM_COMPUTE_PSC.
Parameters:
[in] pwmp pointer to a PWMDriver object
[in] percentage percentage as an integer between 0 and 10000
Returns:
The pulse width to be passed to pwmEnableChannel().

Definition at line 306 of file platforms/STM32/pwm_lld.h.


Typedef Documentation

PWM channel type.

Definition at line 130 of file platforms/STM32/pwm_lld.h.

typedef uint16_t pwmcnt_t

PWM counter type.

Definition at line 135 of file platforms/STM32/pwm_lld.h.

typedef struct PWMDriver PWMDriver

Type of a structure representing an PWM driver.

Definition at line 140 of file platforms/STM32/pwm_lld.h.

typedef void(* pwmcallback_t)(PWMDriver *pwmp)

PWM notification callback type.

Parameters:
[in] pwmp pointer to a PWMDriver object

Definition at line 147 of file platforms/STM32/pwm_lld.h.


Enumeration Type Documentation

enum pwmstate_t

Driver state machine possible states.

Enumerator:
PWM_UNINIT 

Not initialized.

PWM_STOP 

Stopped.

PWM_READY 

Ready.

Definition at line 59 of file pwm.h.

enum pwmmode_t

PWM logic mode.

Enumerator:
PWM_OUTPUT_DISABLED 

Output not driven, callback only.

PWM_OUTPUT_ACTIVE_HIGH 

Idle is logic level 0.

PWM_OUTPUT_ACTIVE_LOW 

Idle is logic level 1.

Definition at line 68 of file pwm.h.


Function Documentation

void pwmInit ( void   ) 

PWM Driver initialization.

Definition at line 59 of file pwm.c.

References pwm_lld_init().

Referenced by halInit().

Here is the call graph for this function:

void pwmObjectInit ( PWMDriver pwmp  ) 

Initializes the standard part of a PWMDriver structure.

Parameters:
[in] pwmp pointer to a PWMDriver object

Definition at line 69 of file pwm.c.

References PWMDriver::pd_config, and PWMDriver::pd_state.

Referenced by pwm_lld_init().

void pwmStart ( PWMDriver pwmp,
const PWMConfig config 
)

Configures and activates the PWM peripheral.

Parameters:
[in] pwmp pointer to a PWMDriver object
[in] config pointer to a PWMConfig object

Definition at line 84 of file pwm.c.

References chDbgAssert, chDbgCheck, chSysLock, chSysUnlock, PWMDriver::pd_config, PWMDriver::pd_state, pwm_lld_start(), PWM_READY, and PWM_STOP.

Here is the call graph for this function:

void pwmStop ( PWMDriver pwmp  ) 

Deactivates the PWM peripheral.

Parameters:
[in] pwmp pointer to a PWMDriver object

Definition at line 102 of file pwm.c.

References chDbgAssert, chDbgCheck, chSysLock, chSysUnlock, PWMDriver::pd_state, pwm_lld_stop(), PWM_READY, and PWM_STOP.

Here is the call graph for this function:

void pwmEnableChannel ( PWMDriver pwmp,
pwmchannel_t  channel,
pwmcnt_t  width 
)

Enables a PWM channel.

Programs (or reprograms) a PWM channel.

Parameters:
[in] pwmp pointer to a PWMDriver object
[in] channel PWM channel identifier (0...PWM_CHANNELS-1)
[in] width PWM pulse width as clock pulses number

Definition at line 122 of file pwm.c.

References chDbgAssert, chDbgCheck, chSysLock, chSysUnlock, PWMDriver::pd_state, PWM_CHANNELS, pwm_lld_enable_channel(), and PWM_READY.

Here is the call graph for this function:

void pwmDisableChannel ( PWMDriver pwmp,
pwmchannel_t  channel 
)

Disables a PWM channel.

The channel is disabled and its output line returned to the idle state.

Parameters:
[in] pwmp pointer to a PWMDriver object
[in] channel PWM channel identifier (0...PWM_CHANNELS-1)

Definition at line 144 of file pwm.c.

References chDbgAssert, chDbgCheck, chSysLock, chSysUnlock, PWMDriver::pd_state, PWM_CHANNELS, pwm_lld_disable_channel(), and PWM_READY.

Here is the call graph for this function:

void pwm_lld_init ( void   ) 

Low level PWM driver initialization.

Definition at line 206 of file platforms/STM32/pwm_lld.c.

References PWMDriver::pd_enabled_channels, PWMDriver::pd_tim, and pwmObjectInit().

Referenced by pwmInit().

Here is the call graph for this function:

void pwm_lld_start ( PWMDriver pwmp  ) 
void pwm_lld_stop ( PWMDriver pwmp  ) 

Deactivates the PWM peripheral.

Parameters:
[in] pwmp pointer to the PWMDriver object
[in] pwmp pointer to a PWMDriver object

Definition at line 370 of file platforms/STM32/pwm_lld.c.

References NVICDisableVector(), PWMDriver::pd_enabled_channels, PWMDriver::pd_state, PWMDriver::pd_tim, and PWM_READY.

Referenced by pwmStop().

Here is the call graph for this function:

void pwm_lld_enable_channel ( PWMDriver pwmp,
pwmchannel_t  channel,
pwmcnt_t  width 
)

Enables a PWM channel.

Parameters:
[in] pwmp pointer to a PWMDriver object
[in] channel PWM channel identifier (0...PWM_CHANNELS-1)
[in] width PWM pulse width as clock pulses number

Definition at line 421 of file platforms/STM32/pwm_lld.c.

References PWMConfig::pc_channels, PWMChannelConfig::pcc_callback, PWMDriver::pd_config, PWMDriver::pd_enabled_channels, and PWMDriver::pd_tim.

Referenced by pwmEnableChannel().

void pwm_lld_disable_channel ( PWMDriver pwmp,
pwmchannel_t  channel 
)

Disables a PWM channel.

The channel is disabled and its output line returned to the idle state.

Parameters:
[in] pwmp pointer to a PWMDriver object
[in] channel PWM channel identifier (0...PWM_CHANNELS-1)

Definition at line 446 of file platforms/STM32/pwm_lld.c.

References PWMDriver::pd_enabled_channels, and PWMDriver::pd_tim.

Referenced by pwmDisableChannel().


Generated on Sun Nov 28 2010 14:09:58 for ChibiOS/RT by doxygen 1.7.1