Because of the holidays, TI E2E™ design support forum responses will be delayed from Dec. 25 through Jan. 2. Thank you for your patience.

MSP430FR6047: Simulating IQmath in Python

Part Number: MSP430FR6047

Tool/software:

I'm trying to simulate some IQmath operations in Python. I've noticed that _Q15div(0x003c, 0xff88) doesn't result in 0xc000, but rather 0xc001. The correct answer is -0.5 (0xc000), but the division returns -0.499969482421875 (0xc001). I noticed an accuracy table in the IQmath pdf of 14 bits for _QNdiv whichmay be the reason for the difference. I'd like to know:

* Is the -0.4999 answer correct for the library? or should it be -0.5? i.e. is it a bug?

* Is there a way to do this math in Python (or other high level language) to come to the same result? If I divide 60 (0x003c) by -120 (0xff88), I get -0.5.

My goal is to simulate the firmware in Python. It really doesn't matter too much to my code if the math is a little inaccurate, but I do need to simulate that (which is harder to do).

Thank you.

  • Are you going to create a virtual machine and simulate the machine code?

  • Simulate the machine code. I want to replicate the machine code's output. I had to do something similar to replicate floating point rounding errors last year for another processor.

  • There is nothing special about IQ math. It is just a simplified version of fixed point. Using the usual integer operations.

    Fixed point addition and subtraction is trivial but multiplication and division require fixing up the binary point. With additional hazards of course. One of those what to do with the extra bits on the least significant end that get lost. Do you just truncate or round? The choice will effect the lsb of the result.

    Looking at the code in _QNdiv.o I see references to the multiply hardware. I am not going to dig any deeper but this suggests it is using the multiplier to compute a reciprocal. Faster but introduces its own source of errors.

**Attention** This is a public forum