void init_pwm_tiaokuan(INT16U g_u16Frequency01)
{
S_DRVPWM_TIME_DATA_T_TiaoKuan sPt01;
// Enable PWM clock //
DrvPWM_Open();
HWREG(0x50000030)|=0x00001000; //GPA_MFP的12位 设置PA12为PWM0
UNLOCKREG();
DrvSYS_SetHCLKSource(0); //外部晶振
LOCKREG();
sPt01.u8Mode = DRVPWM_TOGGLE_MODE;
sPt01.u32Frequency = g_u16Frequency01;//g_u16Frequency;
sPt01.u32HighPulseRatio = 50; // High Pulse peroid : Total Pulse peroid = 1 : 100 //
sPt01.i32Inverter = 0;
// Select PWM engine clock //
// DrvPWM_SelectClockSource(DRVPWM_TIMER0, DRVPWM_HCLK);
HWREG(0x50000208)|=0x00100000;//APBCLK PWM01EN=1
// DrvPWM_SetTimerClk_TiaoKuan(DRVPWM_TIMER0,&sPt01);
HWREG(0x40040000)|=0x0000003f; //PPR
HWREG(0x40040004)|=0x00000004;//CSR time0输入,1分频
HWREG(0x40040008)|=0x00000004;//PCR 自动重装模式,PWM time0使能
HWREG(0x40040010)|=0x00003fff;//CMR 自动重装模式,PWM time0使能
HWREG(0x4004000C)|=0x0000fffe;//CNR 自动重装模式,PWM counter
//运行以下两句CMR CNR会清0
// DrvPWM_SetTimerIO(DRVPWM_TIMER0, 1);
HWREG(0x4004007C)|=0x00000001; //使能输出 POE03
// DrvPWM_Enable(DRVPWM_TIMER0, 1);
HWREG(0x40040008)|=0x00000001;//PCR PWM time0使能
}
想自己设置pwm宽度,有的地方没用库函数
调试时到
HWREG(0x4004007C)|=0x00000001; //使能输出 POE03
就会清CMR CNR
不知道那里出错 |