/**************************************************************************** * C LANGUAGE SAMPLE 2: SAMPLE2.C * * * * This is a demonstration program to be used with the AD12-8G A/D board. * * The program uses timer driven interrupts to read 17 channels of data. * * This program is running in the manual gain mode for whichever mux board * * is attached. The following pins must be jumpered on the AD12-8G. * * 1) PIN 6, CTR2 OUT JUMPERED TO PIN 4, CTR1 CLK * * 2) PIN 5, CTR1 OUT JUMPERED TO PIN 24, INT IN * * This program must be built using the large model. * * * * LAST MODIFICATION: 2/3/98 * * * ****************************************************************************/ #include #include #include #include #include #include #include "a12gdrvc.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 A12GDRV routine. If they are not global then the driver will not find their segment. */ unsigned pntbuf[200],statcode,task; int datbuf[200],params[5]; 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: a12gdrv - entry point to driver package. * * * * OUTPUT: Returns the error code supplied by the driver routine. * * * ****************************************************************************/ unsigned call_driver() { char Input_Char; /* this section extracts the offset of the parameters that we will pass to the assembly driver */ statcode = 0; a12gdrv(FP_OFF(&task),FP_OFF(params),FP_OFF(&statcode)); /* this section checks for an error code */ if (statcode > 0) { printf("TASK %i has returned an error code of %i.\n",task,statcode); printf("Press 'C' to continue, any other key to exit.\n"); Input_Char = toupper(getche()); printf("\n"); if (Input_Char == 'C') statcode = 0; return(statcode); } else return(0); } /* end call_driver */ /**************************************************************************** * FUNCTION: setup -- local routine * * * * PURPOSE: Sets up the driver for 17 point address and sets up the * * counters that sync the interrupts. * * * * 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; task = 0; params[0] = Address; /* assigning the base address */ params[1] = 5; /* IRQ5 */ params[2] = 0; /* non-programmable gains */ status = call_driver(); /* call routine to call ext module */ if (status > 0) return(status); /* if status > 0 then error */ /* now reset the task list */ task = 11; params[0] = 2; status = call_driver(); /* call routine to call ext module */ if (status > 0) return(status); /* if status > 0 then error */ /* now assign the point range for 1 sub-multiplexer board attached to AD12-8G channel 0, and AD12-8G channel 1 is a direct input. */ task = 5; params[0] = 0; /* point range is 0 thru 16, for a total of 17 points */ params[1] = 16; status = call_driver(); /* call routine to call ext module */ if (status > 0) return(status); /* if status > 0 then error */ /* program the counters that trigger the interrupts. The output freq of the two counters is 1000 hz. Since counter 2 is driven by the system clock, the speed of the counters will depend on the host machine. These value are used on a 20MHz 386 computer. */ task = 14; params[0] = 2; /* set up up counter 2 */ params[1] = 3; /* to mode 3 */ params[2] = 100; status = call_driver(); /* call routine to call ext module */ if (status > 0) return(status); /* if status > 0 then error */ task = 14; params[0] = 1; /* set up up counter 1 */ params[1] = 3; /* to mode 3 */ params[2] = 5; status = call_driver(); /* call routine to call ext module */ if (status > 0) return(status); /* if status > 0 then error */ /* Set the driver settle time, only needed for faster computers */ task = 11; params[0] = 4; params[1] = 25; status = call_driver(); /* call routine to call ext module */ if (status > 0) return(status); /* if status > 0 then error */ return(0); } /* end setup */ /**************************************************************************** * FUNCTION: get_readings -- local routine * * * * PURPOSE: Reads the first 17 points in the point list using timer * * driven interrupts. * * * * INPUT: None. * * * * CALLS: call_driver - entry point to driver package. * * * * OUTPUT: Returns the error code supplied by the driver routine. * * * ****************************************************************************/ unsigned get_readings() { unsigned channel,I,status,*temp,offpntbuf,offdatbuf; int *temp1; /* now reset the task list index */ task = 11; params[0] = 1; status = call_driver(); /* call routine to call ext module */ if (status > 0) return(status); /* if status > 0 then error */ /* calculate the offset to the buffers so the driver can return the data. datbuf will contain the data read from the channels and pnt buffer will contain the channel and gain info. */ temp1 = datbuf; offdatbuf = FP_OFF(temp1); temp = pntbuf; offpntbuf = FP_OFF(temp); /* now use task 9 to do timer driven interrupt data acquisition */ /* first tell driver to start acquisition */ task = 9; params[0] = 1; /* sub task 1, interrupt scan */ params[1] = 17; /* number of points to gather */ params[2] = 0; params[3] = 0; status = call_driver(); /* call routine to call ext module */ if (status > 0) return(status); /* if status > 0 then error */ /* now wait for end of scan */ do { task = 9; params[0] = 2; /* sub task 2, wait for end of scan */ status = call_driver(); /* call routine to call ext module */ if (status > 0) return(status); /* if status > 0 then error */ } while (params[1] != 0); if (status > 0) return(status); /* if status > 0 then error */ /* now get the read information */ task = 9; params[0] = 3; /* sub task 3 - get the data */ params[1] = offdatbuf; /* offset to data bufffer */ params[2] = offpntbuf; /* offset to the point buffer */ params[3] = 17; /* number of samples returned here */ status = call_driver(); /* call routine to call ext module */ if (status > 0) return(status); /* if status > 0 then error */ /* now if OK list the data to the screen */ clrscr(); printf("\n CHANNEL VALUE\n"); printf(" ------- ------\n"); for (I = 0;I <= params[3] - 1;I++) { channel = (pntbuf[I] & 0xff00) / 256; /* upper bits contain ch number */ printf(" %2i %5i\n",channel,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(); puts(" SAMPLE2.C : AD12-8G Interrupt Driven Acquisition\n"); puts("This is a demonstration program to be used with the AD12-8G A/D board."); puts("The program uses timer driven interrupts to read 17 channels of data."); puts("This program is running in the manual gain mode for whichever mux board"); puts("is attached.\n"); Address=AskForBaseAddress(0x350); clrscr(); printf("\n\n\nBoard Configuration:\n\n"); printf(" -- The Base Address is %x hex\n",Address); puts(" -- The following pins must be jumpered: (required)"); puts(" PIN 6, CTR2 OUT JUMPERED TO PIN 4, CTR1 CLK"); puts(" PIN 5, CTR1 OUT JUMPERED TO PIN 24, INT IN"); puts(" -- All remaining jumper settings are irrelevant."); puts("\n\n\n\nPress any key to continue."); getch(); status = setup(Address); /* set up program and the driver */ if (status != 0) return; /* is status > 0 then board error */ do { status = get_readings(); /* display current values */ if (status != 0) return; /* if status > 0 then error */ /* check for program exit */ printf("\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 */ } while (ch != 'E' && ch != 'e'); } /* end main program */