user15341: I am trying to use Timer2 in an Uno in fast PWM mode.  Can someone explain how to set up the TCCR2A & B registers?  
Currently I have:
  TCCR2A |= _BV(WGM21) | _BV(WGM20);
  TCCR2B &= ~_BV(WGM22);

  TCCR2A = (TCCR2A | _BV(COM2A1)) & ~_BV(COM2A0);
  TCCR2A &= ~(_BV(COM2B1) | _BV(COM2B0));
  TCCR2B = (TCCR2B & ~(_BV(CS12) | _BV(CS11))) | _BV(CS10);

I would like to have the inverted value on TCCR2B, but I think it can be inverted using OCR2B ^= 255, correct?  This is to have a varying signal on Pin11 and its inverse on Pin3, the signal is generated by varying the OCR2B value.
Thanks

user7508: If you want to get two complementary PWM signals, you have to set the
same value to both output compare registers. This is necessary to have
the two signals in phase. You also have to configure one PWM in
non-inverting mode and the other in inverting mode. For example:
TCCR2A = _BV(COM2A1)  // non-inverting PWM on OC2A
       | _BV(COM2B0)  // PWM on OC2B:
       | _BV(COM2B1)  //    inverting mode
       | _BV(WGM20)   // fast PWM
       | _BV(WGM21);  // ditto
TCCR2B = _BV(CS10);   // clock at F_CPU / 1
OCR2A  = 84;          // duty cycle ~ 1/3
OCR2B  = 84;          // same signal, complemented

Checked on the scope: when pin 3 goes high pin 11 goes low and
vice-versa.

15341: <p>I am trying to use Timer2 in an Uno in fast PWM mode.  Can someone explain how to set up the TCCR2A &amp; B registers?  </p>

<p>Currently I have:</p>

<pre><code>  TCCR2A |= _BV(WGM21) | _BV(WGM20);
  TCCR2B &amp;= ~_BV(WGM22);

  TCCR2A = (TCCR2A | _BV(COM2A1)) &amp; ~_BV(COM2A0);
  TCCR2A &amp;= ~(_BV(COM2B1) | _BV(COM2B0));
  TCCR2B = (TCCR2B &amp; ~(_BV(CS12) | _BV(CS11))) | _BV(CS10);
</code></pre>

<p>I would like to have the inverted value on TCCR2B, but I think it can be inverted using OCR2B ^= 255, correct?  This is to have a varying signal on Pin11 and its inverse on Pin3, the signal is generated by varying the OCR2B value.</p>

<p>Thanks</p>
 7508: <p>If you want to get two complementary PWM signals, you have to set <em>the
same</em> value to both output compare registers. This is necessary to have
the two signals in phase. You also have to configure one PWM in
non-inverting mode and the other in inverting mode. For example:</p>

<pre class="lang-c++ prettyprint-override"><code>TCCR2A = _BV(COM2A1)  // non-inverting PWM on OC2A
       | _BV(COM2B0)  // PWM on OC2B:
       | _BV(COM2B1)  //    inverting mode
       | _BV(WGM20)   // fast PWM
       | _BV(WGM21);  // ditto
TCCR2B = _BV(CS10);   // clock at F_CPU / 1
OCR2A  = 84;          // duty cycle ~ 1/3
OCR2B  = 84;          // same signal, complemented
</code></pre>

<p>Checked on the scope: when pin 3 goes high pin 11 goes low and
vice-versa.</p>
