我获得一块nano130板,想做PWM波实验,不成功。
贴一下部分程序:
void TM0_Init(void)
{
/* Step 1. Enable and Select Timer clock source */
CLK->CLKSEL1 = (CLK->CLKSEL1 & ~CLK_CLKSEL1_TMR0_MASK) | CLK_CLKSEL1_TMR0_HXT; //Select 12Mhz for Timer0 clock source
CLK->APBCLK |= CLK_APBCLK_TMR0_EN; //Enable Timer0 clock source
/* Step 2. Select Operation mode */
TIMER0->CTL = (TIMER0->CTL & ~TIMER_CTL_MODESEL_MASK) | TIMER_CTL_MODESEL_PERIODIC; //Select periodic mode for operation mode
/* Step 3. Select Time out period = (Period of timer clock input) * (8-bit Prescale + 1) * (24-bit TCMP)*/
//不分频
TIMER0->PRECNT=0; // Set Prescale [0~255]
TIMER0->CMPR = 0xffff; // Set TCMPR [0~16777215]
// (1/12000000)*(255+1)*(46875) = 1HZ
/* Step 4. Enable interrupt */
TIMER0->ISR = TIMER0->ISR; //Write 1 to clear for safty
TIMER0->IER = TIMER_IER_TMRIE;
NVIC_EnableIRQ(TMR0_IRQn); //Enable Timer0 Interrupt
/* Step 5. Enable Timer module */
TIMER0->CTL |= TIMER_CTL_TMREN; //Enable Timer0
}
void PWM_Init()
{
CLK->APBCLK|=0X00100000;
PWM0->PRES=2; //预分频为1
PWM0->CLKSEL=4; //1分频
PWM0->CTL=0X000D; //连续模式,反相关,使能PWM定时器0开始运行
PWM0->INTEN=1; //中断禁止
PWM0->INTSTS=1; //写1清中断标志
PWM0->OE=1; //使能通道0
PWM0->DUTY0=0X40008000; //占空比50%
}
使用PWM0的0通道,测板子上JP16的79腿,没波形。请高手指教,谢谢! |