/***************************************************************************** * SAMPLE2.C : TIMER DRIVEN INTERRUPTS * * * * This is a demonstration program to acquire data using timer driven * * interrupts. * * This program must be built using the large model. * * * * The board should be set as follows: * * -- Polarity set to bipolar -- S2 TO BIP * * -- 16 channel singled ended mode -- S3 TO 16CH * * -- On board clock set to 1 MHz -- CLOCK jumper to 1MHZ * * * * LAST MODIFICATION: 2/3/98 * * * *****************************************************************************/ #include #include #include #include #include #include "aa16drvc.h" #ifndef FALSE #define FALSE 0 #define TRUE !FALSE #endif /* These variable MUST be declared as global. They are the ones whose offsets are passed to the driver routine. If they are not global then the driver will not find their segment. */ unsigned pntbuf[50],statcode,task; int datbuf[50],params[7]; unsigned AskForBaseAddress(unsigned int OldOne) { char msg[7]; int NewOne = 0, Success = 0, Dummy; int AddrInputPosX, AddrInputPosY; puts("\nPlease enter the Base Address for your card (in hex)"); printf("or press ENTER for %X.\n>", OldOne); AddrInputPosX = wherex(); AddrInputPosY = wherey(); do { gotoxy(AddrInputPosX, AddrInputPosY); clreol(); msg[0] = 5; msg[1] = 0; cgets(msg); sscanf(msg + 2, "%x", &NewOne); Success = 1; Dummy = NewOne; if (msg[1] == 0) { gotoxy(AddrInputPosX, AddrInputPosY); printf("%X", OldOne); Success = 1; Dummy = OldOne; } } while(!Success); return (Dummy); } /* end of AskForBaseAddress */ /***************************************************************************** * FUNCTION: call_driver -- local routine * * * * PURPOSE: Performs the call to the driver package. * * * * INPUT: None. * * * * CALLS: aa16drv - entry point to driver package. * * * * OUTPUT: Returns the error code supplied by the driver routine. * * * *****************************************************************************/ unsigned call_driver() { aa16drv(FP_OFF(&task),FP_OFF(params),FP_OFF(&statcode)); /* call the driver */ /* this section checks for an error code */ if (statcode > 0) { printf("A status error code of %i was detected.\n",statcode); printf("Program terminated."); return(statcode); } else return(0); } /* end call_driver */ /***************************************************************************** * FUNCTION: setup -- local routine * * * * PURPOSE: Sets up the driver package to read all 16 A/D channels. * * * * INPUT: None. * * * * CALLS: call_driver - entry point to driver package. * * * * OUTPUT: Returns the error code supplied by the driver routine. * * * *****************************************************************************/ unsigned setup(Address) { unsigned I,status; /* initialize the board */ params[0] = Address; /* starting board address */ params[1] = 5; /* 5 VOLT scale */ task = 0; status = call_driver(); if (status > 0) return(status); /* set up the timers to divide the 1 MHz clock by 1000 to get 100Hz */ task = 14; params[0] = 1; /* set up counter 1 */ params[1] = 3; /* counter 1 set to mode 3 */ params[2] = 100; /* divide by 100 */ status = call_driver(); if (status > 0) return(status); /* set up the timers to divide the 1 MHz clock by 1000 to get 100Hz */ task = 14; params[0] = 2; /* set up counter 2 */ params[1] = 3; /* counter 2 set to mode 3 */ params[2] = 10; /* divide by 10 */ status = call_driver(); if (status > 0) return(status); /* Set the sample and hold settle time, this is only required for very fast computers such as 386's. */ task = 11; params[0] = 5; /* subtask 5 of task 11 */ params[1] = 50; /* settle count */ status = call_driver(); if (status > 0) return(status); /* Clear the point list. */ task = 11; params[0] = 2; /* subtask 2 of task 11 */ status = call_driver(); if (status > 0) return(status); /* install all channels of 1 sub mulitplexer into the point list, thus only channel 0 of the A/D is used. */ task = 5; params[0] = 0; /* lower point address limit */ params[1] = 15; /* upper point address limit */ status = call_driver(); if (status > 0) return(status); /* Install point address 0 as a reference junction in degrees F */ task = 10; params[0] = 2; /* sub task 2, install curve */ params[1] = 0; /* setup point address 0 */ params[2] = 84; /* ASCII T = reference junction */ params[3] = 70; /* ASCII F = degrees F */ //status = call_driver(); if (status > 0) return(status); /* Install point address 1 as a type T thermocouple in degress F */ task = 10; params[0] = 2; /* sub task 2, install curve */ params[1] = 1; /* setup point address 1 */ params[2] = 116; /* ASCII t = t thermocouple */ params[3] = 70; /* ASCII F = degrees F */ status = call_driver(); if (status > 0) return(status); /* assign proper gain code for t type thermocouple to point address 1, which for this driver is gain code = 5 */ task = 4; params[0] = 1; /* range for gain assignment */ params[1] = 1; /* is point address 1 only */ params[2] = 5; /* assign gain code 5 */ status = call_driver(); return(status); } /* end setup */ /***************************************************************************** * FUNCTION: get_readings -- local routine * * * * PURPOSE: Reads the 16 A/D channels and displays them on the screen. * * * * INPUT: None. * * * * CALLS: call_driver - entry point to driver package. * * * * OUTPUT: Returns the error code supplied by the driver routine. * *****************************************************************************/ unsigned get_readings() { unsigned I,status; /* Reset the point list index. */ task = 11; params[0] = 1; /* subtask 1, reset point list index */ status = call_driver(); if (status > 0) return(status); /* now take the conversions, the driver will not exit until all conversions have been made. */ task = 9; params[0] = 1; /* subtask 1 - install ints */ params[1] = 5; /* use IRQ 5 */ params[2] = 16; /* do 16 conversions */ params[3] = FP_OFF(datbuf); /* offset of data buffer */ params[4] = FP_OFF(pntbuf); /* offset of point/gain buffer */ params[5] = 1; status = call_driver(); if (status > 0) return(status); /* exit if error */ /* this loop waits for the driver to signal that it has completed all conversions. If this were an application, other task could be performed within this loop while waiting for the conversion to be completed. */ task = 9; params[0] = 2; /* subtask 2, check int status */ do { /* other code could be placed here while you are waiting */ status = call_driver(); } while (params[1] > 0); /* this will be 0 when done */ /* now if OK list the data to the screen */ clrscr(); printf("\n POINT ADDRESS GAIN VALUE\n"); printf(" ------------- ---- -----\n"); for (I = 0;I < 16;I++) { printf("%12i%13i%10i\n",pntbuf[I] / 256,pntbuf[I] & 0xff,datbuf[I]); } return(0); } /* end get_readings */ /***************************************************************************** * FUNCTION: main -- local routine * * * * PURPOSE: Controls program flow, detects when user is ready to exit. * * * * INPUT: None. * * * * CALLS: setup - set up program and drivers. * * get_readings - read the A/D channels and display. * * * * OUTPUT: None. * *****************************************************************************/ void main() { unsigned int Address; unsigned status; char ch; clrscr(); printf( " SAMPLE2.C : TIMER DRIVEN INTERRUPTS \n" " \n" " This is a demonstration program to acquire data using timer driven \n" " interrupts. \n\n" ); Address=AskForBaseAddress(0x350); clrscr(); printf( "\n\n\n Board Configuration:\n\n"); printf(" -- Base Address is %x hex\n",Address); printf(" -- Polarity set to bipolar -- S2 TO BIP (required) \n" " -- Range is 5 volts \n" " -- 16 channel singled ended mode -- S3 TO 16CH (required) \n" " -- On board clock set to 1 MHz -- CLOCK jumper to 1MHZ (required) \n" " -- Both TMP jumpers must be installed (required) \n" " -- The offset must be in STD position (required) \n" " -- One jumper is on OV0; none on OT (required) \n" " -- All other jumper settings are irrelevant \n"); printf("\n\n\nPress any key to continue, or press 'E' to exit."); ch=getch(); clrscr(); status = setup(Address); /* set up program and the driver */ if (status != 0) return; /* is status > 0 then board error */ while (ch != 'E' && ch != 'e') { /* display current values for the 16 channels */ status = get_readings(); if (status != 0) return; /* if status > 0 then error */ /* check for program exit */ printf("\n\nPress 'E' to exit the program. Press any other key to rescan the data..."); while (!kbhit()); /* wait for key press */ ch = getch(); /* read the char */ } clrscr(); } /* end main program */