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.

TMS320F28069M: using DELAY_US

Part Number: TMS320F28069M
Other Parts Discussed in Thread: MOTORWARE

Hi, I am hoping to get some assistance to figure out how to use delay_us. i looked at this forum topic:

https://e2e.ti.com/support/microcontrollers/c2000-microcontrollers-group/c2000/f/c2000-microcontrollers-forum/719122/compiler-tms320f28335-delay-and-other-built-in-macro-functions-reference-manual?tisearch=e2e-sitesearch&keymatch=delay_ms#

However, I am not sure how to apply it in my application. I am modifying Instaspin Lab 12b. I've tried adding F2806x_sysCtrl.c to my project and f2806x_usDelay.asm. then I added several more files from those same examples. I've done #include with some of the associated files.... I keep getting errors. 

Can someone detail what I need to #include, what files I need to add, and what I need to add to my code to be able to use delay_us?

Alternately, is there a simpler solution?

Thanks!

  • Deborah,

    I think the issue might be that the InstaSPIN labs are using motorware vs the headerfiles that our examples are constructed with.  So there are likely defines that are not present in the motorware labs.

    Can you C/P the errors that you are getting from CCS when you try and compile the lab after manually adding the F2806x_usDelay.asm file?

    Best,

    Matthew

  • Hi Matthew,

    I was able to find an arrangement that didn't give me errors today, but it isn't actually doing anything. 

    It is really straight forward, so maybe you can tell me what I am missing to make it work. 

    I now only have the f2086x_usDelay.asm file added to my project.

    it looks like this:

           .def _DSP28x_usDelay
           .sect "ramfuncs"
    
            .global  __DSP28x_usDelay
    _DSP28x_usDelay:
            SUB    ACC,#1
            BF     _DSP28x_usDelay,GEQ    ;; Loop if ACC >= 0
            LRETR 

    In my proj_lab12b.c file I've added:

    #define DELAY_US(A)  DSP28x_usDelay(((((long double) A * 1000.0L) /\
                         (long double)CPU_RATE) - 9.0L) / 5.0L)
                         
    #define CPU_RATE   11.111L   // for a 90MHz CPU clock speed (SYSCLKOUT)
     

    I am calling it like this (for instance):

    DELAY_US(100000L);

    I've tried shorter and longer times and loops to try and see if it is working. It doesn't seem to be doing anything. What am I doing wrong?

  • This looks correct, esp if the compiler/linker isn't throwing an error at you.  I know that the output file format(coff ABI vs EABI) treats function names a bit differently, so sometimes there is not a need for the "_" in front of the assembly function.  If that were the case then the compiler would have given an error that function xxxx could not be found.

    I would also make sure there is a section in your .cmd file called "ramfuncs" for placement, but again I think if that were the issue you would have gotten a linker error/warning.

    Can you put a breakpoint at the Delay_US function call, and then view the dis-assembly View->Disassembly.  Then let's use the assembly step function to see exactly what is going on(or not) when the function is called.  These should be green arrows to assembly step, vs the yellow arrows that C step.

    Best,

    Matthew

  • Hi Matthew,

    I didn't change anything for the assembly function. Would the already existing "_" harm anything?

    I double-checked and I do have "ramfuncs" in the cmd file: 

    MEMORY
    {
    PAGE 0 :
    
       BEGIN       : origin = 0x000000, length = 0x000002    /* BEGIN is used for the "boot to SARAM" bootloader mode   */
       RAMM0       : origin = 0x000050, length = 0x0003B0
       RAML0_L8    : origin = 0x008000, length = 0x00B800	 /* on-chip RAM block RAML0-L8. From 0x13800 to 0x14000 is reserved for InstaSPIN */
    
       RESET       : origin = 0x3FFFC0, length = 0x000002
       FPUTABLES   : origin = 0x3FD590, length = 0x0006A0	 /* FPU Tables in Boot ROM */
       IQTABLES    : origin = 0x3FDC30, length = 0x000B50    /* IQ Math Tables in Boot ROM */
       IQTABLES2   : origin = 0x3FE780, length = 0x00008C    /* IQ Math Tables in Boot ROM */
       IQTABLES3   : origin = 0x3FE80C, length = 0x0000AA	 /* IQ Math Tables in Boot ROM */
    
       BOOTROM    : origin = 0x3FF3B0, length = 0x000C10
    
    
    PAGE 1 :
    
       BOOT_RSVD   : origin = 0x000002, length = 0x00004E    /* Part of M0, BOOT rom will use this for stack */
       RAMM1       : origin = 0x000400, length = 0x000400    /* on-chip RAM block M1 */
       USB_RAM     : origin = 0x040000, length = 0x000800    /* USB RAM */
    }
    
    
    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,
                            LOAD_START(_RamfuncsLoadStart),
                            LOAD_END(_RamfuncsLoadEnd),
                            RUN_START(_RamfuncsRunStart),
                            LOAD_SIZE(_RamfuncsLoadSize),
                                        PAGE = 0
       .text            : > RAML0_L8,   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            : > RAML0_L8,   PAGE = 0
       .econst          : > RAML0_L8,   PAGE = 0
       .esysmem         : > RAML0_L8,   PAGE = 0
    
       IQmath           : > RAML0_L8,   PAGE = 0
       IQmathTables     : > IQTABLES,   PAGE = 0, TYPE = NOLOAD
       
       /* Allocate FPU math areas: */
       FPUmathTables    : > FPUTABLES,  PAGE = 0, TYPE = NOLOAD
       
       /* DMARAML4_6	        : > RAML4_6,      PAGE = 1  /* */
    
    
      /* Uncomment the section below if calling the IQNexp() or IQexp()
          functions from the IQMath.lib library in order to utilize the
          relevant IQ Math table in Boot ROM (This saves space and Boot ROM
          is 1 wait-state). If this section is not uncommented, IQmathTables2
          will be loaded into other memory (SARAM, Flash, etc.) and will take
          up space, but 0 wait-state is possible.
       */
       /*
       IQmathTables2    : > IQTABLES2, PAGE = 0, TYPE = NOLOAD
       {
    
                  IQmath.lib<IQNexpTable.obj> (IQmathTablesRam)
    
       }
       */
       /* Uncomment the section below if calling the IQNasin() or IQasin()
          functions from the IQMath.lib library in order to utilize the
          relevant IQ Math table in Boot ROM (This saves space and Boot ROM
          is 1 wait-state). If this section is not uncommented, IQmathTables3
          will be loaded into other memory (SARAM, Flash, etc.) and will take
          up space, but 0 wait-state is possible.
       */
       /*
       IQmathTables3    : > IQTABLES3, PAGE = 0, TYPE = NOLOAD
       {
    
                  IQmath.lib<IQNasinTable.obj> (IQmathTablesRam)
    
       }
       */
    
       Cla1Prog         : > RAML0_L8,       PAGE = 0
       unsecure_data    : > RAML0_L8,       PAGE = 0
    }
    

    I put breakpoints around the code where I called the Delay_US function, ran the debugger and viewed the disassembly. I do not see any arrows, either green or yellow. 

    I scrolled through and it never ends. Never any arrows. Any ideas? 

    Could we schedule a bit of time for chatting or something? I think your morning overlaps with my afternoon/evening. If its possible just let me know what time.

  • Deborah,

    I'll contact you off forum to see if we can set something up.

    Best,

    Matthew

  • For anyone else looking at this problem, Matthew determined I also needed to add

    extern void DSP28x_usDelay(uint32_t Count);

    to my main.h file.

    we also moved

    #define DELAY_US(A) DSP28x_usDelay(((((long double) A * 1000.0L) /\
    (long double)CPU_RATE) - 9.0L) / 5.0L)

    from my project file to the main.h file.

    It works great now!