>Probably didn''t explain the whole thing too well, but the PIC will >essentialy be for real time monitoring of 32 analogue inputs via >multiplexors and 16 or more digital inputs. It will also have to control 8 >digital outputs depending on either the state of the analogue inputs or on >a >request from the I2C master. The master can request the value of any of >the >analogue or digital channels. > >Now my first idea was to perform all the monitoring and control in the main >loop, and use the interrupt purely for comms. There is no fixed >requirement >for the loop time, this isn't a closed loop control system so the >monitoring >does not have to work to an exact period. > >Thinking about this a bit further, I guess I could do monitoring under a >timer interrupt. If I checked the state of the SSPIF flag after every >critical section I could ensure a reasonable latency for the comms, and >there should be no way the I2C should be able to retreive a half written >word. The main loop would effectively be empty, just a watchdog reset I >guess. > >Alternatively, I could move the I2C out of interrupt control and just poll >it in the main loop, but perform monitoring under a timer interrupt. This >would mean worst case latency would be the entire monitor rouine...unless I >split it up into smaller chunks. > >Any comments? I'm most impressed with the response to this so far! > >Mike > Hi Mike, I would say start with time analysis of every task. From this you get all necessary information. Then put the slowest task to main and the fastest to ISR. To comunicate between the two tasks, you would need only from main to isr with bit flags and double buffered results from isr. You can spare all your copying very easy, total 4-6 instruktions. Andrej _________________________________________________________________________ Get Your Private, Free E-mail from MSN Hotmail at http://www.hotmail.com. Share information about yourself, create your own public profile at http://profiles.msn.com. -- http://www.piclist.com hint: To leave the PICList mailto:piclist-unsubscribe-request@mitvma.mit.edu