| Nano100AN Series BSP V3.02.002 The Board Support Package for Nano100AN Series

Macros | Functions
PWM Exported Functions
NANO100 Device Driver » PWM Driver

## Macros
#define | PWM_ENABLE_OUTPUT_INVERTER(pwm, u32ChannelMask)
| This macro enable output inverter of specified channel(s) More...
#define | PWM_GET_CAPTURE_RISING_DATA(pwm, u32ChannelNum)
| This macro get captured rising data. More...
#define | PWM_GET_CAPTURE_FALLING_DATA(pwm, u32ChannelNum)
| This macro get captured falling data. More...
#define | PWM_SET_PRESCALER(pwm, u32ChannelNum, u32Prescaler)
| This macro set the prescaler of the selected channel. More...
#define | PWM_SET_DIVIDER(pwm, u32ChannelNum, u32Divider)
| This macro set the divider of the selected channel. More...
#define | PWM_SET_CMR(pwm, u32ChannelNum, u32CMR)
| This macro set the duty of the selected channel. More...
#define | PWM_SET_CNR(pwm, u32ChannelNum, u32CNR)
| This macro set the period of the selected channel. More...

## Functions
uint32_t | PWM_ConfigOutputChannel (PWM_T *pwm, uint32_t u32ChannelNum, uint32_t u32Frequency, uint32_t u32DutyCycle)
| This function config PWM generator and get the nearest frequency in edge aligned auto-reload mode. More...
uint32_t | PWM_ConfigCaptureChannel (PWM_T *pwm, uint32_t u32ChannelNum, uint32_t u32UnitTimeNsec, uint32_t u32CaptureEdge)
| This function config PWM capture and get the nearest unit time. More...
void | PWM_Start (PWM_T *pwm, uint32_t u32ChannelMask)
| This function start PWM module. More...
void | PWM_Stop (PWM_T *pwm, uint32_t u32ChannelMask)
| This function stop PWM module. More...
void | PWM_ForceStop (PWM_T *pwm, uint32_t u32ChannelMask)
| This function stop PWM generation immediately by clear channel enable bit. More...
void | PWM_EnableCapture (PWM_T *pwm, uint32_t u32ChannelMask)
| This function enables PWM capture of selected channels. More...
void | PWM_DisableCapture (PWM_T *pwm, uint32_t u32ChannelMask)
| This function disables PWM capture of selected channels. More...
void | PWM_EnableOutput (PWM_T *pwm, uint32_t u32ChannelMask)
| This function enables PWM output generation of selected channels. More...
void | PWM_DisableOutput (PWM_T *pwm, uint32_t u32ChannelMask)
| This function disables PWM output generation of selected channels. More...
void | PWM_EnableDeadZone (PWM_T *pwm, uint32_t u32ChannelNum, uint32_t u32Duration)
| This function enable Dead zone of selected channel. More...
void | PWM_DisableDeadZone (PWM_T *pwm, uint32_t u32ChannelNum)
| This function disable Dead zone of selected channel. More...
void | PWM_EnableCaptureInt (PWM_T *pwm, uint32_t u32ChannelNum, uint32_t u32Edge)
| This function enable capture interrupt of selected channel. More...
void | PWM_DisableCaptureInt (PWM_T *pwm, uint32_t u32ChannelNum, uint32_t u32Edge)
| This function disable capture interrupt of selected channel. More...
void | PWM_ClearCaptureIntFlag (PWM_T *pwm, uint32_t u32ChannelNum, uint32_t u32Edge)
| This function clear capture interrupt flag of selected channel. More...
uint32_t | PWM_GetCaptureIntFlag (PWM_T *pwm, uint32_t u32ChannelNum)
| This function get capture interrupt flag of selected channel. More...
void | PWM_EnablePeriodInt (PWM_T *pwm, uint32_t u32ChannelNum, uint32_t u32IntPeriodType)
| This function enable period interrupt of selected channel. More...
void | PWM_DisablePeriodInt (PWM_T *pwm, uint32_t u32ChannelNum)
| This function disable period interrupt of selected channel. More...
void | PWM_ClearPeriodIntFlag (PWM_T *pwm, uint32_t u32ChannelNum)
| This function clear period interrupt of selected channel. More...
uint32_t | PWM_GetPeriodIntFlag (PWM_T *pwm, uint32_t u32ChannelNum)
| This function get period interrupt of selected channel. More...
void | PWM_EnablePDMA (PWM_T *pwm, uint32_t u32ChannelNum, uint32_t u32RisingFirst, uint32_t u32Mode)
| This function enable capture PDMA of selected channel. More...
void | PWM_DisablePDMA (PWM_T *pwm, uint32_t u32ChannelNum)
| This function disable capture PDMA of selected channel. More...

## Detailed Description

## Macro Definition Documentation

## ◆ PWM_ENABLE_OUTPUT_INVERTER

#define PWM_ENABLE_OUTPUT_INVERTER | ( |  | pwm,
|  |  | u32ChannelMask
| ) |  |

This macro enable output inverter of specified channel(s)

Parameters

  [in] | pwm | The base address of PWM module
  [in] | u32ChannelMask | Combination of enabled channels. Each bit corresponds to a channel Bit 0 represents channel 0, bit 1 represents channel 1...

Returns
  None

Definition at line 75 of file pwm.h.

## ◆ PWM_GET_CAPTURE_FALLING_DATA

#define PWM_GET_CAPTURE_FALLING_DATA | ( |  | pwm,
|  |  | u32ChannelNum
| ) |  |

This macro get captured falling data.

Parameters

  [in] | pwm | The base address of PWM module
  [in] | u32ChannelNum | PWM channel number. Valid values are between 0~5

Returns
  None

Definition at line 102 of file pwm.h.

## ◆ PWM_GET_CAPTURE_RISING_DATA

#define PWM_GET_CAPTURE_RISING_DATA | ( |  | pwm,
|  |  | u32ChannelNum
| ) |  |

This macro get captured rising data.

Parameters

  [in] | pwm | The base address of PWM module
  [in] | u32ChannelNum | PWM channel number. Valid values are between 0~5

Returns
  None

Definition at line 93 of file pwm.h.

## ◆ PWM_SET_CMR

#define PWM_SET_CMR | ( |  | pwm,
|  |  | u32ChannelNum,
|  |  | u32CMR
| ) |  |

This macro set the duty of the selected channel.

Parameters

  [in] | pwm | The base address of PWM module
  [in] | u32ChannelNum | PWM channel number. Valid values are between 0~5
  [in] | u32CMR | Duty of specified channel. Valid values are between 0~0xFFFF

Returns
  None

Note
  This new setting will take effect on next PWM period

Definition at line 142 of file pwm.h.

## ◆ PWM_SET_CNR

#define PWM_SET_CNR | ( |  | pwm,
|  |  | u32ChannelNum,
|  |  | u32CNR
| ) |  |

This macro set the period of the selected channel.

Parameters

  [in] | pwm | The base address of PWM module
  [in] | u32ChannelNum | PWM channel number. Valid values are between 0~5
  [in] | u32CNR | Period of specified channel. Valid values are between 0~0xFFFF

Returns
  None

Note
  This new setting will take effect on next PWM period
  PWM counter will stop if period length set to 0

Definition at line 158 of file pwm.h.

## ◆ PWM_SET_DIVIDER

#define PWM_SET_DIVIDER | ( |  | pwm,
|  |  | u32ChannelNum,
|  |  | u32Divider
| ) |  |

This macro set the divider of the selected channel.

Parameters

  [in] | pwm | The base address of PWM module
  [in] | u32ChannelNum | PWM channel number. Valid values are between 0~5
  [in] | u32Divider | Clock divider of specified channel. Valid values are PWM_CLK_DIV_1 PWM_CLK_DIV_2 PWM_CLK_DIV_4 PWM_CLK_DIV_8 PWM_CLK_DIV_16

Returns
  None

Definition at line 130 of file pwm.h.

## ◆ PWM_SET_PRESCALER

#define PWM_SET_PRESCALER | ( |  | pwm,
|  |  | u32ChannelNum,
|  |  | u32Prescaler
| ) |  |

This macro set the prescaler of the selected channel.

Parameters

  [in] | pwm | The base address of PWM module
  [in] | u32ChannelNum | PWM channel number. Valid values are between 0~5
  [in] | u32Prescaler | Clock prescaler of specified channel. Valid values are between 1 ~ 0xFF

Returns
  None

Note
  Every even channel N, and channel (N + 1) share a prescaler. So if channel 0 prescaler changed, channel 1 will also be affected.

Definition at line 114 of file pwm.h.

## Function Documentation

## ◆ PWM_ClearCaptureIntFlag()

void PWM_ClearCaptureIntFlag | ( | PWM_T * | pwm,
|  | uint32_t | u32ChannelNum,
|  | uint32_t | u32Edge
| ) |  |

This function clear capture interrupt flag of selected channel.

Parameters

  [in] | pwm | The base address of PWM module
  [in] | u32ChannelNum | PWM channel number. Valid values are between 0~5
  [in] | u32Edge | Capture interrupt type. It could be either PWM_RISING_LATCH_INT_FLAG PWM_FALLING_LATCH_INT_FLAG PWM_RISING_FALLING_LATCH_INT_FLAG

Returns
  None

Definition at line 425 of file pwm.c.

## ◆ PWM_ClearPeriodIntFlag()

void PWM_ClearPeriodIntFlag | ( | PWM_T * | pwm,
|  | uint32_t | u32ChannelNum
| ) |  |

This function clear period interrupt of selected channel.

Parameters

  [in] | pwm | The base address of PWM module
  [in] | u32ChannelNum | PWM channel number. Valid values are between 0~5

Returns
  None

Definition at line 477 of file pwm.c.

## ◆ PWM_ConfigCaptureChannel()

uint32_t PWM_ConfigCaptureChannel | ( | PWM_T * | pwm,
|  | uint32_t | u32ChannelNum,
|  | uint32_t | u32UnitTimeNsec,
|  | uint32_t | u32CaptureEdge
| ) |  |

This function config PWM capture and get the nearest unit time.

Parameters

  [in] | pwm | The base address of PWM module
  [in] | u32ChannelNum | PWM channel number. Valid values are between 0~5
  [in] | u32UnitTimeNsec | Unit time of counter
  [in] | u32CaptureEdge | Condition to latch the counter

Returns
  Nearest unit time in nano second

Note
  Since every two channels, (0 & 1), (2 & 3), (4 & 5), shares a prescaler. Call this API to configure PWM frequency may affect existing frequency of other channel.

Definition at line 142 of file pwm.c.

## ◆ PWM_ConfigOutputChannel()

uint32_t PWM_ConfigOutputChannel | ( | PWM_T * | pwm,
|  | uint32_t | u32ChannelNum,
|  | uint32_t | u32Frequency,
|  | uint32_t | u32DutyCycle
| ) |  |

This function config PWM generator and get the nearest frequency in edge aligned auto-reload mode.

Parameters

  [in] | pwm | The base address of PWM module
  [in] | u32ChannelNum | PWM channel number. Valid values are between 0~5
  [in] | u32Frequency | Target generator frequency
  [in] | u32DutyCycle | Target generator duty cycle percentage. Valid range are between 0 ~ 100. 10 means 10%, 20 means 20%...

Returns
  Nearest frequency clock in nano second

Note
  Since every two channels, (0 & 1), (2 & 3), (4 & 5), shares a prescaler. Call this API to configure PWM frequency may affect existing frequency of other channel.

Definition at line 37 of file pwm.c.

## ◆ PWM_DisableCapture()

void PWM_DisableCapture | ( | PWM_T * | pwm,
|  | uint32_t | u32ChannelMask
| ) |  |

This function disables PWM capture of selected channels.

Parameters

  [in] | pwm | The base address of PWM module
  [in] | u32ChannelMask | Combination of enabled channels. Each bit corresponds to a channel. Set bit 0 to 1 enables channel 0 output, set bit 1 to 1 enables channel 1 output...

Returns
  None

Definition at line 308 of file pwm.c.

## ◆ PWM_DisableCaptureInt()

void PWM_DisableCaptureInt | ( | PWM_T * | pwm,
|  | uint32_t | u32ChannelNum,
|  | uint32_t | u32Edge
| ) |  |

This function disable capture interrupt of selected channel.

Parameters

  [in] | pwm | The base address of PWM module
  [in] | u32ChannelNum | PWM channel number. Valid values are between 0~5
  [in] | u32Edge | Capture interrupt type. It could be either PWM_RISING_LATCH_INT_ENABLE PWM_FALLING_LATCH_INT_ENABLE PWM_RISING_FALLING_LATCH_INT_ENABLE

Returns
  None

Definition at line 409 of file pwm.c.

## ◆ PWM_DisableDeadZone()

void PWM_DisableDeadZone | ( | PWM_T * | pwm,
|  | uint32_t | u32ChannelNum
| ) |  |

This function disable Dead zone of selected channel.

Parameters

  [in] | pwm | The base address of PWM module
  [in] | u32ChannelNum | PWM channel number. Valid values are between 0~5

Returns
  None

Definition at line 375 of file pwm.c.

## ◆ PWM_DisableOutput()

void PWM_DisableOutput | ( | PWM_T * | pwm,
|  | uint32_t | u32ChannelMask
| ) |  |

This function disables PWM output generation of selected channels.

Parameters

  [in] | pwm | The base address of PWM module
  [in] | u32ChannelMask | Combination of enabled channels. Each bit corresponds to a channel Set bit 0 to 1 disables channel 0 output, set bit 1 to 1 disables channel 1 output...

Returns
  None

Definition at line 346 of file pwm.c.

## ◆ PWM_DisablePDMA()

void PWM_DisablePDMA | ( | PWM_T * | pwm,
|  | uint32_t | u32ChannelNum
| ) |  |

This function disable capture PDMA of selected channel.

Parameters

  [in] | pwm | The base address of PWM module
  [in] | u32ChannelNum | PWM channel number. Valid values are 0 and 2

Returns
  None

Definition at line 523 of file pwm.c.

## ◆ PWM_DisablePeriodInt()

void PWM_DisablePeriodInt | ( | PWM_T * | pwm,
|  | uint32_t | u32ChannelNum
| ) |  |

This function disable period interrupt of selected channel.

Parameters

  [in] | pwm | The base address of PWM module
  [in] | u32ChannelNum | PWM channel number. Valid values are between 0~5

Returns
  None

Definition at line 466 of file pwm.c.

## ◆ PWM_EnableCapture()

void PWM_EnableCapture | ( | PWM_T * | pwm,
|  | uint32_t | u32ChannelMask
| ) |  |

This function enables PWM capture of selected channels.

Parameters

  [in] | pwm | The base address of PWM module
  [in] | u32ChannelMask | Combination of enabled channels. Each bit corresponds to a channel. Set bit 0 to 1 enables channel 0 output, set bit 1 to 1 enables channel 1 output...

Returns
  None

Definition at line 285 of file pwm.c.

## ◆ PWM_EnableCaptureInt()

void PWM_EnableCaptureInt | ( | PWM_T * | pwm,
|  | uint32_t | u32ChannelNum,
|  | uint32_t | u32Edge
| ) |  |

This function enable capture interrupt of selected channel.

Parameters

  [in] | pwm | The base address of PWM module
  [in] | u32ChannelNum | PWM channel number. Valid values are between 0~5
  [in] | u32Edge | Capture interrupt type. It could be either PWM_RISING_LATCH_INT_ENABLE PWM_FALLING_LATCH_INT_ENABLE PWM_RISING_FALLING_LATCH_INT_ENABLE

Returns
  None

Definition at line 393 of file pwm.c.

## ◆ PWM_EnableDeadZone()

void PWM_EnableDeadZone | ( | PWM_T * | pwm,
|  | uint32_t | u32ChannelNum,
|  | uint32_t | u32Duration
| ) |  |

This function enable Dead zone of selected channel.

Parameters

  [in] | pwm | The base address of PWM module
  [in] | u32ChannelNum | PWM channel number. Valid values are between 0~5
  [in] | u32Duration | Dead Zone length in PWM clock count, valid values are between 0~0xFF, but 0 means there is no dead zone.

Returns
  None

Definition at line 359 of file pwm.c.

## ◆ PWM_EnableOutput()

void PWM_EnableOutput | ( | PWM_T * | pwm,
|  | uint32_t | u32ChannelMask
| ) |  |

This function enables PWM output generation of selected channels.

Parameters

  [in] | pwm | The base address of PWM module
  [in] | u32ChannelMask | Combination of enabled channels. Each bit corresponds to a channel. Set bit 0 to 1 enables channel 0 output, set bit 1 to 1 enables channel 1 output...

Returns
  None

Definition at line 334 of file pwm.c.

## ◆ PWM_EnablePDMA()

void PWM_EnablePDMA | ( | PWM_T * | pwm,
|  | uint32_t | u32ChannelNum,
|  | uint32_t | u32RisingFirst,
|  | uint32_t | u32Mode
| ) |  |

This function enable capture PDMA of selected channel.

Parameters

  [in] | pwm | The base address of PWM module
  [in] | u32ChannelNum | PWM channel number. Valid values are 0 and 2
  [in] | u32RisingFirst | Order of captured data transferred by PDMA. It could be either PWM_CAP_PDMA_RFORDER_R PWM_CAP_PDMA_RFORDER_F
  [in] | u32Mode | Captured data transferred by PDMA interrupt type. It could be either PWM_RISING_LATCH_PDMA_ENABLE PWM_FALLING_LATCH_PDMA_ENABLE PWM_RISING_FALLING_LATCH_PDMA_ENABLE

Returns
  None

Definition at line 509 of file pwm.c.

## ◆ PWM_EnablePeriodInt()

void PWM_EnablePeriodInt | ( | PWM_T * | pwm,
|  | uint32_t | u32ChannelNum,
|  | uint32_t | u32IntPeriodType
| ) |  |

This function enable period interrupt of selected channel.

Parameters

  [in] | pwm | The base address of PWM module
  [in] | u32ChannelNum | PWM channel number. Valid values are between 0~5
  [in] | u32IntPeriodType | This parameter is not used

Returns
  None

Note
  All channels share the same period interrupt type setting.

Definition at line 454 of file pwm.c.

## ◆ PWM_ForceStop()

void PWM_ForceStop | ( | PWM_T * | pwm,
|  | uint32_t | u32ChannelMask
| ) |  |

This function stop PWM generation immediately by clear channel enable bit.

Parameters

  [in] | pwm | The base address of PWM module
  [in] | u32ChannelMask | Combination of enabled channels. Each bit corresponds to a channel. Bit 0 is channel 0, bit 1 is channel 1...

Returns
  None

Definition at line 268 of file pwm.c.

## ◆ PWM_GetCaptureIntFlag()

uint32_t PWM_GetCaptureIntFlag | ( | PWM_T * | pwm,
|  | uint32_t | u32ChannelNum
| ) |  |

This function get capture interrupt flag of selected channel.

Parameters

  [in] | pwm | The base address of PWM module
  [in] | u32ChannelNum | PWM channel number. Valid values are between 0~5

Returns
  Capture interrupt flag of specified channel

Return values

  0 | Capture interrupt did not occurred
  PWM_RISING_LATCH_INT_FLAG | Rising edge latch interrupt occurred
  PWM_FALLING_LATCH_INT_FLAG | Falling edge latch interrupt occurred
  PWM_RISING_FALLING_LATCH_INT_FLAG | Rising and falling edge latch interrupt occurred

Definition at line 441 of file pwm.c.

## ◆ PWM_GetPeriodIntFlag()

uint32_t PWM_GetPeriodIntFlag | ( | PWM_T * | pwm,
|  | uint32_t | u32ChannelNum
| ) |  |

This function get period interrupt of selected channel.

Parameters

  [in] | pwm | The base address of PWM module
  [in] | u32ChannelNum | PWM channel number. Valid values are between 0~5

Returns
  Period interrupt flag of specified channel

Return values

  0 | Period interrupt did not occurred
  1 | Period interrupt occurred

Definition at line 491 of file pwm.c.

## ◆ PWM_Start()

void PWM_Start | ( | PWM_T * | pwm,
|  | uint32_t | u32ChannelMask
| ) |  |

This function start PWM module.

Parameters

  [in] | pwm | The base address of PWM module
  [in] | u32ChannelMask | Combination of enabled channels. Each bit corresponds to a channel. Bit 0 is channel 0, bit 1 is channel 1...

Returns
  None

Definition at line 227 of file pwm.c.

## ◆ PWM_Stop()

void PWM_Stop | ( | PWM_T * | pwm,
|  | uint32_t | u32ChannelMask
| ) |  |

This function stop PWM module.

Parameters

  [in] | pwm | The base address of PWM module
  [in] | u32ChannelMask | Combination of enabled channels. Each bit corresponds to a channel. Bit 0 is channel 0, bit 1 is channel 1...

Returns
  None

Definition at line 248 of file pwm.c.