21ic问答首页 - 关于HCF32460的PWM问题
关于HCF32460的PWM问题
黑小虎2024-07-01
请教一下各位,关于小华MCU,timerA的PWM输出,使用IO口为PC15,配置功能如下:但是目前从示博器来看输出波形一直保持不变,但是从打印来看,定时器是已经启动开始计数了。
void timer_init(uint16_t CompareValue)
{
/* MCU Peripheral registers write unprotected. */
LL_PERIPH_WE(LL_PERIPH_GPIO | LL_PERIPH_FCG | LL_PERIPH_PWC_CLK_RMU);
stc_tmra_init_t stcTmraInit;
stc_tmra_pwm_init_t stcPwmInit;
/************************gpio config***************************/
stc_gpio_init_t stcGpioInit;
(void)GPIO_StructInit(&stcGpioInit);
stcGpioInit.u16PinDir = PIN_DIR_OUT;
stcGpioInit.u16PinOutputType = PIN_OUT_TYPE_CMOS; //CMOS正常输出
(void)GPIO_Init(ENCODER_OUT_PORT, ENCODER_OUT_PIN, &stcGpioInit);
/* 1. Enable TimerA peripheral clock. */
FCG_Fcg2PeriphClockCmd(FCG2_PERIPH_TMRA_4, ENABLE);
/* 2. Set a default initialization value for stcTmraInit. */
(void)TMRA_StructInit(&stcTmraInit);
/* 3. Modifies the initialization values depends on the application. */
stcTmraInit.sw_count.u16CountMode = TMRA_MD_SAWTOOTH; //锯齿波计数模式
stcTmraInit.sw_count.u16CountDir = TMRA_DIR_UP; //向上计数
stcTmraInit.u32PeriodValue = 10000U-1U; //自动重装载值
(void)TMRA_Init(CM_TMRA_4, &stcTmraInit);
/* 4. Set the comparison reference value. */
(void)TMRA_PWM_StructInit(&stcPwmInit);
stcPwmInit.u32CompareValue = 5000U-1; //20/40 50%占空比
GPIO_SetFunc(ENCODER_OUT_PORT, ENCODER_OUT_PIN, GPIO_FUNC_4);
(void)TMRA_PWM_Init(CM_TMRA_4, TMRA_CH6, &stcPwmInit);
TMRA_PWM_OutputCmd(CM_TMRA_4, TMRA_CH6, ENABLE);
/*(void)TMRA_PWM_StructInit(&stcPwmInit);
stcPwmInit.u32CompareValue = 20U-1; //20/40 50%占空比
GPIO_SetFunc(ENCODER_IN_PORT, ENCODER_IN_PIN, GPIO_FUNC_4);
(void)TMRA_PWM_Init(CM_TMRA_4, TMRA_CH5, &stcPwmInit);
TMRA_PWM_OutputCmd(CM_TMRA_4, TMRA_CH5, ENABLE);*/
/* MCU Peripheral registers write protected. */
LL_PERIPH_WP(LL_PERIPH_GPIO | LL_PERIPH_FCG | LL_PERIPH_PWC_CLK_RMU);
/* Starts TimerA. */
TMRA_Start(CM_TMRA_4);
}
void timer_init(uint16_t CompareValue)
{
/* MCU Peripheral registers write unprotected. */
LL_PERIPH_WE(LL_PERIPH_GPIO | LL_PERIPH_FCG | LL_PERIPH_PWC_CLK_RMU);
stc_tmra_init_t stcTmraInit;
stc_tmra_pwm_init_t stcPwmInit;
/************************gpio config***************************/
stc_gpio_init_t stcGpioInit;
(void)GPIO_StructInit(&stcGpioInit);
stcGpioInit.u16PinDir = PIN_DIR_OUT;
stcGpioInit.u16PinOutputType = PIN_OUT_TYPE_CMOS; //CMOS正常输出
(void)GPIO_Init(ENCODER_OUT_PORT, ENCODER_OUT_PIN, &stcGpioInit);
/* 1. Enable TimerA peripheral clock. */
FCG_Fcg2PeriphClockCmd(FCG2_PERIPH_TMRA_4, ENABLE);
/* 2. Set a default initialization value for stcTmraInit. */
(void)TMRA_StructInit(&stcTmraInit);
/* 3. Modifies the initialization values depends on the application. */
stcTmraInit.sw_count.u16CountMode = TMRA_MD_SAWTOOTH; //锯齿波计数模式
stcTmraInit.sw_count.u16CountDir = TMRA_DIR_UP; //向上计数
stcTmraInit.u32PeriodValue = 10000U-1U; //自动重装载值
(void)TMRA_Init(CM_TMRA_4, &stcTmraInit);
/* 4. Set the comparison reference value. */
(void)TMRA_PWM_StructInit(&stcPwmInit);
stcPwmInit.u32CompareValue = 5000U-1; //20/40 50%占空比
GPIO_SetFunc(ENCODER_OUT_PORT, ENCODER_OUT_PIN, GPIO_FUNC_4);
(void)TMRA_PWM_Init(CM_TMRA_4, TMRA_CH6, &stcPwmInit);
TMRA_PWM_OutputCmd(CM_TMRA_4, TMRA_CH6, ENABLE);
/*(void)TMRA_PWM_StructInit(&stcPwmInit);
stcPwmInit.u32CompareValue = 20U-1; //20/40 50%占空比
GPIO_SetFunc(ENCODER_IN_PORT, ENCODER_IN_PIN, GPIO_FUNC_4);
(void)TMRA_PWM_Init(CM_TMRA_4, TMRA_CH5, &stcPwmInit);
TMRA_PWM_OutputCmd(CM_TMRA_4, TMRA_CH5, ENABLE);*/
/* MCU Peripheral registers write protected. */
LL_PERIPH_WP(LL_PERIPH_GPIO | LL_PERIPH_FCG | LL_PERIPH_PWC_CLK_RMU);
/* Starts TimerA. */
TMRA_Start(CM_TMRA_4);
}
赞0
评论
2024-07-06
赞0
评论
2024-07-01
PC15在数据手册IO功能为FUN4,TIMA_4_PWM6
您需要登录后才可以回复 登录 | 注册