PWM pulse after interrupt

I am trying to generate 5 Pulse after interrupt after reading ZCD (here i am using Rising edge and falling edge Interrupt)but in DSO there is some undesirable drift in output signal. for any comment Thanks in advance .

int a=0;
int b=0;
void setup()
{
noInterrupts();
pinMode(9,OUTPUT);
pinMode(10,OUTPUT);
attachInterrupt(0,stateChange,RISING);
attachInterrupt(1,stateChange1,FALLING);
interrupts();
}
void stateChange()

{
a=1;
}

void stateChange1()
{
b=1;
}
void loop()
{
if (a==1)
{ digitalWrite(10,LOW);

for(int i =0;i<5;i++)
{
digitalWrite(9,HIGH);
delay(1);
digitalWrite(9,LOW);
delay(1);

}
a=0;
}

if(b==1)
{digitalWrite(9,LOW);

for(int i =0;i<5;i++)
{
digitalWrite(10,HIGH);
delay(1);
digitalWrite(10,LOW);
delay(1);

}

b=0;
}
}

Please modify your post and use the code button </> so your code looks like this and is easy to copy to a text editor. See How to use the Forum

What is the interval between interrupts?

You should define the variables that are updated in the ISR as volatile

volatile byte a=0;

and just use a byte variable so that there is only a single read needed to get the value in loop(). With a multi-byte variable (such as an int) there is a risk that the ISR will change the value while it is being read.

Explain exactly what you mean by “some undesirable drift”

…R

  noInterrupts();
  pinMode(9,OUTPUT);
  pinMode(10,OUTPUT);
  attachInterrupt(0,stateChange,RISING);
  attachInterrupt(1,stateChange1,FALLING);
  interrupts();

Why are you disabling interrupts here? There is no need to disable interrupts when attaching handlers.

stateChange() and stateChange1() are hardly better names than f123() and f143(). Use names that convey what the function does. They do NOT change the state of anything.

Please edit your post, select the code, and put it between [code][/code] tags.

You can do that by hitting the “Code” icon above the posting area. It is the first icon, with the symbol: </>

How to use this forum

a and b should be qualified volatile.

Edit: this has already been pointed out.