This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

error in isqrt64.asm function in power meter library of msp430f6736

Other Parts Discussed in Thread: MSP430F6736, EVM430-F6736

Hi there

I'm developing a power meter using the ref design and a MSP430F6736.

I'm also using the ti energy library (its the same as the one that comes with the TI EVM single phase meter) to calculate the various values needed.

I noticed in the debugger, that the return from the asm function isqrt64() for the current value is completely wrong.

Does anyone have an updated version of this code or does anyone have an explanation of why the value returned is wrong?

i'm using ccs v6.1 (compiler V4.4)  and the library "energy library code slac488" of 21 may 2012 although the code for the .asm is 27 jan 2012.

My compiler settings are large code model and small data model.

thanks in advance

  • Hi Moshe,

    I am bringing in a metering expert to comment on your questions regarding the EVM430-F6736 and MSP430-ENERGY-LIBRARY, please allow some time for them to respond.

    Regards,
    Ryan
  • thank you Ryan, i really appreciate that!

    moshe

  • An update to the above....

    the ASM function is NOT wrong...but there is one odd issue.

    On line 31 there is the statement: STACK_USED .set 20

    But the function is pushing 8 regs (REG4 to REG11) each being 4 bytes, and then does PUSH REG11 on line 45 which is a further 2bytes.

    So the total stack requirements is really 8x4 + 2 = 36 bytes not 20.   OR am i misunderstanding something here???

    There is a further issue.

    In emeter-foreground.c line 639 (or thereabouts) there is the statement "x = isqrt64(tmp) >> 26;"

    Surely this should be x = isqrt64(tmp) >> 32; ?? As i notice that the integer portion of the square root is in R13 & R14 and 'x' is an unsigned 32bit variable.

    And then a few lines down there is the statement x = mul48u_32_16(x, i);

    This returns a 48bit value but x is only a 32 bit value...???

    And finally:

    x gets assigned to phase->metrology.current.readings.I_rms which is an unsigned 32 bit value...but we still are missing the MSB from the return of mul48u_32_16. 

  • Thanks for the input Moshe. I believe those stack usage numbers only affect the debugger. They won't stop the code working. I will vet all these assembly language files, to make sure all the stack usage figures are correct for the next release. The rest of your comments are things which might look odd, but should be OK. The current is a 32 bit number, and the maximum current we ever deal with will not reach the top bit of the word.

  • thanks Steve.

    Would you know what algorithm was used in the square root calculation?

  • Take a look at the pure C version of the routine in isqrt64.c, which should be a lot easier to follow than the assembly language ones. You might recognise this as the binary equivalent of on the simple algorithms many of use learn in high school for findings the square roots of decimal numbers.

**Attention** This is a public forum