-2

I'm using avr-gcc from the Debian Linux repository. I have noticed that the program on a real breadboard is 1000 times slower than it should be.

For example, with the code

#define F_CPU 8000
#include <util/delay.h>

_delay_ms(1000);

the delay is really about a second. However, F_CPU should be 8000000. And with F_CPU 8000000, you have to expect 1000 seconds!

What am I doing wrong? How do I achieve the expected speed of execution?

Darryl Noakes
  • 2,207
  • 1
  • 9
  • 27
  • 2
    Your code cannot be compiled. Please provide the actual code that you actually used. How are your set up fuses? Default clock source is 1MHz internal RC oscillator not 8Mhz – Peter Plesník Jul 18 '23 at 15:09
  • Assuming you're not using external circuitry to run your part at 8000 Hz, F_CPU is off by a factor of 1000. – TomServo Jul 18 '23 at 21:47
  • @TomServo The OP stated that. That value was to demonstrate that it needed to be off by a factor of a 1000 to get the correct delay. – Darryl Noakes Jul 18 '23 at 23:36
  • @DarrylNoakes As has been pointed out, that's not the code that's running. Almost twenty years of using Atmel parts, including the part indicated, tell me that we're not seeing the real code here. – TomServo Jul 19 '23 at 00:13
  • 1
    @TomServo Yes, indeed. I fully agree with that. What I was starting to say was that that code was to show what `F_CPU` would _need_ to be to get the correct delay. I don't know why the OP needed to do it that way, though; simply stating that the delay is wrong would be enough. However, the issue was caused by other sources, so there isn't much point discussing any of this much more, except from the point of view of general question quality. – Darryl Noakes Jul 19 '23 at 00:33

1 Answers1

-1

I'm sorry, I have a bug in my code related to interrupt handling failure.