问答

汇集网友智慧,解决技术难题

21ic问答首页 - TAG - ECCP5
  • KF32A单片ECCP5的pwm模式的用法(比较值装载问题) sos

    关于增强型CCP5,配置:请问是不是每次装载比较值都需要重新配置PWM设置。 void cfg_ECCP5() { ECCP_PWM_Mode_Config(ECCP5_SFR,ECCP_PWM_FREE); //PWM自由模式, ECCP_Channel_Output_Mode(ECCP5_SFR,ECCP_CHANNEL_1,ECCP_OUTPUT_COMPLEMENTARY); //互补输出模式 ECCP_Channel_Output_Mode(ECCP5_SFR,ECCP_CHANNEL_2,ECCP_OUTPUT_COMPLEMENTARY); //互补输出模式 ECCP_Channel_Output_Mode(ECCP5_SFR,ECCP_CHANNEL_3,ECCP_OUTPUT_INDEPENDENT); //独立输出模式 ECCP_Channel_Output_Mode(ECCP5_SFR,ECCP_CHANNEL_4,ECCP_OUTPUT_INDEPENDENT); //独立输出模式 ECCP_Channel_Shutdown_Signal(ECCP5_SFR,ECCP_CHANNEL_1,ECCP_CHANNEL_SHUTDOWN_FORBID); //禁止自动关断 ECCP_Channel_Shutdown_Signal(ECCP5_SFR,ECCP_CHANNEL_2,ECCP_CHANNEL_BKIN_INACTIVE); //使能自动关断,ECCPx_BKIN引脚上的低电平 ECCP_Channel_Shutdown_Signal(ECCP5_SFR,ECCP_CHANNEL_3,ECCP_CHANNEL_BKIN_INACTIVE); //禁止自动关断 ECCP_Channel_Shutdown_Signal(ECCP5_SFR,ECCP_CHANNEL_4,ECCP_CHANNEL_BKIN_INACTIVE); //使能自动关断,ECCPx_BKIN引脚上的低电平 ECCP_PWM_Restart_Enable(ECCP5_SFR,TRUE); //使能自动重启 ECCP_PWM_Move_Phase_Enable(ECCP5_SFR,TRUE); //使能移相 ECCP_Channel_Pin_Ctl(ECCP5_SFR,ECCP_CHANNEL_2,ECCP_PORT_LOW,PIN_INACTIVE); //关闭状态为低电平 ECCP_Channel_Pin_Ctl(ECCP5_SFR,ECCP_CHANNEL_2,ECCP_PORT_HIGH,PIN_ACTIVE); //关闭状态为高电平 ECCP_Channel_Pin_Ctl(ECCP5_SFR,ECCP_CHANNEL_3,ECCP_PORT_LOW,PIN_INACTIVE); //关闭状态为低电平 ECCP_Channel_Pin_Ctl(ECCP5_SFR,ECCP_CHANNEL_3,ECCP_PORT_HIGH,PIN_ACTIVE); //关闭状态为高电平 ECCP_Channel_Pin_Ctl(ECCP5_SFR,ECCP_CHANNEL_4,ECCP_PORT_LOW,PIN_INACTIVE); //关闭状态为低电平 ECCP_Channel_Pin_Ctl(ECCP5_SFR,ECCP_CHANNEL_4,ECCP_PORT_HIGH,PIN_TRISTATE); //关闭状态为三态 ECCP_Channel_Output_Control(ECCP5_SFR,ECCP_CHANNEL_1,ECCP_PORT_LOW,ECCP_CHANNEL_OUTPUT_PWM_ACTIVE); //强制输出高电平 ECCP_Channel_Output_Control(ECCP5_SFR,ECCP_CHANNEL_1,ECCP_PORT_HIGH,ECCP_CHANNEL_OUTPUT_PWM_ACTIVE); //PWM输出,高有效 ECCP_Channel_Output_Control(ECCP5_SFR,ECCP_CHANNEL_2,ECCP_PORT_LOW,ECCP_CHANNEL_OUTPUT_PWM_ACTIVE); //PWM输出,高有效 ECCP_Channel_Output_Control(ECCP5_SFR,ECCP_CHANNEL_2,ECCP_PORT_HIGH,ECCP_CHANNEL_OUTPUT_PWM_ACTIVE); //PWM输出,高有效 ECCP_Channel_Output_Control(ECCP5_SFR,ECCP_CHANNEL_3,ECCP_PORT_LOW,ECCP_CHANNEL_OUTPUT_PWM_ACTIVE); //PWM输出,高有效 ECCP_Channel_Output_Control(ECCP5_SFR,ECCP_CHANNEL_3,ECCP_PORT_HIGH,ECCP_CHANNEL_OUTPUT_PWM_ACTIVE); //PWM输出,高有效 ECCP_Channel_Output_Control(ECCP5_SFR,ECCP_CHANNEL_4,ECCP_PORT_LOW,ECCP_CHANNEL_OUTPUT_PWM_ACTIVE); //PWM输出,高有效 ECCP_Channel_Output_Control(ECCP5_SFR,ECCP_CHANNEL_4,ECCP_PORT_HIGH,ECCP_CHANNEL_OUTPUT_PWM_ACTIVE); //PWM输出,高有效 //ECCP_Dead_Time_Config(ECCP5_SFR,ECCP_CHANNEL_2,0x00); //通道死区延时时间123公用 ECCP_Dead_Time_Config(ECCP5_SFR,ECCP_CHANNEL_1,0x80); //通道死区延时时间 ECCP_Set_Compare_Result(ECCP5_SFR,ECCP_CHANNEL_1,0x2000); //PWM占空比 ECCP_Set_Compare_Result(ECCP5_SFR,ECCP_CHANNEL_2,0x4000); //PWM占空比 ECCP_Set_Compare_Result(ECCP5_SFR,ECCP_CHANNEL_3,0x6000); //PWM占空比 ECCP_Set_Compare_Result(ECCP5_SFR,ECCP_CHANNEL_4,0x800); //PWM占空比 } 如果我将如下装载比较值单独放到main(),是没有PWM输出,pwm处于关闭状态(注:前面已经配置好PWM初始化) ECCP_Set_Compare_Result(ECCP5_SFR,ECCP_CHANNEL_1,0x2000); //PWM占空比 ECCP_Set_Compare_Result(ECCP5_SFR,ECCP_CHANNEL_2,0x4000); //PWM占空比 ECCP_Set_Compare_Result(ECCP5_SFR,ECCP_CHANNEL_3,0x6000); //PWM占空比 ECCP_Set_Compare_Result(ECCP5_SFR,ECCP_CHANNEL_4,0x800); //PWM占空比 如何可以单独装载比较值,不需要每次都要初始化PWM配置

    KF32A ECCP5 PWM 芯旺

    1140浏览量 0回复量 关注量