Range Calculated is to long, over 200000.0 meters!

Hi everybody!

I’m testing the DW1000 API Samples ex_06a_ss_twr_init and ex_06a_ss_twr_resp like they are in the API folder, just ported to the Microchip micro PIC18F27Q10 and using the DWM1000 module, The polled transmited and received messages are well received but the calculated renged distance (distance = tof * SPEED_OF_LIGHT;) is to long (in the range 199768.0 to 203034.0 meters aprox.) which is exagerated, no variations exists when I move both initiator and responder! Can someone of the Decawave experts please tell what do I need to do to fix the ranged calculation?
Here I append the parameters code definitions of the responder
The only parameter I’ve changed in the initiator is the RESP_RX_TIMEOUT_UUS to 1600 like this:

#define RESP_RX_TIMEOUT_UUS 1600 // 210

Regards…

// Responder definition of parameters
/* Example application name and version to display on LCD screen. */
#define APP_NAME “DS TWR INIT v1.3”

/* Default communication configuration. We use here EVK1000’s mode 4. See NOTE 1 below. /
static dwt_config_t config = {
2, /
Channel number. /
DWT_PRF_64M, /
Pulse repetition frequency. /
DWT_PLEN_128, /
Preamble length. Used in TX only. /
DWT_PAC8, /
Preamble acquisition chunk size. Used in RX only. /
9, /
TX preamble code. Used in TX only. /
9, /
RX preamble code. Used in RX only. /
0, /
0 to use standard SFD, 1 to use non-standard SFD. use non-std SFD for better performance /
DWT_BR_6M8, /
Data rate. /
DWT_PHRMODE_STD, /
PHY header mode. /
(129 + 8 - 8) /
SFD timeout (preamble length + 1 + SFD length - PAC size). Used in RX only. */
};

/* Default antenna delay values for 64 MHz PRF. See NOTE 2 below. */
#define TX_ANT_DLY 16436
#define RX_ANT_DLY 16436

/* Frames used in the ranging process. See NOTE 3 below. /
static uint8 rx_poll_msg[] = {0x41, 0x88, 0, 0xCA, 0xDE, ‘W’, ‘A’, ‘V’, ‘E’, 0xE0, 0, 0};
static uint8 tx_resp_msg[] = {0x41, 0x88, 0, 0xCA, 0xDE, ‘V’, ‘E’, ‘W’, ‘A’, 0xE1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
/
Length of the common part of the message (up to and including the function code, see NOTE 3 below). /
#define ALL_MSG_COMMON_LEN 10
/
Index to access some of the fields in the frames involved in the process. /
#define ALL_MSG_SN_IDX 2
#define RESP_MSG_POLL_RX_TS_IDX 10
#define RESP_MSG_RESP_TX_TS_IDX 14
#define RESP_MSG_TS_LEN 4
/
Frame sequence number, incremented after each transmission. */
static uint8 frame_seq_nb = 0x00;

/* Buffer to store received messages.

  • Its size is adjusted to longest frame that this example code is supposed to handle. */
    #define RX_BUF_LEN 20
    static uint8 rx_buffer[RX_BUF_LEN];

/* Hold copy of status register state here for reference so that it can be examined at a debug breakpoint. */
static uint32 status_reg = 0;

/* UWB microsecond (uus) to device time unit (dtu, around 15.65 ps) conversion factor.

  • 1 uus = 512 / 499.2 µs and 1 µs = 499.2 * 128 dtu. */
    #define UUS_TO_DWT_TIME 65536

/* Delay between frames, in UWB microseconds. See NOTE 1 below. */
#define POLL_RX_TO_RESP_TX_DLY_UUS 1320 // 330 (I need to change it to 1320 to get polled by the initiator)

/* Timestamps of frames transmission/reception.

  • As they are 40-bit wide, we need to define a 64-bit int type to handle them. */
    typedef unsigned long long uint64;
    static uint64 poll_rx_ts;
    static uint64 resp_tx_ts;

/* Declaration of static functions. */
static uint64 get_rx_timestamp_u64(void);
static void resp_msg_set_ts(uint8 *ts_field, const uint64 ts);

The main code programmed in the responder is the same as the sample!
The main code programmed in the initiator is the same as the sample, just adding the XLCD function to display the distance!

Hi ,
Something wrong with the antenna delay , could you check what it is , I suspect 0.
When porting the 32-bit code to a 8-bit processor some bits may be shifted (Ltlle / big-Endian) but also some other potentialissues may arise.
Please consult APS019 on driving the DW1000 with a 8-bit processors APS019_Driving_DW1000_from_8-bit_MCU.pdf (570.1 KB)

Hi DecaLeo,

I tested different values for Antenna Delay and nothing happened, but is a good Idea to check the App note APS019, I’m gonna read this App note to see if I find out something wrong with the code of the 8-bit processor… I’ll let you know about it soon.

Thanks!

Hi DecaLeo,

I’ve already found the problem, following the APS019 I found in the function resp_msg_get_ts that is in the main function that ts_field pointer variable within the for cycle is not casted to uint32, and that function should be like the next code:

static void resp_msg_get_ts(uint8 *ts_field, uint32 *ts)
{
int i;
*ts = 0;
for (i = 0; i < RESP_MSG_TS_LEN; i++)
{
*ts += (uint32)ts_field[i] << (i * 8);
}
}

Right now both the initiator and the responder are ranging well , thanks for your help…

REGARDS