ESP32_RTOS_SDK V1.1.0

- Main Page
- Modules
- Data Structures
- Files

Data Structures | Macros | Functions
PWM Driver APIs
Driver APIs

PWM driver APIs. More...

## Data Structures

struct | pwm_param

## Macros

#define | PWM_CHANNEL_NUM_MAX 8
#define | TIMER0 0
#define | TIMER1 1
#define | TIMER2 2
#define | TIMER3 3
#define | CHANNEL0 0
#define | CHANNEL1 1
#define | CHANNEL2 2
#define | CHANNEL3 3
#define | CHANNEL4 4
#define | CHANNEL5 5
#define | CHANNEL6 6
#define | CHANNEL7 7
#define | OUTPUT_LOW 0
#define | OUTPUT_HIGH 1
#define | REF_TICK_CLK 0
#define | APB_CLK 1

## Functions

void | pwm_init (uint32 period, uint32 *duty, uint32 pwm_channel_num, uint32(*pin_info_list)[3])
| PWM function initialization, including GPIO, frequency and duty cycle. More...
void | pwm_set_duty (uint32 duty, uint8 channel)
| Set the duty cycle of a PWM channel. More...
uint32 | pwm_get_duty (uint8 channel)
| Get the duty cycle of a PWM channel. More...
void | pwm_set_period (uint32 period)
| Set PWM period, unit : us. More...
uint32 | pwm_get_period (void)
| Get PWM period, unit : us. More...
void | pwm_start (void)
| Starts PWM. More...
void | ledc_set_base_hclk (uint8 timer_sel, uint8 apb_clk_sel)
| Set high_speed channel base clock. More...
void | ledc_set_base_lclk (uint8 timer_sel, uint8 apb_clk_sel)
| Set low_speed channel base clock. More...
void | ledc_set_hperiod (uint8 timer_sel, uint32 div_num, uint8 timer_lim)
| Set high_speed channel frequency. More...
void | ledc_set_lperiod (uint8 timer_sel, uint32 div_num, uint8 timer_lim)
| Set low_speed channel frequency. More...
void | ledc_set_ltimer (uint8 chan_num, uint8 timer_sel)
| Select one timer for one low_speed channel. More...
void | ledc_set_htimer (uint8 chan_num, uint8 timer_sel)
| Select one timer for one high_speed channel. More...
void | ledc_set_idle_hlevel (uint8 chan_num, uint8 idle_level)
| Set high_speed channel output (as high or low) when idle. More...
void | ledc_set_idle_llevel (uint8 chan_num, uint8 idle_level)
| Set low_speed channel output (as high or low) when idle. More...
void | ledc_set_hduty (uint8 chan_num, uint32 hpoint_val, uint32 duty_val, uint8 increase, uint16 duty_num, uint16 duty_cycle, uint16 duty_scale)
| Set high_speed channel duty. More...
void | ledc_set_lduty (uint8 chan_num, uint32 hpoint_val, uint32 duty_val, uint8 increase, uint16 duty_num, uint16 duty_cycle, uint16 duty_scale)
| Set low_speed channel duty. More...
void | ledc_hstart (uint8 chan_num)
| Enable one high_speed channel. More...
void | ledc_lstart (uint8 chan_num)
| Enable one low_speed channel. More...
void | ledc_timer_hpause (uint8 timer_sel)
| Pause one of the timers for high_speed channel. More...
void | ledc_timer_lpause (uint8 timer_sel)
| Pause one of the timers for low_speed channel. More...
void | ledc_timer_hunpause (uint8 timer_sel)
| Unpause one of the timers for high_speed channel. More...
void | ledc_timer_lunpause (uint8 timer_sel)
| Unpause one of the timers for low_speed channel. More...
void | ledc_timer_hstop (uint8 timer_sel)
| Stop one of the timers for high_speed channel. More...
void | ledc_timer_lstop (uint8 timer_sel)
| Stop one of the timers for low_speed channel. More...

## Detailed Description

PWM driver APIs.

## Function Documentation

void ledc_hstart | ( | uint8 | chan_num | ) |

Enable one high_speed channel.

Parameters

  uint8 | chan_num : channel to pick

Returns
  null

void ledc_lstart | ( | uint8 | chan_num | ) |

Enable one low_speed channel.

Parameters

  uint8 | chan_num : channel to pick

Returns
  null

void ledc_set_base_hclk | ( | uint8 | timer_sel,
|  | uint8 | apb_clk_sel
| ) |  |

Set high_speed channel base clock.

Parameters

  uint8 | timer_sel : timer to set
  uint8 | apb_clk_sel : pick clock source for timer

Returns
  null

void ledc_set_base_lclk | ( | uint8 | timer_sel,
|  | uint8 | apb_clk_sel
| ) |  |

Set low_speed channel base clock.

Parameters

  uint8 | timer_sel : timer to set
  uint8 | apb_clk_sel :pick clock source for timer

Returns
  null

void ledc_set_hduty | ( | uint8 | chan_num,
|  | uint32 | hpoint_val,
|  | uint32 | duty_val,
|  | uint8 | increase,
|  | uint16 | duty_num,
|  | uint16 | duty_cycle,
|  | uint16 | duty_scale
| ) |  |

Set high_speed channel duty.

Parameters

  uint8 | chan_num : 8 channels in total,value from 0~7
  uint32 | hpoint_val : output high when counter equals this value
  uint32 | duty_val : output low after counter equals this value
  uint8 | increase : 1 - increase duty ratio, 0 - decrease duty ratio
  uint16 | duty_num : generate interrupt after duty_num * duty_cycle outputs
  uint16 | duty_cycle : increase or decrease duty ratio every duty_cycle outputs
  uint16 | duty_scale : the range of changing on duty ratio

Returns
  null

void ledc_set_hperiod | ( | uint8 | timer_sel,
|  | uint32 | div_num,
|  | uint8 | timer_lim
| ) |  |

Set high_speed channel frequency.

frequency=base_clk_frequency*div_num*(2^timer_lim)/256

Parameters

  uint8 | timer_sel : timer to set
  uint32 | div_num : set first divider
  uint8 | timer_lim : set second divider

Returns
  null

void ledc_set_htimer | ( | uint8 | chan_num,
|  | uint8 | timer_sel
| ) |  |

Select one timer for one high_speed channel.

Parameters

  uint8 | chan_num : channel to pick
  uint8 | timer_sel : timer to set

Returns
  null

void ledc_set_idle_hlevel | ( | uint8 | chan_num,
|  | uint8 | idle_level
| ) |  |

Set high_speed channel output (as high or low) when idle.

Parameters

  uint8 | chan_num : channel to pick
  uint8 | idle_level : choose output as high or low

Returns
  null

void ledc_set_idle_llevel | ( | uint8 | chan_num,
|  | uint8 | idle_level
| ) |  |

Set low_speed channel output (as high or low) when idle.

Parameters

  uint8 | chan_num : channel to pick
  uint8 | idle_level : choose output as high or low

Returns
  null

void ledc_set_lduty | ( | uint8 | chan_num,
|  | uint32 | hpoint_val,
|  | uint32 | duty_val,
|  | uint8 | increase,
|  | uint16 | duty_num,
|  | uint16 | duty_cycle,
|  | uint16 | duty_scale
| ) |  |

Set low_speed channel duty.

Parameters

  uint8 | chan_num : 8 channels in total, value from 0~7
  uint32 | hpoint_val : output high when counter equals this value
  uint32 | duty_val : output low after counter equals this value
  uint8 | increase : 1 - increase duty ratio, 0 - decrease duty ratio
  uint16 | duty_num : generate interrupt after duty_num * duty_cycle outputs
  uint16 | duty_cycle : increase or decrease duty ratio every duty_cycle outputs
  uint16 | duty_scale : the range of changing on duty ratio

Returns
  null

void ledc_set_lperiod | ( | uint8 | timer_sel,
|  | uint32 | div_num,
|  | uint8 | timer_lim
| ) |  |

Set low_speed channel frequency.

frequency=base_clk_frequency*div_num*(2^timer_lim)/256

Parameters

  uint8 | timer_sel : timer to set
  uint32 | div_num : set first divider
  uint8 | timer_lim : set second divider

Returns
  null

void ledc_set_ltimer | ( | uint8 | chan_num,
|  | uint8 | timer_sel
| ) |  |

Select one timer for one low_speed channel.

Parameters

  uint8 | chan_num : channel to pick
  uint8 | timer_sel : timer to set

Returns
  null

void ledc_timer_hpause | ( | uint8 | timer_sel | ) |

Pause one of the timers for high_speed channel.

Parameters

  uint8 | timer_sel : timer to set

Returns
  null

void ledc_timer_hstop | ( | uint8 | timer_sel | ) |

Stop one of the timers for high_speed channel.

Parameters

  uint8 | timer_sel : timer to set

Returns
  null

void ledc_timer_hunpause | ( | uint8 | timer_sel | ) |

Unpause one of the timers for high_speed channel.

Parameters

  uint8 | timer_sel : timer to set

Returns
  null

void ledc_timer_lpause | ( | uint8 | timer_sel | ) |

Pause one of the timers for low_speed channel.

Parameters

  uint8 | timer_sel : timer to set

Returns
  null

void ledc_timer_lstop | ( | uint8 | timer_sel | ) |

Stop one of the timers for low_speed channel.

Parameters

  uint8 | timer_sel : timer to set

Returns
  null

void ledc_timer_lunpause | ( | uint8 | timer_sel | ) |

Unpause one of the timers for low_speed channel.

Parameters

  uint8 | timer_sel : timer to set

Returns
  null

uint32 pwm_get_duty | ( | uint8 | channel | ) |

Get the duty cycle of a PWM channel.

Duty cycle will be (duty * 45)/(period *1000).

Parameters

  uint8 | channel : PWM channel number

Returns
  Duty cycle of PWM output.

uint32 pwm_get_period | ( | void |  | ) |

Get PWM period, unit : us.

Parameters

  null |

Returns
  PWM period, unit : us.

void pwm_init | ( | uint32 | period,
|  | uint32 * | duty,
|  | uint32 | pwm_channel_num,
|  | uint32(*) | pin_info_list[3]
| ) |  |

PWM function initialization, including GPIO, frequency and duty cycle.

Attention
  This API can be called only once.

Parameters

  uint32 | period : pwm frequency
  uint32 | *duty : duty cycle
  uint32 | pwm_channel_num : PWM channel number
  uint32 | (*pin_info_list)[3] : GPIO parameter of PWM channel, it is a pointer of n x 3 array which defines GPIO register, IO reuse of corresponding pin and GPIO number.

Returns
  null

void pwm_set_duty | ( | uint32 | duty,
|  | uint8 | channel
| ) |  |

Set the duty cycle of a PWM channel.

Set the time that high level signal will last, duty depends on period, the maximum value can be period *1000 / 45. For example, 1KHz PWM, duty range is 0~22222

Attention
  After set configuration, pwm_start needs to be called to take effect.

Parameters

  uint32 | duty : duty cycle
  uint8 | channel : PWM channel number

Returns
  null

void pwm_set_period | ( | uint32 | period | ) |

Set PWM period, unit : us.

For example, for 1KHz PWM, period is 1000 us.

Attention
  After set configuration, pwm_start needs to be called to take effect.

Parameters

  uint32 | period : PWM period, unit : us.

Returns
  null

void pwm_start | ( | void |  | ) |

Starts PWM.

Attention
  This function needs to be called after PWM configuration is changed.

Parameters

  null |

Returns
  null