#include "EPWM.h"
void EPWM_IO_Init()
{
GPIO_Write_Mode_Bits(GPIOC_SFR, GPIO_PIN_MASK_9, GPIO_MODE_RMP);
GPIO_Write_Mode_Bits(GPIOE_SFR, GPIO_PIN_MASK_2, GPIO_MODE_RMP);
GPIO_Pin_RMP_Config(GPIOC_SFR,GPIO_Pin_Num_9,GPIO_RMP_AF2); //EPWM13B-PC9
GPIO_Pin_RMP_Config(GPIOE_SFR,GPIO_Pin_Num_2,GPIO_RMP_AF2); //EPWM13A-PE2
}
void EPWM13_Init()
{
EPWM_Reset(EPWM13_SFR); // 外设复位
EPWM_Work_Mode_Config(EPWM13_SFR,EPWM_TIMER_MODE);
EPWM_Work_Clock_Select(EPWM13_SFR,EPWM_CLK_HFCLK); //EPWM_CLK=HFCLK时钟选择高频时钟16M
EPWM_TxPRSC_Value_Config(EPWM13_SFR,0);
EPWM_TxPHS_Value_Config(EPWM13_SFR, 0x00000000);
EPWM_Counter_Mode_Select(EPWM13_SFR,EPWM_COUNT_UP_DOWM_OF);
EPWM_Phase_Register_Loading_Enable(EPWM13_SFR, TRUE);
// EPWM_Phase_Direction_Config(EPWM13_SFR,EPWM_SYNC_TRIGGER_UP);
// EPWM_SYNC_Event_Out_Select(EPWM13_SFR,EPWM_SYNC_EVENT_OUT_COUNT0);
EPWM_Duty_Cycle_RegisterABCD_Config(EPWM13_SFR, EPWM_REGISTER_A,0x00001000);// 设置A占空比
EPWM_Duty_Cycle_RegisterABCD_Config(EPWM13_SFR, EPWM_REGISTER_B,0x00001000);// 设置B占空比
EPWM_TxCNT_Value_Config(EPWM13_SFR, 0x00000000);
EPWM_TxPPX_Value_Config(EPWM13_SFR, 0x00002000); //配置周期寄存器(PWM周期)
EPWM_EPWMxAB_OUTPUT_Select(EPWM13_SFR,EPWM_REGISTER_A,EPWM_CERA_DD_EPWMAB_OUT,EPWM_OUT_HIGH);
EPWM_EPWMxAB_OUTPUT_Select(EPWM13_SFR,EPWM_REGISTER_A,EPWM_CERA_DU_EPWMAB_OUT,EPWM_OUT_LOW);
EPWM_EPWMxAB_OUTPUT_Select(EPWM13_SFR,EPWM_REGISTER_B,EPWM_CERB_DD_EPWMAB_OUT,EPWM_OUT_HIGH);
EPWM_EPWMxAB_OUTPUT_Select(EPWM13_SFR,EPWM_REGISTER_B,EPWM_CERB_DU_EPWMAB_OUT,EPWM_OUT_LOW);
// EPWM_EPWMxAB_OUTPUT_Select(EPWM13_SFR,EPWM_REGISTER_A,EPWM_CE0_EPWMAB_OUT,EPWM_OUT_LOW);
// EPWM_EPWMxAB_OUTPUT_Select(EPWM13_SFR,EPWM_REGISTER_B,EPWM_CE0_EPWMAB_OUT,EPWM_OUT_LOW);
EPWM_Continuous_Mandatory_Output_Config(EPWM13_SFR,EPWM_REGISTER_A,EPWM_OUT_PROHIBIT);
EPWM_Continuous_Mandatory_Output_Config(EPWM13_SFR,EPWM_REGISTER_B,EPWM_OUT_PROHIBIT);
//DB
EPWM_Dead_Zone_Input_Select(EPWM13_SFR,EPWM_EPWMA_UP_EPWMA_DOWM);
EPWM_Dead_Zone_Output_Polarity_Select(EPWM13_SFR,EPWM_EPWMA_NTOGGLE_EPWMB_NTOGGLE);
EPWM_Dead_Zone_Output_Select(EPWM13_SFR,EPWM_UP_ENABLE_DOWN_ENABLE);
EPWM_Dead_Zone_Time_Config(EPWM13_SFR,EPWM_UP_EDGE_DEAD_ZONE,0x200);
EPWM_Dead_Zone_Time_Config(EPWM13_SFR,EPWM_DOWM_EDGE_DEAD_ZONE,0x200);
// EPWM_Global_Loading_Enable(EPWM13_SFR,FALSE);
EPWM_Updata_Event_Enable(EPWM13_SFR,TRUE);
EPWM_Updata_Event_Generate_Enable(EPWM13_SFR,TRUE);
EPWM_Enable(EPWM13_SFR,TRUE);
}