Problem with _delay_ms function

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

Hello Guys,

i am executing the following code on my Atmega8515 board. The crystal is of 8MHz.LED is connected to the output pint of PORT A. The problem is i am not getting one second delay between ON and OFF. The delay seems to be around 8 Seconds. :cry:

#include  // avr header file for IO ports
#include  
int main(void)
{
	unsigned char i; // temporary variable
	DDRA = 0x00; // set PORTA for input
	PORTA = 0x00; // turn ON all LEDs initially

	while(1)
	{
	
		PORTA = 0x01;
		_delay_ms(1000);
		PORTB = 0x00;
		_delay_ms(1000);

	}
	return 1;
}

My final aim is to drive two servo connect to PinA.1 and PinA.2 for which i will change the timings in range of (1 - 2 ms). Can anyone suggest any other method for driving servos.
I guess timer can be used but i am not sure how.

Regards
Nitin D

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

check the CLK div 8 fuse in the fuses.
sounds typically like it is set, so the processor is running 8 times slower then you think it is.

regards

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

In WinAVR delay() has terrafic restrictions !!! Read
WinAVR-folder\doc\avr-libc\avr-libc-user-manual.pdf

6.28 : Basic busy-wait delay loops
page 166

and be cool ! :lol:

CVAVR delay is real nice one.

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

nitindamame wrote:
My final aim is to drive two servo connect to PinA.1 and PinA.2 for which i will change the timings in range of (1 - 2 ms). Can anyone suggest any other method for driving servos.

I guess timer can be used but i am not sure how.


Timer yes ! See 8 servo control by one timer
http://avr123.nm.ru/z13.htm - google will translate it for you. Source code need not translations.

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

Quote:

In WinAVR delay() has terrafic restrictions !!!

Are you using an old version by any chance? For more than a year most of the previous restrictions of _delay_ms() and _delay_us() have been removed.

Cliff

PS I'll move this to GCC...

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

Quote:
For more than a year most of the previous restrictions of _delay_ms() and _delay_us() have been removed.

While the restrictions remain in the documentation. I just double checked the on-line version, and my locally installed (WinAVR-20081205), and they both still specify the 262.14/F_CPU [ms/MHz].

As of January 15, 2018, Site fix-up work has begun! Now do your part and report any bugs or deficiencies here

No guarantees, but if we don't report problems they won't get much of  a chance to be fixed! Details/discussions at link given just above.

 

"Some questions have no answers."[C Baird] "There comes a point where the spoon-feeding has to stop and the independent thinking has to start." [C Lawson] "There are always ways to disagree, without being disagreeable."[E Weddington] "Words represent concepts. Use the wrong words, communicate the wrong concept." [J Morin] "Persistence only goes so far if you set yourself up for failure." [Kartman]

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

Quote:

and they both still specify the 262.14/F_CPU [ms/MHz].

but then have an additional paragraph that the older docs didn't have about coarser granularity abovete threshold. But I agree it is a bit misleading.

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

Oh dear.. That was really sloppy reading of me. I just glansed over

Quote:
The maximal possible delay is 262.14 ms / F_CPU in MHz.

and didn't read more as I thought that was conclusive.
Sorry..

As of January 15, 2018, Site fix-up work has begun! Now do your part and report any bugs or deficiencies here

No guarantees, but if we don't report problems they won't get much of  a chance to be fixed! Details/discussions at link given just above.

 

"Some questions have no answers."[C Baird] "There comes a point where the spoon-feeding has to stop and the independent thinking has to start." [C Lawson] "There are always ways to disagree, without being disagreeable."[E Weddington] "Words represent concepts. Use the wrong words, communicate the wrong concept." [J Morin] "Persistence only goes so far if you set yourself up for failure." [Kartman]

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

JohanEkdahl wrote:
Oh dear.. That was really sloppy reading of me. I just glansed over
Quote:
The maximal possible delay is 262.14 ms / F_CPU in MHz.

and didn't read more as I thought that was conclusive.
Sorry..
It looks conclusive to me.

Iluvatar is the better part of Valar.

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

Starting with WinAVR 20081205, there are some new built in functions including this one:
void __builtin_avr_delay_cycles(unsigned long __n);

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

Hey guys

Thanks for all your replies. The problem was with the fuse settings.

Regards
Nitin