I've got a unexpected problem with Interrupts. Would be nice to discuss it.
I use Timer0 to have about 16000 fast interrupts (FIQ) per second. There is a AD-Conversation and a few lines of long long int aritmetic to compute. Inside this FIQ-routine there is a static counter. When it reaches 16000 it is reseted and a Software interrupt (SWI) is generated every second.
The SWI-routine has do to some computations and then to display it all on a special three wire conected display.
The programm does not work with 16000 Timer0 Interrupts per second. It is terminated by Abort-Mode. This comes a little unexpected to my. The effect is gone if i turn down FIQ frequency downto 100Hz. Is it possible that interrupts create a stack overflow?
Should i post my code?
How do you expect that your SWI will be finished in 1/16000th of a second, i.e. when it is time for the next FIQ? Remember, you only have 62.5us in total for both FIQ and SWI.
You only require one result/second to be displayed, so why not let your main loop handle the display output whenever it sees the flag that the FIQ has collected 16000 samples?
Soory, was my fault. I didn't explained that the SWI leads to IRQ. I expect that the FIQ can interrupt the IRQ. Isn't it so?
Here's the code:
//************************************************************************* void FIQ_Handler()__fiq __ram { static long long unsigned int ACC1,ACC2,ACC3; static unsigned int int_counter; T0CLRI = 0; ADCCON = 0x6A3; // software conv., single-ended, conv. enabled while (!ADCSTA){} // wait for end of conversion ACC1 += ADCDAT >> 16; ACC2 += ACC1; ACC3 += ACC2; if (!(int_counter++ & 0x3FFF)) // every 16384 { SWICFG = 2; // create a softwareinterrupt ACC3_transfer = ACC3; } } //************************************************************************* void IRQ_Handler()__irq { static long long unsigned int ACC3D,D1,D2,D3,D1D,D2D; char text[10]; D1 = ACC3_transfer - ACC3D; D2 = D1 - D1D; D3 = D2 - D2D; ACC3D = ACC3_transfer; D1D = D1; D2D = D2; sprintf(text,"%8.d",(D3 * 125) >> 27); SDA5708_printf(text); SWICFG = 0; // clear softwareinterrupt BIT } //*************************************************************************
The sence of this floating average computation is to increase resolution of my 12 Bit AD-Conversation while distortions are decreased. YEAH it works properly with lower rates. But with higher rates, 16384 for example, my arm likes to have a vacation in abort mode. :-)
You have given a bit too little information about what you do.
But the SWI is not an interrupt flag that will start when the FIQ handler ends. The SWI is an instruction that will immediately (unless interrupts are enabled and an interrupt occurrs before the SWI instruction is executed) make the ARM enter the SVC mode. So if your FIQ handler executes the SWI instruction, the application with enter the SVC mode and start processing the SWI while still being in the FIQ handler. If you have enabled recursive FIQ before the SWI instruction, then you will nest a second FIQ interrupt.
If you want to, you can fake a low-priority interrupt from your FIQ handler, and let this IRQ handler perform the display output. But unless your code supports nested IRQ, all other interrupts (except FIQ) will be blocked until the display output is done.
Because of this, it is best to do all time-consuming operations in the main loop - possibly in a separate thread in case you use an RTOS.
George, You are probably generating the SWI in the FIQ to speed up the handling of the results. But, at the same time you have the following instruction in the FIQ handler:
while (!ADCSTA){} // wait for end of conversion
Have you measured the duration of the loop?
In addition, if your FIQ handler generates a SWI, and the SWI generates an IRQ as you asserted (probably by setting the IRQ flag, then returning immediately?), then the FIQ and IRQ handling are asynchronous - how can you guarantee the integrity of the displayed results without a buffer?
View all questions in Keil forum