util_delay_basic(3)

πŸ“¦ version 2.2.1, in fedora 43, fedora 44, opensuse-leap 16.0

πŸ’– util_delay_basic(3) πŸ’–

okay bestie, welcome to avr-libc's little corner of the delay world πŸ¦‹ this one's a manual page from the avr-libc manual, and it's all about making your microcontroller wait on purpose. no cap.


✨ NAME ✨

util_delay_basic β€” the header that gives you the most basic, no-frills busy-wait delay loops. it's giving "we have a timer at home" but like, intentionally.


🌸 SYNOPSIS 🌸

πŸŽ€ Functions

void _delay_loop_1 (uint8_t __count)
void _delay_loop_2 (uint16_t __count)

πŸ’… Detailed Description πŸ’…

#include <util/delay_basic.h>

so here's the tea β˜• the functions in this header file implement simple delay loops that perform a busy-waiting. they're the "just stand there and count" of embedded programming. you'd typically use them to facilitate short delays in the program execution. they're implemented as count-down loops with a well-known CPU cycle count per loop iteration. and because that's literally all they do β€” no timer hardware, no fancy scheduler β€” no other processing can occur simultaneously. it should be kept in mind that the functions described here do not disable interrupts. not me forgetting that and getting jumpscared by an ISR mid-delay 😭

in general, for long delays, the use of hardware timers is much preferrable, as they free the CPU, and allow for concurrent processing of other events while the timer is running. main character energy honestly πŸ‘‘ but β€” and this is the important part β€” in particular for very short delays, the overhead of setting up a hardware timer is too much compared to the overall delay time. so for a tiny lil pause, these loops ate. periodt.

Two inline functions are provided for the actual delay algorithms. slay πŸ’–


⭐ Function Documentation ⭐

🌈 void _delay_loop_1 (uint8_t __count)

delay loop using an 8-bit counter __count, so up to 256 iterations are possible. (the value 256 would have to be passed as 0.) the loop executes three CPU cycles per iteration, not including the overhead the compiler needs to setup the counter register.

thus, at a CPU speed of 1 MHz, delays of up to 768 microseconds can be achieved. cute and quick, bestie πŸŽ€

πŸ¦‹ void _delay_loop_2 (uint16_t __count)

delay loop using a 16-bit counter __count, so up to 65536 iterations are possible. (the value 65536 would have to be passed as 0.) the loop executes four CPU cycles per iteration, not including the overhead the compiler requires to setup the counter register pair. (pair!! two registers!! iconic teamwork πŸ’…)

thus, at a CPU speed of 1 MHz, delays of up to about 262.1 milliseconds can be achieved. okay that's actually a real chunk of time, go off 🌸


πŸ’œ Author πŸ’œ

Generated automatically by Doxygen for avr-libc from the source code. so technically nobody wrote this by hand, it just materialized ✨ we love an automated king.


okay that's the whole page, you're officially a delay-loop girlie now 🫢 go forth and busy-wait responsibly (or don't β€” use a hardware timer for the long ones, iykyk πŸ’€).

Version 2.1.0 β€” Sat Jan 29 2022 πŸ’– mwah, see u next manpage bestie 😘

πŸ“¦ where this page comes from