So i tried to implement a very simple example.
I have two esp32 Wrover modules with the DW3000.
One of them send a message every 50ms, in the payload is the tx_timestamp of its local clock.
The other one is receiving the message and calculates the rx_timestamp of the local clock, POA and clock-offset.
During the whole time i am not moving the boards. So in my understanding the POA and the diff (between rs_ts and tx_ts) should stay constant.
But as you can see in the image, it does not stay the same. The time difference is increasing by about 40us everytime the clocks resets.
And even between the resets, the value is fluctuating in the ns area (diff_diff is the difference of from one diff to the next, so the 1. Derivative)
And i donât even know how i should describe the POAâŠ
I am not sure if I am doing everything correctly, or if i have a logical flaw somewhere, as i am new to this thematic, so any help would be appreciated.
I am calculating the difference like this:
#define DWT_TIME_UNITS (1.0 / 63.8976e9)
uint64_t rx_ts = get_rx_timestamp_u64();
//uint64_t tx_ts read from the received message
float clockOffsetRatio = ((float)dwt_readclockoffset()) / (uint32_t)(1 << 26);
double diff = (((double)rx_ts - ((double)tx_ts*(1-clockOffsetRatio)))*DWT_TIME_UNITS);
And the POA:
float poa_uint16_to_radian(uint16_t poa_uint16)
{
/*
Convert a 14-bit signed POA value (stored in uint16) to radians.
POA format: signed 14-bit fixed-point (rad Ă 2^11)
Parameters:
poa_uint16 (int): Raw POA value (0â16383 range assumed)
Returns:
float: Phase in radians (range: -Ï to +Ï)
*/
uint16_t poa_14bit = 0;
int16_t poa_signed = 0;
float phase_rad = 0;
// 1. Extract 14-bit value
poa_14bit = poa_uint16 & 0x3FFF;
// 2. Convert to signed 14-bit integer
if (poa_14bit >= 8192){
poa_signed = poa_14bit - 16384; // Two's complement for negative values
}
else{
poa_signed = poa_14bit;
}
// 3. Convert fixed-point value to radians
phase_rad = poa_signed / 2048.0; // Since value is in rad Ă 2^11
return phase_rad;
}
dwt_readdiagnostics(&rx_diag);
uint16_t poa = rx_diag.ipatovPOA;
float radians = poa_uint16_to_radian(poa);
Thanks
Emil