Interrupt issue

econjack

Well-known member
I am using a Teensy 4.1 with Win 10 in the Arduino IDE 1.8.19. I have a large project of 12,000 lines of C code that controls a 5 band HF, CW/SSB Software Define Transceiver. One of the encoders is placed in the Encoders.cpp file and has an ISR named EncoderFilter() which is couple via the attachInterrupt() call. I'm using the Rotary library that is distributed with the Arduino IDE to control the encoder. The interrupt code from the library's Example directory works flawlessly, using pins 14 and 15 for CW and CCW moment. I know it's heresy to put debug statements in an ISR, but I did and confirmed that the encoder indeed does sense the CW/CCW movement and correctly assigns the value into filterEncoderMove . This is the code:

Code:
void EncoderFilter()
{
  char result;

  result = filterEncoder.process();   // Read the encoder
  if (result == 0) {                  // Nothing read
    filterEncoderMove = 0;
  } else {
    filterEncoderMove = (int) result; // 16 = CW, 32 = CCW
 }
}
There are 22 files in the project. The filterEncoderMove variable is a global volatile int data type. However, trying to examine filterEncoderMove in loop() consistently says the value is zero, even though I know it is properly set in the function. I tried for hours to figure this out.

I have my problem fixed, but I don't know why it fixes it. To explain: because a Software Define Radio has a lot of stuff going on, I used the FASTRUN directive before loop(). I did NOT do that for the encoder function because the documentation says that functions, by default, are placed in the FASTRUN section of RAM1. I think I misunderstood that. As soon as I placed FASTRUN in front of the code above, loop() started processing the interrupt correctly. My question is: why didn't the interrupt work without FASTRUN? Does a FASTRUN loop() using interrupts need the ISR to be marked as FASTRUN? The project is Open Source so you can see the code if you wish in the Files section here.
 
Back
Top