|
我用示波器测得时候总达不到微妙级延时示波器显示为2.5us - 7us范围,请帮分析一下?
void Delay_us(int time) //1us
{
unsigned int val = (PCLK>>1)/1000000 - 1; //1us
v_pPWMregs->rTCFG0 &= ~(0xff<<8);
v_pPWMregs->rTCFG0 |= 0<<8; //prescaler = 0+1
v_pPWMregs->rTCFG1 &= ~(0xf<<12);
v_pPWMregs->rTCFG1 |= 0<<12; //Timer3 mux = 1/2
v_pPWMregs->rTCNTB3 = val;
// v_pPWMregs->rTCMPB3 = val>>1; // 50%
v_pPWMregs->rTCON &= ~(0xf<<16);
v_pPWMregs->rTCON |= 0xb<<16; //interval, inv-off, update TCNTB3&TCMPB3, start timer 3
v_pPWMregs->rTCON &= ~(2<<16); //clear manual update bit
while(time--) {
while(v_pPWMregs->rTCNTO3>=val>>1);
while(v_pPWMregs->rTCNTO3>1);
};
}
|
|