Michael Shiloh wrote: > My compiler (C2C) doesn't support the volatile keyword, so I guess I > should either turn off optimization or look carefully at the generated > assembly code and make sure that when volatile registers are read they > really are read from hardware. > Ha! Get a real compiler. Sorry to be so blunt, but look at it this way.. You ought to generate $800 in about 2 or 3 days. So why play with inferior products, when the better ones are very reasonable? > > In more general terms, Chris and others warn me away from sharing > executable code between int and main line code. Point taken. Any > comments on sharing variables between int and main line code? I A very solid way to make ints and main line code cooperate is to block execution of one or the other. If you want to run main line code without any interruption, then you simply turn of GIE. This can be hazardous, though, as you begin to damage your chances of highly predictable real time response. So flip over the coin. Make a flag, which the main line code sets when it wants to go to work on something, and if the int runs in this time period, it leaves the variables/item/peripheral/etc alone for the duration. This way, you can let the remainder of the interrupts, and even other portions of the same interrupt, run without compromise. It is a very soft way to overlap competing services. As an example, I did some code where five devices would share a spi bus. The interrupt was going to run the analog to digital converters (2 of the devices) from a regularly timed interrupt (TMR0 divided down). The other devices, a flash part and two others I forget, were occasional access. So I setup this flag, which the main routine set during access. During this period, the interrupt would simply skip over the atod conversions for a brief period. Since the analog software filter did not run if there was not a conversion (they were flagged to run from int to main as well) then I did not compromise my filtered reads. If you have a case where the int may be already partway through a process (example when a multi-part process takes multiple interrupts, keep track of phase with flags), and the main line code would interfere with this op, then make two flags. One says the int is busy and the mainline may not execute, the other says the main line is busy and the int may not run. You can surely see 0xF4240 (million for the newbies) permutations of this idea. Chris~ -- http://www.piclist.com hint: The list server can filter out subtopics (like ads or off topics) for you. See http://www.piclist.com/#topics