/* INOUT.H */ /* Routines for D/A and encoder boards */ /* D/A routine */ void put_da(int channel,float voltage) { /* 2 channels numbered 0 and 1 */ /* Routine returns the voltage within limits */ #define daadd 0x304 /* Address of D/A board */ #define umax 5. /* Maximum D/A voltage */ int dacount,msb,lsb; if (voltage>umax) {voltage=umax;} /* Output limiting */ if (voltage<-umax) {voltage=-umax;} dacount=2048-(int)(voltage*2047./umax); msb=(int)(dacount/16); lsb=dacount-msb*16; lsb=lsb*16; outp(daadd+channel*2,lsb); outp(daadd+1+channel*2,msb); } /* Encoder routines */ /* Board initialization & reset of counter */ void encoder_init() { #define encadd 0x310 /* Address of encoder board */ outp(encadd+2,0x68); outp(encadd+2,0xC3); outp(encadd+2,0xA0); outp(encadd+2,0x05); outp(encadd+6,0x00); } /* Routine to read the counter */ float get_encoder() { union returner {char in[3];long out;} rd; rd.out=0; outp(encadd+2,0x03); rd.in[0]=inp(encadd+4); rd.in[1]=inp(encadd+4); rd.in[2]=inp(encadd+4); if(rd.out>=8388608)rd.out=rd.out-16777216; return (float)(rd.out)*0.0031415926; }