title: Timer on atmega328p
body: <p>So we had a task in school that every 10ms a variable (millisekunden)
  schould increase by 10. We were using the CTC Mode, i set the OCR0A to 157, the
  prescaler was 1024. The variable (millisekunden) increases every 10ms for 10, and
  when it reaches 1000 , we schould print it out, and repeat that every 1000.
  I always get an error : avrdude: verification error, first mismatch at byte 0x0000
  0x00 != 0x0c
  avrdude: verification error; content mismatch
  Can anyone check out my code if it is even correct programmed? Im using atmega328p
  it has 16MHz. So i calculated 1/ 16 MHz * 1024(prescaler) * OCRA(157) and we get 10milli
  seconds.</p>
  <hr />
  <pre><code>#include &quot;Arduino.h&quot;
  
  unsigned long int t_ref; 
  
  volatile unsigned long int millisekunden; // milli seconds timer
  unsigned long int last_msg;               
  char buffer[64];
  unsigned int c;
  
  void setup() {
   
    // Timer 0 
    TCCR0A |= (1 &lt;&lt; WGM01);               // CTC Modus
    TCCR0B |= (1 &lt;&lt; CS02) | (1 &lt;&lt; CS00); // Prescaler 1024
    
    OCR0A = 155;
  
    // Compare Interrupt 
    TIMSK0 |= (1 &lt;&lt; OCIE0A);
  
    Serial.begin(9600);
  }
  
  void loop() {
    if (millisekunden - last_msg &gt;= 1000) {
      sprintf(buffer, &quot;t=[%lu] PINB=[%2.2x]&quot;, millisekunden,PINB);
      Serial.println(buffer);
      last_msg = millisekunden;
    }
  
  }
   
  // Timer-Interrupt-Routine
  ISR(TIMER0_COMPA_vect) {
    millisekunden = millisekunden + 10;
  }
  </code></pre>
  <hr />
  <p>datasheet from µC : <a href="https://ww1.microchip.com/downloads/en/DeviceDoc/Atmel-7810-Automotive-Microcontrollers-ATmega328P_Datasheet.pdf" rel="nofollow noreferrer">https://ww1.microchip.com/downloads/en/DeviceDoc/Atmel-7810-Automotive-Microcontrollers-ATmega328P_Datasheet.pdf</a></p>