//some things to try -- autodetect polarity and number of channels // by taking readings in 'silent mode' after the lpt port# has been // input. Take 5000 samples or so, with bipolar control bits set, // and if any are negative, keep software on bipolar mode, else // set the control bit to unipolar mode. // Another thing to try: autodetect which channels (0 thru 7) are on // the same way. Take 5000 samples and for those channels that are // always between +1mv and -1mv, don't sample. // Another: autodetect the LPT number (1,2 or 3) write data to them.. // These things make program More user friendly and more prone to errors... #include //using the internal clk won't give a #include //big speed boost -- see page 12, 13 #include //my program uses 24 clks/conversion #include //see page14 and pg15 diagram 11a,b //for program that uses 15 or 16 clks // per conversion. (5000/s -> 8000/s) int DPORT; int SPORT; //with mux on, this program //gets ~5000sps (not bad!!!) clockTB1(int ch, int polarity); //predefined because it is called from within function setup() doADC(int ch, int polarity); //predefined function because it is called from within clockTB1() //////////////////////////////////////////////////////////////////////////// //////////////////// SETUP() /////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////// setup(){ int multiVar; int channels, polarity; char unibi[9]; cout << "Please enter your LPT port number (1,2 or 3)\n\n"; cin >> multiVar; //semi-autodetection part.. DPORT = *(( int far *)MK_FP(0x40, 6) + multiVar); SPORT=DPORT+1; cout << "\nHow many analogue channels would you like to work with today?\n\n"; cin >> channels; if (channels > 8 || channels < 1){ cout << "There are only 1 to 8 channels selectable, please try again.\n"; return(0);} clrscr(); cout << "OK, we will use analog input pins zero to " << channels-1; cout << " which is " << channels << " channels\n\n\n"; delay(1000); cout << "A later version of this program will allow you to select differential\n"; cout << "inputs, labelled channels and operation with some polar and some unipolar\n"; cout << "channels.\n\nBut for now please answer the question below..\n\n\n"; cout << "Do you want all your channels unipolar (0 to 5V analog inputs)\n"; cout << "Or do you want them all to be bipolar (-2.047 to +2.047V inputs)?\n\n"; cin >> unibi; clrscr(); if (unibi[0] == 'u'){ polarity = 'u'; cout << "OK, all channels zero thru " << channels-1 << " will be set to unipolar\n"; cout << "operation.. be sure to set the switch on the A2DMAX to unipolar operation.\n\n"; delay(1000); } else { polarity = 'b'; cout << "OK, channels zero thru " << channels-1 << " will be set to bipolar\n"; cout << "operation.. be sure to set the switch on the A2DMAX to bipolar operation.\n\n"; delay(1000); } cout << "\nPress any key to carry out your analog to digital conversions\n\n"; cout << "To quit anytime, press q."; while(getch()!='q'){ clrscr(); for(multiVar=0; multiVar 100) bit[i] = 1; else bit[i] = 0; bit[i] = bit[i] * pow(2, i); // (i = i*2^i) (binary to decimal formula) } digVal = bit[0]+bit[1]+bit[2]+bit[3]+bit[4]+bit[5]+bit[6]+bit[7]+bit[8]+bit[9]+bit[10]+bit[11]; if (polarity == 'b'){ //bipolar operation if (digVal>2047){ //2047 is as high as it gets, anything above digVal = digVal-4095;} //2047 is actually negative. } /* switch (ch) { case 0: cout << "\n\n\n ch0 " << digVal << "mv"; break; case 1: cout << " ch1 " << digVal << "mv"; break; case 2: cout << " ch2 " << digVal << "mv"; break; case 3: cout << " ch3 " << digVal << "mv" << "\n\n\n"; break; case 4: cout << " ch4 " << digVal << "mv"; break; case 5: cout << " ch5 " << digVal << "mv"; break; case 6: cout << " ch6 " << digVal << "mv"; break; case 7: cout << " ch7 " << digVal << "mv\n"; } */ switch (ch) { case 0: cout << "\n\n ch0 " << digVal << "mv\n\n"; break; case 1: cout << " ch1 " << digVal << "mv\n\n"; break; case 2: cout << " ch2 " << digVal << "mv\n\n"; break; case 3: cout << " ch3 " << digVal << "mv\n\n"; break; case 4: cout << " ch4 " << digVal << "mv\n\n"; break; case 5: cout << " ch5 " << digVal << "mv\n\n"; break; case 6: cout << " ch6 " << digVal << "mv\n\n"; break; case 7: cout << " ch7 " << digVal << "mv\n\n"; } } //////////////////////////////////////////////////////////////////////////// //////////////////// MAIN() //////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////// void main(){ setup(); }