1.配置PWM写成子程序结构PWM_Init(); PWM端口无输出
2.将配置PWM展开则PWM输出正常
请问各位大佬是什么原因导致这个问题?
void SYS_Init(void)//写成子程序形式无输出
{
CLKInit();
GPIOInit();
DataInit();
EEROM_Init();
WDT_CLEAR_RESET_FLAG();
WDT_RESET_COUNTER();
BuzzInit();
PWM_Init();//
initLogic();
}
void SYS_Init(void)//展开有输出
{
CLKInit();
GPIOInit();
DataInit();
EEROM_Init();
WDT_CLEAR_RESET_FLAG();
WDT_RESET_COUNTER();
BuzzInit();
//PWM 配置
GPIO_SetMode(P4, BIT0, GPIO_PMD_OUTPUT);
GPIO_SetMode(P4, BIT2, GPIO_PMD_OUTPUT);
/*Set Pwm mode*/
PWMA->PCR |= PWM_PCR_CH0MOD_Msk;//自动重载
PWMA->PCR |= PWM_PCR_CH0INV_Msk;//反向
PWMA->PCR |= 0x02;//正常模式
/*Set PWM Timer clock prescaler*/
PWM_SET_PRESCALER(PWMA, PWM_CH0, 1); // Divided by 2
/*Set PWM Timer clock divider select*/
PWM_SET_DIVIDER(PWMA, PWM_CH0, PWM_CLK_DIV_1);
/*Set PWM Timer duty*/
PWMA->CMR0 = 500;
/*Set PWM Timer period*/
PWMA->CNR0 = 2000;
/* Enable PWM Output pin */
PWMA->POE |= PWM_POE_PWM0_Msk;
// PWMA->POE |= 0xffffffff;
/* Enable Timer period Interrupt */
PWMA->PIER |= PWM_PIER_PWMIE0_Msk;
/* Enable PWMB NVIC */
NVIC_EnableIRQ((IRQn_Type)(PWMA_IRQn));
/* Enable PWM Timer */
PWMA->PCR |= PWM_PCR_CH0EN_Msk;
initLogic();
}
/*---------------------------------------------------------------------------------------------------------*/
/* MAIN function */
/*---------------------------------------------------------------------------------------------------------*/
int main(void)
{
volatile uint32_t u32InitCount;
/* Unlock protected registers */
SYS_UnlockReg();
/* Init System, peripheral clock and multi-function I/O */
SYS_Init();
/* Lock protected registers */
SYS_LockReg();
while(1)
{
}
}
|