initial code added for device under test (DUT) ammeter#2
authorstephen
Wed, 08 Mar 2017 12:16:44 +0000
changeset 437330bec02cfc
parent 42 d1d3b9da2ea3
child 44 1983a3cc0647
initial code added for device under test (DUT) ammeter#2
stateManager.c
stateManager.h
     1.1 --- a/stateManager.c	Wed Jan 25 14:50:20 2017 +0000
     1.2 +++ b/stateManager.c	Wed Mar 08 12:16:44 2017 +0000
     1.3 @@ -91,17 +91,13 @@
     1.4  {
     1.5  	float fValue;
     1.6  	int Value;
     1.7 -
     1.8  	CPhidgetInterfaceKit_setRatiometric (IFK, PTRUE);				// set to ratiometric
     1.9  	sleep(2);														// wait at least 800ms
    1.10  	CPhidgetInterfaceKit_getSensorRawValue(IFK, AMPINDEX, &Value);   // Ampmeter
    1.11 -
    1.12  	// Calibration
    1.13  	// when the phidget is not connected to anything it returns a voltage of -2mA. 
    1.14  	// this must be adjusted to zero by adding 2mA
    1.15  	Value += 2;
    1.16 -
    1.17 -
    1.18  	// http://www.phidgets.com/documentation/Phidgets/1122.pdf
    1.19  	// If you want maximum accuracy, you can use the RawSensorValue property from the PhidgetInterfaceKit. 
    1.20  	// To adjust a formula, substitute (SensorValue) with (RawSensorValue / 4.095)
    1.21 @@ -113,6 +109,28 @@
    1.22  	return fValue * -1;							 // invert so + is charging and - is amp draw
    1.23  }
    1.24  
    1.25 +int getDUTAmps(CPhidgetInterfaceKitHandle IFK)
    1.26 +{
    1.27 +	float fValue;
    1.28 +	int Value;
    1.29 +	CPhidgetInterfaceKit_setRatiometric (IFK, PTRUE);				// set to ratiometric
    1.30 +	sleep(2);														// wait at least 800ms
    1.31 +	CPhidgetInterfaceKit_getSensorRawValue(IFK, DUTINDEX, &Value);   // Ampmeter
    1.32 +	// Calibration
    1.33 +	// when the phidget is not connected to anything it returns a voltage of -2mA. 
    1.34 +	// this must be adjusted to zero by adding 2mA
    1.35 +	Value += 2;
    1.36 +	// http://www.phidgets.com/documentation/Phidgets/1122.pdf
    1.37 +	// If you want maximum accuracy, you can use the RawSensorValue property from the PhidgetInterfaceKit. 
    1.38 +	// To adjust a formula, substitute (SensorValue) with (RawSensorValue / 4.095)
    1.39 +	//
    1.40 +	// The formula to translate SensorValue into Current is:
    1.41 +	// DC Amps = (SensorValue / 13.2) - 37.8787	
    1.42 +	fValue = Value;
    1.43 +	fValue = (((fValue/4.095)/13.2)-37.8787)*1000;  // multiply raw value to get amps
    1.44 +	return fValue ;	
    1.45 +}
    1.46 +
    1.47  int updateSnapshotfile(const char *snapFileName, int Voltage, int Amps,  int state, int spiking)
    1.48  {
    1.49  	// Snapshot file is a single line file, overwritten each time with the current and latest values
    1.50 @@ -144,7 +162,7 @@
    1.51  	}		
    1.52  }
    1.53  
    1.54 -int updateLogfile(FILE *logfile, int Voltage, int Amps, int state, int spiking, const char *progName)
    1.55 +int updateLogfile(FILE *logfile, int Voltage, int Amps, int dutAmps, int state, int spiking, const char *progName)
    1.56  {   
    1.57  	time_t rawTime;
    1.58  	struct tm * timeInfo;
    1.59 @@ -166,7 +184,14 @@
    1.60  	}
    1.61  	else
    1.62  	{
    1.63 -		snprintf( logEntry, 200, "%s %s %s %d %d %s %s\n", timeStr, hostName, progName, Voltage, Amps, getStateDesc(state), spikingStr );
    1.64 +		if (dutAmps>0) {
    1.65 +			snprintf( logEntry, 200, "%s %s %s %d %d %s %s DUT: %d\n", 
    1.66 +				timeStr, hostName, progName, Voltage, Amps, getStateDesc(state), spikingStr, dutAmps );
    1.67 +		} else {
    1.68 +			// same as oldie
    1.69 +			snprintf( logEntry, 200, "%s %s %s %d %d %s %s\n", 
    1.70 +				timeStr, hostName, progName, Voltage, Amps, getStateDesc(state), spikingStr);
    1.71 +		}
    1.72  		fputs( logEntry, logfile );
    1.73  		fflush( logfile );
    1.74  		return 0;
    1.75 @@ -342,6 +367,7 @@
    1.76  	int err;
    1.77  	int lightTrigger;
    1.78  	int prevVoltage = 0, Voltage = 0, Amps = 0;
    1.79 +	int dutAmps=0;
    1.80  	int tts;
    1.81  	int newState = 0;
    1.82  	int ret;
    1.83 @@ -447,6 +473,7 @@
    1.84  		spiking = testVoltageSpike(&prevVoltage, &prevVoltageTime, &Voltage, &VoltageTime);
    1.85  		
    1.86  		Amps = getAmps(IFK);
    1.87 +		dutAmps = getDUTAmps(IFK);
    1.88  
    1.89  		getnewState (Voltage,
    1.90  			bootflag,
    1.91 @@ -456,7 +483,7 @@
    1.92  			sleepHourEnd,
    1.93  			sleepMinEnd);
    1.94  
    1.95 -		updateLogfile (logfile, Voltage, Amps, newState, spiking, progName);
    1.96 +		updateLogfile (logfile, Voltage, Amps, dutAmps, newState, spiking, progName);
    1.97  		updateSnapshotfile (snapFileName, Voltage, Amps, newState, spiking);
    1.98  
    1.99  		// Now Update the LCD
     2.1 --- a/stateManager.h	Wed Jan 25 14:50:20 2017 +0000
     2.2 +++ b/stateManager.h	Wed Mar 08 12:16:44 2017 +0000
     2.3 @@ -23,6 +23,7 @@
     2.4  #define IFK_WAIT_TIME   5000    //  5 second wait time
     2.5  #define LCD_WAIT_TIME   10000   // 10 second wait time
     2.6  
     2.7 +#define DUTINDEX    0 // Index of Device Under Test (DUT) ammeter
     2.8  #define VOLTINDEX   1
     2.9  #define AMPINDEX    0
    2.10