giving delay function to output
I suggest you look into using a hardware timer rather than using delay(), I suspect it will give you more accurate timing.

Timer configuration is not as straight forwards as using delay - they don't work in milliseconds or microseconds, but instead in multiples of clock cycles, which (I find) makes configuring them a little difficult to understand, but it is possible to set the interval of a timer within its own interrupt routine.

Another advantage to using timers is that your code can do other things whilst waiting between interrupts.

Have a read here for more information and simple examples:
http://playground.arduino.cc/code/timer1
or just Google "Arduino timers" for other examples and explanations.