コード例 #1
0
ファイル: AD5933.cpp プロジェクト: HugoSBIO/drive
bool AD5933_Class::getComplexTetra(int millisDelay, double gainFactor, double vPhaseShift, double iPhaseShift, double &impVal, double &phase) {

	int rVoltage, iVoltage, rCurrent, iCurrent;

	int ctrReg = getByte(0x80); // Get the content of Control Register and put it into ctrReg

	delay(millisDelay);
	digitalWrite(IV_MUX, LOW); // Voltage measurement
	delay(millisDelay);

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

	delay(millisDelay);
	digitalWrite(IV_MUX, HIGH); // Current measurement
	delay(millisDelay);

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

	getComplexRawOnce(rCurrent, iCurrent);

	impVal = gainFactor * (getMag(rVoltage, iVoltage) / getMag(rCurrent, iCurrent));
	phase = (atan2(iVoltage, rVoltage) - vPhaseShift) - (atan2(iCurrent, rCurrent) - iPhaseShift);
	return true;
}
コード例 #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::getGainFactorC(double cResistance, int avgNum, double &gainFactor, double &pShift, bool retStandBy)
{
	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;
	}
	//delay(delayTimeInit);
	if (setCtrMode(START_FREQ_SWEEP, ctrReg) == false)
	{
		return false;
	}

	int t1 = 0, rImag, rReal;
	double tSum = 0, tSumP = 0;
	while (t1 < avgNum) // Until reached pre-defined number for averaging.
	{
		getComplexRawOnce(rReal, rImag);
		tSum += getMag(rReal, rImag);
		tSumP += atan2(rImag, rReal);
		if (setCtrMode(REPEAT_FREQ, ctrReg) == false)
		{
			return false;
		}
		t1++;
	}
	double mag = tSum / (double)avgNum;
	pShift = tSumP / (double)avgNum;

	if (retStandBy == false)
	{
		gainFactor = mag * cResistance;
		return true;
	}

	if ( setCtrMode(STAND_BY, ctrReg) == false)
	{
		return false;
	}
	resetAD5933();
	// Gain Factor is different from one of the datasheet in this program. Reciprocal Value.
	gainFactor = mag * cResistance;
	return true;
}
コード例 #4
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!
}
コード例 #5
0
ファイル: AD5933.cpp プロジェクト: HugoSBIO/drive
bool AD5933_Class::getGainFactorTetra(double calResistance, int avgNum, double &gainFactor, double &vPShift, double &iPShift, bool retStandBy){

	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 index = 0, iVoltage = 0, rVoltage = 0, iCurrent = 0, rCurrent = 0;
	double voltageSum = 0, currentSum = 0, voltagePhaseSum = 0, currentPhaseSum = 0;

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

	if (setCtrMode(REPEAT_FREQ, ctrReg) == false) {
		return false;
	}
	// Until reached pre-defined number for averaging.
	while (index < avgNum) {

		getComplexRawOnce(rVoltage, iVoltage);

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

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

		index++;
	}

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

	index = 0; // Reset index for current

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

	while (index < avgNum) {

		getComplexRawOnce(rCurrent, iCurrent);

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

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

		index++;
	}

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

	vPShift = voltagePhaseSum / ((double) avgNum);
	iPShift = currentPhaseSum / ((double) avgNum);

	if (retStandBy == false){
		gainFactor = calResistance * (currentMag / voltageMag);
		return true;
	}

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

	resetAD5933();

	gainFactor = calResistance * (currentMag / voltageMag);

	return true;
}
コード例 #6
0
ファイル: AD5933.cpp プロジェクト: HugoSBIO/drive
bool AD5933_Class::getGainFactorS_TP(double cResistance, int avgNum, double startFreq, double endFreq, double &GF_Init, double &GF_Incr, double &PS_Init, double &PS_Incr)
{
	int ctrReg = getByte(0x80);
	byte numIncrementBackup = numIncrement;
	long incrHexBackup = incrHex;
	setNumofIncrement(1);
	setIncrement(endFreq - startFreq);
	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 sumMag = 0, sumPhase = 0;
	for (t1 = 0; t1 < avgNum; t1++)
	{
		getComplexRawOnce(rReal, rImag); // Only for real and Imag components.
		sumMag += getMag(rReal, rImag);
		sumPhase += atan2(rImag, rReal);

		if (setCtrMode(REPEAT_FREQ, ctrReg) == false)
		{
			return false;
		}
	}
	GF_Init = (sumMag / avgNum) * cResistance;
	PS_Init = sumPhase / avgNum;

	setCtrMode(INCR_FREQ, ctrReg);
	sumMag = 0;
	sumPhase = 0;

	for (t1 = 0; t1 < avgNum; t1++)
	{
		getComplexRawOnce(rReal, rImag); // Only for real and Imag components.
		sumMag += getMag(rReal, rImag);
		sumPhase += atan2(rImag, rReal);

		if (setCtrMode(REPEAT_FREQ, ctrReg) == false)
		{
			return false;
		}
	}
	GF_Incr = ((sumMag / avgNum) * cResistance - GF_Init) / numIncrementBackup;
	PS_Incr = ((sumPhase / avgNum) - PS_Init) / numIncrementBackup;


	if (setCtrMode(POWER_DOWN, ctrReg) == false)
	{
		return false;
	}
	setNumofIncrement(numIncrementBackup);
	setIncrementinHex(incrHexBackup);
	return true; // Succeed!
}
コード例 #7
0
ファイル: AD5933.cpp プロジェクト: m4loman/Impalyzer
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!
}