speed up the code

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?

:-)

Parents
  • instead of waiting in the interrupt to finish ADC to convert, you should definitely make an interrupt on ADC conversion itself! You can initialize the ADC to use a timer and after conversion you raise your FIQ.
    (At to moment, you have your FIQ on timer interrupt and make the conversion in the FIQ itself - that is a bad design concept)

    Other little optimization possibilities: instead of shifting the values in the interrupt by 16, you can do this outside the interrupt so that in the table, already the shifted values are placed... this shortens the interrupt also for probably 50ns.

Reply
  • instead of waiting in the interrupt to finish ADC to convert, you should definitely make an interrupt on ADC conversion itself! You can initialize the ADC to use a timer and after conversion you raise your FIQ.
    (At to moment, you have your FIQ on timer interrupt and make the conversion in the FIQ itself - that is a bad design concept)

    Other little optimization possibilities: instead of shifting the values in the interrupt by 16, you can do this outside the interrupt so that in the table, already the shifted values are placed... this shortens the interrupt also for probably 50ns.

Children
More questions in this forum