mirror of
https://github.com/espressif/esp-idf.git
synced 2026-10-01 18:50:34 +03:00
@@ -21,6 +21,8 @@
|
||||
#include "driver/periph_ctrl.h"
|
||||
#include "esp_intr_alloc.h"
|
||||
#include "soc/soc_caps.h"
|
||||
#include "hal/mcpwm_types.h"
|
||||
#include "soc/mcpwm_caps.h"
|
||||
|
||||
#ifndef SOC_MCPWM_SUPPORTED
|
||||
#error MCPWM is not supported in this chip target
|
||||
@@ -30,6 +32,7 @@
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
|
||||
/**
|
||||
* @brief IO signals for the MCPWM
|
||||
*
|
||||
@@ -87,6 +90,8 @@ typedef enum {
|
||||
MCPWM_UNIT_MAX, /*!<Num of MCPWM units on ESP32*/
|
||||
} mcpwm_unit_t;
|
||||
|
||||
_Static_assert(MCPWM_UNIT_MAX == SOC_MCPWM_PERIPH_NUM, "MCPWM unit number not equal to chip capabilities");
|
||||
|
||||
/**
|
||||
* @brief Select MCPWM timer
|
||||
*/
|
||||
@@ -101,29 +106,16 @@ typedef enum {
|
||||
* @brief Select MCPWM operator
|
||||
*/
|
||||
typedef enum {
|
||||
MCPWM_OPR_A = 0, /*!<Select MCPWMXA, where 'X' is timer number*/
|
||||
MCPWM_OPR_B, /*!<Select MCPWMXB, where 'X' is timer number*/
|
||||
MCPWM_OPR_MAX, /*!<Num of operators to each timer of MCPWM*/
|
||||
} mcpwm_operator_t;
|
||||
MCPWM_GEN_A = 0, /*!<Select MCPWMXA, where 'X' is operator number*/
|
||||
MCPWM_GEN_B, /*!<Select MCPWMXB, where 'X' is operator number*/
|
||||
MCPWM_GEN_MAX, /*!<Num of generators to each operator of MCPWM*/
|
||||
} mcpwm_generator_t;
|
||||
|
||||
/**
|
||||
* @brief Select type of MCPWM counter
|
||||
*/
|
||||
typedef enum {
|
||||
MCPWM_UP_COUNTER = 1, /*!<For asymmetric MCPWM*/
|
||||
MCPWM_DOWN_COUNTER, /*!<For asymmetric MCPWM*/
|
||||
MCPWM_UP_DOWN_COUNTER, /*!<For symmetric MCPWM, frequency is half of MCPWM frequency set*/
|
||||
MCPWM_COUNTER_MAX, /*!<Maximum counter mode*/
|
||||
} mcpwm_counter_type_t;
|
||||
|
||||
/**
|
||||
* @brief Select type of MCPWM duty cycle mode
|
||||
*/
|
||||
typedef enum {
|
||||
MCPWM_DUTY_MODE_0 = 0, /*!<Active high duty, i.e. duty cycle proportional to high time for asymmetric MCPWM*/
|
||||
MCPWM_DUTY_MODE_1, /*!<Active low duty, i.e. duty cycle proportional to low time for asymmetric MCPWM, out of phase(inverted) MCPWM*/
|
||||
MCPWM_DUTY_MODE_MAX, /*!<Num of duty cycle modes*/
|
||||
} mcpwm_duty_type_t;
|
||||
//definitions and macros to be back-compatible before IDFv4.1
|
||||
#define MCPWM_OPR_A MCPWM_GEN_A ///< @deprecated
|
||||
#define MCPWM_OPR_B MCPWM_GEN_B ///< @deprecated
|
||||
#define MCPWM_OPR_MAX MCPWM_GEN_MAX ///< @deprecated
|
||||
typedef mcpwm_generator_t mcpwm_operator_t; ///< @deprecated
|
||||
|
||||
/**
|
||||
* @brief MCPWM carrier oneshot mode, in this mode the width of the first pulse of carrier can be programmed
|
||||
@@ -141,15 +133,6 @@ typedef enum {
|
||||
MCPWM_CARRIER_OUT_IVT_EN, /*!<Disable carrier output inversion*/
|
||||
} mcpwm_carrier_out_ivt_t;
|
||||
|
||||
/**
|
||||
* @brief MCPWM select sync signal input
|
||||
*/
|
||||
typedef enum {
|
||||
MCPWM_SELECT_SYNC0 = 4, /*!<Select SYNC0 as input*/
|
||||
MCPWM_SELECT_SYNC1, /*!<Select SYNC1 as input*/
|
||||
MCPWM_SELECT_SYNC2, /*!<Select SYNC2 as input*/
|
||||
} mcpwm_sync_signal_t;
|
||||
|
||||
/**
|
||||
* @brief MCPWM select fault signal input
|
||||
*/
|
||||
@@ -167,25 +150,20 @@ typedef enum {
|
||||
MCPWM_HIGH_LEVEL_TGR, /*!<Fault condition occurs when fault input signal goes low to high*/
|
||||
} mcpwm_fault_input_level_t;
|
||||
|
||||
/**
|
||||
* @brief MCPWM select action to be taken on MCPWMXA when fault occurs
|
||||
*/
|
||||
typedef enum {
|
||||
MCPWM_NO_CHANGE_IN_MCPWMXA = 0, /*!<No change in MCPWMXA output*/
|
||||
MCPWM_FORCE_MCPWMXA_LOW, /*!<Make MCPWMXA output low*/
|
||||
MCPWM_FORCE_MCPWMXA_HIGH, /*!<Make MCPWMXA output high*/
|
||||
MCPWM_TOG_MCPWMXA, /*!<Make MCPWMXA output toggle*/
|
||||
} mcpwm_action_on_pwmxa_t;
|
||||
|
||||
/**
|
||||
* @brief MCPWM select action to be taken on MCPWMxB when fault occurs
|
||||
*/
|
||||
typedef enum {
|
||||
MCPWM_NO_CHANGE_IN_MCPWMXB = 0, /*!<No change in MCPWMXB output*/
|
||||
MCPWM_FORCE_MCPWMXB_LOW, /*!<Make MCPWMXB output low*/
|
||||
MCPWM_FORCE_MCPWMXB_HIGH, /*!<Make MCPWMXB output high*/
|
||||
MCPWM_TOG_MCPWMXB, /*!<Make MCPWMXB output toggle*/
|
||||
} mcpwm_action_on_pwmxb_t;
|
||||
/// @deprecated MCPWM select action to be taken on MCPWMXA when fault occurs
|
||||
typedef mcpwm_output_action_t mcpwm_action_on_pwmxa_t;
|
||||
#define MCPWM_NO_CHANGE_IN_MCPWMXA MCPWM_ACTION_NO_CHANGE /*!< @deprecated No change in MCPWMXA output*/
|
||||
#define MCPWM_FORCE_MCPWMXA_LOW MCPWM_ACTION_FORCE_LOW /*!< @deprecated Make MCPWMXA output low*/
|
||||
#define MCPWM_FORCE_MCPWMXA_HIGH MCPWM_ACTION_FORCE_HIGH /*!< @deprecated Make MCPWMXA output high*/
|
||||
#define MCPWM_TOG_MCPWMXA MCPWM_ACTION_TOGGLE /*!< @deprecated Make MCPWMXA output toggle*/
|
||||
|
||||
/// @deprecated MCPWM select action to be taken on MCPWMXB when fault occurs
|
||||
typedef mcpwm_output_action_t mcpwm_action_on_pwmxb_t;
|
||||
#define MCPWM_NO_CHANGE_IN_MCPWMXB MCPWM_ACTION_NO_CHANGE /*!< @deprecated No change in MCPWMXB output*/
|
||||
#define MCPWM_FORCE_MCPWMXB_LOW MCPWM_ACTION_FORCE_LOW /*!< @deprecated Make MCPWMXB output low*/
|
||||
#define MCPWM_FORCE_MCPWMXB_HIGH MCPWM_ACTION_FORCE_HIGH /*!< @deprecated Make MCPWMXB output high*/
|
||||
#define MCPWM_TOG_MCPWMXB MCPWM_ACTION_TOGGLE /*!< @deprecated Make MCPWMXB output toggle*/
|
||||
|
||||
/**
|
||||
* @brief MCPWM select capture signal input
|
||||
@@ -196,29 +174,6 @@ typedef enum {
|
||||
MCPWM_SELECT_CAP2, /*!<Select CAP2 as input*/
|
||||
} mcpwm_capture_signal_t;
|
||||
|
||||
/**
|
||||
* @brief MCPWM select capture starts from which edge
|
||||
*/
|
||||
typedef enum {
|
||||
MCPWM_NEG_EDGE = 0, /*!<Capture starts from negative edge*/
|
||||
MCPWM_POS_EDGE, /*!<Capture starts from positive edge*/
|
||||
} mcpwm_capture_on_edge_t;
|
||||
|
||||
/**
|
||||
* @brief MCPWM deadtime types, used to generate deadtime, RED refers to rising edge delay and FED refers to falling edge delay
|
||||
*/
|
||||
typedef enum {
|
||||
MCPWM_BYPASS_RED = 0, /*!<MCPWMXA = no change, MCPWMXB = falling edge delay*/
|
||||
MCPWM_BYPASS_FED, /*!<MCPWMXA = rising edge delay, MCPWMXB = no change*/
|
||||
MCPWM_ACTIVE_HIGH_MODE, /*!<MCPWMXA = rising edge delay, MCPWMXB = falling edge delay*/
|
||||
MCPWM_ACTIVE_LOW_MODE, /*!<MCPWMXA = compliment of rising edge delay, MCPWMXB = compliment of falling edge delay*/
|
||||
MCPWM_ACTIVE_HIGH_COMPLIMENT_MODE, /*!<MCPWMXA = rising edge delay, MCPWMXB = compliment of falling edge delay*/
|
||||
MCPWM_ACTIVE_LOW_COMPLIMENT_MODE, /*!<MCPWMXA = compliment of rising edge delay, MCPWMXB = falling edge delay*/
|
||||
MCPWM_ACTIVE_RED_FED_FROM_PWMXA, /*!<MCPWMXA = MCPWMXB = rising edge delay as well as falling edge delay, generated from MCPWMXA*/
|
||||
MCPWM_ACTIVE_RED_FED_FROM_PWMXB, /*!<MCPWMXA = MCPWMXB = rising edge delay as well as falling edge delay, generated from MCPWMXB*/
|
||||
MCPWM_DEADTIME_TYPE_MAX,
|
||||
} mcpwm_deadtime_type_t;
|
||||
|
||||
/**
|
||||
* @brief MCPWM config structure
|
||||
*/
|
||||
@@ -241,7 +196,6 @@ typedef struct {
|
||||
mcpwm_carrier_out_ivt_t carrier_ivt_mode; /*!<Invert output of carrier*/
|
||||
} mcpwm_carrier_config_t;
|
||||
|
||||
|
||||
/**
|
||||
* @brief This function initializes each gpio signal for MCPWM
|
||||
* @note
|
||||
@@ -276,7 +230,7 @@ esp_err_t mcpwm_set_pin(mcpwm_unit_t mcpwm_num, const mcpwm_pin_config_t *mcpwm_
|
||||
* @brief Initialize MCPWM parameters
|
||||
*
|
||||
* @param mcpwm_num set MCPWM unit(0-1)
|
||||
* @param timer_num set timer number(0-2) of MCPWM, each MCPWM unit has 3 timers
|
||||
* @param timer_num set timer number(0-2) of MCPWM, each MCPWM unit has 3 timers.
|
||||
* @param mcpwm_conf configure structure mcpwm_config_t
|
||||
*
|
||||
* @return
|
||||
@@ -303,28 +257,28 @@ esp_err_t mcpwm_set_frequency(mcpwm_unit_t mcpwm_num, mcpwm_timer_t timer_num, u
|
||||
*
|
||||
* @param mcpwm_num set MCPWM unit(0-1)
|
||||
* @param timer_num set timer number(0-2) of MCPWM, each MCPWM unit has 3 timers
|
||||
* @param op_num set the operator(MCPWMXA/MCPWMXB), 'X' is timer number selected
|
||||
* @param gen set the generator(MCPWMXA/MCPWMXB), 'X' is operator number selected
|
||||
* @param duty set duty cycle in %(i.e for 62.3% duty cycle, duty = 62.3) of each operator
|
||||
*
|
||||
* @return
|
||||
* - 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_operator_t op_num, float duty);
|
||||
esp_err_t mcpwm_set_duty(mcpwm_unit_t mcpwm_num, mcpwm_timer_t timer_num, mcpwm_generator_t gen, float duty);
|
||||
|
||||
/**
|
||||
* @brief Set duty cycle of each operator(MCPWMXA/MCPWMXB) in us
|
||||
*
|
||||
* @param mcpwm_num set MCPWM unit(0-1)
|
||||
* @param timer_num set timer number(0-2) of MCPWM, each MCPWM unit has 3 timers
|
||||
* @param op_num set the operator(MCPWMXA/MCPWMXB), 'x' is timer number selected
|
||||
* @param duty set duty value in microseconds of each operator
|
||||
* @param gen set the generator(MCPWMXA/MCPWMXB), 'x' is operator number selected
|
||||
* @param duty_in_us set duty value in microseconds of each operator
|
||||
*
|
||||
* @return
|
||||
* - 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_operator_t op_num, uint32_t duty);
|
||||
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);
|
||||
|
||||
/**
|
||||
* @brief Set duty either active high or active low(out of phase/inverted)
|
||||
@@ -333,14 +287,14 @@ esp_err_t mcpwm_set_duty_in_us(mcpwm_unit_t mcpwm_num, mcpwm_timer_t timer_num,
|
||||
*
|
||||
* @param mcpwm_num set MCPWM unit(0-1)
|
||||
* @param timer_num set timer number(0-2) of MCPWM, each MCPWM unit has 3 timers
|
||||
* @param op_num set the operator(MCPWMXA/MCPWMXB), 'x' is timer number selected
|
||||
* @param duty_num set active low or active high duty type
|
||||
* @param gen set the generator(MCPWMXA/MCPWMXB), 'x' is operator number selected
|
||||
* @param duty_type set active low or active high duty type
|
||||
*
|
||||
* @return
|
||||
* - 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_operator_t op_num, mcpwm_duty_type_t duty_num);
|
||||
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);
|
||||
|
||||
/**
|
||||
* @brief Get frequency of timer
|
||||
@@ -358,40 +312,41 @@ uint32_t mcpwm_get_frequency(mcpwm_unit_t mcpwm_num, mcpwm_timer_t timer_num);
|
||||
*
|
||||
* @param mcpwm_num set MCPWM unit(0-1)
|
||||
* @param timer_num set timer number(0-2) of MCPWM, each MCPWM unit has 3 timers
|
||||
* @param op_num set the operator(MCPWMXA/MCPWMXB), 'x' is timer number selected
|
||||
* @param gen set the generator(MCPWMXA/MCPWMXB), 'x' is operator number selected
|
||||
*
|
||||
* @return
|
||||
* - duty cycle in % of each operator(56.7 means duty is 56.7%)
|
||||
*/
|
||||
float mcpwm_get_duty(mcpwm_unit_t mcpwm_num, mcpwm_timer_t timer_num, mcpwm_operator_t op_num);
|
||||
float mcpwm_get_duty(mcpwm_unit_t mcpwm_num, mcpwm_timer_t timer_num, mcpwm_operator_t gen);
|
||||
|
||||
/**
|
||||
* @brief Use this function to set MCPWM signal high
|
||||
*
|
||||
* @param mcpwm_num set MCPWM unit(0-1)
|
||||
* @param timer_num set timer number(0-2) of MCPWM, each MCPWM unit has 3 timers
|
||||
* @param op_num set the operator(MCPWMXA/MCPWMXB), 'x' is timer number selected
|
||||
* @param gen set the operator(MCPWMXA/MCPWMXB), 'x' is timer number selected
|
||||
|
||||
*
|
||||
* @return
|
||||
* - ESP_OK Success
|
||||
* - ESP_ERR_INVALID_ARG Parameter error
|
||||
*/
|
||||
esp_err_t mcpwm_set_signal_high(mcpwm_unit_t mcpwm_num, mcpwm_timer_t timer_num, mcpwm_operator_t op_num);
|
||||
esp_err_t mcpwm_set_signal_high(mcpwm_unit_t mcpwm_num, mcpwm_timer_t timer_num, mcpwm_generator_t gen);
|
||||
|
||||
/**
|
||||
* @brief Use this function to set MCPWM signal low
|
||||
*
|
||||
* @param mcpwm_num set MCPWM unit(0-1)
|
||||
* @param timer_num set timer number(0-2) of MCPWM, each MCPWM unit has 3 timers
|
||||
* @param op_num set the operator(MCPWMXA/MCPWMXB), 'x' is timer number selected
|
||||
* @param gen set the operator(MCPWMXA/MCPWMXB), 'x' is timer number selected
|
||||
|
||||
*
|
||||
* @return
|
||||
* - 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_operator_t op_num);
|
||||
esp_err_t mcpwm_set_signal_low(mcpwm_unit_t mcpwm_num, mcpwm_timer_t timer_num, mcpwm_generator_t gen);
|
||||
|
||||
/**
|
||||
* @brief Start MCPWM signal on timer 'x'
|
||||
*
|
||||
@@ -578,7 +533,7 @@ esp_err_t mcpwm_fault_init(mcpwm_unit_t mcpwm_num, mcpwm_fault_input_level_t int
|
||||
* - 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_action_on_pwmxa_t action_on_pwmxa, mcpwm_action_on_pwmxb_t action_on_pwmxb);
|
||||
mcpwm_output_action_t action_on_pwmxa, mcpwm_output_action_t action_on_pwmxb);
|
||||
|
||||
/**
|
||||
* @brief Set cycle-by-cycle mode on fault detection, once fault occur in cyc mode MCPWM signal resumes as soon as fault signal becomes inactive
|
||||
@@ -596,7 +551,7 @@ esp_err_t mcpwm_fault_set_oneshot_mode(mcpwm_unit_t mcpwm_num, mcpwm_timer_t tim
|
||||
* - 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_action_on_pwmxa_t action_on_pwmxa, mcpwm_action_on_pwmxb_t action_on_pwmxb);
|
||||
mcpwm_output_action_t action_on_pwmxa, mcpwm_output_action_t action_on_pwmxb);
|
||||
|
||||
/**
|
||||
* @brief Disable fault signal
|
||||
|
||||
Reference in New Issue
Block a user