hexagon5un / AVR-Programming

Code examples for the book "Make: AVR Programming"
http://littlehacks.org/AVR-Programming
MIT License
725 stars 340 forks source link

strange behavior with Chapter 5 serialOrgan/organ.c #21

Open ka80 opened 7 years ago

ka80 commented 7 years ago

The microsecond delay in organ.c doesn't work for me using avr-gcc 4.8.1.

for (i = 0; i < period; i++) {
    _delay_us(1);
}

The delay is much longer than expected (~7*period). I can get the code to work using _delay_loop_2(), but it's sparked my curiosity trying to figure out what's going on.

In case anybody else is also curious, I started a thread on AVRFreaks to discuss a code fragment that demonstrates the problem.