Hi all,

I'm trying to understand step by step the imepdance measurement examples so I can confidently design my code. However, I don't undestand why 0.5 is added to the frequency control word in these codes. Is it an offset? I tried to find this in the user manual but I only manage to get the formula for the FCW and it doesn't mention this + 0.5.

This is the line of code:

* FCW = FREQ * 2^26 / 16e6 */

#define FCW ((uint32_t)(((uint64_t)FREQ << 26) / 16000000 + 0.5))

Thanks!!

Hi,

The idea is to round the result to nearest integer. Say, if result is 123.4, then final output is (uint32_t)(123.4+0.5)=123, if result is 123.5, then output is (uint32_t)(123.5+0.5) = 124.

But I doubt if this equation works as expected. I think it should be

#define FCW ((uint32_t)(((

float)FREQ << 26) / 16000000 + 0.5))#define FCW ((uint32_t)(((uint64_t)FREQ << 26) / 16000000

.0f+ 0.5))Otherwise there is no intermediate result of 123.4 .

Regards,

Neo