最近在学习新唐nano130,发现PWM 有抖动的情况。附件所示:程序如下:请高人们解析:
int32_t main (void)
{
S_DRVPWM_TIME_DATA_T sPt;
////STR_PDMA_T sPDMA;
uint8_t u8Timer;
int32_t i32TestLoop = 1;
uint8_t u8ItemOK;
/* Enable PWM clock */
PWM_Init(0);
/* Set PWM pins */
GCR->PA_H_MFP = (GCR->PA_H_MFP & ~(PA12_MFP_MASK | PA13_MFP_MASK | PA15_MFP_MASK)) |
PA12_MFP_PWM0_CH0 | PA13_MFP_PWM0_CH1 | PA15_MFP_PWM0_CH3;
GCR->PB_H_MFP = (GCR->PB_H_MFP & ~PB11_MFP_MASK) | PB11_MFP_PWM1_CH0;
GCR->PE_L_MFP = (GCR->PE_L_MFP & ~PE0_MFP_MASK) | PE0_MFP_PWM1_CH2;
while (i32TestLoop)
{
u8ItemOK = 1;
g_u16Frequency = 100;
if (i32TestLoop && u8ItemOK)
{
g_u32Pulse = 0;
g_u8PWMCount = 1;
/* PWM Timer property */
/*
* clock = 12MHz / 2 = 6Mhz.
* CN = clock / freq - 1
*/
sPt.u8Mode = PWM_CTL_CHMOD_AUTO_RELOAD;
sPt.u8PreScale = 1; // actually 1 + 1
sPt.u8Div = PWM_CLKSEL_CLKSEL_DIV1;
sPt.u32Cn = 6000000 / g_u16Frequency - 1;
sPt.u16Cm = sPt.u32Cn / 2; // 50% duty ratio
sPt.u8Inv = 0; // Disable inverter
u8Timer = 0;
/* Set PWM Timer0 Configuration */
PWM_SetClk(u8Timer, &sPt);
/* Enable Output for PWM Timer0 */
PWM_ConfigOutput(u8Timer, 1);
/* Enable Interrupt Sources of PWM Timer0 and install call back function */
//// PWM_EnableInt(u8Timer);
/* Enable the PWM Timer 0 */
PWM_Enable(u8Timer);
while (g_u8PWMCount);
while(1);
}
}
}
|