Main Page | Modules | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages | Examples

daqcard.c

Go to the documentation of this file.
00001 /************************************************************************************************/
00002 /*! \file daqcard.c
00003 *  \brief Low-level c-code containing the "dscud.h"-related functions used with the DAQ card.
00004 *  \author $Author: jayhawk_hokie $
00005 *  \version $Revision: 1.7 $
00006 *  \date    $Date: 2007/08/02 23:18:28 $
00007 ************************************************************************************************/
00008 /*! 
00009 *
00010 ************************************************************************************************/
00011 
00012 #include <sys/time.h>
00013 #include "daqcard.h"
00014 #include "dscud.h"
00015 
00016 /*
00017 static int kbhit()
00018 {
00019         struct timeval timeout;
00020         fd_set rfds;
00021 
00022         timeout.tv_sec = 0;
00023         timeout.tv_usec = 0;
00024 
00025         FD_ZERO(&rfds);
00026         FD_SET(0, &rfds);
00027 
00028         return select(0+1, &rfds, NULL, NULL, &timeout);
00029 }
00030 */
00031 
00032 void DAConvert(card_t *mycard, int _channel, int _code)
00033 {
00034         switch (_channel)
00035         {
00036                 case 1:
00037                         if((mycard->result = dscDAConvert( mycard->dscb, mycard->chan38, _code)) != DE_NONE)
00038                         {
00039                                 dscGetLastError(&mycard->errorParams);
00040                                 fprintf(stderr, "%s %s\n", ERROR_PREFIX, mycard->errorParams.errstring);        
00041                         }
00042                         break;
00043                 case 2:
00044                         if((mycard->result = dscDAConvert( mycard->dscb, mycard->chan37, _code)) != DE_NONE)
00045                         {
00046                                 dscGetLastError(&mycard->errorParams);
00047                                 fprintf(stderr, "%s %s\n", ERROR_PREFIX, mycard->errorParams.errstring);        
00048                         }
00049                         break;
00050                 default:
00051                         printf(" bad channel vale: %d \n", _channel);
00052                         break;
00053         }
00054 }
00055 
00056 double ADscan(card_t *mycard, int _channel)
00057 {
00058         double out_voltage;
00059         if( (mycard->result = dscADScan( mycard->dscb, &(mycard->dscadscan), mycard->samples) ) != DE_NONE )
00060         {
00061                 fprintf(stderr, "%s%s\n", ERROR_PREFIX, dscGetErrorString( mycard->result) );
00062                 free( mycard->samples ); /* remember to free memory */
00063                 return 0;
00064         }
00065         /* NOTE: re-evaluate the following line for hardcoding issues. */
00066         mycard->voltage = (short)(mycard->dscadscan.sample_values[_channel]) / 32768.0 * 5.0; /* for 5V range */
00067         /* added the power thing in denominator (why?) */
00068         out_voltage = ((double)mycard->voltage)/pow(2,mycard->dscadsettings.gain); /* NOTE: this casting from a float to a double might not be good.*/
00069         return out_voltage;
00070 }
00071 
00072 
00073 int InitDAQCard(card_t *mycard)
00074 {
00075         /* Initialize the dscud library*/
00076         if( dscInit( DSC_VERSION ) != DE_NONE )
00077         {
00078                 dscGetLastError(&(mycard->errorParams));
00079                 fprintf( stderr, "%s %s\n", ERROR_PREFIX, (mycard->errorParams).errstring );
00080                 return 0;
00081         }
00082 
00083         /* Initialize the DMM-32-AT board */
00084         mycard->dsccb.boardtype = DSC_DMM32;
00085         mycard->dsccb.base_address = 0x300;
00086         mycard->dsccb.int_level = 3;
00087         mycard->dsccb.dma_level = 3;
00088         mycard->dsccb.clock_freq = 10000000l;
00089         if(dscInitBoard(DSC_DMM32, &(mycard->dsccb), &(mycard->dscb))!= DE_NONE)
00090         {
00091                 dscGetLastError(&(mycard->errorParams));
00092                 fprintf(stderr, "%s %s\n", ERROR_PREFIX, (mycard->errorParams).errstring);
00093                 return 1;
00094         }
00095 
00096         /* settings for AD scanning
00097          NOTE: These DAQ card settings will affect the calibration values needed for things
00098          like the MotionPak.  That is, the scale factor and bias given in the MoPak manual 
00099          would be correct if the DAQ card didn't have to perform conversions on the input signal.
00100          But since the DAQ card needs to shift and scale the input range to match its full scale
00101          voltage range, we must calculate our own calibration values.  That calibration is done 
00102          in a stand-alone executable, but we leave this reminder here so that the user remembers that
00103          fact in case the following settings are modified.
00104          Current Settings as of 5/24/04: Range = 10, Polarity = Bi, Gain = 1.
00105          As of 6/27/06, Range setting changed to 5
00106         */
00107 
00108         /* mycard->dscadsettings.range = RANGE_10; // 10 V range */
00109         mycard->dscadsettings.range = RANGE_5; /* 5 V range */
00110         /*mycard->dscadsettings.polarity = UNIPOLAR;  unipolar */
00111         mycard->dscadsettings.polarity = BIPOLAR; /* bipolar */
00112         mycard->dscadsettings.gain = GAIN_1;
00113         mycard->dscadsettings.load_cal = (BYTE)TRUE; /* calibration (???????????) */
00114         mycard->dscadsettings.current_channel = 0; /* from example (???) */
00115         mycard->dscadsettings.scan_interval = 2; /* from example (???) */
00116         
00117         mycard->result = dscADSetSettings( mycard->dscb, &(mycard->dscadsettings) );
00118         /*printf(" result is %d\n",mycard->result);*/
00119         /*if ( (mycard->result = dscADSetSettings( mycard->dscb, &(mycard->dscadsettings) ) ) != DE_NONE );
00120         {
00121                 printf("its in here stupid!\n");
00122                 fprintf(stderr, "%s%s\n", ERROR_PREFIX, dscGetErrorString( mycard->result ) );
00123                 return 0;
00124         
00125         }*/
00126         mycard->dscadscan.low_channel = (BYTE) 0;
00127         mycard->dscadscan.high_channel = (BYTE) 15;
00128         mycard->dscadscan.gain = GAIN_1;
00129 
00130         /* NOTE changed WORD to SWORD in this line to make compiler happy */
00131         mycard->samples = (SWORD*)malloc( sizeof(SWORD) * ( mycard->dscadscan.high_channel - mycard->dscadscan.low_channel + 1) );
00132 
00133         /* for analog thusters:*/
00134         mycard->chan38 = 0;
00135         mycard->chan37 = 1;
00136         /* for digital thrusters:*/
00137         BYTE config_bytes = 0x80;
00138         dscDIOSetConfig(mycard->dscb, &config_bytes);
00139 
00140 
00141         return 0;
00142 }
00143 /*Funtion to send a digital signal to daqcard */
00144 void DIOOutputByte(card_t *mycard,int port,BYTE output_b)
00145 {
00146         
00147         /*Sends digital signal to daqcard and prints an error message if operation fails */
00148         if( ( mycard->result = dscDIOOutputByte(mycard ->dscb, port, (BYTE)( output_b ) ) ) != DE_NONE ) {
00149                 dscGetLastError(&mycard->errorParams);
00150                 fprintf( stderr, "%s %s\n", ERROR_PREFIX, (mycard->errorParams).errstring );
00151         }
00152 }
00153 
00154 void ShutDownDAQCard(card_t *mycard)
00155 {
00156         /* free memory used by sample values */
00157         free(mycard->samples);
00158         
00159         /* free driver resources */
00160         dscFree();
00161 }
00162 
00163 /* Do not change the comments below - they will be added automatically by CVS*/
00164 /*****************************************************************************
00165 *       $Log: daqcard.c,v $
00166 *       Revision 1.7  2007/08/02 23:18:28  jayhawk_hokie
00167 *       Fixed Warnings.
00168 *       
00169 *       Revision 1.6  2006/06/27 20:15:10  bwilliam
00170 *       Changed to 5V range in initialization. Altered voltage formula
00171 *       in ADScan to match.
00172 *       
00173 *       Revision 1.5  2005/02/25 19:42:45  cakinli
00174 *       Attempt 5:
00175 *       Created Makefiles and organized include directives to reduce the number of
00176 *       include paths.  Reorganized libraries so that there is now one per source
00177 *       directory.  Each directory is self-contained in terms of its Makefile.
00178 *       The local Makefile in each directory includes src/config.mk, which has all
00179 *       the definitions and general and pattern rules.  So at most, to see what
00180 *       goes into building a target, a person needs to examine the Makefile in
00181 *       that directory, and ../config.mk.
00182 *       
00183 *       Revision 1.4  2004/06/15 15:00:23  shaigunjoe
00184 *       Added changes for digital signal
00185 *       
00186 *       Revision 1.3  2004/05/27 19:08:26  shoemaker
00187 *       Made changes corresponding to new daq card settings and calibration methods
00188 *       
00189 *       Revision 1.2  2004/04/11 19:35:50  shoemaker
00190 *       Fixed bugs in analog code and cleaned up random messages
00191 *       
00192 *       Revision 1.1  2004/03/29 17:42:36  shoemaker
00193 *       Initial submission of lowlevel c-code related to DAQ card
00194 *       
00195 *       
00196 ******************************************************************************/
00197 

Generated on Wed Sep 5 12:54:18 2007 for DSACSS Operational Code by  doxygen 1.3.9.1