Author Topic: Arduino Mega 2560 two interrupt issue  (Read 1388 times)

0 Members and 1 Guest are viewing this topic.

Offline Vindhyachal.taknikiTopic starter

  • Frequent Contributor
  • **
  • Posts: 488
Arduino Mega 2560 two interrupt issue
« on: November 05, 2018, 12:18:09 pm »
1. I am using arduino mega 2560. Connected are 20 segments together, refreshed every 500us. After every 500us, one segment is enable & written.

2. Also a PS2 keyboard is connected to read keys & display on segment. Library used is PS2Keyboard.cpp - PS2Keyboard library Written by Christian Weichel <info@32leaves.net>

3. Ps2 & timer refreshing code of 20 segments works independently correctly. Problem arises when I merge both codes together. In that case what happens is I am not able to read correctly from keyboard. Probably due to when timer interrupt comes, it blocks rest of interrupt until it is processed.

4. Timer 2 is used and for PS2 data line is pin 19 & clock pin is 18.

5. Now how to resolve this issues. Refreshing leds is also important other flickering is observed.

6. I read "http://www.gammon.com.au/interrupts", & read that inside interrupt function, below function can be used to enable interrupt again.

interrupts ();  // allow more interrupts


7. this way code is working, but i am not sure how safe it is use.
in top of timer2 isr I have written:

void timer2_isr_500us()
{
    interrupt();
   
    refresh_led()

}
 

Offline macboy

  • Super Contributor
  • ***
  • Posts: 2287
  • Country: ca
Re: Arduino Mega 2560 two interrupt issue
« Reply #1 on: November 05, 2018, 03:28:57 pm »
Another way is to perform the LED refresh at "task" level, which means inside the main loop, by testing for a flag to be set. The ISR  timer2_isr_500us()  function will set that flag, then return. The main loop will test for the flag, and if set, call the refresh function and clear the flag. Then it can continue with any other periodic work.

The LED refresh process may be briefly interrupted by the PS2 interrupt, but it should work fine. The PS2 ISR should be lean and fast and definitely not do any kind of delay. You may notice slight flicker in the display when typing, but most likely not, especially if all other ISRs are fast like they should be.
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf