Estimating the receive signal power

I’m trying to estimate the received power from an antenna using the formula in section 4.7.2 (dw1000_user_manual_v2.05).
According to the equation, one needs to determine a couple of values set to specific registers:

C = the Channel Impulse Response Power value reported in the CIR_PWR field of Register file: 0x12 – Rx Frame Quality Information [pag 95]
N = the Preamble Accumulation Count value reported in the RXPACC field of Register file: 0x10 – RX Frame Information Register [pag 92]
A= is the value 115.72 for a PRF of 16 MHz, and, the value 121.74 for a PRF of 64 MHz.

I’m not particularly sure on how to properly read those values.
For examples, I used this code for determining the N value:

uint8 buffer[12]; dwt_readfromdevice(0x10, 20, 12, buffer);

Is it correct? Do I need to use another C function in order to read correctly the values C and N into register files 0x12 and 0x10, respectively?

I am not sure what you are showing in you example:

read from register 0x10, offset 20, 12 bytes? Register 0x10 is a 32-bit register/4-bytes only.

Please look at the API SPI read/write functions for correct reading/writing of registers.

So, I tried the following code:

uint16 C = dwt_read16bitoffsetreg(0x12, 0x6); uint16 F1 = dwt_read16bitoffsetreg(0x15, 0x7); uint16 F2 = dwt_read16bitoffsetreg(0x12, 0x2); uint16 F3 = dwt_read16bitoffsetreg(0x12, 0x4); uint16 N = dwt_read16bitoffsetreg(0x10, (0x10 & 0xFFF) >> 0x20);

Only N variable has a value… C and F_i only zeros.

what are you trying to do here: uint16 N = dwt_read16bitoffsetreg(0x10, (0x10 & 0xFFF) >> 0x20);

Please see API/examples of how to read DW IC registers.

Assuming you are using the API
Why don’t u use the dwt_readdiagnostics() function from the API it fills a struct with the values you are looking for, something like this

dwt_rxdiag_t diag;

uint16 C = diag.maxGrowthCIR;
uint16 N = diag.rxPreamCount;

Or read directly from register
uint32 N = ((dwt_read32bitreg(RX_FINFO_ID)& RX_FINFO_RXPACC_MASK)>> RX_FINFO_RXPACC_SHIFT);
which you can typecast to 16 bit since the upper 16 bits should be all zero’s since RX_FINFO_RXPACC_SHIFT=20

For C you could do
uint16 C=dwt_read16bitoffsetreg(RX_FQUAL_ID,CIR_MXG_SHIFT/8);
CIR_MXG_SHIFT/8 = 6 so you read the bits 63-48 from the RX_FQUAL_ID register.
Bitmasking and shifting is not necesarry here since you need the full 16 bits

Dear Gerth
I have seen your message just now.
Thank you very very much for helping me :slight_smile:

It works!

I have the same problem as you. I use the function dwt_readdiagnostics() to read F1, F2, F3, but all of the values are 0.
The code is as follows:
dwt_rxdiag_t diag1;

I don’t know what went wrong with me. Did I read it at the wrong time? F1, F2, F3 register value will automatically clear 0? Are there any other considerations?