Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

6
  • Thats a weird problem. As I know, there is no interrupt priority on AVR chips. If an interrupt happens, while another ISR is currently running, the corresponding flag is set and the ISR execution will happen after the first ISR finishes. Do you have access to an oscilloscope or a logic analyzer? It might be good to check, if the expected signal is getting outputted on the motor2 pin. Maybe there is a hardware problem. Or are you having any code, that might use one of the timers? Commented Feb 25, 2021 at 10:45
  • Thanks for your response @chrisl . I discard hardware problems since the whole system does work in all other situations. I have now tried to change the prescaler of the timers. They were set to 1 but now I have configured them to 8, so timers how a frequency of 2MHz now. Surprisingly, the system does not fail now, the whole sequence is done with no errors and none of the interruptions freeze. I suppose that by reducing the timers' frequency, they may now be working under less "pressure" so that they may not be hitting each other. Commented Feb 25, 2021 at 13:02
  • @chrisl There is what is called "natural priority" - each intrerupt has a number, and they are checked in sequence - interrupts with lower numbers happen before those with higher numbers. If a lower numbered interrupt re-occurs before the higher numbered one has a chance to run it will be responded to in preference to that higher numbered one. Which is why ISRs need to be as short as possible. Commented Feb 25, 2021 at 13:02
  • @Majenko I have implemented these timer interruptions at a frequency way higher than the one the crash I mentioned before happens. When this situation happens and my interruptions stop, none of them have a frequency higher than 500Hz, while, with the same code, they can make simultaneous movements at 4kHz. With this I mean that my code inside interruptions doesn't last enough for not letting other interruptions to happen. In my critical case, the ISR frequencies are low enough to run all the code inside but, with no sense, one of them simply gets stuck. Commented Feb 25, 2021 at 13:08
  • @Majenko Oh, interessting. Didn't know that, thanks :) Commented Feb 25, 2021 at 13:30