0
votes

Well, I'm using Code::Blocks as the IDE, and Win AVR as the compiler. F_CPU is selected as 8000000UL. I'm writing code for Atmega32. But when I run my written code (*.hex file) in Proteus design suite (ISIS) the _delay_ms(1000) doesn't give a delay for 1sec. I don't know if it is write or wrong, I've selected CKSEL fuses to be (0100) Int.RC 8MHz in edit component. What's wrong? please....

3
The internal RC oscillator's frequency is not exact. If you want a precise delay, use an external quartz crystal oscillator. - user529758
It's a computer simulation. Well, I'm not opting for exact 1sec delay. But, the delay func. executes in a blink. - ponir
Also don't expect a simulator to work properly. It won't. Try on the actual device. Then it will. - user529758

3 Answers

2
votes

Have you tried setting the compiler optimization to something other than -O0? From the avr-libc docs regarding delay* functions.

In order for these functions to work as intended, compiler optimizations must be enabled, and the delay time must be an expression that is a known constant at compile-time.

2
votes

Using PWM for servo control I figured out that even with this setting of Internal 8Mhz, Proteus are actually simulated with a clock of 1Mhz. If you change F_CPU to 1000000UL you will see that delay will work just fine.

1
votes

Its just proteus simulation lags. On the real device your delay function will work properly. In order to simulate time delays the good choice is using avr studio program.