PCI-1202/1602/180x Series Card
Multi-Function Boards
User Manual/ Ver. 4.8/ Mar. 2015/ PMH-0014-48/ Page: 57
timer2
for Machine Independent Timer
P180x_DelayUs(…) is designed for PCI-1800/1802 series.
P1202_DelayUs(…) is designed for PEX-1202/PCI-1202 series.
P1602_DelayUs(…) is designed for PCI-1602 series.
/* address of timer 2
= wAd2*4
address of ctrl = wAd3*4
input clock = 8 M
down count 8 time
= 1 μs
down count 65536/8 = 8192 μs --> max 8191 μs */
WORD P180X_DelayUs(WORD wDelayUs)
{
WORD wDownCount,wLow,wHigh,wVal;
double fTimeOut;
if (wDelayUs>=8191) return(InvalidateDelay);
wDownCount=wDelayUs*8;
wLow=wDownCount&0xff;
wHigh=(wDownCount>>8)&0xff;
outport((wAd3*4), 0xb0);
/* timer_2 mode_0 0xb0 */
outport((wAd2*4), wLow);
outport((wAd2*4), wHigh);
fTimeOut=1.0; // wait 1 to stop
for (;;)
{
wVal=inport(wAddrCtrl)&0x01;
if (wVal!=0) return(NoError);
/* if the timer is up, this bit will be 1 */
f=1.0;
if (fTimeOut>6553500.0)
return(DelayTimeOut);
}
}