|
[quote="arunvijaykg"] __irq void timer0_c_irq_handler(void) { int i; status=AT91C_BASE_TC0 ->TC_SR; //Read status register [/quote]
As it is currently, I understand it that the SAM7 will allow interrupts to be executed as soon as you clear the status bit. Anyone, please correct me if I'm wrong. (This is how things work on some other microprocessors at least). Try moving the 'status' line to the bottom of the interrupt and see if it helps.
You can make a test, to see if the interrupt is re-entered, by having a global variable initially set to 0, then increment this variable at the beginning of the interrupt, and decrementing it at the end of the interrupt. You could then turn on a LED if the value is >= 2 right after incrementing the value.
To find the cause of the crash, try making your timer0_c_irq_handler completely empty, so that it only contains the necessary code (eg. to clear the status bit)...
__irq void timer0_c_irq_handler() { (void) AT91C_BASE_TC0->TC_SR; /* no need to set a variable here, as everyone usually do */ #if 0 ... disabled code ... #endif }
You probably want to set window_sum to 0, before the for-loop.
It might be a good idea to initialize window_counter to 0 somewhere; just to make it easier to analyze the data.
In your interrupt, you have something like...
sample_values[window_counter] = ...; window_counter++;
Below that, you have... window_counter = 0; sample_values[window_counter] = ...;
but you do not increment window_counter there, which means you're losing sample values.
I'd suggest doing this in both places: sample_values[window_counter++] = ...; and move that line outside the if-clause, as it's done in both cases...
reg_b = AT91C_BASE_TC0->TC_RB; if(window_counter >= N_SAMPLES) { window_counter = 0; ... new_Value_Flag = 1; } sample_values[window_counter++] = (overflow_counter * 65536) + reg_b - reg_a;
You could save some CPU-time, if you subtract sample_value[window_counter] from window_sum, before writing the new value. -Then you'd be able to get rid of the for-loop. You'd have to clear the array first, to get correct results, though.
|