Two calls to the same interrupt function

was-ja

Well-known member
Hello,

I have a project with Teensy 4.1 where I have
1. external clock (8uS) on pin=0,
2. by receiving the pulse at this clock I should start DMA-SPI transfer as
Code:
EventResponder event;
volatile bool event_happened = true;
void asyncEventResponder(EventResponderRef event_responder)
{ ADC_Done_Count++;
  event_happened = true;
}


void GetADC()
{
  if(event_happened == true)
  { event_happened=false;
    SPI.transfer(SPI_txBuffer, SPI_rxBuffer+18*ADC_Ini_Count, 19, event);
  }
  if(ADC_Ini_Count) ADC_Ini_Count--;
  else { ADC_Ini_Count=ADC_MAX_Count-1; ADC_GC++; }
}

and GetADC is the interrupt function assigned as:

Code:
attachInterrupt(digitalPinToInterrupt(0), GetADC, FALLING);

In addition, every say 128-th call of GetADC I should run additional function

Code:
void RunExcitation();

thank takes 100uS, so, I tried to modify my GetADC as
Code:
void GetADC()
{
  if(event_happened == true)
  { event_happened=false;
    SPI.transfer(SPI_txBuffer, SPI_rxBuffer+18*ADC_Ini_Count, 19, event);
  }
  if(ADC_Ini_Count) ADC_Ini_Count--;
  else { ADC_Ini_Count=ADC_MAX_Count-1; ADC_GC++; }
  if((ADC_Ini_Count&127)==0) RunExcitation();
}

The main problem I am facing right now, if GetADC does not exit before the next interrupt from the pin 0 occur, the system is crushing. Indeed RunExciation() takes 100uS, so I am staying still in GetADC().

I cannot use main loop() function, because on this function I am running heavy numerical computations so I cannot sync it with RunExcitation() function. During call RunExcitation() the computations in the loop() can be delayed, but I cannot predict where I am in the loop() control to stop loop() computations and run RunExcitation() function.

Please, advice me is there any possibility to run RunExcitation() and continuously receive interrupts to GetADC, id if yes, how to proceed.

Thank you!!!
 
It seems that I can solve my issue by using one additional IntervalTimer, that I will start directly after GetADC with 8uS at the previous call, i.e.

Code:
IntervalTimer it;
...
if((ADC_Ini_Count&127)==127) it.begin(RunExcitation, 8);
 
Back
Top