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.

MSPM0-SDK: example code for using the MATHACL

Part Number: MSPM0-SDK

Tool/software:

hi

We would like to have a code example for using the MATHACL for the square root operation. Unfortunately, there is no example in the SDK.

may you help?

thx

Vincenzo

  • Hello Vincenzo,

    I am sorry that we don't have the example. Please refer to the TRM and generate it. There are detailed guide on TRM about how to use the MATHACL.

    Best Regards,

    Janz Bai

  • hi Janz Bai,

    thx a lot. So no plan to make a little example in the SDK, correct?

    just to be sure...

    thx

    Vincenzo

  • Hello Vincenzo,

    I remember that there is no plan to add this in SDK now.

    Best Regards,

    Janz Bai

  • hi Janz Bai,

    I would like to know the steps to calculate the square root of a simple number like 9.

    I tried the following method, but it didn't work. Could you please point out what I did wrong?

     

    MATHACL->CTL = MATHACL_CTL_FUNC_SQRT | // Do square root

                   MATHACL_CTL_OPTYPE_UNSIGNED | // The operand is unsigned

                   MATHACL_CTL_QVAL_Q0; // No fractional

    MATHACL->OP1 = 9U;

    MATHACL->OP2 = 0U;

    while ((MATHACL->STATUS & MATHACL_STATUS_BUSY_MASK) == MATHACL_STATUS_BUSY_NOTDONE) {

        ;

    result = MATHACL->RES1;

    thx

    Vincenzo

  • Hello Vincenzo,

    My HSM colleague will help you on this issue.

    Best Regards,

    Janz Bai

  • Hi, 

    For QURT function, please refer to this section first:

    https://www.ti.com/lit/ug/slau846b/slau846b.pdf

    6.4.3 Square Root (SQRT)

    If you have any question about these steps, please feel free to ask me.

    Regards,

    Helic

  • Hi Helic,

    from the square root step.

    I calculated as below scaled number

    uint32_t sqrtNumber  =  100 ; // Lets find the square root of 100

    uint8_t SFACTOR = 0 ; //scale factor
    uint32_t count = 2  ; //scaled number must be between 1 and 2
    uint32_t SN = 0     ;
    uint16_t result = 0 ;
      do
      {
           SFACTOR++ ; //incease SFACTOR
          count <<= 1 ; //multiply by 2
      } while (count < sqrtNumber ) ;//repeat until UN is less than count
      sqrtNumber  <<= (30-SFACTOR)        ; // convert scaled into UQ2.30 format
    // scaled number = (unscaled * 2^30)/2^SFACTOR = UNSCALED x 2^(30-SFACTOR) in UQ2.30 format
    I have problem to use this SFACTOR while calling SQRT function. I need your help how to use it?
    DL_MathACL_startSqrtOperation(MATHACL, config, sqrt) ;
    I tried to use my own way as below,
    Way1. MATHACL_Regs math_Reg   ; // Create object of MATHACL_Regs structure
    math_Reg.CTL = (0xffffffe5 & 0xe1ffffff & (0xffe0ffff|(SFACTOR << 16))) // (sqrtNumber , Func code & NUMITER & , SFACTOR @ 16-21 bit)
    DL_MathACL_setOperandTwo( MATHACL, sqrtNumber)       ;// Set scaled value in OP2
    DL_MathACL_waitForOperation(MATHACL)                ;    // Wait till completion              
     result = (uint16_t)(DL_MathACL_getResultOne(MATHACL) >> 16)        ; // Get integer part
                       
    result : result = 0 ;// Not working
    Way2.
    __STATIC_INLINE void DL_GPIO_setValueCTL(MATHACL_Regs* math_cl, uint32_t data) // Create a function
    {
        math_cl-> CTL = data ;
    }
    Call this function
    DL_GPIO_setValueCTL(MATHACL, (0xffffffe5 & 0xe1ffffff & (0xffe0ffff|(SFACTOR << 16))))  ; // Set Function squareroot
    DL_MathACL_setOperandTwo( MATHACL, sqrtNumber)       ;// Set scaled value in OP2
    DL_MathACL_waitForOperation(MATHACL)                 ;    // Wait till completion              
    result = (uint16_t)(DL_MathACL_getResultOne(MATHACL) >> 16)        ; // Get integer part
    result : result = 0 ;// Not working
    I noticed one more printing issue
    in table it is given OP1 for user input as scaled number but in configuration it is OP2. Which one is correct?

    Best Regards

    Tulsi Das

  • Hi Helic,

    I got the answer in my way2.

    I found mistake in my earlier code .

    DL_GPIO_setValueCTL(MATHACL, (0xffffffe5 & 0xe1ffffff & (0xffe0ffff|(SFACTOR << 16))))  ; // Set Function squareroot

    In this line,  0xffe0ffff|(SFACTOR << 16). It must be be 0xffc0ffff|(SFACTOR << 16). Because SFACTOR need 6 bit.

    I feel happy if you could explain how to use : DL_MathACL_startSqrtOperation(MATHACL, config, sqrt) ;

    I have problem to use this SFACTOR while calling SQRT function. I need your help how to use it?

    Best Regards

    Tulsi Das

  • Hi,  and 

    Here is the SQRT operation code example:

    mathacl_sqrt_op_LP_MSPM0G3507_nortos_ticlang.zip

    Regards,

    Helic