예제 #1
0
파일: AD5933.cpp 프로젝트: HugoSBIO/drive
bool AD5933_Class::isValueReady()
{
	if ( (getStatusReg() & 0x02) == 0x02 )
		return true;
	else
		return false;
}
예제 #2
0
파일: AD5933.cpp 프로젝트: HugoSBIO/drive
bool AD5933_Class::compFreqRawSweep(int *arrReal, int *arrImag)
{
	int ctrReg = getByte(0x80); // Get the content of Control Register and put it into ctrReg
	if (setCtrMode(STAND_BY, ctrReg) == false)
	{
		return false;
	}
	if (setCtrMode(INIT_START_FREQ, ctrReg) == false)
	{
		return false;
	}
	if (setCtrMode(START_FREQ_SWEEP, ctrReg) == false)
	{
		return false;
	}

	int t1 = 0;
	while ( (getStatusReg() & 0x04) != 0x04) // Loop while if the entire sweep in not complete
	{
		getComplexRawOnce(arrReal[t1], arrImag[t1]); // Only for real and Imag components.
		if (setCtrMode(INCR_FREQ, ctrReg) == false)
		{
			return false;
		}
		t1++;
	}
	if (setCtrMode(POWER_DOWN, ctrReg) == false)
	{
		return false;
	}
	return true; // Succeed!
}
예제 #3
0
파일: AD5933.cpp 프로젝트: HugoSBIO/drive
bool AD5933_Class::compFreqSweep(double *arrGainFactor, double *arrPShift, double *arrReal, double *arrImag)
{
	int ctrReg = getByte(0x80);
	setCtrMode(STAND_BY, ctrReg);
	setCtrMode(INIT_START_FREQ, ctrReg);
	setCtrMode(START_FREQ_SWEEP, ctrReg);

	int t1 = 0;
	//int cReal, cImag;
	double Z_Val, phase;
	while ( (getStatusReg() & 0x04) != 0x04) // Loop while if the entire sweep in not complete
	{
		/*
    getComplexRawOnce(cReal, cImag); // Only for real and Imag components.
    double magImp = arrGainFactor[t1]/getMag(cReal, cImag);
    double phase = atan2(cImag, cReal) - arrPShift[t1];
    arrReal[t1] = magImp * cos(phase);
    arrImag[t1] = magImp * sin(phase);
		 */
		getComplexOnce(arrGainFactor[t1], arrPShift[t1], arrReal[t1], arrImag[t1], Z_Val, phase);

		if (setCtrMode(INCR_FREQ, ctrReg) == false)
		{
			return false;
		}
		t1++;
	}
	setCtrMode(POWER_DOWN, ctrReg);
	return true;


}
//
// Check for controller errors
//
bool
self::checkControllerErrors(void)
{
    UInt32	status_reg;

    status_reg = getStatusReg();
    if (TWE_STATUS_ERRORS(status_reg) || !warnControllerStatus(status_reg))
	return(false);
    return(true);
}
////////////////////////////////////////////////////////////////////////////////
// Handle a controller interrupt.
//
// We are on the workloop.
//
void
self::handleInterrupt(void)
{
    EscaladeCommand *ec;
    UInt32	status_reg;
    UInt8	tag;

    status_reg = getStatusReg();

    // Host interrupt - not used
    if (status_reg & TWE_STATUS_HOST_INTERRUPT) {
	debug(4, "host interrupt");
	setControlReg(TWE_CONTROL_CLEAR_HOST_INTERRUPT);
    }
    // Command interrupt - not currently used
    if (status_reg & TWE_STATUS_COMMAND_INTERRUPT) {
	debug(4, "command interrupt");
	setControlReg(TWE_CONTROL_MASK_COMMAND_INTERRUPT);
    }
    // Attention interrupt - one or more AENs to be fetched
    if (status_reg & TWE_STATUS_ATTENTION_INTERRUPT) {
	setControlReg(TWE_CONTROL_CLEAR_ATTENTION_INTERRUPT);
	supportThreadAddWork(ST_DO_AEN);
    }
    // Completion interrupt - work done
    if (status_reg & TWE_STATUS_RESPONSE_INTERRUPT) {
	while (!(getStatusReg() & TWE_STATUS_RESPONSE_QUEUE_EMPTY)) {
	    tag = getResponseReg();
	    ec = findCommand(tag);
	    if (ec == NULL) {		// bogus completion
		error("completed invalid tag %d", tag);
		continue;
	    }
	    // Perform command completion
	    // Note that once this is called, the command
	    // must not be touched here as it may have been
	    // invalidated.
	    ec->complete();
	}
    }
}
예제 #6
0
bool AD5933_Class::getImpedance(double gainFactor, double &impVal) {
	while ( (getStatusReg() & 0x02) != 0x02 ); // Wait until measurement is complete.

	int rComp, iComp;

	byte impData[4];
	blockRead(0x94, 4, impData);
	rComp = impData[0] * 16 * 16 + impData[1];
	iComp = impData[2] * 16 * 16 + impData[3];

	double magSq = getMag(rComp, iComp);
	impVal = gainFactor / magSq;
	return true;
}
예제 #7
0
파일: AD5933.cpp 프로젝트: HugoSBIO/drive
bool AD5933_Class::getGainFactorS_Set(double cResistance, int avgNum, double *gainFactorArr, double *pShiftArr)
{
	int ctrReg = getByte(0x80);
	if (setCtrMode(STAND_BY, ctrReg) == false)
	{
		return false;
	}
	if (setCtrMode(INIT_START_FREQ, ctrReg) == false)
	{
		return false;
	}
	if (setCtrMode(START_FREQ_SWEEP, ctrReg) == false)
	{
		return false;
	}

	int t1 = 0;
	int rImag, rReal;
	double mag;
	while ( (getStatusReg() & 0x04) != 0x04) // Loop while if the entire sweep in not complete
	{
		double tSumMag = 0, tSumPhase = 0;
		for (int t2 = 0; t2 < avgNum; t2++)
		{
			getComplexRawOnce(rReal, rImag); // Only for real and Imag components.
			tSumMag += getMag(rReal, rImag);
			tSumPhase += atan2(rImag, rReal);
			if (setCtrMode(REPEAT_FREQ, ctrReg) == false)
			{
				return false;
			}
		}
		//Serial.println(t1);
		gainFactorArr[t1] = (tSumMag / avgNum) * cResistance;
		pShiftArr[t1] = tSumPhase / avgNum;

		if (setCtrMode(INCR_FREQ, ctrReg) == false)
		{
			return false;
		}
		t1++;
	}
	if (setCtrMode(POWER_DOWN, ctrReg) == false)
	{
		return false;
	}
	return true; // Succeed!
}
//
// Wait up to waittime seconds for the status bits to be set.
//
// Note that this spins, and should be avoided when possible.
//
bool
self::waitStatusBits(UInt32 bits, int waittime)
{
    UInt32	status_reg = 0;
    int		i;

    for (i = 0; i < (waittime * 100); i++) {
	status_reg = getStatusReg();
	if ((status_reg & bits) == bits)
	    return(true);
	IODelay(10000);
    }
    debug(2, "timed out waiting for status bits 0x%08x, have status 0x%08x",
	  (uint)bits, (uint)status_reg);
    return(false);
}
//
// Post a request, returns false if the controller is busy.
//
bool
self::postCommand(EscaladeCommand *ec)
{
    UInt32	status_reg;

    // check that the command queue is not full
    status_reg = getStatusReg();
    if (status_reg & TWE_STATUS_COMMAND_QUEUE_FULL)
	return(false);

    // and post the command
    pciNub->ioWrite32(8, (UInt32)ec->commandPhys, registerMap);

    // mark as posted
    ec->wasPosted();
    return(true);
}
예제 #10
0
bool AD5933_Class::tempUpdate() {

	if (setCtrMode(TEMP_MEASURE) == false)
	{
#if LOGGING1
		printer->println("tempUpdate - Failed to set the control bit");
#endif
		return false;
	}

	while ( (getStatusReg() & 0x01) != 0x01)
	{
		; // Wait Until Get Vaild Temp. Measurement.
	}

	return true;
}
예제 #11
0
파일: AD5933.cpp 프로젝트: HugoSBIO/drive
bool AD5933_Class::tempUpdate()
// Function to update temperature information without reading.
{
	if (setCtrMode(TEMP_MEASURE) == false)
	{
#if LOGGING1
		printer->println("getTemperature - Failed to set the control bit");
#endif
		return false;
	}

	while ( getStatusReg() & 0x01 != 0x01)
	{
		; // Wait Until Get Vaild Temp. Measurement.
	}

	return true;
}
예제 #12
0
파일: AD5933.cpp 프로젝트: HugoSBIO/drive
bool AD5933_Class::getComplexOnce(double gainFactor, double pShift, double &vReal, double &vComp, double &impVal, double &phase)
{
	while ( (getStatusReg() & 0x02) != 0x02 ); // Wait until measurement is complete.

	int rComp, iComp;

	byte impData[4];
	blockRead(0x94, 4, impData);
	rComp = impData[0] * 16 * 16 + impData[1];
	iComp = impData[2] * 16 * 16 + impData[3];

	double magSq = getMag(rComp, iComp);
	impVal = gainFactor / magSq;
	phase = atan2(iComp, rComp) - pShift;
	vReal = impVal * cos(phase);
	vComp = impVal * sin(phase);

	return true;
}
예제 #13
0
파일: AD5933.cpp 프로젝트: HugoSBIO/drive
bool AD5933_Class::getComplexRawOnce(int &realComp, int &imagComp)
{
	while ( (getStatusReg() & 0x02) != 0x02 ); // Wait until measurement is complete.

	int rComp, iComp;

	byte impData[4];
	blockRead(0x94, 4, impData);
	rComp = impData[0] * 16 * 16 + impData[1];
	iComp = impData[2] * 16 * 16 + impData[3];

	//double magSq = square((double)rComp) + square((double)iComp);
	//double td1=gainFactor/magSq;
	//realComp = abs(rComp)*td1;
	//imagComp = abs(iComp)*td1;
	realComp = rComp;
	imagComp = iComp;

	return true;
}
//
// Drain the response queue, discard all the responses
//
bool
self::drainResponseQueue(void)
{
    UInt32		status_reg;
    //UInt8		tag;

    // spin pulling responses until none left
    for (;;) {
	// check controller status
	status_reg = getStatusReg();
	if (!warnControllerStatus(status_reg)) {
	    error("unexpected controller status 0x%08x", (uint)status_reg);
	    return(false);
	}

	// check for more status
	if (status_reg & TWE_STATUS_RESPONSE_QUEUE_EMPTY)
	    break;
	//tag = getResponseReg();
    }
    return(true);
}
예제 #15
0
파일: AD5933.cpp 프로젝트: HugoSBIO/drive
bool AD5933_Class::performFreqSweep(double gainFactor, double *arrSave)
// Function to perform frequency Sweep, Just call it once to do it. It automatically do all the step.
// double gainFactor - You need to call getGainFactor(double,int)
//
// double *arrSave - Just put the name of the array to save it. It should have right number of entries to save it.
// If not, hidden error will be occur.
{
	int ctrReg = getByte(0x80); // Get the content of Control Register and put it into ctrReg
	if (setCtrMode(STAND_BY, ctrReg) == false)
	{
#if LOGGING1
		printer->println("performFreqSweep - Failed to setting Stand By Status!");
#endif
		return false;
	}
	if (setCtrMode(INIT_START_FREQ, ctrReg) == false)
	{
#if LOGGING1
		printer->println("performFreqSweep - Failed to setting initialization with starting frequency!");
#endif
		return false;
	}
	//delay(delayTimeInit);
	if (setCtrMode(START_FREQ_SWEEP, ctrReg) == false)
	{
#if LOGGING1
		printer->println("performFreqSweep - Failed to set to start frequency sweeping!");
#endif
		return false;
	}

	int t1 = 0;
	while ( (getStatusReg() & 0x04) != 0x04 ) // Loop while if the entire sweep in not complete
	{
		//delay(delayTimeInit);
		arrSave[t1] = gainFactor / getMagOnce(); // Calculated with Gain Factor
#if LOGGING1
		printer->print("performFreqSweep - arrSave[");
		printer->print(t1);
		printer->print("] = ");
		printer->println(arrSave[t1]);
#endif
		if (setCtrMode(INCR_FREQ, ctrReg) == false)
		{
#if LOGGING1
			printer->println("performFreqSweep - Failed to set for increasing frequency!");
#endif
			return false;
		}
		t1++;
		//getByte(0x80);
	}
	if (setCtrMode(POWER_DOWN, ctrReg) == false)
	{
#if LOGGING1
		printer->println("performFreqSweep - Completed sweep, but failed to power down");
#endif
		return false;
	}
	return true; // Succeed!
}
예제 #16
0
bool AD5933_Class::getGainFactorsTetraSweep(double cResistance, int avgNum, double *gainFactorArr, double *vShiftArr, double *cShiftArr){

	int ctrReg = getByte(0x80);
	if (setCtrMode(STAND_BY, ctrReg) == false)
	{
		return false;
	}
	if (setCtrMode(INIT_START_FREQ, ctrReg) == false)
	{
		return false;
	}
	if (setCtrMode(START_FREQ_SWEEP, ctrReg) == false)
	{
		return false;
	}

	int arrayIndex = 0;

	while ( (getStatusReg() & 0x04) != 0x04) { // While the fequency sweep isn't complete

		//////

		int averageIndex = 0, iVoltage = 0, rVoltage = 0, iCurrent = 0, rCurrent = 0;
		double voltageSum = 0, currentSum = 0, voltagePhaseSum = 0, currentPhaseSum = 0;


		digitalWrite(IV_MUX, LOW); //Toggle current / voltage multiplexer to voltage
		delay(10);

		if (setCtrMode(REPEAT_FREQ, ctrReg) == false) {
			return false;
		}

		// Until reached pre-defined number for averaging.
		while (averageIndex < avgNum) {

			getComplexRawOnce(rVoltage, iVoltage);

			voltageSum += getMag(rVoltage, iVoltage);
			voltagePhaseSum += atan2(iVoltage, rVoltage);

			if (setCtrMode(REPEAT_FREQ, ctrReg) == false) {
				return false;
			}

			averageIndex++;
		}

		digitalWrite(IV_MUX, HIGH); // Toggle current / voltage multiplexer to current
		delay(10); // delay for mux to settle

		averageIndex = 0; // Reset index for current

		if (setCtrMode(REPEAT_FREQ, ctrReg) == false) {
			return false;
		}

		while (averageIndex < avgNum) {

			getComplexRawOnce(rCurrent, iCurrent);

			currentSum += getMag(rCurrent, iCurrent);
			currentPhaseSum += atan2(iCurrent, rCurrent);

			if (setCtrMode(REPEAT_FREQ, ctrReg) == false) {
				return false;
			}

			averageIndex++;
		}

		double voltageMag = voltageSum / ((double) avgNum);
		double currentMag = currentSum / ((double) avgNum);

		gainFactorArr[arrayIndex] = cResistance * (currentMag / voltageMag);
		vShiftArr[arrayIndex] = voltagePhaseSum / ((double) avgNum);
		cShiftArr[arrayIndex] = currentPhaseSum / ((double) avgNum);

		//////

		if (setCtrMode(INCR_FREQ, ctrReg) == false){
			return false;
		}

		arrayIndex++;
	}

	if (setCtrMode(POWER_DOWN, ctrReg) == false){
		return false;
	}
	return true; // Succeed!
}