I have an Arduino Nano with an 328P and need all 6 PWM pins.
Thus, I had to adjust the prescaler and WGM Mode of Timer0.
It is now in phase correct PWM mode with a prescaler of 1.
TCCR0A = _BV(COM0A1) | _BV(COM0B1) | _BV(WGM00);
TCCR0B = _BV(CS00);
Now I need a working time calculation for other libraries, but since Timer0 had that duty everything is out of order now.
I tried adjusting the wiring.c
// the prescaler is set so that timer0 ticks every 64 clock cycles, and the
// the overflow handler is called every 256 ticks.
#define MICROSECONDS_PER_TIMER0_OVERFLOW (clockCyclesToMicroseconds(64 * 256))
to this
#define MICROSECONDS_PER_TIMER0_OVERFLOW (clockCyclesToMicroseconds(1 * 510))
But it's like I didn't change anything. (tested other settings that were changed so it was compiled anew )
Whole Code:
void setup() {
// Set Timer 0, 1 and 2
// Register A: Output A and B to non-inverted PWM and PWM mode to phase correct.
// Register B: Pre Scaler to 1.
TCCR0A = _BV(COM0A1) | _BV(COM0B1) | _BV(WGM00);
TCCR0B = _BV(CS00);
TCCR1A = _BV(COM1A1) | _BV(COM1B1) | _BV(WGM10);
TCCR1B = _BV(CS10);
TCCR2A = _BV(COM2A1) | _BV(COM2B1) | _BV(WGM20);
TCCR2B = _BV(CS20);
pinMode(8, OUTPUT);
}
void loop() {
digitalWrite(8, LOW);
delay(65000);
digitalWrite(8, HIGH);
delay(65000);
}
#define SCALE_UP(x) x<<6
and then use it like suchdelay(SCALE_UP(1000))