Hallo, would be nice if someone could take a look on my code. It's just a little toy to delay an analog signal.
How can i optimize the speed?
unsigned short int Buff[3200]; //***************************************************** int main (void) { * * * * } //***************************************************** void FIQ_Handler()__fiq __ram // Timer 1 => Fast Interrupt { static unsigned int position; T1CLRI = 0;// Clear Timer1 Interrupt DAC0DAT = Buff[position] << 16; // read from ring_buffer while (!ADCSTA){} // wait for AD conversion Buff[position] = ADCDAT >> 16; // write to ring_buffer ADCCON = 0x6A3; // start a new AD conversation if (++position >= Buffer_length) position = 0; } //*****************************************************
I tested the speed of the code by doing some port-toggling and then oszilloscoping. Unfortunately software seems to be the limiting element.
Should i use a pointer instead of the variable position? But as i'am a relative beginner in C i tried but it didn't works in the wanted way :-(
Should i try to write the interrupt-routine in assembler? Does anybody would like to give me some big hint? I have no idea how to place the assembler routine inside the IRQ routine.
How can i tell the assembler routine where the Buff[3200] array is located? How can i tell the assambler routine where the variable Buffer_length is located?
:-)
@ Per Westermark
Thank you very much for your patience with my ignorance. I think now i will get it :-)
One additional question: What's the reason for this enumerated type?
enum { ARRAY_SIZE = 1000 };
Does enumerated type make sence with only one member? Or is it a very special trick?
Best regards
Yes, is does.
"Or is it a very special trick?"
No, it's quite a common technique:
It's similar to a #define, except that it is handled by the compiler, not the preprocessor.
Therefore the compiler knows the name of the symbol, and the debugger may also be able to make use of it...
c-faq.com/.../enumvsdefine.html c-faq.com/.../enumprint.html
I very much prefer enumerators than #defines for specifying sizes etc.
An enumerator survives the preprocesor, a #define doesn't. In some situations it may be an idea to just use a const int instead.
Especially if using C++ ?