芯片是NUC120
PWM初始化程序如下:
//--------------------------------------------
void InitPWM1(void)
{
/* Step 1. GPIO initial */
SYS->GPAMFP.PWM1_AD14=1;
/* Step 2. Enable and Select PWM clock source*/
SYSCLK->APBCLK.PWM01_EN = 1;//Enable PWM clock
SYSCLK->CLKSEL1.PWM01_S = 0;//Select 12Mhz for PWM clock source
//主时钟在进入PWM定时器之前被(CP01+1)分频
PWMA->PR.CP01=11; //Prescaler 0~255, Setting 0 to stop output clock
//PWM定时器16分频
PWMA->CSR.CSR1=3; // PWM clock = clock source/(Prescaler + 1)/divider
//clock divider->0:/2, 1:/4, 2:/8, 3:/16, 4:/1
//PWM定时器每计数一个时间:12M/(11+1)*16=16us
/* Step 3. Select PWM Operation mode */
//PWM0 自动重装载模式
PWMA->CR.CH1MOD=1; //0:One-shot mode, 1:Auto-load mode
//CNR and CMR will be auto-cleared after setting CH0MOD form 0 to 1.
PWMA->CNR1=0xFFFF; //周期 65535*16=1.048560S
PWMA->CMR1=0x3FFF; //占空比=(CMR+1)/(CNR+1)
PWMA->CR.CH1INV=0; //Inverter->0ff, 1n PWM输出极性反转
PWMA->CR.CH1EN=1; //PWM function->0isable, 1:Enable
PWMA->OE.PWM1=1; //Output to pin->0asble, 1:Enable
}
不知道什么原因造成的?
PWM所在的管脚要不要设置为输出模式 |