Hi,
Mocroprocessor: AT91SAM7s128 Toolchain: RealView MDK-ARM Version: 3.20
I have the following ADC code need to be run while interrupts disabled to eliminate 60hz noise. So I put it inside SWI (all interrupts are disabled in SWI).
int __swi(1) GetRawCountsFromExternalADC2DataBuffer(unsigned short * P); int __SWI_1 (unsigned short * P) { unsigned int Index; unsigned int Sum; // Start the ADC StartPWMC(); do // Eliminate first reading { // Check if the ADC ready for the data Sum = CheckADCReady(); }while(Sum == 0); SelectSpiPort(SPI_ADC); GetDataFromSpi(); // Start get 1024 readins for(Index = 0; Index < TOTAL_SAMPLE; Index ++) { do { // Check if the ADC ready for the data Sum = CheckADCReady(); }while(Sum == 0); SelectSpiPort(SPI_ADC); *(P + Index) = (unsigned short)GetDataFromSpi(); } // Stop the ADC StopPWMC(); return(1); }
The problem is that all interrupts (Timer and UART) will be stopped after it runs for random time. I also use the spuriouse interrupt handler to fix the problem, but it is not working.
The following code is used to catch the spurious interrupts.
// STORE SPURIOUS INTERRUPT HANDLER TO AIC_SPU AT91C_BASE_AIC->AIC_SPU = (unsigned long) SpuriousInterruptHandler; static void SpuriousInterruptHandler(void) { // END OF INTERRUPT AT91C_BASE_AIC->AIC_EOICR = 0; }
If I am not using disable/enable interrupts for ADC code (data with 60hz will not right), the code runs without any problem.
Any comments are appreciated!
Yes, I have __swi(0). SWI0 is used to program one page of the flash memory. It works very well. I use it for firmware upgrade and storing calibration constants into flash (flash like EEPROM) without any problems.
The difference between SWI0 and SWI1 is the time spent for the operation.
SWI0 only spents couple of mini seconds to finish. And the SWI1 needs at least 16ms, sometime it can use up to 256 mini seconds if I want high resolution reading.
Another difference is SWI1 is used much much more often than SWI0.
Thanks for the link! I will try the updated SWI handler.
Regards, Xiao
Quick Update:
The updated SWI handler is not working.
Xiao
It is really frustrating problem.
I use the RTOS when I first started this project and RTOS stops randomly. I was told by some posts on this forum that Keil has a fix for the "RTOS stop" (related to interrupt detection).
I stopped using RTOS and have the same problem again. I think there something wrong in this compiler dealing with the interrupt. Actually RTOS does the pretty much same thing as I do. Both use SWI very offen.