On Jul 4, 2011, at 7:36 PM, Jim Hatley wrote: > 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. Yes, as I said it is *usually* amateurish and/or inaccurate. I don't fault avr-libc for having calibrated delay loops. Have used them in my own code temporarily, but never shipped code. Can be handy for creating a high CPU load condition to see how other parts of one's code runs. Also handy for altering the order events are processed when one suspects some things are happening at the same time and not being handled correctly. The calibrated delay loops in the library also serve as examples that one may expand on for other purposes. One key thing to learn to be a good embedded programmer is to not trust any canned libraries, or even the built-in intrinsics of the compiler. Its this lack of trust which forms the basis for many's dislike/distrust of C++. "Distrust" doesn't mean "don't use". It means "verify." I always include a disassembly listing in my avr-gcc builds. Spend a fair bit of time looking at the generated code before deciding it is acceptable or not. Often make changes in the C so as to simplify the generated assembly. Come to think of it, "Never say never because never is never true." I did ship code once with calibrated delay loops. Used a PIC16C505 which doesn't have interrupts or timers. Or UART. And I needed to send an asynchronous serial bit stream. That one little chip replaced an entire PC from someone else's design. -- David Kelly N4HHE, dkelly@HiWAAY.net ======================================================================== Whom computers would destroy, they must first drive mad.
Message
Re: [AVR-Chat] Delay functions and "__builtin_avr_delay_cycles".
2011-07-05 by David Kelly
Attachments
- No local attachments were found for this message.