/**************************************************/ /* Software control function generator */ /* Using the printer port */ /* Single square wave pulse on ext trigger */ /* Frequency depends on the loop value entered */ /**************************************************/ #include #include #include #include #include unsigned char trigg, inval, top, topcnt, printcontrol ; int loop, base, angle ; float maxv, minv ; /***********************************************/ /* Reads the input data */ /***********************************************/ unsigned char readport() { unsigned char dummy ; dummy = inp(base + 2) ; outp((base + 2), (dummy & 0X0D)) ; inval = (inp(base + 1) & 0XF0) >> 4 ; outp((base + 2), (dummy | 0X02)) ; inval = (inval | inp(base + 1) & 0XF0) ^ 0X88 ; return inval ; } /*************************************************/ /* output the high voltage */ /*************************************************/ void set_high() { unsigned int cnt, cntmax, bincode ; unsigned char pol, inprt ; int int_vout ; float vout, hvout ; time_t t, end_t ; if (maxv >= 0 ) { pol = 1 ; hvout = maxv ; } else { pol = 0 ; hvout = maxv * -1 ; } vout = 511.0 * (hvout / 5.0) ; int_vout = vout ; if (pol == 1) bincode = int_vout + 0X0200 ; else bincode = 0X0200 - int_vout ; printf("Setting high Voltage level: Vout %8.2f\n", maxv) ; cntmax = bincode & 0X3FF ; cnt = cntmax ; inprt = cnt ; topcnt = cnt >> 8 ; topcnt = topcnt & 0X03 ; if (topcnt == 0X00) top = (top & 0X02) | 0X01 ; if (topcnt == 0X01) top = top & 0X02 ; if (topcnt == 0X02) top = top | 0X05 ; if (topcnt == 0X03) top = (top & 0X02) | 0X04 ; outp(base, inprt) ; outp(base + 2, top) ; t = time(NULL) ; end_t = t + loop ; while(t < end_t) { t = time(NULL) ; } /* delay(loop) ; */ } /*************************************************/ /* output the low voltage */ /*************************************************/ void set_low() { unsigned int cnt, cntmin, bincode ; unsigned char pol, inprt ; int int_vout ; float vout, lvout ; if (minv >= 0 ) { pol = 1 ; lvout = minv ; } else { pol = 0 ; lvout = minv * -1 ; } vout = 511.0 * (lvout / 5.0) ; int_vout = vout ; if (pol == 1) bincode = int_vout + 0X0200 ; else bincode = 0X0200 - int_vout ; printf("Setting low voltage level: Vout %8.2f\n",minv) ; cntmin = bincode & 0X3FF ; cnt = cntmin ; inprt = cnt ; topcnt = cnt >> 8 ; topcnt = topcnt & 0X03 ; if (topcnt == 0X00) top = (top & 0X02) | 0X01 ; if (topcnt == 0X01) top = top & 0X02 ; if (topcnt == 0X02) top = top | 0X05 ; if (topcnt == 0X03) top = (top & 0X02) | 0X04 ; outp(base, inprt) ; outp(base + 2, top) ; } /**********************************************************/ /* Wait for high level and then return if signal goes low */ /**********************************************************/ void low_trig() { printf("Wait for signal to go high\n") ; while ((readport() & 0X01) != 0X01) ; printf("Waiting for low trigger \n") ; while ((readport() & 0X01) != 0X00) ; } /**********************************************************/ /* Wait for low level and then return if signal goes high */ /**********************************************************/ void hi_trig() { printf("Wait for signal to go low\n") ; while ((readport() & 0X01) != 0X00) ; printf("Waiting for high trigger\n") ; while ((readport() & 0X01) != 0X01) ; } /*****************************************************/ /* Main Program */ /*****************************************************/ int main(void) { int LPT1 = 0X378 ; int LPT2 = 0X278 ; int LPT3 = 0X3BC ; int dummy ; clrscr() ; base = LPT2 ; top = 0 ; printf ("SINGLE PULSE GENERATOR\n\n") ; printf ("Enter Pulse width in seconds ") ; scanf("%d", &loop) ; fflush(stdin) ; printf ("Enter max Voltage ") ; scanf("%f", &maxv) ; fflush(stdin) ; printf ("Enter min Voltage ") ; scanf("%f", &minv) ; fflush(stdin) ; printf ("Enter trigger level (0 or 1) ") ; scanf("%d", &trigg) ; fflush(stdin) ; set_low() ; if (trigg == 1) { printf("Triggering on logic 1 pulse \n\n") ; hi_trig() ; } else { printf("Triggering on logic 0 pulse\n\n") ; low_trig() ; } set_high() ; set_low() ; return 0 ; }