On Fri, 11 Sep 2009 21:34:17 -0500, you wrote: >Does the volatile keyword for a variable (using C30 PIC24) guarantee an >atomic operation when accessed regarding interrupts? i.e. if I declare >a volatile DWORD elapsed_time and increment it in the timer interrupt, >do I need to worry about disabling interrupts to access it in the main >loop? I always do, just wondering if I could live without it, and can't >think of a simple test to prove it. No - Volatile simply tells the compiler that a variable's value can change outside of the normal program flow, and so should not, for example, be optimised into a register ( not really applicable to PICs in practice). Atomicity is a completely seperate issue as far as the compiler is concerned To guarantee an atomic read in the foreground you do need to either disable the interrupt, set a flag to tell the int code not to touch it, synchronise the read with the int process, or re-read values to check for changes. e.g. read lsbyte read msbyte(s) read lsbyte again and compare to first read - if different read msbyte(s) again, The latter method makes the (usually reasonable) assumptoin that only a single int can occur during the read process. -- http://www.piclist.com PIC/SX FAQ & list archive View/change your membership options at http://mailman.mit.edu/mailman/listinfo/piclist