We are running a survey to help us improve the experience for all of our members. If you see the survey appear, please take the time to tell us about your experience if you can.
Hi there All, I have a problem which seemed to be defying explanation, but I have come up with a theory. Could I possibly have some feedback on whether the following is likely, plausible, possible, untrue or downright rubbish? If one reads the contents of a CAN or ADC chip register at a particular address, then the label volatile is placed upon that address to prevent the compiler optimising out repeat readings of the address. If one reads the contents of the address into a variable, then the compiler would automatically treat the contents of this variable with similar care. Is it possible that there has been an oversight with statements where the contents of a variable depend on the contents of a volatile by way of an if statement, ie...
normal_var=volatile_var;
normal_var=voltile_var; if (normal_var=0x00) { another_normal_var+=1; }
Hi Erik, I think your message hit exact the problem.. "The interrupt variable may share the location with an extremely rarely accessed variable in the mainstream and when - and only when - the interrupt happens while this little rarely active piece of code is running, you program will go astray." Now I try to explain... I use this refresh_global for the display updating with a refresh period of ca.300ms. 1.And change of the display contents is not so fast, may be only in the case if one would rotate the potentiometer. May be here one can not exactly say if one refresh was missed or not(it's just too fast for eye). 2.This variable has only some places in the program where it's changed - it's really rarely accessed variable and I had luck that in that moment this variable was accessed in the mainstream this ISR has not occured. Does it somehow hit the problem? With best wishes, S.
Does it somehow hit the problem? It does hit the reason to apply volatile where needed. Erik
to Erik Thanks, P.S. I've understood you answer that what I've written trying to explain why my code "has not failed" were correct?
I've understood you answer that what I've written trying to explain why my code "has not failed" were correct? Yes Erik