const int pwmPin1 = 3; // Connect the first PWM output to digital pin 3
const int pwmPin2 = 5; // Connect the second PWM output to digital pin 5
void setup() {
// Set the PWM pins as outputs
pinMode(pwmPin1, OUTPUT);
pinMode(pwmPin2, OUTPUT);
// Configure Timer 2 for Phase Correct PWM mode
TCCR2A = _BV(WGM20); // Phase Correct PWM mode, WGM21 = 0
TCCR2B = _BV(CS20); // No prescaler
// Set the initial duty cycle to 45%
OCR2A = 45 * 255 / 100; // Convert percentage to 8-bit value
OCR2B = 45 * 255 / 100; // Convert percentage to 8-bit value
// Set the dead time (2 microseconds)
OCR2A += 2 * (F_CPU / 1000000) - 1;
// Enable PWM outputs with non-inverting mode
TCCR2A |= _BV(COM2A1) | _BV(COM2B1); // Clear OC2A/OC2B on compare match when up-counting, set on compare match when down-counting
}
void loop() {
// Your main code goes here
}