void PWM_Init()
{
//S_DRVPWM_TIME_DATA_T sPt_0;
//uint8_t u8Timer_0;
/* Enable PWM clock */
DrvPWM_Open();
/* Set PWM0 Pin */
outpw(&SYS->GPAMFP, inpw(&SYS->GPAMFP) | (0x1<<(12)));
/* Selcect pwm0 clock source */
DrvPWM_SelectClockSource(DRVPWM_TIMER0, DRVPWM_EXT_12M);
/* PWM Timer property */
sPt_0.u8Mode = DRVPWM_ONE_SHOT_MODE;
sPt_0.u32Frequency = 0;
sPt_0.u8PreScale = 1;
sPt_0.u8ClockSelector = DRVPWM_CLOCK_DIV_1;
sPt_0.u8HighPulseRatio = 50;
sPt_0.i32Inverter = FALSE;
sPt_0.u32Duty = 0;
//u8Timer_0 = DRVPWM_TIMER0;
/* PWM Timer0 Configuration */
pwmcll=DrvPWM_SetTimerClk(DRVPWM_TIMER0, &sPt_0);
/* Enable in/out for PWM Timer0 */
DrvPWM_SetTimerIO(DRVPWM_TIMER0, 1);
/* Enable Interrupt Sources of PWM Timer0 and install call back function */
DrvPWM_EnableInt(DRVPWM_TIMER0, 0, PWM0Callbackfn);
/* Enable the PWM Timer 0 */
DrvPWM_Enable(DRVPWM_TIMER0, 1);
}
void PWM0Callbackfn()
{
/* Add your code here */
PWMA->CMR0 = 30-1;
PWMA->CNR0 = 60-1; // PWM0 占空比= (CMR+1)/(CNR+1) = 30/60 = 1/2 50%
conter++;
if(conter==300000)
{
DrvPWM_DisableInt(DRVPWM_TIMER0);
}
}
根据技术手册提供的计算:PWM频率= PWMxy_CLK/(prescale+1)*(clock divider)/(CNR+1);
12000000/(1+1)/1/60=100000HZ;
可是管脚输出的频率不是100000HZ,这是什么原因? |