Skip to content

Commit

Permalink
bugfix in 110kbps tuning
Browse files Browse the repository at this point in the history
  • Loading branch information
thotro committed Jul 21, 2015
1 parent 4d617b6 commit 3ca4cf8
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 6 deletions.
2 changes: 2 additions & 0 deletions examples/BasicReceiver/BasicReceiver.ino
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ void setup() {
DW1000.setDefaults();
DW1000.setDeviceAddress(6);
DW1000.setNetworkId(10);
DW1000.enableMode(DW1000.MODE_LONGDATA_RANGE_LOWPOWER);
DW1000.commitConfiguration();
Serial.println("Committed configuration ...");
// DEBUG chip info and registers pretty printed
Expand Down Expand Up @@ -82,6 +83,7 @@ void loop() {
Serial.print("Data is ... "); Serial.println(message);
Serial.print("FP power is [dBm] ... "); Serial.println(DW1000.getFirstPathPower());
Serial.print("RX power is [dBm] ... "); Serial.println(DW1000.getReceivePower());
Serial.print("Signal quality is ... "); Serial.println(DW1000.getReceiveQuality());
received = false;
}
if(error) {
Expand Down
1 change: 1 addition & 0 deletions examples/BasicSender/BasicSender.ino
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ void setup() {
DW1000.setDefaults();
DW1000.setDeviceAddress(5);
DW1000.setNetworkId(10);
DW1000.enableMode(DW1000.MODE_LONGDATA_RANGE_LOWPOWER);
DW1000.commitConfiguration();
Serial.println("Committed configuration ...");
// DEBUG chip info and registers pretty printed
Expand Down
1 change: 1 addition & 0 deletions examples/RangingAnchor/RangingAnchor.ino
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,7 @@ void loop() {
Serial.print("Range is [m] "); Serial.println(timeComputedRange.getAsMeters());
//Serial.print("FP power is [dBm] ... "); Serial.println(DW1000.getFirstPathPower());
//Serial.print("RX power is [dBm] ... "); Serial.println(DW1000.getReceivePower());
//Serial.print("Receive quality is ... "); Serial.println(DW1000.getReceiveQuality());
} else {
transmitRangeFailed();
}
Expand Down
21 changes: 16 additions & 5 deletions src/DW1000.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,12 +60,12 @@ boolean DW1000Class::_frameCheck = true;
boolean DW1000Class::_permanentReceive = false;
int DW1000Class::_deviceMode = IDLE_MODE;
// modes of operation
const byte DW1000Class::MODE_LONGDATA_RANGE_LOWPOWER[] = {TRX_RATE_110KBPS, TX_PULSE_FREQ_16MHZ, TX_PREAMBLE_LEN_1024};
const byte DW1000Class::MODE_LONGDATA_RANGE_LOWPOWER[] = {TRX_RATE_110KBPS, TX_PULSE_FREQ_16MHZ, TX_PREAMBLE_LEN_2048};
const byte DW1000Class::MODE_SHORTDATA_FAST_LOWPOWER[] = {TRX_RATE_6800KBPS, TX_PULSE_FREQ_16MHZ, TX_PREAMBLE_LEN_128};
const byte DW1000Class::MODE_LONGDATA_FAST_LOWPOWER[] = {TRX_RATE_6800KBPS, TX_PULSE_FREQ_16MHZ, TX_PREAMBLE_LEN_1024};
const byte DW1000Class::MODE_SHORTDATA_FAST_ACCURACY[] = {TRX_RATE_6800KBPS, TX_PULSE_FREQ_64MHZ, TX_PREAMBLE_LEN_128};
const byte DW1000Class::MODE_LONGDATA_FAST_ACCURACY[] = {TRX_RATE_6800KBPS, TX_PULSE_FREQ_64MHZ, TX_PREAMBLE_LEN_1024};
const byte DW1000Class::MODE_LONGDATA_RANGE_ACCURACY[] = {TRX_RATE_110KBPS, TX_PULSE_FREQ_64MHZ, TX_PREAMBLE_LEN_1024};
const byte DW1000Class::MODE_LONGDATA_RANGE_ACCURACY[] = {TRX_RATE_110KBPS, TX_PULSE_FREQ_64MHZ, TX_PREAMBLE_LEN_2048};
// SPI settings
const SPISettings DW1000Class::_fastSPI = SPISettings(16000000L, MSBFIRST, SPI_MODE0);
const SPISettings DW1000Class::_slowSPI = SPISettings(2000000L, MSBFIRST, SPI_MODE0);
Expand Down Expand Up @@ -246,6 +246,7 @@ void DW1000Class::tune() {
byte tcpgdelay[LEN_TC_PGDELAY];
byte fspllcfg[LEN_FS_PLLCFG];
byte fsplltune[LEN_FS_PLLTUNE];
byte fsxtalt[LEN_FS_XTALT];
// AGC_TUNE1
if(_pulseFrequency == TX_PULSE_FREQ_16MHZ) {
writeValueToBytes(agctune1, 0x8870, LEN_AGC_TUNE1);
Expand Down Expand Up @@ -563,6 +564,8 @@ void DW1000Class::tune() {
} else {
// TODO proper error/warning handling
}
// mid range XTAL trim (TODO here we assume no calibration data available in OTP)
//writeValueToBytes(fsxtalt, 0x60, LEN_FS_XTALT);
// write configuration back to chip
writeBytes(AGC_TUNE, AGC_TUNE1_SUB, agctune1, LEN_AGC_TUNE1);
writeBytes(AGC_TUNE, AGC_TUNE2_SUB, agctune2, LEN_AGC_TUNE2);
Expand All @@ -581,6 +584,7 @@ void DW1000Class::tune() {
writeBytes(TX_CAL, TC_PGDELAY_SUB, tcpgdelay, LEN_TC_PGDELAY);
writeBytes(FS_CTRL, FS_PLLTUNE_SUB, fsplltune, LEN_FS_PLLTUNE);
writeBytes(FS_CTRL, FS_PLLCFG_SUB, fspllcfg, LEN_FS_PLLCFG);
//writeBytes(FS_CTRL, FS_XTALT_SUB, fsxtalt, LEN_FS_XTALT);
}

/* ###########################################################################
Expand Down Expand Up @@ -901,6 +905,7 @@ DW1000Time DW1000Class::setDelay(const DW1000Time& delay) {
delayBytes[1] &= 0xFE;
writeBytes(DX_TIME, NO_SUB, delayBytes, LEN_DX_TIME);
// adjust expected time with configured antenna delay
futureTime.setTimestamp(delayBytes);
futureTime += _antennaDelay;
return futureTime;
}
Expand Down Expand Up @@ -1184,9 +1189,15 @@ void DW1000Class::clearTransmitStatus() {
writeBytes(SYS_STATUS, NO_SUB, _sysstatus, LEN_SYS_STATUS);
}

float DW1000Class::getNoiseValue() {
// TODO
return -1;
float DW1000Class::getReceiveQuality() {
byte noiseBytes[LEN_STD_NOISE];
byte fpAmpl2Bytes[LEN_FP_AMPL2];
unsigned int noise, f2;
readBytes(RX_FQUAL, STD_NOISE_SUB, noiseBytes, LEN_STD_NOISE);
readBytes(RX_FQUAL, FP_AMPL2_SUB, fpAmpl2Bytes, LEN_FP_AMPL2);
noise = (unsigned int)noiseBytes[0] | ((unsigned int)noiseBytes[1] << 8);
f2 = (unsigned int)fpAmpl2Bytes[0] | ((unsigned int)fpAmpl2Bytes[1] << 8);
return (float)f2 / noise;
}

float DW1000Class::getFirstPathPower() {
Expand Down
6 changes: 5 additions & 1 deletion src/DW1000.h
Original file line number Diff line number Diff line change
Expand Up @@ -115,9 +115,11 @@
// RX frame quality
#define RX_FQUAL 0x12
#define LEN_RX_FQUAL 8
#define STD_NOISE_SUB 0x00
#define FP_AMPL2_SUB 0x02
#define FP_AMPL3_SUB 0x04
#define CIR_PWR_SUB 0x06
#define LEN_STD_NOISE 2
#define LEN_FP_AMPL2 2
#define LEN_FP_AMPL3 2
#define LEN_CIR_PWR 2
Expand Down Expand Up @@ -225,8 +227,10 @@
#define FS_CTRL 0x2B
#define FS_PLLCFG_SUB 0x07
#define FS_PLLTUNE_SUB 0x0B
#define FS_XTALT_SUB 0x0E
#define LEN_FS_PLLCFG 4
#define LEN_FS_PLLTUNE 1
#define LEN_FS_XTALT 1

// PMSC
#define PMSC 0x36
Expand Down Expand Up @@ -449,7 +453,7 @@ class DW1000Class {
/* receive quality information. */
static float getReceivePower();
static float getFirstPathPower();
static float getNoiseValue();
static float getReceiveQuality();

/* interrupt management. */
static void interruptOnSent(boolean val);
Expand Down

0 comments on commit 3ca4cf8

Please sign in to comment.