I didn't know how properly to name this topic...
Ok, i am still novice in programming the AVR's this way.
I am using Arduino and C++ programming because it's much easier for a starter.
So i am trying various methods of coding to see the advantages and disadvantages of various approaches.
I came across this interesting thing and am pretty confused with it.
There are two codes here doing practically the very same basic thing; flashing the LED diode.
Yet! The first one is working in proper timings and LED flashes to correct rate, while the second one seems somehow corrupts the timings and LED flashes at somewhat slower rate!??
How can it be? What i am missing here?
First one:
Second one:
My main aim is to examine the behavior (accuracy and speed) when global variable is pulled out of RAM instead out of register.
Obviously something is going wrong and corrupts the timings, what?

Ok, i am still novice in programming the AVR's this way.
I am using Arduino and C++ programming because it's much easier for a starter.
So i am trying various methods of coding to see the advantages and disadvantages of various approaches.
I came across this interesting thing and am pretty confused with it.
There are two codes here doing practically the very same basic thing; flashing the LED diode.
Yet! The first one is working in proper timings and LED flashes to correct rate, while the second one seems somehow corrupts the timings and LED flashes at somewhat slower rate!??
How can it be? What i am missing here?
First one:
Code:
void setup() { pinMode(LED_BUILTIN, OUTPUT); } void loop() { digitalWrite(LED_BUILTIN, HIGH); delay(100); digitalWrite(LED_BUILTIN, LOW); delay(100); }
Code:
volatile byte state = HIGH; void setup() { pinMode(LED_BUILTIN, OUTPUT); } void loop() { digitalWrite(LED_BUILTIN, state); delay(100); state = !state; delay(100); }
My main aim is to examine the behavior (accuracy and speed) when global variable is pulled out of RAM instead out of register.
Obviously something is going wrong and corrupts the timings, what?


Comment