volatile type of variable #84
-
|
Hello, |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
|
Hi Guillermo, Here's a link where I found the differences between register and memory storage. I hope it helps, |
Beta Was this translation helpful? Give feedback.
Hi Guillermo,
I hope my answer clears up the concept. As you said, variables defined with the
volatilequalifier are not loaded from a storage register, but from RAM memory. By default, if you don't declare it asvolatile, the microprocessor accesses the value of the variable by storing it in a register because it is quicker in comparison to accessing it from RAM memory (a way of optimizing time). However, this can lead to problems when the variable is at the same time being updated outside of the main program flow. This occurs, for instance, when you apply an interrupt and your ISR modifies the value of a variable that is already being used in another function inside the program. In that…