_delay_ms

Go To Last Post
7 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I want to ask how precise _delay_ms in util/delay.h in avr gcc is??...
as when simulating a delay of 1000ms the stop watch goes from 400us to 66000us for atmega32 at 4mhz....thats not 1000ms
and when simulating a delay of 2ms the stop watch goes from 400us to 5000us for atmega32 at 4mhz....

any clues??

and this macro

loose_delay(delay)   \
  for (__temp0 = 0; __temp0 < delay; __temp0++) { \
    for (__temp1 = 0; __temp1 < 0x00FF; __temp1++); \
  }

for loose_delay(120) goes from 400us to 97000us....

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Read up on _delay_ms, it is dependend on the clock and I don't think you can get 1000ms anyway.

John Samperi

Ampertronics Pty. Ltd.

https://www.ampertronics.com.au

* Electronic Design * Custom Products * Contract Assembly

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

We have seen 1000ms being commonly used in functions and we are using this for external oscillator stabilization....

Anyway, these are not giving precise delays, even delay of 2ms is not exact as mentioned earlier...

any specific link for _delay_ms()??

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

anubhavh wrote:
any specific link for _delay_ms()??
The default installation site for the file with the source code (and comments) for that function is c:\winavr\avr\include\util\delay.h

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Have a look at my code in the projects section:
https://www.avrfreaks.net/index.php?module=Freaks%20Academy&func=viewItem&item_type=project&item_id=665

The macros are extensions to the ideas in "delay.h".
Depending on cpu frequency they range to more than 500 seconds @8MHz.
The accuracy of all macros is a single clock cycle.
Regards,
heinrichs.hj

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

_delay_ms has a limit as to the value that you can pass to it. The limit is 262.14 / F_CPU. So for 4MHz, the maximum is 65.535. Within that limit, the delay is accurate (though there is a slight overhead for each call).

Regards,
Steve A.

The Board helps those that help themselves.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Oh for the love of Pete - anubhavh would you PLEASE stop cross posting?!?!

First I log on this morning and find I've got a PM from you about this so I answered that. Then I added a further reply to one of you other threads you created asking this same question and now find I wasted my time as the answer was already given here.

THIS is why you should not cross post.

The nett effect is simply that I won't bother answering any of your questions in future (so don't bother PMing me again either)