Yahoo Groups archive

AVR-Chat

Index last updated: 2026-04-28 22:41 UTC

Message

Re: [AVR-Chat] Delay functions and "__builtin_avr_delay_cycles".

2011-07-05 by Jim Hatley

I agree with David ... don't use "built-in delay codes" ... roll your own if absolutely required.

Software timing loops are not a good idea but sometimes the only way to make something work. It is easy to get in to trouble ... been there done that. I use them but very carefully when there is no other way.

Suggest you write an assembly language routine - not C - to do your own timing method. Use it within your C program so that it will always stays the same. This way you will have consistent timing. If the code that the compiler generates changes due to an compiler upgrade or whatever your C timing routine is in trouble and no longer doing what you think it is. Just try and find that problem.

Be sure interrupts are disabled during software timing efforts as interrupts cause your timing routine to generate much longer times than called for. I know ... not always possible but one must be careful.

And at times, a string of NOPs or a routine with NOPs can work for small delays.

Jim




  ----- Original Message ----- 
  From: Cat C 
  To: avr-chat@yahoogroups.com 
  Sent: Monday, July 04, 2011 4:20 PM
  Subject: RE: [AVR-Chat] Delay functions and "__builtin_avr_delay_cycles".


    

  Thanks David,
  You'd think there should be a way to tell, if it's mentioned in the documentation like that...
  Regarding empty loops... we're not all as professional as you are :-)
  Cat

  > To: AVR-Chat@yahoogroups.com
  > From: dkelly@hiwaay.net
  > Date: Mon, 4 Jul 2011 17:05:09 -0500
  > Subject: Re: [AVR-Chat] Delay functions and "__builtin_avr_delay_cycles".
  > 
  > 
  > On Jul 4, 2011, at 2:55 PM, Cat C wrote:
  > 
  > > Hi there,
  > > Looking at the delay functions, I see that: void _delay_us 
  > > (
  > > double 
  > > __us )has a maximal possible delay is 768 us / F_CPU in MHz.
  > > But:If the avr-gcc toolchain has __builtin_avr_delay_cycles(unsigned long) 
  > > support, maximal possible delay is 4294967.295 us/ F_CPU in MHz.
  > > How do I know if the avr-gcc toolchain has __builtin_avr_delay_cycles(unsigned long) support?
  > > Thanks,
  > > Cat
  > 
  > 
  > "Use the source (sic) Luke".
  > 
  > Consult the avr-libc sources. I don't remember how much is shipped with WinAVR, or how much is shipped with AVR Studio 5.0. It doesn't really matter else I would go look because even if you go looking at the original source you need to build a test case and select "generate a disassembly listing" and have a look at exactly what code was generated. Else the original library sources you are looking at may not be the ones used for your CPU.
  > 
  > Burning CPU cycles in empty loops is usually a very amateurish and inaccurate means to an end.
  > 
  > --
  > David Kelly N4HHE, dkelly@HiWAAY.net
  > ========================================================================
  > Whom computers would destroy, they must first drive mad.
  > 



  [Non-text portions of this message have been removed]



  

[Non-text portions of this message have been removed]

Attachments

Move to quarantaine

This moves the raw source file on disk only. The archive index is not changed automatically, so you still need to run a manual refresh afterward.