/**************************************************************************** * C LANGUAGE SAMPLE 3: SAMPLE3.C * * * * This sample exercises the AD12-8G's programmable gain amplifier by * * reading a user selected channel repeatedly at each gain. * * This program must be built using the large model. * * * * LAST MODIFICATION DATE: 2/4/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; datbuf[200],params[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; 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: Initializes driver. * * * * INPUT: None. * * * * CALLS: call_driver(), local routine * * * * OUTPUT: Returns error code supplied by the driver routine. * * * ****************************************************************************/ unsigned setup(Address) { unsigned status; /* This function performs board initialization by calling task 0 of the driver. */ task = 0; /* TASK0 - Initialize driver. See manual for a complete task description. */ statcode = 0; /* Clear the global status variable before the call to the driver. */ params[0] = Address; /* Stores the card base address. */ params[1] = 5; /* Stores IRQ5 - Not needed for this sample. */ params[2] = 0; /* Stores the sub-multiplexer mode. In this case, no sub-multiplexer is needed. */ status = call_driver(); if (status != 0) return(status); task = 11; /* Resent the sttle time for faster computers. */ params[0] = 4; params[1] = 100; status = call_driver(); return(status); } /**************************************************************************** * FUNCTION: get_readings() -- local routine * * * * PURPOSE: With a user selected channel, this routine takes a total of * * nine readings, using a different gain level each time. This * * routine utilizes TASK18, set programmable gains, to accomplish* * this. Note: This sample will only work with an AD12-8G. * * * * INPUT: None. * * * * CALLS: call_driver, local routine * * * * OUTPUT: Returns error code supplied by the driver. * * * ****************************************************************************/ unsigned get_readings() { char x; unsigned status; unsigned user_channel,gain_value; clrscr(); do { gotoxy(1,6); /* Goto the 'top' of the display */ for(x=0;x<8;x++) /* This loop runs through all of the gain codes. */ { user_channel = x * 16; gain_value = x; /* Set the gain value. */ if (gain_value != 0) /* Because the gain codes jump from 0 to 8, it is necessary to offset the value. */ gain_value += 7; task=18; params[0]= gain_value; /* Set the gain with a call to task 18 */ status=call_driver(); if (status>0) return(status); task=6; params[0]=user_channel; status=call_driver(); if (status != 0) return(status); printf("counts on channel #%i, Gain code of %i: %i \n",user_channel/16, gain_value,params[1]); }; printf("\n\n\nPress any key to continue."); if (status !=0) return(status); } while (!kbhit()); getch(); return(status); } /**************************************************************************** * 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(" SAMPLE3.C : AD12-8G BOARD\n"); puts("This program demonstrates the use of driver Task 18, Set "); puts("Programmable Gain. The program reads from all eight channels, "); puts("using a different gain setting for each. The data is constantly "); puts("refreshed until a key is pressed.\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(" -- All other 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(); 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 restart...\n"); ch = getch(); /* read the char */ } while (ch != 'E' && ch != 'e'); } /* end main program */