Content originally posted in LPCWare by MarcVonWindscooting on Fri Jan 10 15:09:50 MST 2014
You have not clarified how the received message r (pulse train) and the SWUART output s correlate.
It sounds, like you're outputting the received message on the SWUART, or some debugging output
as a function of r .
Sending s takes 20bytes*10bits/byte*10us/bit = 2ms.
MRT channel m1 starts transmission of s every 10ms.
Another MRT channel m2 (repetitive) does the bit outputs, 10us. This is the SWUART.
1. possibility:
If m1 an m2 were started very close to each other, they end up being triggered very close (in time) to each other (at least every 10ms). As m1 clears a flag that is interpreted by m2 you end up with the question, how the MRT handler for both m1 and m2 should be implemented. Which one handle first?
However, from the times calculated above (2ms<->10ms) I see, that this ISR should never face the condition that the flag should be set because a new message has just arrived and the condition, that the flag must be reset because the last bit will be sent. I would check that with an ASSERT() or similar to be absolutely sure about it.
If you started/stopped the MRT m2, I would not be so optimistic about that part. Then, I wouldn't bet a used 1N4148 on it. At a rate of 10us and other ISRs to handle...
2.possibility:
The SCT decoder decodes r at 1ms avg. You don't say much about the length of train to decode.
So because of your program's misbehaviour, let's assume you get the next message r as early as 2ms. Right at the time when the last bit of the previous message is about to leave the SWUART.
How does SWUART shift out up to 20bytes 8 bits, each? There's no machine data type that holds that much data. How do you encode the number of remaining bits inside MRT m2? How do you update that message or append the next? Both contents and length without the high-speed MRT m2 interfering? 32bits you can do with an (atomic) write, everything bigger needs more care. 20bytes are five times as much plus the length encoding...
My guess is: you have a race condition while updating your output message and/or length, if not already withing the MRT handler. 2. possibility much more likely.