• Join
  • Sign In with my.TI Login
Texas Instruments
  • Products
  • Applications
  • Tools & Software
  • Support & Community
  • Sample & Buy
  • About TI
Sample & Purchase Cart Sample & Purchase Cart
  • Search
  • Advanced
TI E2E™ Community
  • Support Forums
  • Blogs
  • Groups
  • Videos
  • 简体中文
  • More ...
TI Home » TI E2E Community » Support Forums » Microcontrollers » C2000™ Microcontrollers » C2000 32-bit Microcontrollers Forum » Urgent: CLAsin function Issue
Share
C2000™ Microcontrollers
  • Forums
  • Announcements
  • E2E Wiki
Options
  • Subscribe via RSS
C2000 Resources
  • Product Folder
  • C2000 Training Portal
  • C2000 Technical Training Catalog
  • C2000 Datasheets, App Notes, User Guides
  • C2000 Hardware Design Kits
  • controlSUITE for C2000 Software Library


  • InstaSPIN Resources
  • What is InstaSPIN?
  • Videos and Support


  • InstaSPIN-FOC and InstaSPIN-MOTION Resources
  • What is InstaSPIN-FOC?
  • What is InstaSPIN-MOTION?
  • Product Folder: F28069F, F28068F, F28062F, F28068M, F28069M
  • User’s Guide
  • Technical User’s Manual
  • Tools
  • Forums

    Urgent: CLAsin function Issue

    This question is answered
    Frank H Zhang
    Posted by Frank H Zhang
    on Apr 28 2012 20:38 PM
    Expert1360 points

    Hi,

    The CLAsin function from CLAmath library didn't work properly in my project, so I did a few simple experiments.

    Here is the testing conditions:

    Note: I only used Task1 in my experiments, and CLA_isr was triggered by EPWM1A

    ========================================================================================

    In the Main source file:

           #pragma DATA_SECTION(sineStep, "CpuToCla1MsgRAM");
           float sineStep;

           #pragma DATA_SECTION(SinePointCounter, "Cla1DataRAM");
           Uint16   SinePointCounter;

    Main ( )

    {

             Initialize the system and everything necessary.

             .............................................

             SinePointCounter = 1;

             .............................................

             Initialize CLA registers

             (  note:   Cla1Regs.MMEMCFG.bit.RAM1E = 1;   )

            .............................................

             sineStep = 0.0138396;

            ..............................................

              Enable the things necessary.

    }

    =============================================================================================

    In the "CLAShared.h"  file:

    extern  Uint16   SinePointCounter;

    extern   float      sineStep;

    ................................

    ==============================================================================================

    In the "CLA.asm" file:

          .cdecls   C,LIST,"CLAShared.h"

          .include   "CLAmathLib_type0.inc"

    CLA_DEBUG .set  1

          .sect    "Cla1Prog"
          .align  2


    _Cla1Prog_Start:

    _Cla1Task1:
        .if CLA_DEBUG == 1
            MDEBUGSTOP
        .endif

    ..................................................................................................

    Experiments  Content ----  See bottom

    .................................................................................................

        MSTOP                                            ; end of task                                                (20)
        MNOP
        MNOP
        MNOP
    _Cla1T1End:

    ===================================================================================================

    Experiments  Content

    experiment1:

    MMOV32      MR0,        @_SinePointCounter

    CLAsin      result,     sineStep

    .......................................................

    In the watch window,  SinePointCounter is equal to 1 ( correct), and  result is also correct.

    experiment2:

    MMOV32      MR0,        @_SinePointCounter

    MMOV32      @_SinePointCounter,      MR0

    CLAsin      result,     sineStep

    .........................................................................................

    In the watch window,  SinePointCounter is equal to 1 ( correct), and  result is also correct.

    experiment3:

    MMOV32      MR0,        @_SinePointCounter

    CLAsin      result,     sineStep

    MMOV32      @_SinePointCounter,      MR0

    .........................................................................................

    In the watch window,  SinePointCounter is equal to 0  ( Wrong ) , and  result is correct.

    I hope someone could help me understand  why Experiment #3 didn't work.

    Thank you.


    Report Abuse
    • Reply
    You have posted to a forum that requires a moderator to approve posts before they are publicly available.
    All Replies
    • Frank H Zhang
      Posted by Frank H Zhang
      on Apr 29 2012 23:32 PM
      Expert1360 points

      Hi,

      Here is my Linker file.   

      Note: It is a modifed version of the linker from the Cla_Adc example in ControlSUITE.     (By the way, I am using TMS320F28035)

      //*************************************************************************************************

      MEMORY
      {
      PAGE 0 :
         /* BEGIN is used for the "boot to SARAM" bootloader mode   */
       
         BEGIN                   : origin = 0x000000, length = 0x000002
         RAMM0                  : origin = 0x000050, length = 0x0003B0
         RAML0L1              : origin = 0x008000, length = 0x000C00
         RAML3                   : origin = 0x009000, length = 0x001000
         RESET                  : origin = 0x3FFFC0, length = 0x000002
         IQTABLES             : origin = 0x3FE000, length = 0x000B50     /* IQ Math Tables in Boot ROM */
         IQTABLES2           : origin = 0x3FEB50, length = 0x00008C     /* IQ Math Tables in Boot ROM */
         IQTABLES3           : origin = 0x3FEBDC, length = 0x0000AA     /* IQ Math Tables in Boot ROM */

         BOOTROM            : origin = 0x3FF27C, length = 0x000D44


      PAGE 1 :

         BOOT_RSVD                     : origin = 0x000002, length = 0x00004E     /* Part of M0, BOOT rom will use this for stack */
         RAMM1                                : origin = 0x000480, length = 0x000380     /* on-chip RAM block M1 */
         RAML2                                 : origin = 0x008C00, length = 0x000400
         CLA1_MSGRAMLOW       : origin = 0x001480, length = 0x000080
         CLA1_MSGRAMHIGH      : origin = 0x001500, length = 0x000080
      }


      SECTIONS
      {
         /* Setup for "boot to SARAM" mode:
            The codestart section (found in DSP28_CodeStartBranch.asm)
            re-directs execution to the start of user code.  */
         codestart          : > BEGIN,     PAGE = 0
         ramfuncs         : > RAMM0      PAGE = 0
         .text                   : > RAML0L1,   PAGE = 0
         .cinit                  : > RAMM0,     PAGE = 0
         .pinit                 : > RAMM0,     PAGE = 0
         .switch             : > RAMM0,     PAGE = 0
         .reset                : > RESET,     PAGE = 0, TYPE = DSECT /* not used, */

         .stack                  : > RAMM1,     PAGE = 1
         .ebss                   : > RAML0L1,     PAGE = 0
         .econst                : > RAML0L1,     PAGE = 0
         .esysmem         : > RAML0L1,     PAGE = 0

         CLAmathTables    : > RAML2,     PAGE = 1
          
         IQmath                  : > RAML0L1,   PAGE = 0
         IQmathTables     : > IQTABLES,  PAGE = 0, TYPE = NOLOAD

         Cla1Prog         : LOAD = RAML0L1,
                            RUN = RAML3,
                            LOAD_START(_Cla1funcsLoadStart),
                            LOAD_END(_Cla1funcsLoadEnd),
                            RUN_START(_Cla1funcsRunStart),
                            PAGE = 0

         Cla1ToCpuMsgRAM  : > CLA1_MSGRAMLOW,   PAGE = 1
         CpuToCla1MsgRAM  : > CLA1_MSGRAMHIGH,  PAGE = 1

             Cla1DataRAM            : > RAML2, PAGE = 1

      }

      Report Abuse
      • Reply
      You have posted to a forum that requires a moderator to approve posts before they are publicly available.
    • Vishal_Coelho
      Posted by Vishal_Coelho
      on Apr 30 2012 12:15 PM
      Expert5725 points

      Frank,

      The macro CLAsin does not do a context save/restore operation on the registers MR0-MR3. It changes MR0 which is why you are seeing an incorrect value when you write to SinePointCounter

      Regards,

      Vishal

      Report Abuse
      • Reply
      You have posted to a forum that requires a moderator to approve posts before they are publicly available.
    • Frank H Zhang
      Posted by Frank H Zhang
      on Apr 30 2012 16:29 PM
      Expert1360 points

      Hi Vishal,

      Thank you for pointing that out. That is really important for me to know. But the question now is how I can use CLAsin in the middle of my code ?

      Is that the limitation of using CLAsin or other functions from CLAmath library? only at the beginning or at the end of the task?

      Could you maybe show me an example which is little bit more complicated than the example in ControlSUITE? The existing CLAmath examples are too simple, and there is only one operation in each task, so it would never reveal this kind of issue.

      Thank you.

      Report Abuse
      • Reply
      You have posted to a forum that requires a moderator to approve posts before they are publicly available.
    • Vishal_Coelho
      Posted by Vishal_Coelho
      on Apr 30 2012 17:03 PM
      Verified Answer
      Verified by Frank H Zhang
      Expert5725 points

      Frank,

      You can save and restore the registers in code as follows. In the CLA.asm file:

      ;declare these at the top of the file

      _sin_tmp1 .usect "Cla1DataRAM",2
      _sin_tmp2 .usect "Cla1DataRAM",2

      _sin_tmp3 .usect "Cla1DataRAM",2
      _sin_tmp4 .usect "Cla1DataRAM",2

      ;define the following macros

      CONTEXT_SAVE  .macro

         MMOV32   @_sin_tmp1,MR0

         MMOV32   @_sin_tmp2,MR1

         MMOV32   @_sin_tmp3,MR2

         MMOV32   @_sin_tmp4,MR3

         .endm

      CONTEXT_RESTORE .macro

        MMOV32   MR0,@_sin_tmp1

        MMOV32   MR1,@_sin_tmp2

        MMOV32   MR2,@_sin_tmp3

        MMOV32   MR3,@_sin_tmp4

        .endm

      ;You can wrap these macros around the CLAsin macro

      CONTEXT_SAVE

      CLAsin  result,SinePointer

      CONTEXT_RESTORE

      The new compiler, 6.1.0 supports C code on the CLA and is currently available through CCS.  In the next few days, v400 of the CLAmath library will be releasing on controlSUITE. It provides C wrappers for all the routines and allows them to be called from within a task.

      Regards,

      Vishal

      Report Abuse
      • Reply
      You have posted to a forum that requires a moderator to approve posts before they are publicly available.
    • Frank H Zhang
      Posted by Frank H Zhang
      on Apr 30 2012 17:48 PM
      Expert1360 points

      Hi Vishal,

      Thank you so much for your help.

      Report Abuse
      • Reply
      You have posted to a forum that requires a moderator to approve posts before they are publicly available.
    TI E2E™ Community
    • Support Forums
    • Blogs
    • Videos
    • Groups
    • Site Support & Feedback
    • Settings
    TI E2E™ Community Groups
    • TI University Program
    • Make the Switch
    • Microcontroller Projects
    • Motor Drive & Control
    Other Communities
    • Deyisupport
    • Designsomething.org
    • beagleboard.org
    • TI on Element 14
    • TI on TechXchangeSM
    Other Technical & Support Resources
    • WEBENCH® Design Center
    • Product Information Centers
    • Technical Documents
    • TI Design Network
    • TI Technical Articles
    • TI Training

    All content and materials on this site are provided "as is". TI and its respective suppliers and providers of content make no representations about the suitability of these materials for any purpose and disclaim all warranties and conditions with regard to these materials, including but not limited to all implied warranties and conditions of merchantability, fitness for a particular purpose, title and non-infringement of any third party intellectual property right. TI and its respective suppliers and providers of content make no representations about the suitability of these materials for any purpose and disclaim all warranties and conditions with respect to these materials. No license, either express or implied, by estoppel or otherwise, is granted by TI. Use of the information on this site may require a license from a third party, or a license from TI.

    Content on this site may contain or be subject to specific guidelines or limitations on use. All postings and use of the content on this site are subject to the Terms of Use of the site; third parties using this content agree to abide by any limitations or guidelines and to comply with the Terms of Use of this site. TI, its suppliers and providers of content reserve the right to make corrections, deletions, modifications, enhancements, improvements and other changes to the content and materials, its products, programs and services at any time or to move or discontinue any content, products, programs, or services without notice.

    Follow Us Texas Instruments on Facebook Texas Instruments on Twitter Texas Instruments on LinkedIn Texas Instruments on Google+
    TI Worldwide | Contact Us | my.TI Login | Site Map | Corporate Citizenship | mobile m.ti.com (Mobile Version)

    TI is a global semiconductor design and manufacturing company. Innovate with 100,000+ analog ICs and
    embedded processors, along with software, tools and the industry’s largest sales/support staff.

    © Copyright 1995-2013 Texas Instruments Incorporated. All rights reserved.
    Trademarks | Privacy Policy | Terms of Use