#include #include #include #include #include #include "SSH0XDRV.H" unsigned BaseAddress=0x0350; unsigned LoadValue = 0; void ExitProgram(uint errorCode) { clrscr(); puts("A fatal error occured, program halted!"); printf("Error code returned was %i.\n", errorCode); } 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 */ int main(void) { uint *buf = (unsigned*) malloc(8); char Choice = 0; uint i, error; clrscr(); BaseAddress=AskForBaseAddress(BaseAddress); // Prompt for base address SetBaseAddress(BaseAddress); // Tell driver the base address // to use puts("Borland C Language Sample for SSH-0x. Version 1.06\n\n"); puts("This sample will show how to use the driver in mode 3."); puts("Specs for mode 3:"); puts(" External Trigger initiated."); puts(" Hardware timed periodic acquisition, w/o initial delay."); puts(" Process is gated by SEL3.\n"); puts("A/D Card setup:"); printf(" Card is at base address %3X Hex.\n", BaseAddress); if (AD_NAME() == AD128CARD) puts(" Remove jumpers D0-D3 on your AD12-8 card.\n"); puts(""); puts("SSH-0x Card setup:"); puts(" Please place the A/D CH SEL jumper at 0."); puts(" Switches A and B should be ON, C should be OFF on MODE CONTROL."); puts(" MASTER, 2, and 3 should be ON. Switches 1 and 4 should be OFF.\n"); puts("Press any key to continue...\n"); getch(); clrscr(); puts("Hold will be enabled by setting OP3 (PIN 10) high."); puts("When you set EXTTRG low, eight data points will be taken from"); puts("the SSH-0x card, one from each channel. (If you are using an"); puts("SSH-04 card, CH4-CH7 should be ignored.) When EXTTRG is set high"); puts("again the card will then be placed back into Sample mode and the"); puts("values will be displayed. Press a key to proceed..."); getch(); // The clock input for the AD12-8 card is 14.318Mhz / 32 // The first counter is loaded with the value 2, so that the input // to the second counter is approximately 223721.5908Hz // With a load value of 22372, we will get a 10Hz sampling rate. if (AD_NAME() == AD128CARD) LoadValue = 22372; // Assuming the clock jumper is set for a 1Mhz input, the input to // the second counter will be 500000Hz. A load value of 50000 is // required to achieve a 10Hz sampling rate. if (AD_NAME() == AD1216CARD) LoadValue = 50000; clrscr(); puts("Set external trigger (EXTTRG) low to start, or press a key to exit."); while (!Choice) { // As long as user wants to // continue // Call driver --- // Parameter list // 1 : First channel is channel number 0 // 2 : Last channel is channel number 7 // 3 : Repeat for 2 passes // 4 : Trigger source is by EXTTRG going low // 5 : No initial delay // 6 : Acquistion controlled by counters, so period is LoadValue // 7 : IRQ not necessary, set to 0 // 8 : Use Mode 3 // 9 : Data buffer is buf error = PerformSSHDataAcquisition(0,7,2,0,0,LoadValue,0,3,buf); if (error) { ExitProgram(error); return error; } EnableHold(); // Enable Hold clrscr(); if (ReadTriggerStatus()) { // If still low puts("You must release the trigger to continue."); // prompt release while (ReadTriggerStatus()); // until released } clrscr(); puts(" Pass 1 Pass 2 "); puts("\n Channel Volts Channel Volts\n"); // display data for for (i=0;i<=7;i++) // 8 channels used printf(" %2u % 1.3f " " %2u % 1.3f\n\r", i, (float)(buf[i] * (10.0 / 4096.0)) - 5.0, i, (float)(buf[i + 8] * (10.0 / 4096.0)) - 5.0); // display in volts puts("\n"); puts("\n\n\nSet external trigger (EXTTRG) low to continue or press a key"); puts("to exit."); while (!kbhit() && !ReadTriggerStatus()) // repeat until key // is pressed if (kbhit()) Choice = TRUE; } puts("Exiting Sample 3 program..."); return 0; }