> I must measure the input signal with 1 =B5s precision. > I use the RBIF interrupt to detect the edges of the input signal, > timer 0 to measure the lenght of the signal. I use timer 1 with the CPP > to output the result signal. > TMR2 is used to generate the frequency of the output > signal. The problem is that RBI interrupt can occur while > executing the tmr2 interrupt code, and the measure of > the input signal will be faulty because the RBI does not > react immediately. So I've used nested > interrupts with a software stack (I found this method in the piclist > source code library), but there is always a > part of the code where interrupts are disabled. I gather that you are actually measuring and producing individual pulses, not really a regular PWM train. Otherwise, you could produce the output PWM with a CCP module in PWM mode and timer 2. What is the shortest and longest pulse duration? What is the maximum pulse rate? Apparently your minimum pulse length is shorter than the interrupt routin= e time. This implies you need hardware to help in capturing a pulse. The easiest way to capture individual pulses accurately is to use two CCP modules in capture mode on opposite pulse edges, but that leaves no hardware for producing an accurately timed output pulse. How about using the INT interrupt to capture the pulse leading edge, and = a CCP module in capture mode for the trailing edge. The INT interrupt either clears or grabs timer 1 as soon as possible. The trailing edge ca= n come any time after that, whether done with the INT interrupt or not. Th= e capture interrupt processes the trailing edge info when it gets around to it because the timer 1 snapshot is saved in the CCP module. You would have to offset for the latency between the INT edge and when timer 1 gets cleared. This still leaves the second CCP module and timer 2 for the pulse output. If that's no good either, you probably need external hardware. Gate a clock onto the timer 1 input only during the pulse, then take an interrup= t on the trailing edge. Or put the whole counter externally and read it on the pulse trailing edge. That leaves timer 1 and a CCP module in compare mode to produce an exactly measured output pulse. If speed is this important, consider switching to the 18F452. Same pinout, but twice as fast and more INT interrupts. ***************************************************************** Embed Inc, embedded system specialists in Littleton Massachusetts (978) 742-9014, http://www.embedinc.com -- http://www.piclist.com hint: PICList Posts must start with ONE topic: [PIC]:,[SX]:,[AVR]: ->uP ONLY! [EE]:,[OT]: ->Other [BUY]:,[AD]: ->Ads