title: LCD's delays with precise timer interrupts
body: <p>I'm developing a system that allows to set a square wave period, then, once setted, it drives a led with a square wave with the setted period.
  Anyway if i set the period, the output square wave isn't consistent, with heavy random period variation.</p>
  
  <p>I'm using a standard CTC timer because i need multiple output, so i can't use one single pwm output. I'm also using a piece of code that i use often, so i'm sure that this piece of code works well.</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-html lang-html prettyprint-override"><code>if(oldtack!=tack)
  {
      oldtack=tack;
         
   if((oldtack%(period/2))==0)
   {
    PORTB^=((1&lt;&lt;PORTB0)|(1&lt;&lt;PORTB1)|(1&lt;&lt;PORTB2)|(1&lt;&lt;PORTB3)|(1&lt;&lt;PORTB4)|(1&lt;&lt;PORTB5));
   }
  }</code></pre>
  </div>
  </div>
  </p>
  
  <p>This above is the code that i often use, already tested and quite sure that works.</p>
  
  <p>The only thing that is different from my usual code is the LCD.</p>
  
  <p>I'm using an I2C LCD display with a library that i found in internet. I'm afraid that this LCD and its library is affecting the precision of the period of my system, that i need as precise as possible.</p>
  
  <p>Can you help me?</p>
  
  <p>Here the whole code: <a href="https://pastebin.com/J6zCzcqi" rel="nofollow noreferrer">https://pastebin.com/J6zCzcqi</a></p>
  
  <p>EDIT
  I'm using this library: <a href="https://davidegironi.blogspot.com/2013/06/an-avr-atmega-library-for-hd44780-based.html" rel="nofollow noreferrer">https://davidegironi.blogspot.com/2013/06/an-avr-atmega-library-for-hd44780-based.html</a></p>