/***************************************************************************** * C LANGUAGE SAMPLE 5: SAMPLE5.C * * * * This program demonstrates the use of driver task 20 to read the * * frequency of an unknown TTL waveform. The following pins should * * be jumpered as described below: * * PIN 4 (CLK1) TO PIN 6 (OUT2) * * PIN 5 (OUT1) TO PIN 26 (IP2) AND PIN 21 (GATE0) * * Connect the unknown waveform to PIN 2 (CLK0) and PIN 11 (COMMON) * * 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],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; 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 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; params[0] = Address; /* assign the base address to param[0] */ params[1] = 5; /* IRQ5 */ params[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 * * * * PURPOSE: * * * * 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; double freq; int loop; task = 20; params[0] = 1000; /* Choose a 1000 mS gate pulse */ status = call_driver(); if (status != 0) return(status); freq = params[1]; printf("\nThe frequency is %lf. \n",freq); 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(" SAMPLE5.C : AD12-8G Measure Frequency\n"); puts("This sample demonstrates the use task 20 to measure the frequency"); puts("of an unknown TTL waveform.\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(" -- The board should be set to programmable gains (required)"); puts(" -- The following connections must be made: (required)"); puts(" PIN 4 (CLK1) TO PIN 6 (OUT2)"); puts(" PIN 5 (OUT1) TO PIN 26 (IP2) AND PIN 21 (GATE0)"); puts(" -- Connect the unknown waveform to PIN 2 (CLK0) and PIN 11 (COMMON)"); puts(" -- All remaining jumper settings are irrelevant."); puts("\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 */