Quantcast
Channel: 蓝牙论坛 - 最近的话题
Viewing all articles
Browse latest Browse all 7513

利用Timer1的Up-and-Down mode做PWM的问题

$
0
0

如题,我的程序如下:

void PWM_Init(void)
{
P1DIR |= BV(0);             //P10定义为输出
P1SEL |= BV(0);            //P10设置为外设功能;
PERCFG |= BV(6);

T1CTL = 0x0F;              //128分频,Up&Down模式
T1CCTL0 = 0x64;        //CMP = 100, Clear output on compare-up,set on 0
T1CC0H = 0xFF;         
T1CC0L = 0x00;

T1CCTL2 = 0x64; 
T1CC2 = 256 * sPWM_P10;
T1CC2H = T1CC2/256; 
T1CC2L = T1CC2%256; 
}

sPWM_P10 = (uint8)(0xFF * (100 - nPWM) * 0.01);   // nPWM取值在0~100

问题:

在执行程序后

nPWM = 0,输出正PWM = 0%;

nPWM = 1,输出正PWM = 99%;

nPWM = 20,输出正PWM = 80%;

nPWM = 80,输出正PWM = 20%;

nPWM = 99,输出正PWM = 1%;

nPWM = 100,输出正PWM = 100%;

请教下,为何在nPWM=0,和nPWM=100时,输出正PWM的值是相反的?


Viewing all articles
Browse latest Browse all 7513

Trending Articles