Motor Control Pulse Width Modulator (MCPWM)
ESP32 has two MCPWM units which can be used to control different types of motors. Each unit has three pairs of PWM outputs.
Further in documentation the outputs of a single unit are labeled PWMxA
/ PWMxB
.
More detailed block diagram of the MCPWM unit is shown below. Each A/B pair may be clocked by any one of the three timers Timer 0, 1 and 2. The same timer may be used to clock more than one pair of PWM outputs. Each unit is also able to collect inputs such as SYNC SIGNALS
, detect FAULT SIGNALS
like motor overcurrent or overvoltage, as well as obtain feedback with CAPTURE SIGNALS
on e.g. a rotor position.
Description of this API starts with configuration of MCPWM’s Timer and Generator submodules to provide the basic motor control functionality. Then it discusses more advanced submodules and functionalities of a Fault Handler, signal Capture and Carrier.
Contents
Configure a basic functionality of the outputs
Operate the outputs to drive a motor
Adjust how the motor is driven
Synchronize sync timers to work together
Capture external signals to provide additional control over the outputs
Use Fault Handler to detect and manage faults
Add a higher frequency Carrier, if output signals are passed through an isolation transformer
Extra configuration of Resolution.
Configure
The scope of configuration depends on the motor type, in particular how many outputs and inputs are required, and what will be the sequence of signals to drive the motor.
In this case we will describe a simple configuration to control a brushed DC motor that is using only some of the available MCPWM’s resources. An example circuit is shown below. It includes a H-Bridge to switch polarization of a voltage applied to the motor (M) and to provide sufficient current to drive it.
Configuration covers the following steps:
Selection of a MCPWM unit that will be used to drive the motor. There are two units available on-board of ESP32 and enumerated in
mcpwm_unit_t
.Initialization of two GPIOs as output signals within selected unit by calling
mcpwm_gpio_init()
. The two output signals are typically used to command the motor to rotate right or left. All available signal options are listed inmcpwm_io_signals_t
. To set more than a single pin at a time, use functionmcpwm_set_pin()
together withmcpwm_pin_config_t
.Selection of a timer. There are three timers available within the unit. The timers are listed in
mcpwm_timer_t
.Setting of the timer frequency and initial duty within
mcpwm_config_t
structure.Setting timer resolution if necessary, by calling
mcpwm_group_set_resolution()
andmcpwm_timer_set_resolution()
Calling of
mcpwm_init()
with the above parameters to make the configuration effective.
Operate
To operate a motor connected to the MCPWM unit, e.g. turn it left or right, or vary the speed, we should apply some control signals to the unit’s outputs. The outputs are organized into three pairs. Within a pair they are labeled “A” and “B” and each driven by a submodule called an “Generator”. To provide a PWM signal, the Operator itself, which contains two Generator, should be clocked by one of three available Timers. To make the API simpler, each Timer is automatically associated by the API to drive an Operator of the same index, e.g. Timer 0 is associated with Operator 0.
There are the following basic ways to control the outputs:
We can drive particular signal steady high or steady low with function
mcpwm_set_signal_high()
ormcpwm_set_signal_low()
. This will make the motor to turn with a maximum speed or stop. Depending on selected output A or B the motor will rotate either right or left.Another option is to drive the outputs with the PWM signal by calling
mcpwm_start()
ormcpwm_stop()
. The motor speed will be proportional to the PWM duty.To vary PWM’s duty call
mcpwm_set_duty()
and provide the duty value in %. Optionally, you may callmcpwm_set_duty_in_us()
, if you prefer to set the duty in microseconds. Checking of currently set value is possible by callingmcpwm_get_duty()
. Phase of the PWM signal may be altered by callingmcpwm_set_duty_type()
. The duty is set individually for each A and B output usingmcpwm_generator_t
in specific function calls. The duty value refers either to high or low output signal duration. This is configured when callingmcpwm_init()
, as discussed in section Configure, and selecting one of options frommcpwm_duty_type_t
.
Note
Call function mcpwm_set_duty_type()
every time after mcpwm_set_signal_high()
or mcpwm_set_signal_low()
to resume with previously set duty cycle.
Adjust
There are couple of ways to adjust a signal on the outputs and changing how the motor operates.
Set specific PWM frequency by calling
mcpwm_set_frequency()
. This may be required to adjust to electrical or mechanical characteristics of particular motor and driver. To check what frequency is set, use functionmcpwm_get_frequency()
.Introduce a dead time between outputs A and B when they are changing the state to reverse direction of the motor rotation. This is to make up for on/off switching delay of the motor driver FETs. The dead time options are defined in
mcpwm_deadtime_type_t
and enabled by callingmcpwm_deadtime_enable()
. To disable this functionality callmcpwm_deadtime_disable()
.Synchronize outputs of operator submodules, e.g. to get raising edge of PWM0A/B and PWM1A/B to start exactly at the same time, or shift them between each other by a given phase. Synchronization is triggered by
SYNC SIGNALS
shown on the block diagram of the MCPWM above, and defined inmcpwm_sync_signal_t
. To attach the signal to a GPIO callmcpwm_gpio_init()
. You can then enable synchronization with functionmcpwm_sync_configure()
. As input parameters provide MCPWM unit, timer to synchronize, the synchronization signal and a phase to delay the timer.
Note
Synchronization signals are referred to using two different enumerations. First one mcpwm_io_signals_t
is used together with function mcpwm_gpio_init()
when selecting a GPIO as the signal input source. The second one mcpwm_sync_signal_t
is used when enabling or disabling synchronization with mcpwm_sync_configure()
or mcpwm_sync_disable()
.
Vary the pattern of the A/B output signals by getting MCPWM counters to count up, down and up/down (automatically changing the count direction). Respective configuration is done when calling
mcpwm_init()
, as discussed in section Configure, and selecting one of counter types frommcpwm_counter_type_t
. For explanation of how A/B PWM output signals are generated, see ESP32 Technical Reference Manual > Motor Control PWM (MCPWM) [PDF].
Synchronize
Each PWM timer has a synchronization input and a synchronization output. The synchronization input can be selected from other timers’ synchronization outputs or GPIO signals via the GPIO matrix. Timer’s synchronization signal can be generated from either the input sync signal or when the count value reaches peak/zero. Thus, the PWM timers can be chained together with their phase-locked. During synchronization, the PWM timer clock prescaler will reset its counter in order to synchronize the PWM timer clock.
The functionality is enabled in following steps:
Make sure the PWM timer and operator are already configured so that sync will inherit its config (count mode, freq and duty).
Enabling sync input of the timer by invoking
mcpwm_sync_configure()
, selecting desired signal input frommcpwm_sync_signal_t
, and setting the desired phase range from 0 to 999 which is mapped to 0%~99.9%. 0 means zero phase is applied and output is fired at the same time. And selecting desired counting direction.Enabling one of sync event source from another timer or from external GPIO input.
To sync with another timer:
Enabling sync output of another timer by invoking mcpwm_set_timer_sync_output()
and selecting desired event to generate sync output from mcpwm_timer_sync_trigger_t
.
To sync with GPIO positive edge input (negative edge requires mcpwm_sync_invert_gpio_synchro()
):
Configuring GPIOs to act as the sync signal inputs by calling functions mcpwm_gpio_init()
or mcpwm_set_pin()
, which were described in section Configure.
It’s normal condition that chained sync signal may have tens or even hundreds of nanoseconds of delay between each timer output due to hardware limitation. To sync two timers accurately it is required to have the third timer occupied to produce sync event that can be consumed parallel by other two timer, so that those two timer will have no delay between each other but have the same delay between the timer which provides events. Another solution is introducing an external GPIO event source so that all three timers can be synced together with no delay.
If not required anymore, the capture functionality may be disabled with mcpwm_sync_disable()
.
Capture
One of requirements of BLDC (Brushless DC, see figure below) motor control is sensing of the rotor position. To facilitate this task each MCPWM unit provides three sensing inputs together with dedicated hardware. The hardware is able to detect the input signal’s edge and measure time between signals. As result the control software is simpler and the CPU power may be used for other tasks.
The capture functionality may be used for other types of motors or tasks. The functionality is enabled in two steps:
Configuration of GPIOs to act as the capture signal inputs by calling functions
mcpwm_gpio_init()
ormcpwm_set_pin()
, that were described in section Configure.Enabling of the functionality itself by invoking
mcpwm_capture_enable_channel()
, selecting desired signal input frommcpwm_capture_channel_id_t
, setting the signal edge, signal count prescaler and user callback withinmcpwm_capture_config_t
Within the second step above a 32-bit capture timer is enabled. The timer runs continuously driven by the APB clock. The clock frequency is typically 80 MHz. On each capture event the capture timer’s value is stored in time-stamp register that may be then checked by calling mcpwm_capture_signal_get_value()
. The edge of the last signal may be checked with mcpwm_capture_signal_get_edge()
. Those data are also provided inside callback function as event data cap_event_data_t
If not required anymore, the capture functionality may be disabled with mcpwm_capture_disable_channel()
.
Capture prescale is different from other modules as it is applied to the input signal, not the timer source. Prescaler has maintained its own level state with the initial value set to low and is detecting the positive edge of the input signal to change its internal state. That means if two pairs of positive and negative edges are passed to input, the prescaler’s internal state will change twice. ISR will report on this internal state change, not the input signal. For example, setting prescale to 2 will generate ISR callback on each positive edge of input if both edge is selected via mcpwm_capture_config_t
. Or each 2 positive edges of input if only one edge is selected though mcpwm_capture_config_t
.
Fault Handler
Each unit of the MCPWM is able to sense external signals with information about failure of the motor, the motor driver or any other device connected to the MCPWM. There are three fault inputs per unit that may be routed to user selectable GPIOs. The MCPWM may be configured to perform one of four predefined actions on A/B outputs when a fault signal is received:
lock current state of the output
set the output low
set the output high
toggle the output
The user should determine possible failure modes of the motor and what action should be performed on detection of particular fault, e.g. drive all outputs low for a brushed motor, or lock current state for a stepper motor, etc. As result of this action the motor should be put into a safe state to reduce likelihood of a damage caused by the fault.
The fault handler functionality is enabled in two steps:
Configuration of GPIOs to act as fault signal inputs. This is done in analogous way as described for capture signals in section above. It includes setting the signal level to trigger the fault as defined in
mcpwm_fault_input_level_t
.Initialization of the fault handler by calling either
mcpwm_fault_set_oneshot_mode()
ormcpwm_fault_set_cyc_mode()
. These functions set the mode that MCPWM should operate once fault signal becomes inactive. There are two modes possible:
State of MCPWM unit will be locked until reset -
mcpwm_fault_set_oneshot_mode()
.The MCPWM will resume operation once fault signal becoming inactive -
mcpwm_fault_set_cyc_mode()
.The function call parameters include selection of one of three fault inputs defined in
mcpwm_fault_signal_t
and specific action on outputs A and B defined inmcpwm_action_on_pwmxa_t
andmcpwm_action_on_pwmxb_t
.
Particular fault signal may be disabled at the runtime by calling mcpwm_fault_deinit()
.
Carrier
The MCPWM has a carrier submodule used if galvanic isolation from the motor driver is required by passing the A/B output signals through transformers. Any of A and B output signals may be at 100% duty and not changing whenever motor is required to run steady at the full load. Coupling of non alternating signals with a transformer is problematic, so the signals are modulated by the carrier submodule to create an AC waveform, to make the coupling possible.
To use the carrier submodule, it should be first initialized by calling mcpwm_carrier_init()
. The carrier parameters are defined in mcpwm_carrier_config_t
structure invoked within the function call. Then the carrier functionality may be enabled by calling mcpwm_carrier_enable()
.
The carrier parameters may be then altered at a runtime by calling dedicated functions to change individual fields of the mcpwm_carrier_config_t
structure, like mcpwm_carrier_set_period()
, mcpwm_carrier_set_duty_cycle()
, mcpwm_carrier_output_invert()
, etc.
This includes enabling and setting duration of the first pulse of the career with mcpwm_carrier_oneshot_mode_enable()
. For more details, see ESP32 Technical Reference Manual > Motor Control PWM (MCPWM) > PWM Carrier Submodule [PDF].
To disable carrier functionality call mcpwm_carrier_disable()
.
Interrupts
Registering of the MCPWM interrupt handler is possible by calling mcpwm_isr_register()
. Note if mcpwm_capture_enable_channel()
is used then a default ISR routine will be installed hence please do not call this function to register any more.
Resolution
The default resolution for MCPWM group and MCPWM timer are configured to 10MHz and 1MHz in mcpwm_init()
, which might be not enough for some applications.
The driver also provides two APIs that can be used to override the default resolution: mcpwm_group_set_resolution()
and mcpwm_timer_set_resolution()
.
Note that, these two APIs won’t update the frequency and duty automatically, to achieve that, one has to call mcpwm_set_frequency()
and mcpwm_set_duty()
accordingly.
To get PWM pulse that is below 15Hz, please set the resolution to a lower value. For high frequency PWM with limited step range, please set them with higher value.
Application Example
MCPWM example are located under: peripherals/mcpwm:
Control of BLDC (brushless DC) motor with hall sensor feedback - peripherals/mcpwm/mcpwm_bldc_hall_control
Brushed DC motor control - peripherals/mcpwm/mcpwm_brushed_dc_control
Servo motor control - peripherals/mcpwm/mcpwm_servo_control
HC-SR04 sensor with capture - peripherals/mcpwm/mcpwm_capture_hc_sr04
API Reference
Header File
Enumerations
-
enum mcpwm_timer_direction_t
Values:
-
enumerator MCPWM_TIMER_DIRECTION_UP
Counting direction: Increase
-
enumerator MCPWM_TIMER_DIRECTION_DOWN
Counting direction: Decrease
-
enumerator MCPWM_TIMER_DIRECTION_UP
-
enum mcpwm_timer_event_t
Values:
-
enumerator MCPWM_TIMER_EVENT_ZERO
MCPWM timer counts to zero
-
enumerator MCPWM_TIMER_EVENT_PEAK
MCPWM timer counts to peak
-
enumerator MCPWM_TIMER_EVENT_ZERO
-
enum mcpwm_timer_count_mode_t
Values:
-
enumerator MCPWM_TIMER_COUNT_MODE_PAUSE
MCPWM timer paused
-
enumerator MCPWM_TIMER_COUNT_MODE_UP
MCPWM timer counting up
-
enumerator MCPWM_TIMER_COUNT_MODE_DOWN
MCPWM timer counting down
-
enumerator MCPWM_TIMER_COUNT_MODE_UP_DOWN
MCPWM timer counting up and down
-
enumerator MCPWM_TIMER_COUNT_MODE_PAUSE
-
enum mcpwm_timer_execute_cmd_t
Values:
-
enumerator MCPWM_TIMER_STOP_AT_ZERO
MCPWM timer stops when couting to zero
-
enumerator MCPWM_TIMER_STOP_AT_PEAK
MCPWM timer stops when counting to peak
-
enumerator MCPWM_TIMER_START_NO_STOP
MCPWM timer starts couting
-
enumerator MCPWM_TIMER_START_STOP_AT_ZERO
MCPWM timer starts counting and stops when couting to zero
-
enumerator MCPWM_TIMER_START_STOP_AT_PEAK
MCPWM timer starts counting and stops when counting to peak
-
enumerator MCPWM_TIMER_STOP_AT_ZERO
-
enum mcpwm_generator_action_t
Values:
-
enumerator MCPWM_GEN_ACTION_KEEP
Generator action: Keep the same level
-
enumerator MCPWM_GEN_ACTION_LOW
Generator action: Force to low level
-
enumerator MCPWM_GEN_ACTION_HIGH
Generator action: Force to high level
-
enumerator MCPWM_GEN_ACTION_TOGGLE
Generator action: Toggle level
-
enumerator MCPWM_GEN_ACTION_KEEP
Header File
Functions
-
esp_err_t mcpwm_gpio_init(mcpwm_unit_t mcpwm_num, mcpwm_io_signals_t io_signal, int gpio_num)
This function initializes each gpio signal for MCPWM.
Note
This function initializes one gpio at a time.
- Parameters
mcpwm_num – set MCPWM unit(0-1)
io_signal – set MCPWM signals, each MCPWM unit has 6 output(MCPWMXA, MCPWMXB) and 9 input(SYNC_X, FAULT_X, CAP_X) ‘X’ is timer_num(0-2)
gpio_num – set this to configure gpio for MCPWM, if you want to use gpio16, gpio_num = 16
- Returns
ESP_OK Success
ESP_ERR_INVALID_ARG Parameter error
-
esp_err_t mcpwm_set_pin(mcpwm_unit_t mcpwm_num, const mcpwm_pin_config_t *mcpwm_pin)
Initialize MCPWM gpio structure.
Note
This function initialize a group of MCPWM GPIOs at a time.
- Parameters
mcpwm_num – set MCPWM unit(0-1)
mcpwm_pin – MCPWM pin structure
- Returns
ESP_OK Success
ESP_ERR_INVALID_ARG Parameter error
-
esp_err_t mcpwm_init(mcpwm_unit_t mcpwm_num, mcpwm_timer_t timer_num, const mcpwm_config_t *mcpwm_conf)
Initialize MCPWM parameters.
Note
The default resolution configured for MCPWM group and timer are 160M / 16 = 10M and 10M / 10 = 1M The default resolution can be changed by calling mcpwm_group_set_resolution() and mcpwm_timer_set_resolution(), before calling this function.
- Parameters
mcpwm_num – set MCPWM unit(0-1)
timer_num – set timer number(0-2) of MCPWM, each MCPWM unit has 3 timers.
mcpwm_conf – configure structure mcpwm_config_t
- Returns
ESP_OK Success
ESP_ERR_INVALID_ARG Parameter error
-
esp_err_t mcpwm_group_set_resolution(mcpwm_unit_t mcpwm_num, unsigned long int resolution)
Set resolution of the MCPWM group.
Note
This will override default resolution of group(=10,000,000). This WILL NOT automatically update frequency and duty. Call mcpwm_set_frequency() and mcpwm_set_duty() manually to set them back.
- Parameters
mcpwm_num – set MCPWM unit(0-1)
resolution – set expected frequency resolution
- Returns
ESP_OK Success
ESP_ERR_INVALID_ARG Parameter error
-
esp_err_t mcpwm_timer_set_resolution(mcpwm_unit_t mcpwm_num, mcpwm_timer_t timer_num, unsigned long int resolution)
Set resolution of each timer.
Note
This WILL override default resolution of timer(=1,000,000). This WILL NOT automatically update frequency and duty. Call mcpwm_set_frequency() and mcpwm_set_duty() manually to set them back.
- Parameters
mcpwm_num – set MCPWM unit(0-1)
timer_num – set timer number(0-2) of MCPWM, each MCPWM unit has 3 timers
resolution – set expected frequency resolution
- Returns
ESP_OK Success
ESP_ERR_INVALID_ARG Parameter error
-
esp_err_t mcpwm_set_frequency(mcpwm_unit_t mcpwm_num, mcpwm_timer_t timer_num, uint32_t frequency)
Set frequency(in Hz) of MCPWM timer.
- Parameters
mcpwm_num – set MCPWM unit(0-1)
timer_num – set timer number(0-2) of MCPWM, each MCPWM unit has 3 timers
frequency – set the frequency in Hz of each timer
- Returns
ESP_OK Success
ESP_ERR_INVALID_ARG Parameter error
-
esp_err_t mcpwm_set_duty(mcpwm_unit_t mcpwm_num, mcpwm_timer_t timer_num, mcpwm_generator_t gen, float duty)
Set duty cycle of each operator(MCPWMXA/MCPWMXB)
- Parameters
mcpwm_num – set MCPWM unit(0-1)
timer_num – set timer number(0-2) of MCPWM, each MCPWM unit has 3 timers
gen – set the generator(MCPWMXA/MCPWMXB), ‘X’ is operator number selected
duty – set duty cycle in %(i.e for 62.3% duty cycle, duty = 62.3) of each operator
- Returns
ESP_OK Success
ESP_ERR_INVALID_ARG Parameter error
-
esp_err_t mcpwm_set_duty_in_us(mcpwm_unit_t mcpwm_num, mcpwm_timer_t timer_num, mcpwm_generator_t gen, uint32_t duty_in_us)
Set duty cycle of each operator(MCPWMXA/MCPWMXB) in us.
- Parameters
mcpwm_num – set MCPWM unit(0-1)
timer_num – set timer number(0-2) of MCPWM, each MCPWM unit has 3 timers
gen – set the generator(MCPWMXA/MCPWMXB), ‘x’ is operator number selected
duty_in_us – set duty value in microseconds of each operator
- Returns
ESP_OK Success
ESP_ERR_INVALID_ARG Parameter error
-
esp_err_t mcpwm_set_duty_type(mcpwm_unit_t mcpwm_num, mcpwm_timer_t timer_num, mcpwm_generator_t gen, mcpwm_duty_type_t duty_type)
Set duty either active high or active low(out of phase/inverted)
Note
Call this function every time after mcpwm_set_signal_high or mcpwm_set_signal_low to resume with previously set duty cycle
- Parameters
mcpwm_num – set MCPWM unit(0-1)
timer_num – set timer number(0-2) of MCPWM, each MCPWM unit has 3 timers
gen – set the generator(MCPWMXA/MCPWMXB), ‘x’ is operator number selected
duty_type – set active low or active high duty type
- Returns
ESP_OK Success
ESP_ERR_INVALID_ARG Parameter error
-
uint32_t mcpwm_get_frequency(mcpwm_unit_t mcpwm_num, mcpwm_timer_t timer_num)
Get frequency of timer.
- Parameters
mcpwm_num – set MCPWM unit(0-1)
timer_num – set timer number(0-2) of MCPWM, each MCPWM unit has 3 timers
- Returns
frequency of timer
-
float mcpwm_get_duty(mcpwm_unit_t mcpwm_num, mcpwm_timer_t timer_num, mcpwm_operator_t gen)
Get duty cycle of each operator.
- Parameters
mcpwm_num – set MCPWM unit(0-1)
timer_num – set timer number(0-2) of MCPWM, each MCPWM unit has 3 timers
gen – set the generator(MCPWMXA/MCPWMXB), ‘x’ is operator number selected
- Returns
duty cycle in % of each operator(56.7 means duty is 56.7%)
-
uint32_t mcpwm_get_duty_in_us(mcpwm_unit_t mcpwm_num, mcpwm_timer_t timer_num, mcpwm_operator_t gen)
Get duty cycle of each operator in us.
- Parameters
mcpwm_num – set MCPWM unit(0-1)
timer_num – set timer number(0-2) of MCPWM, each MCPWM unit has 3 timers
gen – set the generator(MCPWMXA/MCPWMXB), ‘x’ is operator number selected
- Returns
duty cycle in us of each operator
-
esp_err_t mcpwm_set_signal_high(mcpwm_unit_t mcpwm_num, mcpwm_timer_t timer_num, mcpwm_generator_t gen)
Use this function to set MCPWM signal high.
- Parameters
mcpwm_num – set MCPWM unit(0-1)
timer_num – set timer number(0-2) of MCPWM, each MCPWM unit has 3 timers
gen – set the operator(MCPWMXA/MCPWMXB), ‘x’ is timer number selected
- Returns
ESP_OK Success
ESP_ERR_INVALID_ARG Parameter error
-
esp_err_t mcpwm_set_signal_low(mcpwm_unit_t mcpwm_num, mcpwm_timer_t timer_num, mcpwm_generator_t gen)
Use this function to set MCPWM signal low.
- Parameters
mcpwm_num – set MCPWM unit(0-1)
timer_num – set timer number(0-2) of MCPWM, each MCPWM unit has 3 timers
gen – set the operator(MCPWMXA/MCPWMXB), ‘x’ is timer number selected
- Returns
ESP_OK Success
ESP_ERR_INVALID_ARG Parameter error
-
esp_err_t mcpwm_start(mcpwm_unit_t mcpwm_num, mcpwm_timer_t timer_num)
Start MCPWM signal on timer ‘x’.
- Parameters
mcpwm_num – set MCPWM unit(0-1)
timer_num – set timer number(0-2) of MCPWM, each MCPWM unit has 3 timers
- Returns
ESP_OK Success
ESP_ERR_INVALID_ARG Parameter error
-
esp_err_t mcpwm_stop(mcpwm_unit_t mcpwm_num, mcpwm_timer_t timer_num)
Start MCPWM signal on timer ‘x’.
- Parameters
mcpwm_num – set MCPWM unit(0-1)
timer_num – set timer number(0-2) of MCPWM, each MCPWM unit has 3 timers
- Returns
ESP_OK Success
ESP_ERR_INVALID_ARG Parameter error
-
esp_err_t mcpwm_carrier_init(mcpwm_unit_t mcpwm_num, mcpwm_timer_t timer_num, const mcpwm_carrier_config_t *carrier_conf)
Initialize carrier configuration.
- Parameters
mcpwm_num – set MCPWM unit(0-1)
timer_num – set timer number(0-2) of MCPWM, each MCPWM unit has 3 timers
carrier_conf – configure structure mcpwm_carrier_config_t
- Returns
ESP_OK Success
ESP_ERR_INVALID_ARG Parameter error
-
esp_err_t mcpwm_carrier_enable(mcpwm_unit_t mcpwm_num, mcpwm_timer_t timer_num)
Enable MCPWM carrier submodule, for respective timer.
- Parameters
mcpwm_num – set MCPWM unit(0-1)
timer_num – set timer number(0-2) of MCPWM, each MCPWM unit has 3 timers
- Returns
ESP_OK Success
ESP_ERR_INVALID_ARG Parameter error
-
esp_err_t mcpwm_carrier_disable(mcpwm_unit_t mcpwm_num, mcpwm_timer_t timer_num)
Disable MCPWM carrier submodule, for respective timer.
- Parameters
mcpwm_num – set MCPWM unit(0-1)
timer_num – set timer number(0-2) of MCPWM, each MCPWM unit has 3 timers
- Returns
ESP_OK Success
ESP_ERR_INVALID_ARG Parameter error
-
esp_err_t mcpwm_carrier_set_period(mcpwm_unit_t mcpwm_num, mcpwm_timer_t timer_num, uint8_t carrier_period)
Set period of carrier.
- Parameters
mcpwm_num – set MCPWM unit(0-1)
timer_num – set timer number(0-2) of MCPWM, each MCPWM unit has 3 timers
carrier_period – set the carrier period of each timer, carrier period = (carrier_period + 1)*800ns (carrier_period <= 15)
- Returns
ESP_OK Success
ESP_ERR_INVALID_ARG Parameter error
-
esp_err_t mcpwm_carrier_set_duty_cycle(mcpwm_unit_t mcpwm_num, mcpwm_timer_t timer_num, uint8_t carrier_duty)
Set duty_cycle of carrier.
- Parameters
mcpwm_num – set MCPWM unit(0-1)
timer_num – set timer number(0-2) of MCPWM, each MCPWM unit has 3 timers
carrier_duty – set duty_cycle of carrier , carrier duty cycle = carrier_duty*12.5% (chop_duty <= 7)
- Returns
ESP_OK Success
ESP_ERR_INVALID_ARG Parameter error
-
esp_err_t mcpwm_carrier_oneshot_mode_enable(mcpwm_unit_t mcpwm_num, mcpwm_timer_t timer_num, uint8_t pulse_width)
Enable and set width of first pulse in carrier oneshot mode.
- Parameters
mcpwm_num – set MCPWM unit(0-1)
timer_num – set timer number(0-2) of MCPWM, each MCPWM unit has 3 timers
pulse_width – set pulse width of first pulse in oneshot mode, width = (carrier period)*(pulse_width +1) (pulse_width <= 15)
- Returns
ESP_OK Success
ESP_ERR_INVALID_ARG Parameter error
-
esp_err_t mcpwm_carrier_oneshot_mode_disable(mcpwm_unit_t mcpwm_num, mcpwm_timer_t timer_num)
Disable oneshot mode, width of first pulse = carrier period.
- Parameters
mcpwm_num – set MCPWM unit(0-1)
timer_num – set timer number(0-2) of MCPWM, each MCPWM unit has 3 timers
- Returns
ESP_OK Success
ESP_ERR_INVALID_ARG Parameter error
-
esp_err_t mcpwm_carrier_output_invert(mcpwm_unit_t mcpwm_num, mcpwm_timer_t timer_num, mcpwm_carrier_out_ivt_t carrier_ivt_mode)
Enable or disable carrier output inversion.
- Parameters
mcpwm_num – set MCPWM unit(0-1)
timer_num – set timer number(0-2) of MCPWM, each MCPWM unit has 3 timers
carrier_ivt_mode – enable or disable carrier output inversion
- Returns
ESP_OK Success
ESP_ERR_INVALID_ARG Parameter error
-
esp_err_t mcpwm_deadtime_enable(mcpwm_unit_t mcpwm_num, mcpwm_timer_t timer_num, mcpwm_deadtime_type_t dt_mode, uint32_t red, uint32_t fed)
Enable and initialize deadtime for each MCPWM timer.
- Parameters
mcpwm_num – set MCPWM unit(0-1)
timer_num – set timer number(0-2) of MCPWM, each MCPWM unit has 3 timers
dt_mode – set deadtime mode
red – set rising edge delay = red*100ns
fed – set rising edge delay = fed*100ns
- Returns
ESP_OK Success
ESP_ERR_INVALID_ARG Parameter error
-
esp_err_t mcpwm_deadtime_disable(mcpwm_unit_t mcpwm_num, mcpwm_timer_t timer_num)
Disable deadtime on MCPWM timer.
- Parameters
mcpwm_num – set MCPWM unit(0-1)
timer_num – set timer number(0-2) of MCPWM, each MCPWM unit has 3 timers
- Returns
ESP_OK Success
ESP_ERR_INVALID_ARG Parameter error
-
esp_err_t mcpwm_fault_init(mcpwm_unit_t mcpwm_num, mcpwm_fault_input_level_t intput_level, mcpwm_fault_signal_t fault_sig)
Initialize fault submodule, currently low level triggering is not supported.
- Parameters
mcpwm_num – set MCPWM unit(0-1)
intput_level – set fault signal level, which will cause fault to occur
fault_sig – set the fault pin, which needs to be enabled
- Returns
ESP_OK Success
ESP_ERR_INVALID_ARG Parameter error
-
esp_err_t mcpwm_fault_set_oneshot_mode(mcpwm_unit_t mcpwm_num, mcpwm_timer_t timer_num, mcpwm_fault_signal_t fault_sig, mcpwm_output_action_t action_on_pwmxa, mcpwm_output_action_t action_on_pwmxb)
Set oneshot mode on fault detection, once fault occur in oneshot mode reset is required to resume MCPWM signals.
Note
currently low level triggering is not supported
- Parameters
mcpwm_num – set MCPWM unit(0-1)
timer_num – set timer number(0-2) of MCPWM, each MCPWM unit has 3 timers
fault_sig – set the fault pin, which needs to be enabled for oneshot mode
action_on_pwmxa – action to be taken on MCPWMXA when fault occurs, either no change or high or low or toggle
action_on_pwmxb – action to be taken on MCPWMXB when fault occurs, either no change or high or low or toggle
- Returns
ESP_OK Success
ESP_ERR_INVALID_ARG Parameter error
-
esp_err_t mcpwm_fault_set_cyc_mode(mcpwm_unit_t mcpwm_num, mcpwm_timer_t timer_num, mcpwm_fault_signal_t fault_sig, mcpwm_output_action_t action_on_pwmxa, mcpwm_output_action_t action_on_pwmxb)
Set cycle-by-cycle mode on fault detection, once fault occur in cyc mode MCPWM signal resumes as soon as fault signal becomes inactive.
Note
currently low level triggering is not supported
- Parameters
mcpwm_num – set MCPWM unit(0-1)
timer_num – set timer number(0-2) of MCPWM, each MCPWM unit has 3 timers
fault_sig – set the fault pin, which needs to be enabled for cyc mode
action_on_pwmxa – action to be taken on MCPWMXA when fault occurs, either no change or high or low or toggle
action_on_pwmxb – action to be taken on MCPWMXB when fault occurs, either no change or high or low or toggle
- Returns
ESP_OK Success
ESP_ERR_INVALID_ARG Parameter error
-
esp_err_t mcpwm_fault_deinit(mcpwm_unit_t mcpwm_num, mcpwm_fault_signal_t fault_sig)
Disable fault signal.
- Parameters
mcpwm_num – set MCPWM unit(0-1)
fault_sig – fault pin, which needs to be disabled
- Returns
ESP_OK Success
ESP_ERR_INVALID_ARG Parameter error
-
esp_err_t mcpwm_capture_enable(mcpwm_unit_t mcpwm_num, mcpwm_capture_signal_t cap_sig, mcpwm_capture_on_edge_t cap_edge, uint32_t num_of_pulse)
Initialize capture submodule.
Note
Enabling capture feature would also enable the capture interrupt event, users have to register an interrupt handler by
mcpwm_isr_register
, and in there, query the capture data.Note
The capture timer uses APB_CLK (typically 80MHz) as the count source.
- Parameters
mcpwm_num – set MCPWM unit(0-1)
cap_edge – set capture edge, BIT(0) - negative edge, BIT(1) - positive edge
cap_sig – capture pin, which needs to be enabled
num_of_pulse – Input capture signal prescaling, ranges from 0 to 255, representing prescaling from 1 to 256.
- Returns
ESP_OK Success
ESP_ERR_INVALID_ARG Parameter error
-
esp_err_t mcpwm_capture_disable(mcpwm_unit_t mcpwm_num, mcpwm_capture_signal_t cap_sig)
Disable capture signal.
- Parameters
mcpwm_num – set MCPWM unit(0-1)
cap_sig – capture pin, which needs to be disabled
- Returns
ESP_OK Success
ESP_ERR_INVALID_ARG Parameter error
-
esp_err_t mcpwm_capture_enable_channel(mcpwm_unit_t mcpwm_num, mcpwm_capture_channel_id_t cap_channel, const mcpwm_capture_config_t *cap_conf)
Enable capture channel.
- Parameters
mcpwm_num – set MCPWM unit(0-1)
cap_channel – capture channel, which needs to be enabled
cap_conf – capture channel configuration
- Returns
ESP_OK Success
ESP_ERR_INVALID_ARG Parameter error
-
esp_err_t mcpwm_capture_disable_channel(mcpwm_unit_t mcpwm_num, mcpwm_capture_channel_id_t cap_channel)
Disable capture channel.
- Parameters
mcpwm_num – set MCPWM unit(0-1)
cap_channel – capture channel, which needs to be disabled
- Returns
ESP_OK Success
ESP_ERR_INVALID_ARG Parameter error
-
uint32_t mcpwm_capture_signal_get_value(mcpwm_unit_t mcpwm_num, mcpwm_capture_signal_t cap_sig)
Get capture value.
- Parameters
mcpwm_num – set MCPWM unit(0-1)
cap_sig – capture channel on which value is to be measured
- Returns
Captured value
-
uint32_t mcpwm_capture_signal_get_edge(mcpwm_unit_t mcpwm_num, mcpwm_capture_signal_t cap_sig)
Get edge of capture signal.
- Parameters
mcpwm_num – set MCPWM unit(0-1)
cap_sig – capture channel of whose edge is to be determined
- Returns
Capture signal edge: 1 - positive edge, 2 - negtive edge
-
esp_err_t mcpwm_sync_enable(mcpwm_unit_t mcpwm_num, mcpwm_timer_t timer_num, mcpwm_sync_signal_t sync_sig, uint32_t phase_val)
Initialize sync submodule and sets the signal that will cause the timer be loaded with pre-defined value.
Note
Count direction is undefined within this API
- Parameters
mcpwm_num – set MCPWM unit(0-1)
timer_num – set timer number(0-2) of MCPWM, each MCPWM unit has 3 timers
sync_sig – set the synchronization input signal
phase_val – phase value in 1/1000 (for 86.7%, phase_val = 867) which timer moves to on sync signal
- Returns
ESP_OK Success
ESP_ERR_INVALID_ARG Parameter error
-
esp_err_t mcpwm_sync_configure(mcpwm_unit_t mcpwm_num, mcpwm_timer_t timer_num, const mcpwm_sync_config_t *sync_conf)
Initialize sync submodule and sets the signal that will cause the timer be loaded with pre-defined value.
- Parameters
mcpwm_num – set MCPWM unit(0-1)
timer_num – set timer number(0-2) of MCPWM, each MCPWM unit has 3 timers
sync_conf – sync configuration on this timer
- Returns
ESP_OK Success
ESP_ERR_INVALID_ARG Parameter error
-
esp_err_t mcpwm_sync_disable(mcpwm_unit_t mcpwm_num, mcpwm_timer_t timer_num)
Disable sync submodule on given timer.
- Parameters
mcpwm_num – set MCPWM unit(0-1)
timer_num – set timer number(0-2) of MCPWM, each MCPWM unit has 3 timers
- Returns
ESP_OK Success
ESP_ERR_INVALID_ARG Parameter error
-
esp_err_t mcpwm_set_timer_sync_output(mcpwm_unit_t mcpwm_num, mcpwm_timer_t timer_num, mcpwm_timer_sync_trigger_t trigger)
Set sync output on given timer Configures what event triggers MCPWM timer to output a sync signal.
- Parameters
mcpwm_num – set MCPWM unit(0-1)
timer_num – set timer number(0-2) of MCPWM, each MCPWM unit has 3 timers
trigger – set the trigger that will cause the timer to generate a software sync signal. Specifically,
MCPWM_SWSYNC_SOURCE_DISABLED
will disable the timer from generating sync signal.
- Returns
ESP_OK Success
ESP_ERR_INVALID_ARG Parameter error
-
esp_err_t mcpwm_timer_trigger_soft_sync(mcpwm_unit_t mcpwm_num, mcpwm_timer_t timer_num)
Trigger a software sync event and sends it to a specific timer.
Note
This software sync event will have the same effect as hw one, except that:
On esp32s3 the soft sync event can be routed to its output if
MCPWM_SWSYNC_SOURCE_SYNCIN
is selected viamcpwm_set_timer_sync_output()
On esp32 there is no such behavior and soft sync event will only take effect on this timer and can not be propagated to others.
- Parameters
mcpwm_num – set MCPWM unit(0-1)
timer_num – set timer number(0-2) of MCPWM, each MCPWM unit has 3 timers
- Returns
ESP_OK Success
ESP_ERR_INVALID_ARG Function pointer error.
-
esp_err_t mcpwm_sync_invert_gpio_synchro(mcpwm_unit_t mcpwm_num, mcpwm_sync_signal_t sync_sig, bool invert)
Set external GPIO sync input inverter.
- Parameters
mcpwm_num – set MCPWM unit(0-1)
sync_sig – set sync signal of MCPWM, only supports GPIO sync signal
invert – whether GPIO sync source input is inverted (to get negative edge trigger)
- Returns
ESP_OK Success
ESP_ERR_INVALID_ARG Function pointer error.
-
esp_err_t mcpwm_isr_register(mcpwm_unit_t mcpwm_num, void (*fn)(void*), void *arg, int intr_alloc_flags, intr_handle_t *handle)
Register MCPWM interrupt handler, the handler is an ISR. the handler will be attached to the same CPU core that this function is running on.
- Parameters
mcpwm_num – set MCPWM unit(0-1)
fn – interrupt handler function.
arg – user-supplied argument passed to the handler function.
intr_alloc_flags – flags used to allocate the interrupt. One or multiple (ORred) ESP_INTR_FLAG_* values. see esp_intr_alloc.h for more info.
handle – pointer to return handle. If non-NULL, a handle for the interrupt will be returned here.
- Returns
ESP_OK Success
ESP_ERR_INVALID_ARG Function pointer error.
Structures
-
struct mcpwm_pin_config_t
pin number for MCPWM
Public Members
-
int mcpwm0a_out_num
MCPWM0A out pin
-
int mcpwm0b_out_num
MCPWM0A out pin
-
int mcpwm1a_out_num
MCPWM0A out pin
-
int mcpwm1b_out_num
MCPWM0A out pin
-
int mcpwm2a_out_num
MCPWM0A out pin
-
int mcpwm2b_out_num
MCPWM0A out pin
-
int mcpwm_sync0_in_num
SYNC0 in pin
-
int mcpwm_sync1_in_num
SYNC1 in pin
-
int mcpwm_sync2_in_num
SYNC2 in pin
-
int mcpwm_fault0_in_num
FAULT0 in pin
-
int mcpwm_fault1_in_num
FAULT1 in pin
-
int mcpwm_fault2_in_num
FAULT2 in pin
-
int mcpwm_cap0_in_num
CAP0 in pin
-
int mcpwm_cap1_in_num
CAP1 in pin
-
int mcpwm_cap2_in_num
CAP2 in pin
-
int mcpwm0a_out_num
-
struct cap_event_data_t
event data that will be passed into ISR callback
Public Members
-
mcpwm_capture_on_edge_t cap_edge
Which signal edge is detected
-
uint32_t cap_value
Corresponding timestamp when event occurs. Clock rate = APB(usually 80M)
-
mcpwm_capture_on_edge_t cap_edge
-
struct mcpwm_config_t
MCPWM config structure.
Public Members
-
uint32_t frequency
Set frequency of MCPWM in Hz
-
float cmpr_a
Set % duty cycle for operator a(MCPWMXA), i.e for 62.3% duty cycle, duty_a = 62.3
-
float cmpr_b
Set % duty cycle for operator b(MCPWMXB), i.e for 48% duty cycle, duty_b = 48.0
-
mcpwm_duty_type_t duty_mode
Set type of duty cycle
-
mcpwm_counter_type_t counter_mode
Set type of MCPWM counter
-
uint32_t frequency
-
struct mcpwm_carrier_config_t
MCPWM carrier configuration structure.
Public Members
-
uint8_t carrier_period
Set carrier period = (carrier_period + 1)*800ns, carrier_period should be < 16
-
uint8_t carrier_duty
Set carrier duty cycle, carrier_duty should be less than 8 (increment every 12.5%)
-
uint8_t pulse_width_in_os
Set pulse width of first pulse in one shot mode = (carrier period)*(pulse_width_in_os + 1), should be less then 16
-
mcpwm_carrier_os_t carrier_os_mode
Enable or disable carrier oneshot mode
-
mcpwm_carrier_out_ivt_t carrier_ivt_mode
Invert output of carrier
-
uint8_t carrier_period
-
struct mcpwm_capture_config_t
MCPWM config capture structure.
Public Members
-
mcpwm_capture_on_edge_t cap_edge
Set capture edge
-
uint32_t cap_prescale
Prescale of capture signal, ranging from 1 to 256
-
cap_isr_cb_t capture_cb
User defined capture event callback, running under interrupt context
-
void *user_data
User defined ISR callback function args
-
mcpwm_capture_on_edge_t cap_edge
-
struct mcpwm_sync_config_t
MCPWM config sync structure.
Public Members
-
mcpwm_sync_signal_t sync_sig
Set sync input signal that will cause timer to sync
-
uint32_t timer_val
Counter value to be set after sync, in 0 ~ 999, unit: 1 / 1000 * peak
-
mcpwm_timer_direction_t count_direction
Counting direction to be set after sync
-
mcpwm_sync_signal_t sync_sig
Macros
-
MCPWM_OPR_A
- Deprecated:
-
MCPWM_OPR_B
- Deprecated:
-
MCPWM_OPR_MAX
- Deprecated:
-
MCPWM_SELCT_SYNC0
-
MCPWM_SELCT_SYNC1
-
MCPWM_SELCT_SYNC2
-
MCPWM_NO_CHANGE_IN_MCPWMXA
- Deprecated:
No change in MCPWMXA output
-
MCPWM_FORCE_MCPWMXA_LOW
- Deprecated:
Make MCPWMXA output low
-
MCPWM_FORCE_MCPWMXA_HIGH
- Deprecated:
Make MCPWMXA output high
-
MCPWM_TOG_MCPWMXA
- Deprecated:
Make MCPWMXA output toggle
-
MCPWM_NO_CHANGE_IN_MCPWMXB
- Deprecated:
No change in MCPWMXB output
-
MCPWM_FORCE_MCPWMXB_LOW
- Deprecated:
Make MCPWMXB output low
-
MCPWM_FORCE_MCPWMXB_HIGH
- Deprecated:
Make MCPWMXB output high
-
MCPWM_TOG_MCPWMXB
- Deprecated:
Make MCPWMXB output toggle
Type Definitions
-
typedef mcpwm_generator_t mcpwm_operator_t
- Deprecated:
-
typedef mcpwm_output_action_t mcpwm_action_on_pwmxa_t
- Deprecated:
MCPWM select action to be taken on MCPWMXA when fault occurs
-
typedef mcpwm_output_action_t mcpwm_action_on_pwmxb_t
- Deprecated:
MCPWM select action to be taken on MCPWMXB when fault occurs
-
typedef mcpwm_capture_signal_t mcpwm_capture_channel_id_t
MCPWM capture channel ID alias.
-
typedef bool (*cap_isr_cb_t)(mcpwm_unit_t mcpwm, mcpwm_capture_channel_id_t cap_channel, const cap_event_data_t *edata, void *user_data)
Type of capture event callback.
Note
Since this an ISR callback so do not do anything that may block and call APIs that is designed to be used within ISR(usually has ‘_ISR’ postfix)
- Param mcpwm
MCPWM unit(0-1)
- Param cap_channel
capture channel ID
- Param edata
Capture event data, contains capture edge and capture value, fed by the driver
- Param user_data
User registered data, passed from
mcpwm_capture_config_t
- Return
Whether a task switch is needed after the callback function returns, this is usually due to the callback wakes up some high priority task.
Enumerations
-
enum mcpwm_io_signals_t
IO signals for the MCPWM.
6 MCPWM output pins that generate PWM signals
3 MCPWM fault input pins to detect faults like overcurrent, overvoltage, etc.
3 MCPWM sync input pins to synchronize MCPWM outputs signals
3 MCPWM capture input pins to gather feedback from controlled motors, using e.g. hall sensors
Values:
-
enumerator MCPWM0A
PWM0A output pin
-
enumerator MCPWM0B
PWM0B output pin
-
enumerator MCPWM1A
PWM1A output pin
-
enumerator MCPWM1B
PWM1B output pin
-
enumerator MCPWM2A
PWM2A output pin
-
enumerator MCPWM2B
PWM2B output pin
-
enumerator MCPWM_SYNC_0
SYNC0 input pin
-
enumerator MCPWM_SYNC_1
SYNC1 input pin
-
enumerator MCPWM_SYNC_2
SYNC2 input pin
-
enumerator MCPWM_FAULT_0
FAULT0 input pin
-
enumerator MCPWM_FAULT_1
FAULT1 input pin
-
enumerator MCPWM_FAULT_2
FAULT2 input pin
-
enumerator MCPWM_CAP_0
CAP0 input pin
-
enumerator MCPWM_CAP_1
CAP1 input pin
-
enumerator MCPWM_CAP_2
CAP2 input pin
-
enum mcpwm_unit_t
Select MCPWM unit.
Values:
-
enumerator MCPWM_UNIT_0
MCPWM unit0 selected
-
enumerator MCPWM_UNIT_1
MCPWM unit1 selected
-
enumerator MCPWM_UNIT_MAX
Max number of MCPWM units
-
enumerator MCPWM_UNIT_0
-
enum mcpwm_timer_t
Select MCPWM timer.
Values:
-
enumerator MCPWM_TIMER_0
Select MCPWM timer0
-
enumerator MCPWM_TIMER_1
Select MCPWM timer1
-
enumerator MCPWM_TIMER_2
Select MCPWM timer2
-
enumerator MCPWM_TIMER_MAX
Max number of timers in a unit
-
enumerator MCPWM_TIMER_0
-
enum mcpwm_generator_t
Select MCPWM operator.
Values:
-
enumerator MCPWM_GEN_A
Select MCPWMXA, where ‘X’ is operator number
-
enumerator MCPWM_GEN_B
Select MCPWMXB, where ‘X’ is operator number
-
enumerator MCPWM_GEN_MAX
Num of generators to each operator of MCPWM
-
enumerator MCPWM_GEN_A
-
enum mcpwm_carrier_os_t
MCPWM carrier oneshot mode, in this mode the width of the first pulse of carrier can be programmed.
Values:
-
enumerator MCPWM_ONESHOT_MODE_DIS
Enable oneshot mode
-
enumerator MCPWM_ONESHOT_MODE_EN
Disable oneshot mode
-
enumerator MCPWM_ONESHOT_MODE_DIS
-
enum mcpwm_carrier_out_ivt_t
MCPWM carrier output inversion, high frequency carrier signal active with MCPWM signal is high.
Values:
-
enumerator MCPWM_CARRIER_OUT_IVT_DIS
Enable carrier output inversion
-
enumerator MCPWM_CARRIER_OUT_IVT_EN
Disable carrier output inversion
-
enumerator MCPWM_CARRIER_OUT_IVT_DIS
-
enum mcpwm_fault_signal_t
MCPWM select fault signal input.
Values:
-
enumerator MCPWM_SELECT_F0
Select F0 as input
-
enumerator MCPWM_SELECT_F1
Select F1 as input
-
enumerator MCPWM_SELECT_F2
Select F2 as input
-
enumerator MCPWM_SELECT_F0
-
enum mcpwm_sync_signal_t
MCPWM select sync signal input.
Values:
-
enumerator MCPWM_SELECT_NO_INPUT
No sync input selected
-
enumerator MCPWM_SELECT_TIMER0_SYNC
Select software sync signal from timer0 as input
-
enumerator MCPWM_SELECT_TIMER1_SYNC
Select software sync signal from timer1 as input
-
enumerator MCPWM_SELECT_TIMER2_SYNC
Select software sync signal from timer2 as input
-
enumerator MCPWM_SELECT_GPIO_SYNC0
Select GPIO SYNC0 as input
-
enumerator MCPWM_SELECT_GPIO_SYNC1
Select GPIO SYNC1 as input
-
enumerator MCPWM_SELECT_GPIO_SYNC2
Select GPIO SYNC2 as input
-
enumerator MCPWM_SELECT_NO_INPUT
-
enum mcpwm_timer_sync_trigger_t
MCPWM timer sync event trigger.
Values:
-
enumerator MCPWM_SWSYNC_SOURCE_SYNCIN
the input sync signal will be routed to its sync output path
-
enumerator MCPWM_SWSYNC_SOURCE_TEZ
sync signal generated when timer counts to zero
-
enumerator MCPWM_SWSYNC_SOURCE_TEP
sync signal generated when timer counts to peak
-
enumerator MCPWM_SWSYNC_SOURCE_DISABLED
timer does not generate sync signals
-
enumerator MCPWM_SWSYNC_SOURCE_SYNCIN
-
enum mcpwm_fault_input_level_t
MCPWM select triggering level of fault signal.
Values:
-
enumerator MCPWM_LOW_LEVEL_TGR
Fault condition occurs when fault input signal goes from high to low
-
enumerator MCPWM_HIGH_LEVEL_TGR
Fault condition occurs when fault input signal goes low to high
-
enumerator MCPWM_LOW_LEVEL_TGR
-
enum mcpwm_capture_on_edge_t
MCPWM select capture starts from which edge.
Values:
-
enumerator MCPWM_NEG_EDGE
Capture the negative edge
-
enumerator MCPWM_POS_EDGE
Capture the positive edge
-
enumerator MCPWM_BOTH_EDGE
Capture both edges
-
enumerator MCPWM_NEG_EDGE
-
enum mcpwm_intr_t
Interrupt masks for MCPWM capture.
Values:
-
enumerator MCPWM_LL_INTR_CAP0
Capture 0 happened.
-
enumerator MCPWM_LL_INTR_CAP1
Capture 1 happened.
-
enumerator MCPWM_LL_INTR_CAP2
Capture 2 happened.
-
enumerator MCPWM_LL_INTR_CAP0
-
enum mcpwm_counter_type_t
Select type of MCPWM counter.
Values:
-
enumerator MCPWM_FREEZE_COUNTER
Counter freeze
-
enumerator MCPWM_UP_COUNTER
For asymmetric MCPWM
-
enumerator MCPWM_DOWN_COUNTER
For asymmetric MCPWM
-
enumerator MCPWM_UP_DOWN_COUNTER
For symmetric MCPWM, frequency is half of MCPWM frequency set
-
enumerator MCPWM_COUNTER_MAX
Maximum counter mode
-
enumerator MCPWM_FREEZE_COUNTER
-
enum mcpwm_duty_type_t
Select type of MCPWM duty cycle mode.
Values:
-
enumerator MCPWM_DUTY_MODE_0
Active high duty, i.e. duty cycle proportional to high time for asymmetric MCPWM
-
enumerator MCPWM_DUTY_MODE_1
Active low duty, i.e. duty cycle proportional to low time for asymmetric MCPWM, out of phase(inverted) MCPWM
-
enumerator MCPWM_HAL_GENERATOR_MODE_FORCE_LOW
-
enumerator MCPWM_HAL_GENERATOR_MODE_FORCE_HIGH
-
enumerator MCPWM_DUTY_MODE_MAX
Num of duty cycle modes
-
enumerator MCPWM_DUTY_MODE_0
-
enum mcpwm_deadtime_type_t
MCPWM deadtime types, used to generate deadtime, RED refers to rising edge delay and FED refers to falling edge delay.
Values:
-
enumerator MCPWM_DEADTIME_BYPASS
Bypass the deadtime
-
enumerator MCPWM_BYPASS_RED
MCPWMXA Out = MCPWMXA In with no delay, MCPWMXB Out = MCPWMXA In with falling edge delay
-
enumerator MCPWM_BYPASS_FED
MCPWMXA Out = MCPWMXA In with rising edge delay, MCPWMXB Out = MCPWMXB In with no delay
-
enumerator MCPWM_ACTIVE_HIGH_MODE
MCPWMXA Out = MCPWMXA In with rising edge delay, MCPWMXB Out = MCPWMXA In with falling edge delay
-
enumerator MCPWM_ACTIVE_LOW_MODE
MCPWMXA Out = MCPWMXA In with compliment of rising edge delay, MCPWMXB Out = MCPWMXA In with compliment of falling edge delay
-
enumerator MCPWM_ACTIVE_HIGH_COMPLIMENT_MODE
MCPWMXA Out = MCPWMXA In with rising edge delay, MCPWMXB = MCPWMXA In with compliment of falling edge delay
-
enumerator MCPWM_ACTIVE_LOW_COMPLIMENT_MODE
MCPWMXA Out = MCPWMXA In with compliment of rising edge delay, MCPWMXB Out = MCPWMXA In with falling edge delay
-
enumerator MCPWM_ACTIVE_RED_FED_FROM_PWMXA
MCPWMXA Out = MCPWMXB Out = MCPWMXA In with rising edge delay as well as falling edge delay
-
enumerator MCPWM_ACTIVE_RED_FED_FROM_PWMXB
MCPWMXA Out = MCPWMXB Out = MCPWMXB In with rising edge delay as well as falling edge delay
-
enumerator MCPWM_DEADTIME_TYPE_MAX
Maximum number of supported dead time modes
-
enumerator MCPWM_DEADTIME_BYPASS
-
enum mcpwm_output_action_t
MCPWM select action to be taken on the output when event happens.
Values:
-
enumerator MCPWM_ACTION_NO_CHANGE
No change in the output
-
enumerator MCPWM_ACTION_FORCE_LOW
Make output low
-
enumerator MCPWM_ACTION_FORCE_HIGH
Make output high
-
enumerator MCPWM_ACTION_TOGGLE
Make output toggle
-
enumerator MCPWM_ACTION_NO_CHANGE