I'm using an arduino mega 1280 on 64 bit linux, using arduino 0021 software release. I can compile and upload the "blink" sketch without problems, but once uploaded on the board, the delay(1000) function, which is supposed to add a one second delay, is running much quicker.
Namely, delay(1000) results in a delay of perhaps 100 miliseconds (the LED just keeps blinking really quickly). Changing the function call to, for instance, delay(5000) results in the LED blinking a little slower, but still well above once per second.
Bottom line is, the delay() function is working MUCH faster than it should. The sketch "blink without delay" which uses the milis() function seems to work fine. Also, compiling and downloading the "blink" sketch on windows works fine.
Does anyone have a clue what might be the issue here? Maybe something with the Linux version of the arduino libraries?
Are you sure your uploading of the blink sketch was successful? I think the bootloader blinks pin 13 led
at a fast rate if there is no valid sketch in the flash memory.
dafid: The board is configured correctly as Mega (1280) under the tools menu
retrolefty: The arduino software confirms that upload is done. Also, if i change the delay() argument to a higher number, eg: delay(7000), I can tell the difference in the blink rate. Same happens if I output the signal to another pin (I tried with pin 12).
I'm still thinking this might be a compiler/library problem on 64bit Linux, any takers?
Hi dafid,
Thanks for the tip, but that is not the problem. The code is just the standard blink sketch, i.e:
[code]
/*
Blink
Turns on an LED on for one second, then off for one second, repeatedly.
This example code is in the public domain.
*/
void setup() {
// initialize the digital pin as an output.
// Pin 13 has an LED connected on most Arduino boards:
pinMode(13, OUTPUT);
}
void loop() {
digitalWrite(13, HIGH); // set the LED on
delay(1000); // wait for a second
digitalWrite(13, LOW); // set the LED off
delay(1000); // wait for a second
}
and it runs just as expected on the board when it is compiled and uploaded through windows. It is only "turbocharged" when compiled and uploaded through Linux. Also milis() function seems to work fine. I dug up the implementation of delay() and it uses delayMicroseconds() so I'll do some testing on delayMicroseconds() to see if thats the problem or if its some kind of compilation issue.
-Igor[/code]
The first thing I tried is uploading the blink sketch! Changed the board type to UNO in the IDE and uploaded the sketch.
Behold! The LED is always ON, no flickering like on Arduino Mega 1280, and changing the delay() argument to, for instance, delay(5000), which would result in a slower blinking LED on the Mega, appears to do nothing. The LED is constantly on. Uploading the example "Blink without delay" works fine on both Uno and Mega boards.
This suggests that there is something seriously wrong with the Linux 64 bit libraries since the call to the same function (delay(1000)) results in different behaviours on different boards. I fear that many other functions may give unexpected results and I can't trust these libraries... so if anyone has any more clues about these issues I would love to hear some suggestions before installing a copy of window$...
Also, niadh in the topic "Arduino not responding correctly" is also having strange issues on 64 bit linux - maybe this is related?
Is there a place where I can file a bug with the devs about this issue? Open source hardware should have a good IDE implementation for open source software, no?
Igor, You are right - there is nothing to go wrong in your code :).
And since it works from windows and not from linux - it suggests the either the libararies are the problem, or the compiler is.
It would be good to see the avrdump of the file that is downloaded in each case.
As the WINAVR distribution said (dont recall exactly where, will try to track it down) the libraries are identical for all distributions (32, 64, x86, ...) as they vary with the target that is compiled for not the platform that does the compiling...
But since this a case where the behaviour is broken .. it could be the libraies are different - but not deliberately.
--
An asside - to your last message - I saw that delay() (in V21 and V22 from what I understand) which is in wiring.c, appears to be
void delay(unsigned long ms)
{
uint16_t start = (uint16_t)micros();
while (ms > 0) {
if (((uint16_t)micros() - start) >= 1000) {
ms--;
start += 1000;
}
}
}
(Since I am looking at source that I did not use to build the libraries, I am not 100% confident of what I am reading.)
So it does not use delayMicroseconds() but rather loops until it has seen that many lots of 1000 micros() pass by..
And micros is updated by the timer0 interrupt ... and setup() has conditional code to set up timer-0 control registers.
It is all a bit hard in the abstract - as i have 32bit ubuntu and 64 bit windows... and not enough time to reverse this.
I'm running 64 bit linux and Arduino 0021 with both a Mega and a Uno and have had no issues at all with delay(), it is running at the correct speed here. I use the Mega for CNC so I think I would have noticed by now if there was a problem with delay!
I'd suggest backing up your sketches, then completely remove your Arduino directories then download again and reinstall. It sounds like an installation problem.
Which distribution are you using, and what is the output of running avr-gcc -v
dafid: In fact you're right. I looked at wiring.c a couple of days ago and for some reason I remembered it using delayMicroseconds(), but I just checked again and the implementation of delay() is identical in my wiring.c as what you posted above. It does indeed use micros() - my mistake!
stimmer: I'm running 64 bit Arch Linux and Arduino 0021. The IDE installation on Arch is a bit of a mess since it bundles its own patched avrdude and librxtx with it instead of using the system wide ones. Also, the installation requires removing 64 bit gcc and gcc-libs and installing 64 and 32 bit compatible versions of these packages (gcc-multilib), which is pretty hackish IMHO. In addition, the package is not available from official "repository" but it is user contributed, so it is very likely to be an installation problem. I have removed everything and reinstalled again but the results are the same.
I would like to report that I have the same problem using the delay() function on arch 32 bit and avr-gcc 4.5.2
I have the problem on 3 different boards, the arduino nano, arduino duelmilanove 168 and the 328.
On the 168 the LED blinks very fast and on the 328 and the nano the led is just on all the time.
I've duplicated the problem on three different computers running arch. On one of them I downgraded the avr-gcc to 4.3.5 and the problem was still there.
The delay() works ok when I compile my code and upload it using Ubuntu 10.04 and avr-gcc 4.3.5.
I'm baffled by this one. I tried to compile GCC 4.5.2 on Ubuntu but just got too many errors. I also tried to install Arch Linux but Virtualbox was not cooperating, so gave up on that too.
Are either of you able to disassemble the object file and see what the compiler is doing to the delay function?
I wonder if the compiler is misconfigured or picking up a delay function from some other header somewhere... Does Arch set any environment variables that might interfere with GCC, like CFLAGS, CXXFLAGS, C_INCLUDE_PATH, CPLUS_INCLUDE_PATH and LIBRARY_PATH ?
I'll dive into the issue in more detail as soon as I get some free time. I just updated Arch linux and saw it pulled a new gcc in, so I will recompile the sketches and see if anything changes. If I can't figure anything out, I'll get in touch with the Arch linux arduino package maintainer and let him know about this issue, since it seems to be Arch specific.
igor86:
None of those environment variables seem to be set:
None of those variables should be set normally; the makefile sets them, and they basically are only set while make is running (i.e. during the build process).