| Author |
Message |
|
|
Posted: Jun 11, 2012 - 01:57 PM |
|

Joined: Sep 08, 2011
Posts: 116
|
|
using #include<util/delay.h> for avr's what is the maximum delay an avr can produce say for at mega 8 and i couldn't find any good tutorials explaining delay function.
i found a delay.h header file that is to be used in winavr but what if i want do programming,compiling and burning from teminal(linux) or cmd in windows.regardless of having the delay.h header i couldn't understand the delay function.And one question also how does the "delay.h" differs from <util/delay.h>.
im posting the delay header here:
this header file provides time delay in the form of mili second and micro second without affecting any interrupts.
delayms() this function provides delay in the form of mili second .delayus() this function provides delay in the form of micro second.
*/
Code:
#ifndef _DELAY_H_
#define _DELAY_H_
unsigned int delaycounter1,delaycounter2;
void delayms(unsigned int delaytime)
{
for(delaycounter1=0;delaycounter1<=delaytime;delaycounter1++)
{
for(delaycounter2=0;delaycounter2<=800;delaycounter2++)
{
asm("nop");asm("nop");asm("nop");asm("nop");asm("nop");asm("nop");
asm("nop");asm("nop");asm("nop");asm("nop");asm("nop");asm("nop");
}
}
}
void delayus(unsigned int delaytime)
{
for(delaycounter1=0;delaycounter1<=delaytime;delaycounter1++)
{
asm("nop");asm("nop");asm("nop");asm("nop");asm("nop");asm("nop");
asm("nop");asm("nop");asm("nop");asm("nop");
}
}
#endif
|
_________________ *** ***
*********************
the more is see,less i know
Last edited by arun_nr on Jun 11, 2012 - 03:12 PM; edited 1 time in total
|
| |
|
|
|
|
|
Posted: Jun 11, 2012 - 02:59 PM |
|

Joined: Nov 02, 2009
Posts: 3239
Location: Zelenograd, Russia
|
|
 |
_________________ Warning: Grumpy Old Chuff. Reading this post may severely damage your mental health.
|
| |
|
|
|
|
|
Posted: Jun 11, 2012 - 03:01 PM |
|


Joined: Jul 18, 2005
Posts: 62220
Location: (using avr-gcc in) Finchingfield, Essex, England
|
|
|
Quote:
using #include<util/delay.h> for avr's what is the maximum delay an avr can produce say for at mega 8 and i couldn't find any good tutorials explaining delay function.
Do you not have a copy of the user manual on your hard drive then? (must be using AS6!). It's here:
http://www.nongnu.org/avr-libc/user-man ... delay.html
and unequivocal:
Quote:
The maximal possible delay is 262.14 ms / F_CPU in MHz.
When the user request delay which exceed the maximum possible one, _delay_ms() provides a decreased resolution functionality. In this mode _delay_ms() will work with a resolution of 1/10 ms, providing delays up to 6.5535 seconds (independent from CPU frequency). The user will not be informed about decreased resolution.
If the avr-gcc toolchain has __builtin_avr_delay_cycles(unsigned long) support, maximal possible delay is 4294967.295 ms/ F_CPU in MHz. For values greater than the maximal possible delay, overflows results in no delay i.e., 0ms.
I simply don't see the point of the rather half-baked code you posted. It can only really offer the "ms" in delayms() for ONE particular F_CPU value with the hard coded looping constants it contains. What on earth is the point ni reinventing a square wheel? (one is reminded of Hengis Pod's triumph in Carry on Cleo!)
 |
_________________
|
| |
|
|
|
|
|
Posted: Jun 11, 2012 - 03:53 PM |
|

Joined: Sep 08, 2011
Posts: 116
|
|
i got this header from an institute that offer avr courses!
Thanks a lot for your help!  |
_________________ *** ***
*********************
the more is see,less i know
|
| |
|
|
|
|
|
Posted: Jun 11, 2012 - 08:54 PM |
|

Joined: Nov 17, 2004
Posts: 13815
Location: Vancouver, BC
|
|
|
Quote:
It can only really offer the "ms" in delayms() for ONE particular F_CPU value with the hard coded looping constants it contains.
And only on one version of avr-gcc and probably only on one optimization level. |
_________________ Regards,
Steve A.
The Board helps those that help themselves.
|
| |
|
|
|
|
|
Posted: Jun 12, 2012 - 08:47 AM |
|

Joined: May 03, 2009
Posts: 564
Location: Dallas, TX USA
|
|
|
|
|
|
|
Posted: Jun 13, 2012 - 06:02 AM |
|

Joined: Sep 08, 2011
Posts: 116
|
|
hii all,
can u suggest whether this book is good for a newbie to start up..if it's not then can you suggest any good resources?
Thank you.I don't know in which forum to post on that.so parden
the book is
Quote:
C Programming for Embedded Microcontrollers: Learn the C Programming Language using Free and Open Source Software on Embedded Systems with ARM7 Microcontroller Examples
Warwick A. Smith
its a book from elektor |
_________________ *** ***
*********************
the more is see,less i know
|
| |
|
|
|
|
|
Posted: Jun 13, 2012 - 09:12 AM |
|


Joined: Jul 18, 2005
Posts: 62220
Location: (using avr-gcc in) Finchingfield, Essex, England
|
|
| Surely that depends on whether you plan to work with ARM7 or not? I'd have thought you'd want a book about AVR. As such I'd recommend www.smileymicros.com that have good books for helping the beginner to learn about programming AVRs in C. If you prefer Asm then look for books by Chuck Baird at http://www.zbaird.com/ |
_________________
|
| |
|
|
|
|
|
Posted: Jun 13, 2012 - 12:06 PM |
|

Joined: Sep 08, 2011
Posts: 116
|
|
thank you!
smileymicros is the way. |
_________________ *** ***
*********************
the more is see,less i know
|
| |
|
|
|
|
|