View Full Version : probs with delay generation in Avrstudio4.0

06-02-2005, 03:15 PM
I am using Atmega32L with 8MHz crystal.

I wanted to generated a delay of 1sec, i used avr delay generator and give the number of cycles-8000000 and i got code

; =============================
; delay loop generator
; 8000000 cycles:
; -----------------------------
; delaying 7999992 cycles:
ldi R17, $48
WGLOOP0: ldi R18, $BC
WGLOOP1: ldi R19, $C4
WGLOOP2: dec R19
brne WGLOOP2
dec R18
brne WGLOOP1
dec R17
brne WGLOOP0
; -----------------------------
; delaying 6 cycles:
ldi R17, $02
WGLOOP3: dec R17
brne WGLOOP3
; -----------------------------
; delaying 2 cycles:
; =============================

I checked the delay with avrstudio4.0 and I got time taken to executing it is 1second. But when I programmed AVR I got the delay of 8 second. Can you tell me wht is the problem

06-03-2005, 01:02 AM
Hi 8 M cycles does not lead to dealy of one sec ( you have to take into account the execution time for each cycle ) so in case of an 8 Mhz crystal the avr runs at 1.375 x 10 ^-6 seconds / cycle . So you will need about 720000 cycles to generate one second delay .

Dun know if my calc is correct ( try out and let me know ) . Anyhow do check in the AVR studio what is the crystal freq which you have put in .

06-04-2005, 11:39 AM
The delay problem occurs even if you use the library function for delay.
Even the simulator shows delay as expected, but burn the same thing on the chip and the delay is much longer.
I think the internal clock works at a slower speed. How does one configure AVR to use an external crystal?
Can it be configured to work at any speed upto max rated speed using internal clock?