Reference.Volatile History

Hide minor edits - Show changes to markup

June 05, 2010, at 10:45 PM by Equipo Traduccion -
Changed lines 1-11 from:

volatile keyword

volatile is a keyword known as a variable qualifier, it is usually used before the datatype of a variable, to modify the way in which the compiler and subsequent program treats the variable.

Declaring a variable volatile is a directive to the compiler. The compiler is software which translates your C/C++ code into the machine code, which are the real instructions for the Atmega chip in the Arduino.

Specifically, it directs the compiler to load the variable from RAM and not from a storage register, which is a temporary memory location where program variables are stored and manipulated. Under certain conditions, the value for a variable stored in registers can be inaccurate.

A variable should be declared volatile whenever its value can be changed by something beyond the control of the code section in which it appears, such as a concurrently executing thread. In the Arduino, the only place that this is likely to occur is in sections of code associated with interrupts, called an interrupt service routine.

Example

to:

Palabra clave volatile

volatile es una palabra clave conocida como variable clasificada (qualifier), se utiliza habitualmente delante de un tipo de datos, para modicar la forma en la que el compilador y el correspondiente programa trata la variable.

Declarar un variable como volátil es una directiva para el compilador. El compilador es un software que traduce tu código C/C++ en código máquina, que son las instrucciones reales para el chip Atmega de la Arduino.

Específicamente, dirige al compliador para cargar la variable desde memoria RAM y nos desde un registro de almacenamiento, que es una localización de memoria temporal donde las variables se almacenan y son manipuladas. Bajo ciertas condiciones, el valor de la variable almacenada en registros puede ser imprecisa.

Una variable debe ser declarada volatile siempre que su valor pueda ser modificado por algo más allá de la sección del código en el que aparece, como por ejemplo un hilo de ejecución concurrente. En Arduino, el único lugar en el que se podría dar el caso es en secciones de código asociadas a interrupciones, denominadas rutina de servicio de interrupción (interrupt service routine).

Ejemplo

Changed lines 13-14 from:

// toggles LED when interrupt pin changes state

to:

// Conmuta el LED cuando el pin de interrupción cambia de estado

Changed lines 16-17 from:

volatile int state = LOW;

to:

volatile int estado = LOW;

Changed line 21 from:
  attachInterrupt(0, blink, CHANGE);
to:
  attachInterrupt(0, parpadea, CHANGE);
Changed line 26 from:
  digitalWrite(pin, state);
to:
  digitalWrite(pin, estado);
Changed line 29 from:

void blink()

to:

void parpadea()

Changed line 31 from:
  state = !state;
to:
  estado = !estado;
Changed line 35 from:

See also

to:

Ver también

July 02, 2007, at 03:33 AM by Paul Badger -
Changed lines 3-4 from:

volatile is keyword known as a variable qualifier, it used, usually before the datatype of a variable, to modify the way in which the compiler and subsequent program treats a variable.

to:

volatile is a keyword known as a variable qualifier, it is usually used before the datatype of a variable, to modify the way in which the compiler and subsequent program treats the variable.

Changed lines 7-10 from:

Specifically, it directs the compiler to load the variable from RAM and not from a storage register, which is temporary memory where program variables are stored and manipulated. Under certain conditions, the value for a variable stored in registers can be inaccurate.

A variable should be declared volatile whenever its value can be changed by something beyond the control of the program in which it appears, such as a concurrently executing thread. In the Arduino, the only place that this is likely to occur is in code associated with interrupts, called interrupt service routines.

to:

Specifically, it directs the compiler to load the variable from RAM and not from a storage register, which is a temporary memory location where program variables are stored and manipulated. Under certain conditions, the value for a variable stored in registers can be inaccurate.

A variable should be declared volatile whenever its value can be changed by something beyond the control of the code section in which it appears, such as a concurrently executing thread. In the Arduino, the only place that this is likely to occur is in sections of code associated with interrupts, called an interrupt service routine.

May 29, 2007, at 10:17 PM by Paul Badger -
Changed lines 1-2 from:

Volatile Keyword

to:

volatile keyword

volatile is keyword known as a variable qualifier, it used, usually before the datatype of a variable, to modify the way in which the compiler and subsequent program treats a variable.

Changed lines 7-8 from:

What it directs the compiler to do specifically, is to load the variable from RAM and not from a register, which is temporary memory where program variables are stored and manipulated. Under certain conditions, the value for a variable stored in registers can be inaccurate.

to:

Specifically, it directs the compiler to load the variable from RAM and not from a storage register, which is temporary memory where program variables are stored and manipulated. Under certain conditions, the value for a variable stored in registers can be inaccurate.

May 18, 2007, at 05:56 AM by Paul Badger -
Changed lines 5-6 from:

What it directs the compiler to do specifically is to load the variable from RAM and not from a register, which is temporary memory where program variables are stored and manipulated.

to:

What it directs the compiler to do specifically, is to load the variable from RAM and not from a register, which is temporary memory where program variables are stored and manipulated. Under certain conditions, the value for a variable stored in registers can be inaccurate.

May 18, 2007, at 05:54 AM by Paul Badger -
Changed line 33 from:

1!!!! See also

to:

See also

May 18, 2007, at 05:54 AM by Paul Badger -
Changed lines 10-34 from:
to:
// toggles LED when interrupt pin changes state

int pin = 13;
volatile int state = LOW;

void setup()
{
  pinMode(pin, OUTPUT);
  attachInterrupt(0, blink, CHANGE);
}

void loop()
{
  digitalWrite(pin, state);
}

void blink()
{
  state = !state;
}

1!!!! See also

May 18, 2007, at 05:51 AM by Paul Badger -
Added lines 1-10:

Volatile Keyword

Declaring a variable volatile is a directive to the compiler. The compiler is software which translates your C/C++ code into the machine code, which are the real instructions for the Atmega chip in the Arduino.

What it directs the compiler to do specifically is to load the variable from RAM and not from a register, which is temporary memory where program variables are stored and manipulated.

A variable should be declared volatile whenever its value can be changed by something beyond the control of the program in which it appears, such as a concurrently executing thread. In the Arduino, the only place that this is likely to occur is in code associated with interrupts, called interrupt service routines.

Example

Share