Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Diff: ad5933.cpp
- Revision:
- 5:2dc8c3f02788
- Parent:
- 4:1ecb56465953
- Child:
- 6:6b9fc31d51b0
diff -r 1ecb56465953 -r 2dc8c3f02788 ad5933.cpp
--- a/ad5933.cpp Wed May 13 07:52:49 2015 +0000
+++ b/ad5933.cpp Wed May 13 14:07:40 2015 +0000
@@ -34,12 +34,12 @@
{
sCom.frequency(400000);
firstMeasurement = true;
- PGAandVoltout = 0x01;
+ PGAandVoltout = 0x00;
_extClk = extClk;
- if(_extClk)
- setRegister(0x81, 0x08);
- else
- setRegister(0x81, 0x00);
+ //if(_extClk)
+ // setRegister(0x81, 0x08);
+ //else
+ // setRegister(0x81, 0x00);
}
bool AD5933::gotoAdressPointer(uint8_t Adress)
@@ -53,11 +53,7 @@
bool AD5933::setRegister(uint8_t RegisterAdress, uint8_t RegisterValue)
{
sCom.start();
- bool output = sCom.write(WRITE_CMD);
- wait_ms(1);
- sCom.write(RegisterAdress);
- wait_ms(1);
- sCom.write(RegisterValue);
+ bool output = (sCom.write(WRITE_CMD) + sCom.write(RegisterAdress) + sCom.write(RegisterValue)) == 3;
sCom.stop();
return output;
}
@@ -102,43 +98,40 @@
bool AD5933::setControlReg(uint8_t Command)
{
return setRegister(0x80, PGAandVoltout | Command);
- //return setRegister(0x80, Command);
}
bool AD5933::setFrequencySweepParam(unsigned int startFreq, unsigned int stepFreq, unsigned int nrOfSteps)
{
unsigned int startFreqCode = startFreq/CLOCK_FREQ*0x00000004*0x08000000;
unsigned int stepFreqCode = stepFreq/CLOCK_FREQ*0x00000004*0x08000000;
- uint8_t CodeArray[8];
- CodeArray[0] = (uint8_t) (startFreqCode >> 16);
- CodeArray[1] = (uint8_t) (startFreqCode >> 8);
- CodeArray[2] = (uint8_t) (startFreqCode);
- CodeArray[3] = (uint8_t) (stepFreqCode >> 16);
- CodeArray[4] = (uint8_t) (stepFreqCode >> 8);
- CodeArray[5] = (uint8_t) (stepFreqCode);
- CodeArray[6] = (uint8_t) (nrOfSteps >> 8);
- CodeArray[7] = (uint8_t) (nrOfSteps);
- bool output = gotoAdressPointer(0x82);
+ bool output = setRegister(0x82,(startFreqCode >> 16));
+ output &= setRegister(0x83,(startFreqCode >> 8));
+ output &= setRegister(0x84,(startFreqCode));
+ output &= setRegister(0x85,(stepFreqCode >> 16));
+ output &= setRegister(0x86,(stepFreqCode >> 8));
+ output &= setRegister(0x87,(stepFreqCode));
+ output &= setRegister(0x88,(nrOfSteps >> 8));
+ output &= setRegister(0x89,nrOfSteps);
+
firstMeasurement = true;
- return writeBlock(CodeArray, 8) && output;
+ return output;
}
bool AD5933::setSettlingTime(unsigned int nrOfCycles)
{
- uint8_t CodeArray[2];
+ bool output = true;
if (nrOfCycles > 1022) {
- CodeArray[0] = ((nrOfCycles/4) >> 8) | 0x06;
- CodeArray[1] = (uint8_t) (nrOfCycles/4);
+ output &= setRegister(0x8A,((nrOfCycles/4) >> 8) | 0x06);
+ output &= setRegister(0x8B,(nrOfCycles/4));
} else if(nrOfCycles > 511) {
- CodeArray[0] = ((nrOfCycles/4) >> 8) | 0x02;
- CodeArray[1] = (uint8_t) (nrOfCycles/2);
+ output &= setRegister(0x8A,((nrOfCycles/4) >> 8) | 0x02);
+ output &= setRegister(0x8B,(nrOfCycles/2));
} else {
- CodeArray[0] = 0x00;
- CodeArray[1] = (uint8_t) (nrOfCycles);
+ output &= setRegister(0x8A,0x00);
+ output &= setRegister(0x8B,nrOfCycles);
}
- bool output = gotoAdressPointer(0x8A);
- return writeBlock(CodeArray, 2) && output;
+ return output;
}
bool AD5933::setAnalogCircuit(bool PGA, int RangeNr)
@@ -149,6 +142,8 @@
PGAandVoltout = 0x00;
switch(RangeNr) {
+ case 1:
+ PGAandVoltout |= 0x00;
case 2:
PGAandVoltout |= 0x06;
break;
@@ -181,11 +176,8 @@
bool AD5933::Measure(bool increment)
{
if(firstMeasurement) {
- //reset();
- setControlReg(STANDBY);
- wait_ms(10);
setControlReg(INIT_FREQ);
- wait_ms(250);
+ wait_ms(1000);
setControlReg(INIT_SWEEP);
wait_ms(5);
@@ -197,7 +189,7 @@
return getData();
} else {
setControlReg(REPE_FREQ);
- wait_ms(500);
+ wait_ms(5);
return getData();
}
}
@@ -208,13 +200,12 @@
uint8_t data[4];
bool output;
- while((getRegister(0x8F) != 0x02) && i < 10) {
- wait_ms(5);
+ while(((getRegister(0x8F) & 0x02) != 0x02) && i < 10) {
+ wait_ms(50);
i++;
}
if(i == 10)
output = false;
- //return false;
output &= gotoAdressPointer(0x82);
output &= readBlock(data, 4);
@@ -231,13 +222,12 @@
setControlReg(MEAS_TEMP);
wait_ms(5);
- while((getRegister(0x8F) != 0x01) && i < 10) {
- wait_ms(100);
+ while(((getRegister(0x8F) & 0x01) != 0x01) && i < 10) {
+ wait_ms(5);
i++;
}
- //if(i == 10)
-
- //return 100;
+ if(i == 10)
+ return -1;
gotoAdressPointer(0x92);
readBlock(data, 2);