以下代码是在HC32F460初始化定时器A生成三路PWM的代码,TMRA_IN3PWM_CH不能输出PWM,分析一下为什么
时间: 2023-11-28 18:48:23 浏览: 99
```c
#include "HC32F460.h"
#include "hc32f4a0_utility.h"
void PWM_Init(void)
{
stc_tmra_init_t stcTmraInit;
stc_tmra_pwm_init_t stcTmraPwmInit;
DDL_ZERO_STRUCT(stcTmraInit);
DDL_ZERO_STRUCT(stcTmraPwmInit);
Sysctrl_SetPeripheralGate(SysctrlPeripheralTmrA, TRUE);
stcTmraInit.u16ClockDiv = TMRA_CLKDIV_DIV1;
stcTmraInit.u16CountMode = TMRA_MD_SAWTOOTH;
stcTmraInit.u16CountDir = TMRA_DIR_UP;
stcTmraInit.u16PeriodValue = 20000U;
TMRA_Init(TMRA_UNIT, &stcTmraInit);
stcTmraPwmInit.u32PwmCh = TMRA_PWM_U | TMRA_PWM_V | TMRA_PWM_W;
stcTmraPwmInit.u16PwmMode = TMRA_PWM_MD_1;
stcTmraPwmInit.u32PwmState = TMRA_PWM_STATE_ENABLE;
stcTmraPwmInit.u16PwmDtEn = TMRA_PWM_DT_EN_INVALID;
stcTmraPwmInit.u16PwmDeadTime = 0U;
stcTmraPwmInit.u32PwmPortOutputMask = TMRA_PWM_OUT_MASK_CH345;
stcTmraPwmInit.u16PwmIrqMask = TMRA_PWM_IRQ_MASK_CH345;
TMRA_PWM_Init(TMRA_UNIT, TMRA_PWM_CH_UVW, &stcTmraPwmInit);
TMRA_PWM_StructInit(&stcTmraPwmInit);
stcTmraPwmInit.u32PwmCh = TMRA_PWM_U | TMRA_PWM_V | TMRA_PWM_W;
stcTmraPwmInit.u16PwmMode = TMRA_PWM_MD_1;
stcTmraPwmInit.u32PwmState = TMRA_PWM_STATE_ENABLE;
stcTmraPwmInit.u16PwmDtEn = TMRA_PWM_DT_EN_INVALID;
stcTmraPwmInit.u16PwmDeadTime = 0U;
stcTmraPwmInit.u32PwmPortOutputMask = TMRA_PWM_OUT_MASK_CH345;
stcTmraPwmInit.u16PwmIrqMask = TMRA_PWM_IRQ_MASK_CH345;
TMRA_PWM_Init(TMRA_UNIT, TMRA_PWM_CH_UVW, &stcTmraPwmInit);
TMRA_PWM_StructInit(&stcTmraPwmInit);
stcTmraPwmInit.u32PwmCh = TMRA_PWM_U | TMRA_PWM_V | TMRA_PWM_W;
stcTmraPwmInit.u16PwmMode = TMRA_PWM_MD_1;
stcTmraPwmInit.u32PwmState = TMRA_PWM_STATE_ENABLE;
stcTmraPwmInit.u16PwmDtEn = TMRA_PWM_DT_EN_INVALID;
stcTmraPwmInit.u16PwmDeadTime = 0U;
stcTmraPwmInit.u32PwmPortOutputMask = TMRA_PWM_OUT_MASK_CH345;
stcTmraPwmInit.u16PwmIrqMask = TMRA_PWM_IRQ_MASK_CH345;
TMRA_PWM_Init(TMRA_UNIT, TMRA_PWM_CH_UVW, &stcTmraPwmInit);
}
```
根据代码中的注释,这段代码初始化了定时器A,并使其生成三路PWM信号。但是,其中包括的 `TMRA_IN3PWM_CH` 实际上并不是一个 PWM 通道,它只是一个输入捕获通道。因此,这个通道不能用于生成 PWM 信号。
如果需要使用三路 PWM 信号,可以将 `TMRA_IN3PWM_CH` 改为 `TMRA_PWM_CH_V`,并在后面的函数调用中对应修改。
阅读全文