David VanHorn wrote: >>When I use a PIC, I want real-time performance. >> >> > > >Must resist AVR jab.. MUST resist!.. > >So I use interrupts > > >>for anything external and a loop in the main program that checks to >>see if any of my interrupt routines need more processing. I only >>use that if my interrupt routine is going to take too long and then >>it just does the minimal amount of processing necessary and sets >>a flag for the main loop. >> >> > > > Agreed. The interrupt has always been used by me to set flags, which are then served in a prioritized manner by a main loop. The ONLY exception is in the case of a serial characters just received. I even service the serial outbound port in a main loop. Almost everybody uses a "tick" timer, such as tmr0, to set flags at a precise interval. If possible, make the tick interval as large as possible to reduce interrupt overhead. Don't waste a good interrupt on non-essential tasks. For example, the MSSP port rarely needs to use its interrupt, nor should ADC tasks, nor should many others. . To test for the possibility of overrun (missing a "tick" due to heavy interrupt processing), set a port pin when you enter the interrupt and clear it when leaving, then examine it with an oscilloscope while running. If your pin mormally stays true more than 25% of the time, you may have a problem when very infrequent items occur. The most common interrupt error made is making too many changes in the same interrupt. For example, most people have a task that occurs when counterA counts down to 0, and another when counterB counts down to zero, etc. But if they are chained together, there will be a situation where all the tasks will happen in the same interrupt. The best way to solve this is to stagger the tasks by jump tables so that they CAN'T occur at the same time. This is as multitasking as one can get with PIC16. But it works well. --Bob -- Note: To protect our network, attachments must be sent to attach@engineer.cotse.net . 1-520-850-1673 USA/Canada http://beam.to/azengineer -- http://www.piclist.com PIC/SX FAQ & list archive View/change your membership options at http://mailman.mit.edu/mailman/listinfo/piclist