can't solve this bug!  reward if solved

I have a sketch that is receiving interrupt triggers from an external clock via digitalpin 2. The external clock varies from 0Hz up to 500Hz

Every time the clock triggers I have a small ISR that sets a new "clock received flag" called CLKA.

In the main loop I am doing the following: - advancing some counters for sequence position - comparing the current time to a previous time to calculate the current external clock period. -shifting a byte of data in from a SR -shifting two bytes of data out via SRs -reading millis() once -performing a couple of simple mults/divs on some floats

When I start the app everything run fine for about 1-2 minutes but then after the app doesn't crash but all my timing interval values are suddenly wrong and won't change by button input anymore. So if it is sequencing at a certain rate, with shuffle and certain output lengths (called gate) it will suddenly change so that all the gates are super short, no shuffle is present and no input controls will affect them. However all other functions still work.

I was just wondering if anything so far rings any alarm bells?

Since the problems always occur at arround the same period of ellapsed time I naturally looked to see if any variables were overflowing but all of my timing based variables are unsigned long int. Also the millis() function will not reach its max for many days so that can't be the problem either unless there is some issue with using attachinterrupt() and the millis() function?

Instead of using the external interrupt trigger should I just use a timer set to check ports every 1ms? Timing accuracy is really important in this sketch.

I'll paypal anyone who solves this $50!! Been banging my head on this all week :(

Is it possible this problem could be caused by some kind of stack overflow?

I am using a lot of variables and calling a lot of functions within functions.

So far, you've provided a good description. There are just two more items of interest: source for the Sketch and which board you're using.

turned out I was assigning an unisgned int a millis() value so it was overflowing after about 60 seconds.

Give yourself a reward! [smiley=beer.gif]