有个案子准备用MS51FB9AE来开发,目前在调试PWM,但是我自动调节它调不了,送固定值是可以的,非常诡异的事情!请教大神,不知是哪里出的问题?
以下是PWM的初始化,
void SysInti(void)
{ P12_PUSHPULL_MODE; PWM2_P10_OUTPUT_ENABLE;
/**********************************************************************
PWM frequency = Fpwm/((PWMPH,PWMPL) + 1) <Fpwm = Fsys/PWM_CLOCK_DIV>
= (16MHz/8)/(0x7CF + 1)
= 1KHz (1ms)
***********************************************************************/
PWM_IMDEPENDENT_MODE;
PWM_CLOCK_DIV_8;
PWMPH = 0x07;
PWMPL = 0xCf; //1Khz
/*-------- PWM start run--------------*/
set_PWMCON0_LOAD;
set_PWMCON0_PWMRUN;
}
void main(void)
{
SysInti();
while(1){
Delay(200);
if(PWMData<2000)PWMData+=100; else PWMData=100;
PWM2H=PWMData/256;
PWM2L=PWMData;
}
}
void Delay(uint16_t x)
{
uint16_t i,j;
for(i=0;i<x;i++){
for(j=0;j<1000;j++){;}
}
|