I am relatively new to real-time programming, but have been doing a lot of reading (especially on this forum) trying to get up to speed.
I have written code for the ATMega128 to receive (and time) pulses coming in on ICP1 while simultaneously sending and receiving serial data across the serial port. The problem is, my input capture interrupt seems to get held up (significantly at times) by the serial port communication, and when I attempt to capture the time of the pulses coming in on ICP1, get incorrect (or very delayed) values at times, due to this problem. This sort of "collision" of interrupts only occurs once every 15-20 seconds it seems, but it bothers me that it is happening at all. Could anyone recommend a technique to help deal with this problem? I thought that by using the input capture port, delays in the interrupt would not be an issue since the timer value is latched into a register which can be read out at a later time. But apparently my serial port communication is taking so long that, occasionally, a new pulse comes in before I have been able to read out the time value from the ICP register from an old pulse. I have tried changing my serial receive ISR function from 'SIGNAL' to 'INTERRUPT' in the hopes that this would allow the incoming pulses on ICP1 to not be missed or delayed, but the serial communication would not work at all using INTERRUPT rather than SIGNAL, so I switched it back how I had it.