0
我一直試圖在PIC16F877 MCU上使用PWM模塊,但我所得到的只是CCP1/CCP2引腳上的低電平。無法讓PWM在PIC16F877(PICC)上工作
配置和啓動PWM模塊的代碼如下。
// Configure PWM
// Timer 2 (PWM timebase)
TMR2 = 0; //Clear timer
TOUTPS0 = 0;
TOUTPS1 = 0;
TOUTPS2 = 0;
TOUTPS3 = 1; //Postscaler -> 8 (previously set to 0)
T2CKPS0 = 0;
T2CKPS1 = 1; //Prescaler -> 16
TMR2IF = 0;
TMR2IE = 1; //Interrupt
PR2 = 233; //~2.5ms
//PWM1 config
CCPR1L = 0x0F;
CCP1X = 0;
CCP1Y = 0; //PWM1 duty cycle
TRISB2 = 0; //CCP1 pin is output (Error is here, see below)
TMR2ON = 1; //Enable timer
CCP1CON = 0x0c; //CPP1 is a PWM
任何可以在PIC16器件上成功啓動PWM的代碼(PICC)都是有用的。
的'TOUTPS [0-3]'指出'0000'是'1:1' postscalar – Dan
Postcaler是暫時集到0,不是問題。發現問題,見下文。 – NeonMan