Author Topic: Atmega Delay function problem  (Read 4255 times)

0 Members and 1 Guest are viewing this topic.

Offline yalectTopic starter

  • Regular Contributor
  • *
  • Posts: 123
Atmega Delay function problem
« 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
 

Offline IconicPCB

  • Super Contributor
  • ***
  • Posts: 1535
  • Country: au
Re: Atmega Delay function problem
« Reply #1 on: December 27, 2017, 11:09:34 am »
ATmega32 is probably running on internal 1 MHz clock.

What have you told the compiler the clock frequency is?
 

Offline yalectTopic starter

  • Regular Contributor
  • *
  • Posts: 123
Re: Atmega Delay function problem
« Reply #2 on: December 27, 2017, 12:51:44 pm »
Sorry, for internal clock frequency how we do?
Thanks
 

Offline HwAoRrDk

  • Super Contributor
  • ***
  • Posts: 1477
  • Country: gb
Re: Atmega Delay function problem
« Reply #3 on: December 27, 2017, 06:40:55 pm »
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.
 

Offline IconicPCB

  • Super Contributor
  • ***
  • Posts: 1535
  • Country: au
Re: Atmega Delay function problem
« Reply #4 on: December 27, 2017, 08:05:12 pm »
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.
 

Offline westfw

  • Super Contributor
  • ***
  • Posts: 4199
  • Country: us
Re: Atmega Delay function problem
« Reply #5 on: December 28, 2017, 12:01:45 am »
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"
   ^
 

Offline IconicPCB

  • Super Contributor
  • ***
  • Posts: 1535
  • Country: au
Re: Atmega Delay function problem
« Reply #6 on: December 28, 2017, 12:05:03 pm »
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
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf