Timer2 does not respond to my changes

Here is example code that I have been attempting to utilize for setting Timer2. My understanding is that OCR2A = 2 should set the output on PD3 to 2 MHz. However, I measure 8 MHz with my oscilloscope at PD3. Even setting OCR2A to 0 or 1, the output is still 8 MHz. Can someone point out to me my mistake? Thanks.

void set_clock() {  // Configures timer2 for 2MHz output on PD3
  TCCR2B = _BV(CS20);  // prescaler = F_CPU/1
  OCR2A = 2;  // clear timer at 2 count, f = F_CPU/8
  TCCR2A = _BV(COM2B0) | _BV(WGM21);  // toggle PD3 on compare match
  DDRD |= _BV(PORTD3);  // start clock output on XIN/PD3
}

Hint channels A and B are independent. Setting OCR2A won’t have any effect on channel B. Try setting OCR2B. Oh, and set it to 3, not 2.

Well, I read through the manual. ATMEL simply does a horrible job laying out the timer functions in a sensible manner. It's simply ridiculous. They shoot themselves in the foot on this part. I'll just construct a 2MHz timer from hardware in less than 5 minutes and be done with this. What a pathetic controller!

No I think it is you not understanding not the fault of Atmel. All timers for all processors are described in this way. Data sheets are for grown up, they are not beginner tutorials.

ATMEL simply does a horrible job laying out the timer functions in a sensible manner.

XD !
http://www.amazon.com/gp/product/0138003319/ref=as_li_tf_tl?ie=UTF8&tag=ffanar-20&linkCode=as2&camp=1789&creative=9325&creativeASIN=0138003319

phffttt! you guys are amateurs...you can't even set up the timers correctly. You just have bought into all the hype that ATMEL is the best chip since 1970.

[u]You[/u] can't set them up correctly it seems.

You just have bought into all the hype that ATMEL is the best chip since 1970.

No ...,. Absolutely no one thinks that!

JamesPicard: phffttt! you guys are amateurs...you can't even set up the timers correctly. You just have bought into all the hype that ATMEL is the best chip since 1970.

Oh burn! Countless hundred of thousands have figured out the "secrets" of an exceptionally well documentened processor... Except for you. Whew! FINALLY someone called them on their inability to document everything.

Well done.

Timer2 is missing on Leonardo board? Regarding Atmel's data sheet for microcontrollers, AtMega32U4:

– Four 8-bit PWM Channels – Four PWM Channels with Programmable Resolution from 2 to 16 Bits – Six PWM Channels for High Speed Operation, with Programmable Resolution from 2 to 11 Bits

It took me an hour to figure out that even Timer1/Timer3 pretty close in hardware with 3 PWM on each, there are only 4 16-bit PWM, 3 on Timer1 and 1 on Timer 3. When they say 11 bits 6 channel, I realized , that it's on Timer4 . I'm still cant understand where 8-bit 4 channels came from? As only one Timer0 , with 2 channels, why 4? Did they count Timer2 which isn't there?

Exactly Magician! This chip is a toy. A freakn' 8 bit toy. It doesn't even hold a candle to the 64 bit processors I work with. The PWM/Clocking is a mess. Absolutely atrocious job done by ATMEL at laying it out and documentation. You guys are in denial.

Don't feed the trolls.