/***************************************************************************** C LANGUAGE SAMPLE 4: SAMPLE4.C The following program demonstrates the use of driver task 19, Multiple Conversions with Analog Trigger. In this sample, point 0 in the point list is used to trigger A/D conversions. The porgram makes four calls to the task to demonstrate high-side and low-side triggering on both bipolar and unipolar ranges. This program must be built using the large model. LAST MODIFICATION: 2/4/98 *****************************************************************************/ #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 statcode,task; int datbuf[24],param[5]; /* Function to ask for the Base Address */ 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; a12gdrv(FP_OFF(&task),FP_OFF(param),FP_OFF(&statcode)); /* this section checks for an error code */ if (statcode > 0) { if (kbhit()) getch(); 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 package, with the first 16 point addresses. * * * * 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; param[0] = Address; /* assigning board address to param[0] */ param[1] = 5; /* IRQ5 */ param[2] = 1; /* set for programmable gains */ status = call_driver(); /* call routine to call ext module */ if (status > 0) return(status); /* if status > 0 then error */ return(status); } /* end setup */ /***************************************************************************** * FUNCTION: get_readings -- local routine * * * * 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; unsigned offdatbuf; int *temp; temp = datbuf; offdatbuf = FP_OFF(temp); puts("\nFirst case: Bipolar with high-side trigger. Conversions will begin"); puts("when the input voltage exceeds 2.5v."); puts("Press any key to start."); getch(); task = 19; param[0] = offdatbuf; /* Offset to the memory storage location. */ param[1] = 24; /* Number of conversions to perform. */ param[2] = 1024; /* Trigger level in counts. Corresponds to +2.5v in a bipolar 10 volt range (+/-5v). */ param[3] = 1; /* High side trigger. Tells the driver to trigger when the data in the channel exceeds the trigger value. */ param[4] = 0; /* Which data point to trigger on. */ status = call_driver(); if (status != 0) return(status); for(I=0;I<24;I++) { printf("%5d ",datbuf[I]); if (!((I+1) % 8)) printf("\n"); } printf("\n"); puts("Second case: Bipolar with low-side trigger. Conversions will begin"); puts("when the input voltage drops below 2.5v."); puts("Press any key to start."); getch(); task = 19; param[0] = offdatbuf; /* Offset to the memory storage location. */ param[1] = 24; /* Number of conversions to perform. */ param[2] = 1024; /* Trigger level in counts. Corresponds to +2.5v in a bipolar 10 volt range (+/-5v). */ param[3] = -1; /* Low side trigger. Tells the driver to trigger when the data in the channel drops lower than the trigger value. */ param[4] = 0; /* Which data point to trigger on. */ status = call_driver(); if (status != 0) return(status); for(I=0;I<24;I++) { printf("%5d ",datbuf[I]); if (!((I+1) % 8)) printf("\n"); } printf("\n"); puts("Third case: Unipolar with high-side trigger. Conversions will begin"); puts("when the input voltage exceeds 2.5v."); puts("Press any key to start."); getch(); task = 18; param[0] = 9; status = call_driver(); if (status != 0) return(status); task = 19; param[0] = offdatbuf; /* Offset to the memory storage location. */ param[1] = 24; /* Number of conversions to perform. */ param[2] = 1024; /* Trigger level in counts. Corresponds to +2.5v in a unipolar 10 volt range (0-10v). */ param[3] = 1; /* High side trigger. Tells the driver to trigger when the data in the channel exceeds the trigger value. */ param[4] = 0; /* Which data point to trigger on. */ status = call_driver(); if (status != 0) return(status); for(I=0;I<24;I++) { printf("%5d ",datbuf[I]); if (!((I+1) % 8)) printf("\n"); } printf("\n"); puts("Fourth case: Unipolar with low-side trigger. Conversions will begin"); puts("when the input voltage drops below 2.5v."); puts("Press any key to start."); getch(); task = 19; param[0] = offdatbuf; /* Offset to the memory storage location. */ param[1] = 24; /* Number of conversions to perform. */ param[2] = 1024; /* Trigger level in counts. Corresponds to +2.5v in a unipolar 10 volt range (0-10v). */ param[3] = -1; /* Low side trigger. Tells the driver to trigger when the data in the channel drops lower than the trigger value. */ param[4] = 0; /* Which data point to trigger on. */ status = call_driver(); if (status != 0) return(status); for(I=0;I<24;I++) { printf("%5d ",datbuf[I]); if (!((I+1) % 8)) printf("\n"); } printf("\n"); return(status); } /* 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(" SAMPLE4.C : AD12-8G BOARD\n"); puts("The following program demonstrates the use of driver task 19."); puts("This demonstration includes high-side and low-side triggering,"); puts("in both biploar and unipolar modes. To exit the program"); puts("prematurely, press any key.\n"); Address=AskForBaseAddress(0x350); /* Check for card presence at Base Address */ clrscr(); printf("\n\n\nBoard Configuration:\n\n"); printf(" -- The Base Address is %X hex\n",Address); puts(" -- Jumper IRQ5 should be installed (required)"); puts(" -- An adjustable voltage source is needed (required)"); puts(" -- Connect the voltage source to pins 19 (low)"); puts(" and 37 (high) (channel 0 inputs) (required)"); puts(" -- The board should be set to programmable gains (required)"); puts(" -- All other jumper settings are irrevelant."); puts("\n\n\n\nPress any key to start."); 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 A/D 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 */