user7123: I want to change timer0 frequency because I need to use 4 PWM pins at a frequency lower than 500Hz and the SPI on an ATmega328. So I changed timer2 to Fast PWM with 64 divisor, enabled the overflow interrupt for timer2 and disabled the overflow interrupt for timer0:
  TCCR2A = _BV(WGM21) | _BV(WGM20);
  TCCR2B = _BV(CS22);
  TIMSK2 |= (1 << TOIE2); // enable overflow interrupt for timer2
  TIMSK0 &= ~(1 << TOIE0); // disable overflow interrupt for timer0

and changed the ISR vector in wiring.c from ISR(TIMER0_OVF_vect) to ISR(TIMER2_OVF_vect).
But delay doesn't work. What can be the problem?

user10794: 
Now everything works except for delay()

delay() uses micros() and micros() reads the hardware registers, like this:
unsigned long micros() {
    unsigned long m;
    uint8_t oldSREG = SREG, t;

    cli();
    m = timer0_overflow_count;
#if defined(TCNT0)
    t = TCNT0;
#elif defined(TCNT0L)
    t = TCNT0L;
#else
    #error TIMER 0 not defined
#endif

#ifdef TIFR0
    if ((TIFR0 & _BV(TOV0)) && (t < 255))
        m++;
#else
    if ((TIFR & _BV(TOV0)) && (t < 255))
        m++;
#endif

    SREG = oldSREG;

    return ((m << 8) + t) * (64 / clockCyclesPerMicrosecond());
}

You would need to change all those references (TCNT0, TIFR0, TOV0 etc.) to use the Timer 2 equivalents.

7123: <p>I want to change <em>timer0</em> frequency because I need to use 4 PWM pins at a frequency lower than 500Hz and the SPI on an ATmega328. So I changed <em>timer2</em> to <em>Fast PWM</em> with 64 divisor, enabled the overflow interrupt for timer2 and disabled the overflow interrupt for timer0:</p>

<pre><code>  TCCR2A = _BV(WGM21) | _BV(WGM20);
  TCCR2B = _BV(CS22);
  TIMSK2 |= (1 &lt;&lt; TOIE2); // enable overflow interrupt for timer2
  TIMSK0 &amp;= ~(1 &lt;&lt; TOIE0); // disable overflow interrupt for timer0
</code></pre>

<p>and changed the ISR vector in <em>wiring.c</em> from <code>ISR(TIMER0_OVF_vect)</code> to <code>ISR(TIMER2_OVF_vect)</code>.</p>

<p>But <code>delay</code> doesn't work. What can be the problem?</p>
 10794: <blockquote>
  <p>Now everything works except for delay()</p>
</blockquote>

<p><code>delay()</code> uses <code>micros()</code> and <code>micros()</code> reads the hardware registers, like this:</p>

<pre class="lang-c++ prettyprint-override"><code>unsigned long micros() {
    unsigned long m;
    uint8_t oldSREG = SREG, t;

    cli();
    m = timer0_overflow_count;
#if defined(TCNT0)
    t = TCNT0;
#elif defined(TCNT0L)
    t = TCNT0L;
#else
    #error TIMER 0 not defined
#endif

#ifdef TIFR0
    if ((TIFR0 &amp; _BV(TOV0)) &amp;&amp; (t &lt; 255))
        m++;
#else
    if ((TIFR &amp; _BV(TOV0)) &amp;&amp; (t &lt; 255))
        m++;
#endif

    SREG = oldSREG;

    return ((m &lt;&lt; 8) + t) * (64 / clockCyclesPerMicrosecond());
}
</code></pre>

<p>You would need to change all those references (TCNT0, TIFR0, TOV0 etc.) to use the Timer 2 equivalents.</p>
