打印
[KungFu32位 MCU]

KF32A136EPWM问题

[复制链接]
947|1
手机看帖
扫描二维码
随时随地手机跟帖
跳转到指定楼层
楼主
xylonn|  楼主 | 2023-3-2 11:00 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
在KF32A136上使用EPWM模块,
#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);
}





配置好后示波器为何检测不到脉冲,请问哪位大神帮个忙,下面是主程序
#include "main.h"

//asm(".include                \"KF32A156MQV.inc\"        ");

//Main Function

void Delay( volatile uint32_t a, volatile uint32_t b)
{
        volatile uint32_t i;
        volatile uint32_t j;
        for(i=a;i>1;i--)
        {
                j=b;
        while(j--);
        }
}

int main()
{
        uint32_t PWM_DUTY=0x1000;
        SystemInit(48);
    EPWM_IO_Init();
    EPWM13_Init();
        while(1)
        {
                PWM_DUTY += 0x04;
                if(PWM_DUTY >= 0x2000)
                {
                        PWM_DUTY = 0x10;
                }
                EPWM13_SFR->RA = PWM_DUTY;
                EPWM13_SFR->RB = PWM_DUTY;
                Delay(100,100);
                Delay(100,100);
        }
}

使用特权

评论回复
沙发
xinpian101| | 2023-3-15 22:23 | 只看该作者
那可能没配置,这个系列官方提供的有例子吗,或者看看手册,都要配置哪些寄存器。

使用特权

评论回复
发新帖 我要提问
您需要登录后才可以回帖 登录 | 注册

本版积分规则

1

主题

1

帖子

0

粉丝