/****************************************************************************** * Program to use the experimental ADC, ver. beta 2.01 * * * * by * * * * L. Padilla (e-mail: padilla at domain "gae ucm es") * * * * Madrid, 1995 - 1997 * * * * Latest version at http://www.gae.ucm.es/~padilla/extrawork/adc.c * ******************************************************************************/ #define DPPORT 0x0378 /* Data parallel port 1. */ #define SPPORT 0x0379 /* Status parallel port 1. */ #define CPPORT 0x037A /* Control parallel port 1. */ #define CSPORT 0x03FC /* Control serial port 1. */ #define SBIT 0x08 /* Pin 15 parallel port. */ #define SIZE 1500000uL /* Bytes to record. */ #include #include #include main (void) { unsigned char byte, delay; register unsigned char i; register unsigned long j; clock_t time1, time2, time3, time4; FILE * file; printf ("\n"); outp (CPPORT, 0xFB); /* Sets to 0v control pins of parallel port 1 to avoid possible drifts. */ outp (CSPORT, 0x00); /* Sets to around -11v pin number 4 of serial port 1 to feed polarization voltage. */ outp (DPPORT, 0x80); /* Sets initial voltage of DAC (half way). */ file = fopen ("sonido.dat", "wb"); /* In RAM disk (highly recommended) */ time1 = clock (); for (j = 0uL; j < SIZE; j++) /* Digitalizes while space remains. */ { for (i = byte = 0x80; i; i >>= 1) /* Digitalization loop. */ { outp (DPPORT, byte); /* Generates reference V with DAC. */ if (inp (SPPORT) & SBIT) /* Reads result. */ byte |= i >> 1; /* Input signal is higher than DAC. */ else byte = (byte - i) | (i >> 1); /* Signal is lower than DAC. */ } fwrite (& byte, 1, 1, file); /* Stores data in file. */ } time2 = clock (); fclose (file); /* for (j = 0; j < space - 1; j++) /* Filters high frequency (optional). * / (*(buffer + j)) = ((*(buffer + j)) + (*(buffer + j + 1)))/2; /* */ outp (DPPORT, 0x80); /* Sets initial voltage of DAC (half way). */ printf ("Enter delay (0 - 255): "); /* To match play and record times */ scanf ("%u", & delay); /* Waits for enter. */ /* delay = 77; /* */ time3 = clock (); file = fopen ("sonido.dat", "rb"); for (j = 0uL; j < SIZE; j++) { for (i = 0u; i < delay; i++) /* Delay loop. */ ; fread (& byte, 1, 1, file); /* Reads data from file. */ byte = ~ byte; /* Inverts, setting right value, otherwise only exists a phase difference of 180 deg. */ outp (DPPORT, byte); /* Plays digitalization with DAC, but speed will be incorrect. */ /* printf ("%2.2X\n", byte); /* Prints digitalized value (hex). */ /* printf ("%u %u\n", j, byte); /* Prints digitalized value (dec). */ } time4 = clock (); fclose (file); outp (DPPORT, 0x00); /* Sets to 0v the 8 data pins of parallel port 1. */ printf ("Time of record: %lf\n", (float) (time2 - time1)/(float) CLK_TCK); printf ("Time of play : %lf\n", (float) (time4 - time3)/(float) CLK_TCK); printf ("\n"); return 0; }