• 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 » Delay Program -28335
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?
  • InstaSPIN Simulation Tool
  • Product Folder: F28069F, F28068F, F28062F, F28068M, F28069M
  • User’s Guide
  • Technical User’s Manual
  • Tools
  • Forums

    Delay Program -28335

    • malaiyappan m
      Posted by malaiyappan m
      on Feb 11 2009 01:41 AM
      Prodigy90 points

      Dear all,

      anybody can u give me  the delay calculation and sample code for tms320f28335

       

      regards,

      Malaiyappan.M

      Report Abuse
      • Reply
      You have posted to a forum that requires a moderator to approve posts before they are publicly available.
    • malaiyappan m
      Posted by malaiyappan m
      on Feb 11 2009 08:33 AM
      Prodigy90 points

      use 

      DELAY_US(time);

       

      with all header file.

       

      DSP2833x_EXAMPLES.H and all;

       

      Thanks

      malaiyappan

       

       

       

      Report Abuse
      • Reply
      You have posted to a forum that requires a moderator to approve posts before they are publicly available.
    • SAP
      Posted by SAP
      on Feb 12 2009 03:41 AM
      Prodigy200 points

      DSP2833x_usDelay.asm ,  The asm code for the delay is there in this file . you can ad this source in you file and

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

      add the above definition in your header . This a delay code which is availible in the examples code . 

      As Mr. Malaiyappan told the above #define is included in DSP2833x_Examples.h

       

      SAP[Y]

      Report Abuse
      • Reply
      You have posted to a forum that requires a moderator to approve posts before they are publicly available.
    • jianliang sun
      Posted by jianliang sun
      on Sep 23 2009 04:19 AM
      Prodigy10 points

      Hi!

      Could you explain the use of

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

      how to calculate the time ?When the CPU_RATE is 10.000L or 16.667L.and so on!

      Report Abuse
      • Reply
      You have posted to a forum that requires a moderator to approve posts before they are publicly available.
    • Lori Heustess
      Posted by Lori Heustess
      on Sep 23 2009 18:08 PM
      Guru52225 points

      The macro calls an assembly function called DSP28x_usDelay.   You specify the CPU_RATE and pass the macro the number of microseconds of delay you want.  The macro does the conversion for you.  This is from the source file for the delay function:

       

      ;// To use this function:
      ;//
      ;//  1 - update the CPU clock speed in the DSP2803x_Examples.h
      ;//    file. For example:
      ;//    #define CPU_RATE 16.667L // for a 60MHz CPU clock speed
      ;//
      ;//  2 - Call this function by using the DELAY_US(A) macro
      ;//    that is defined in the DSP2803x_Device.h file.  This macro
      ;//    will convert the number of microseconds specified
      ;//    into a loop count for use with this function. 
      ;//    This count will be based on the CPU frequency you specify.
      ;//
      ;//  3 - For the most accurate delay
      ;//    - Execute this function in 0 waitstate RAM. 
      ;//    - Disable interrupts before calling the function
      ;//      If you do not disable interrupts, then think of
      ;//      this as an "at least" delay function as the actual
      ;//      delay may be longer.

      Lori

      Did a reply answer your question? If yes, please click the "yes" button located at the bottom of that post.
      Visit these helpful C2000 Links!
      C2000 TI Wiki Pages
      TI Forum Sitemap
      ControlSUITE
      C2000 Getting Started
      CLA FAQs
      Workshop Material!
      Report Abuse
      • Reply
      You have posted to a forum that requires a moderator to approve posts before they are publicly available.
    • Julian Woloszczuk
      Posted by Julian Woloszczuk
      on Sep 12 2011 10:07 AM
      Intellectual445 points

      Hello,  I'm looking at using the basis of this delay function, too.  When I look at the assember for this -

      _DSP28x_usDelay:
              SUB    ACC,#1
              BF     _DSP28x_usDelay,GEQ    ;; Loop if ACC >= 0
              LRETR

       

      I can see that the ACC register is decremented by one each time. Looking at the ACC register, it appears that it's only 32 bits wide. However, the possible 'loop' values could be bigger than this. Am I missing something?    Thanks,    Julian.

      Report Abuse
      • Reply
      You have posted to a forum that requires a moderator to approve posts before they are publicly available.
    • Lori Heustess
      Posted by Lori Heustess
      on Sep 12 2011 14:00 PM
      Guru52225 points

      Julian Woloszczuk

      Hello,  I'm looking at using the basis of this delay function, too.  When I look at the assember for this -

      _DSP28x_usDelay:
              SUB    ACC,#1
              BF     _DSP28x_usDelay,GEQ    ;; Loop if ACC >= 0
              LRETR

       

      I can see that the ACC register is decremented by one each time. Looking at the ACC register, it appears that it's only 32 bits wide. However, the possible 'loop' values could be bigger than this. Am I missing something?    Thanks,    Julian.

      Yes.  The ACC is 32 bits - so if the value passed to the function to achieve the desired delay exceeds 32-bits, then more than one delay() will need to be called.   The MAX delay would depend on the CPU frequency.

      Regards

      Lori

       

      Did a reply answer your question? If yes, please click the "yes" button located at the bottom of that post.
      Visit these helpful C2000 Links!
      C2000 TI Wiki Pages
      TI Forum Sitemap
      ControlSUITE
      C2000 Getting Started
      CLA FAQs
      Workshop Material!
      Report Abuse
      • Reply
      You have posted to a forum that requires a moderator to approve posts before they are publicly available.
    • Julian Woloszczuk
      Posted by Julian Woloszczuk
      on Sep 13 2011 02:35 AM
      Intellectual445 points

      I'm not sure that explains why the macro call casts values to 'long double', as below.

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

      Also, if I want to put the assembler 'inline', in a .cpp file, I have a few further questions -

      Do I have to put each assembler line in the 'asm statement', as below, or is there a better way?

       

       

      void

       

      DoDelay(Uint64 loop)

       

       

       

      {

       

      asm

      asm

       

      (" MOV AH, @PH");

       

      asm (" MOV AH, @PH");

       

       

      asm (" SUB ACC, #1");

       

       

      asm (" BF -1, GEQ");

       

       

      asm (" LRETR");

      }

      The only reference I can see in the documentation on this is section 6.9 of SPRU514 - the 'C' compiler guide - it only has one example! Is there a more detailed explanation elsewhere?

      Also, you can see from my assembler that I'm assuming my parameter from the 'C++' function is in the 'P' register(s). Is there a way I can reference my C++ parameter by name in the assembler language instructions?  Again, I'm struggling to find a document that covers this.      Looking forward to your help!   Julian.

       

      Report Abuse
      • Reply
      You have posted to a forum that requires a moderator to approve posts before they are publicly available.
    • Julian Woloszczuk
      Posted by Julian Woloszczuk
      on Sep 13 2011 02:37 AM
      Intellectual445 points

      Sorry about the formatting - don't know what happened there :-)

      Report Abuse
      • Reply
      You have posted to a forum that requires a moderator to approve posts before they are publicly available.
    • Julian Woloszczuk
      Posted by Julian Woloszczuk
      on Sep 13 2011 02:39 AM
      Intellectual445 points

      hopefully this is better....

       

      void

      DoDelay(Uint64 loop)

      {

       asm (" MOV AH, @PH");

      asm (" MOV AH, @PH");

      asm (" SUB ACC, #1");

      asm (" BF -1, GEQ");

      asm (" LRETR");

       }

      Report Abuse
      • Reply
      You have posted to a forum that requires a moderator to approve posts before they are publicly available.
    • Edwin Krasser
      Posted by Edwin Krasser
      on Sep 15 2011 01:29 AM
      Expert2220 points

      Hi!

      How long do you want to wait? With a 32 bit counter (using 31 bit) you can wait up to 7 seconds on a 300 MHz Delphino. But you cannot do anything during waiting. Except some interrupt service routines, but the ISR execution time will make your waiting time longer. If you want to have an exact waiting time you will have to use a timer. I suggest to let CPU timer 0 simply count down and wait until the timer reaches the calculated end value:

      void Wait(unsigned long in us)
      { unsigned long int stop;
        asm(" clrc ovm");
        stop = CpuTimer0Regs.TIM.all-CLKS_PER_US*(unsigned long int)us; // CLKS_PER_US = number of ticks per micro second
        while((signed long int)(CpuTimer0Regs.TIM.all-stop)>0);
      }

      This waiting function works (nearly) exact. Independent of interrupts.

      For real long waiting times you will need a periodic timer interrupt incrementing a counter. Then you can implement your extra long delay in software. (a 1 ms periodic interrupt with a long long (64 bit) counter will give you millions of years).

      Hence, I do not recommend to use a delay loop for waiting. Perhaps in examples, but not in real applications where you need an exact waiting time.

      Regards,
      Edwin Krasser

      Report Abuse
      • Reply
      You have posted to a forum that requires a moderator to approve posts before they are publicly available.
    • Julian Woloszczuk
      Posted by Julian Woloszczuk
      on Sep 15 2011 09:36 AM
      Intellectual445 points

      Thanks for the info, Edwin.   I've given this a go, but my TMS320F2812 device's timer register is only 16 bits, so at 150 'ticks' per microsecond, this only gives me a max delay of 436 microseconds. Do you agree?  Yes, I will have to implement a 'proper' timer soon !

      Report Abuse
      • Reply
      You have posted to a forum that requires a moderator to approve posts before they are publicly available.
    • Julian Woloszczuk
      Posted by Julian Woloszczuk
      on Sep 15 2011 10:14 AM
      Intellectual445 points

      Just to clarify, on my CCS, I see the timer as a 16-bit value, and if I read the register into a 32-bit variable (see below), after I've reset the counter, I only see 0xFFFF. Am I missing something here?

       Uint32 cpuReg = CpuTimer0Regs.TIM.all;

      Report Abuse
      • Reply
      You have posted to a forum that requires a moderator to approve posts before they are publicly available.
    • Edwin Krasser
      Posted by Edwin Krasser
      on Sep 16 2011 00:29 AM
      Expert2220 points

      Hi!

      The event manager counters are just 16 bit. You can use one for a 1 ms software counter. But if you want to get a universal wait function you should use the cpu timer 0. It is a 32 bit counter which counts down. And the 0xFFFF after resetting are ok cause it counts down. Just let your program run and stop it by JTAG some seconds later. Then you should see that the counter value has decremented. Here is the initialization I use for an endless 32 bit counter (counting clock cycles):

        CpuTimer0Regs.PRD.all=0xFFFFFFFF;
        CpuTimer0Regs.TPR.bit.TDDR=0;
        CpuTimer0Regs.TPRH.bit.TDDRH=0;
        CpuTimer0Regs.TCR.all=0x8020; // start timer, no interrupts

      With the waiting function (from my first post) you will get a maximum waiting time of 14.3 (=2^31/150E6) seconds at 150 MHz. Independent of ISR load.

      Regards,
      Edwin Krasser

      Report Abuse
      • Reply
      You have posted to a forum that requires a moderator to approve posts before they are publicly available.
    • Julian Woloszczuk
      Posted by Julian Woloszczuk
      on Sep 16 2011 03:21 AM
      Intellectual445 points

      Thanks for the info. I've put your settings into my routine (see below), but although a delay of 1,000us is OK, when I try a value of 10,000us, my while loop doesn't exit. Interestingly, when I stop the processor, I notice that the 'period' register is no longer 0xFFFFFFFF. You'll see I've simplified the routine so it assumes we're starting from 0xFFFFFFFF each time. Any ideas?   Thanks!

      CpuTimer0Regs.PRD.all=0xFFFFFFFF;

      CpuTimer0Regs.TPR.bit.TDDR=0;

      CpuTimer0Regs.TPRH.bit.TDDRH=0;

      CpuTimer0Regs.TCR.all=0x8020; // start timer, no interrupts

       Uint32 ticks_required = 150*number_of_microseconds;

      Uint32 stop_point = 0xFFFFFFFF-ticks_required;

      while (CpuTimer0Regs.TIM.all > stop_point);

      }

      Report Abuse
      • Reply
      You have posted to a forum that requires a moderator to approve posts before they are publicly available.
    12
    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