Society of Robots - Robot Forum
Software => Software => Topic started by: Roboteccan on October 27, 2010, 04:27:17 PM
-
hi, this is my firt program and the 500000ms delay give me 8seg (500000ms=8seg)?
#include<avr/IO.h>
#include<avr/delay.h>
int main()
{
DDRC = 0xFF;
PORTC = 1;
_delay_ms(500000);
PORTC = 8;
_delay_ms(500000);
PORTC = 0;
}
please help, me I think that 8seg=8000ms thanks.
-
Crystal fail.....
Will also lead to bad if not none UART communication to the IC...
Check again the crystal you are using and the crystal you declared ;-)
You should be using a "faster" crystal....
And it's sec not seg ;-)
-
but the axon microcontroller use crystal?
-
_delay_ms(500000);
is 500000 a valid input value for the _delay_ms function?
Look at the source code and function prototype for the _delay_ms function to see what the variable is defined as.
-
I guess 16MHz.... ::)
That should look like:
$crystal = 16000000
If I remember right it's something like this....
The 16 is for crystal values and the zeros are for pointing out that's in the megahertz range....
1000 = kilo (3 zeros)
1000000 = mega (6 zeros)
-
thanks for all the problem is solved :)
-
I put in the configuration 16000000hz but 100000ms=27sec (_delay_ms(100000)) please help me, thanks.
-
You are using AVRLib, right?
_delay_ms(500000);
is 500000 a valid input value for the _delay_ms function?
Look at the source code and function prototype for the _delay_ms function to see what the variable is defined as.
If I remember right, it only accepts 16 bit values. That means the highest time you can do is 65536, not 500000.
Do this and see if it works:
for(i=0;i<10;i++)
delay_ms(50000);
-
If I remember right, it only accepts 16 bit values. That means the highest time you can do is 65536, not 500000.
216 = 65535 :) (65536 values including 0)
-
I am using AVR Studio 4 and I put in the confuguration 16000000hz but it dont work because it give me 100000=27sec.
-
I am using AVR Studio 4 and I put in the confuguration 16000000hz but it dont work because it give me 100000=27sec.
It's not about the frequency, its about the size of the variable passed to the function delay_ms(). Delay accepts a 16 bit unsigned integer. That means it can be any number from 0 to 65535. If you try to put in a larger number you get unexpected results. The longest you can delay using delay_ms() is about 65 and a half seconds (65.535 seconds actually). If you want to delay longer than that you can use multiple calls to delay or you can use a loop like Admin posted.
-
this is my new program
#include<avr/IO.h>
#include<avr/delay.h>
int main()
{
DDRC = 0xFF;
PORTC = 1;
_delay_ms(65000);
PORTC = 0;
}
but it dont work because 65000ms give me 16sec (65000ms=16sec), please help me ???
-
Function Documentation
void _delay_ms ( double __ms )
Perform a delay of __ms milliseconds, using _delay_loop_2().
The macro F_CPU is supposed to be defined to a constant defining the CPU clock frequency (in Hertz).
The maximal possible delay is 262.14 ms / F_CPU in MHz.
When the user request delay which exceed the maximum possible one, _delay_ms() provides a decreased resolution functionality. In this mode _delay_ms() will work with a resolution of 1/10 ms, providing delays up to 6.5535 seconds (independent from CPU frequency). The user will not be informed about decreased resolution.
Also
void _delay_loop_2 ( uint16_t __count )
Delay loop using a 16-bit counter __count, so up to 65536 iterations are possible. (The value 65536 would have to be passed as 0.) The loop executes four CPU cycles per iteration, not including the overhead the compiler requires to setup the counter register pair.
Thus, at a CPU speed of 1 MHz, delays of up to about 262.1 milliseconds can be achieved.
Hope this helps some.
-
but it dont work because 65000ms give me 16sec (65000ms=16sec), please help me ???
hmmmm, thats exactly 1/8th what it should be.
It sounds like the Divide by 8 fuse is set.
Did you change any fuses? Are you using an ISP programmer or the bootloader? Do you have an ISP programmer?
-
I put 64Mhz ATmega640 and all the times work very well 60000ms=1min 8000ms=8sec I dont know why it work, but it work ??? the axon microcontroller with 64Mhz work very well.
-
Seems you messed some number here :-p
Anyhow... It probably happens what admin tells.... You need to set some internal fuses for the Atmega...
Best way you have is to get an Atmel ISP programmer...
Don't say that the Chinese guys won't work but nothing's like mama.... Better get an original ISP programmer ;-)
-
I dont know what is the ISP, in the "GETTING STARTED The Bootloader" dont say nothing about ISP, I only download AVR studio 4 and the FBOOT v1.7 EXE and I configure AVR studio 4 with ATmega640 and 16000000hz. ;D
-
Basically there appears to be a fuse on your microcontroller that somehow got corrupted. This fuse causes your microcontroller to run 8x slower.
As a long term solution, you'll need an ISP programmer (between $16 and $36) to fix the fuse. Its very easy to fix.
(or it could be a mistake in your code somewhere, but less likely)
Its not actually a big deal so no need to panic, but if you feel you need more processing power in the future, let us know and we can help.
-
Please I want the link to download the ISP Programmer because I need that my robotSumo will be very fast, if my axon microcontroller is more slow to processing that is a big disadvantage, please help me.
-
For a robot sumo, 2MHz is plenty fast already.
And ISP programmer is hardware, not software.
Many people recommend this one, although I've never used it before:
http://www.pololu.com/catalog/product/1300 (http://www.pololu.com/catalog/product/1300)