EEVblog® Electronics Community Forum
Electronics => Microcontrollers => Topic started by: yalect on December 27, 2017, 10:47:50 am
-
Hi,
I found problem with Delay function to delay the time that when I set the function for 3000 ms or Delay_ms(3000) it takes 30 second instead of 3 s with protuse simulation like it's shown attached picture I don't know maybe there is configuration for base time.
2) like on the diagram on the picture what's the clock of oscillator? because there is no crystal connected the Atmega.
thank you
-
ATmega32 is probably running on internal 1 MHz clock.
What have you told the compiler the clock frequency is?
-
Sorry, for internal clock frequency how we do?
Thanks
-
AVR-libc assumes a clock speed of 10 MHz if you don't define F_CPU. Coupled with the CPU actually running at 1 MHz, that would explain why your delay is ten times as long as expected.
-
Use Your programer to check whihc fuses are set ( by default ATmega chips come with 1MHz internal clock enabled).
You can on the other hand define clock frequency as 1MHz in your software so that the compiler gives You the correct delay time.
-
You should also be getting warnings out of the compiler if F_CPU is unspecified:
avr-gcc -mmcu=atmega8 -c foo.c
In file included from foo.c:2:0:
/usr/local/avr8-Atmel-3.6.0.487/avr/include/util/delay.h:92:3: warning: #warning "F_CPU not defined for <util/delay.h>" [-Wcpp]
# warning "F_CPU not defined for <util/delay.h>"
^
/usr/local/avr8-Atmel-3.6.0.487/avr/include/util/delay.h:112:3: warning: #warning "Compiler optimizations disabled; functions from <util/delay.h> won't work as designed" [-Wcpp]
# warning "Compiler optimizations disabled; functions from <util/delay.h> won't work as designed"
^
-
Mikro C not GCC compiler is the compiler in question
Best option go to mikro C and see if they have a user discussion group