Answer the question
In order to leave comments, you need to log in
Why is the AVR buggy on calculations in the main program when interrupts are enabled?
Good afternoon. I've run into a problem that I don't understand.
The ATmega32a controller runs on internal 8 MHz. IAR Embedded Workbench for Atmel AVR 6.12. Debugger Chinese noun JTAG adapter.
There is a timer2 interrupt with a frequency of 20kHz, which reads the value of the ADC and does not count anything inside, is executed in microseconds, most of the time the main program is free.
Another interrupt on timer0 at a frequency of 30Hz (!) Is responsible for blinking LEDs, it also doesn’t count anything, it’s fast, everything was controlled not by an oscilloscope.
There are moments in the main program that are very time consuming. Fast Fourier transform, arc cosine with arc tangent and square root, like this:
if (FFTfull){
cli();
fft_input(capture, bfly_buff);
fft_execute(bfly_buff);
fft_output(bfly_buff, spektrum);
FFTfull=0;
sei();
}
cli();
SKV=0*X+0*Y+1*Z; //скалярное произведение векторов
DLV=sqrt(Y*Y+X*X+Z*Z); //длина вектора
COSV=SKV/DLV; //косинус угла
Alpha=acos(COSV)*pi180; //угол
sei();
Answer the question
In order to leave comments, you need to log in
most likely someone ate the stack. try increasing it all the way.
and rewrite the math into tables
Arc cosine on AVR? Are you seriously?
FFT in real time on the AVR is done only according to ready-made tables, and then it fits back-to-back in cycles.
Most likely, you have overlapping memory areas that are used inside the interrupt, which is responsible for updating the LED indication and the memory areas that you use in the main program.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question