Go Down

Topic: Incrementation bug? WTF? [BROKEN COMPILER - SOLVED] (Read 9074 times) previous topic - next topic

dsh

Feb 03, 2011, 10:09 pm Last Edit: Feb 04, 2011, 01:19 am by dsh1 Reason: 1
Could somebody explain this to me. Maybe I'm just plain stupid and overlooked something, but this thing is driving me mad.

This doesn't work (nothing happens):

Code: [Select]

int hue;

void setup()  
{
 hue = 0;
 pinMode(9, OUTPUT);
}

void loop()  
{
 analogWrite(9, hue);    

 hue = hue + 1;
 
 if(hue > 255) hue = 0;
 
 delay(30);                            
}


SURPRISE!!! This works:

Code: [Select]

int hue;

void setup()  
{
 hue = 0;
 pinMode(9, OUTPUT);
}

void loop()  
{
 analogWrite(9, hue);    

 hue = hue + 10;
 
 if(hue > 255) hue = 0;
 
 delay(30);                            
}


And this also works:

Code: [Select]

int hue;
int dupa = 1;

void setup()  
{
 hue = 0;
 pinMode(9, OUTPUT);
}

void loop()  
{
 analogWrite(9, hue);    

 hue = hue + dupa;
 
 if(hue > 255) hue = 0;
 
 delay(30);                            
}

Coding Badly

Quote
This doesn't work (nothing happens)


How long did you wait?

dsh


Quote
This doesn't work (nothing happens)


How long did you wait?



Trust me, long enough. Even if I waited too briefly it still doesn't explain the ones (last one) that work.

stimmer

Which OS, IDE and Arduino are you using?
Due VGA library - http://arduino.cc/forum/index.php/topic,150517.0.html

dsh

Linux 32bit, Arduino IDE, original Arduino UNO.

zeitcheist

Interesting. Compiler problem? Though personally, I think not. Why not use the increment operator?

Coding Badly

Does this work...

Code: [Select]
int hue;
const int dupa = 1;

void setup()  
{
 hue = 0;
 pinMode(9, OUTPUT);
}

void loop()  
{
 analogWrite(9, hue);    

 hue = hue + dupa;
 
 if(hue > 255) hue = 0;
 
 delay(30);                            
}

dsh

#7
Feb 03, 2011, 10:33 pm Last Edit: Feb 03, 2011, 10:37 pm by dsh1 Reason: 1

Does this work...

Code: [Select]
int hue;
const int dupa = 1;

void setup()  
{
 hue = 0;
 pinMode(9, OUTPUT);
}

void loop()  
{
 analogWrite(9, hue);    

 hue = hue + dupa;
 
 if(hue > 255) hue = 0;
 
 delay(30);                            
}



Yeah, this works like charm as I wrote...

No it doesn't, I'm sorry I didn't see the 'const'.

Maybe I should make hue volatile...

How to produce an .S assmebly file from arduino IDE?

stimmer

Which linux distribution?

I think i just discovered a compiler bug in Arch linux, Ubuntu seems to be OK though... I'm wondering if there's a bug affecting some distributions and not others.

The bug would lead to a very similar problem to that which you describe. Please try uploading the Blink example, and tell me if it blinks correctly, or too fast, or not at all.
Due VGA library - http://arduino.cc/forum/index.php/topic,150517.0.html

dsh

#9
Feb 03, 2011, 10:41 pm Last Edit: Feb 03, 2011, 10:42 pm by dsh1 Reason: 1

Which linux distribution?

I think i just discovered a compiler bug in Arch linux, Ubuntu seems to be OK though... I'm wondering if there's a bug affecting some distributions and not others.

The bug would lead to a very similar problem to that which you describe. Please try uploading the Blink example, and tell me if it blinks correctly, or too fast, or not at all.


It's ArchLinux. Blink doesn't work - the light is constantly on, not blinking. AVR-GCC is v 4.5.2-1

stimmer

Read this thread:
http://arduino.cc/forum/index.php/topic,49900.0.html
Although that thread is about the Mega I think it is a similar bug. It affects programs with no initialised global variables, that's why your first example fails but the third one works. The thread also explains how to do a disassembly.
Due VGA library - http://arduino.cc/forum/index.php/topic,150517.0.html

dsh


Read this thread:
http://arduino.cc/forum/index.php/topic,49900.0.html
Although that thread is about the Mega I think it is a similar bug. It affects programs with no initialised global variables, that's why your first example fails but the third one works. The thread also explains how to do a disassembly.


Even if I initialize hue (int hue=0;) it still doesn't work. I tried every combination.

stimmer

Don't initialise to zero, that doesn't avoid the bug. Try initialising to 1.
Due VGA library - http://arduino.cc/forum/index.php/topic,150517.0.html

dsh

@Stimmer:

You are right. Initializing to 1 does solve the problem (if you can call it solution;)).

Also inserting a dummy global variable solves this problem. Did you find out if this is Distro-specific or compiler-version-specific?

stimmer

I don't know how specific it is, so far I've only seen people running Arch linux mention it. Someone on the other thread downgraded the compiler to 4.3.5 (?) on Arch Linux but still had the problem. It isn't affecting Ubuntu.
Due VGA library - http://arduino.cc/forum/index.php/topic,150517.0.html

Go Up