fast pwm mode 7 using the Uno

Hello all,

My question is how fast pwm mode 7 timer2 of the uno works. From reading
the documentation I really could not understand how this mode is supposed
to work.

What I could see using a scope is that OC2A register sets the period.
and OC2B register sets the duty cycle. OC2B must always be less than
OC2A to see a change in of state at OC2B pin.

I could not get OC2A pin to change.

If anyone who is familiar with this mode can let me know if this
is how its used that would be awesome.

Did the documentation include the data sheet?

Did the documentation include the data sheet ?
Yes, a 444 page data sheet.

I could not get OC2A pin to change.

Post the code, using code tags. You probably forgot to declare the pin OUTPUT, or to connect it to the timer.

In the "444 page data sheet", only a small number of pages deal with the timers. Do spend some time going through those few, as you will find it to be a richly rewarding experience.

Here is the code i am using.
OC2B pin resets when timer count is 100, and is set when timer is at BOTTOM (0x00), the number of counts that make up the period is register OC2A
OC2A pin does not change state what ever the setting of COM2Ax bits.

I am just wondering if this is expected behavior as the data sheet does not explain this mode well.

void setup() {

cli();

 TCCR2A = (_BV(COM2A1) | _BV(COM2A0) | _BV(COM2B1) | _BV(WGM21) | _BV(WGM20));  
 TCCR2A &= ~( _BV(COM2B0) ); 
  
 TCCR2B = _BV(CS20) | _BV(WGM22); 
 TCCR2B &= ~( _BV(CS22) | _BV(CS21) );
 
 OCR2A=200; 
 OCR2B=100;
 
 sei();
 
 Serial.print("TCCR2A is "); Serial.println(TCCR2A,HEX);
 Serial.print("TCCR2B is "); Serial.println(TCCR2B,HEX);

 DDRD |=_BV(DDD3);
 DDRB |= _BV(DDB3);

}


void loop() {

  
}

I am just wondering if this is expected behavior as the data sheet does not explain this mode well.

I think it explains the mode quite completely. What do you not understand about the explanation?

BTW these lines do nothing useful. What did you intend by including them?

 TCCR2A &= ~( _BV(COM2B0) ); 
...
 TCCR2B &= ~( _BV(CS22) | _BV(CS21) );

jremington:
I think it explains the mode quite completely. What do you not understand about the explanation?

The diagrams help explain the modes but there isn't a diagram for every mode. Do you any
experiance using mode 7 fast pwm. I am trying to understand that mode.

BTW these lines do nothing useful. What did you intend by including them?

 TCCR2A &= ~( _BV(COM2B0) ); 

...
TCCR2B &= ~( _BV(CS22) | _BV(CS21) );

They useful to me. I want make sure that those bits are reset. Thats the way it is done in
straight C. You have quite the condescending attitude, you know. At least that what it
comes off like.

With mode 7, OCR2A forms the TOP; it makes sense the pin can’t be used to toggle.

Perhaps mode 3 with a TOP of 0xFF would work for you:

const byte pinOC2A = 11;    //port B3 -> pin 11
const byte pinOC2B = 3;     //port D3 -> pin 3

void setup( void )
{
    pinMode( pinOC2A, OUTPUT );
    pinMode( pinOC2B, OUTPUT );
    
    //timer 2    
    TCCR2A = (1<<COM2A1) | (1<<COM2B1) | (1<<WGM21) | (1<<WGM20);
    TCCR2B = (1<<CS20);
    OCR2A = 200;
    OCR2B = 100;
    
}//setup

void loop( void )
{
}//loop

I want make sure that those bits are reset.

They are in each case forced to zero by the previous line.

Since you can't be bothered to add a comment, no one can possibly know your intent.

What is the point in having two different outputs from mode 7? The frequency and duty cycle would be the same for both.

Blackfin:
With mode 7, OCR2A forms the TOP; it makes sense the pin can't be used to toggle.

Perhaps mode 3 with a TOP of 0xFF would work for you:

Ok, that makes sense. I wanted to take some time, go through the data sheet and understand the
difference between the modes. Some of the mode explanations were not clear to me, like mode 7.

Thank you

jremington:
They are in each case forced to zero by the previous line.

Since you can’t be bothered to add a comment, no one can possibly know your intent.

I don’t see a point in having two different outputs from mode 7. The frequency and duty cycle would be the same for both.

Yes, you are correct. Usually I will OR (like the line below)the register in case there are other bits that are high that I am not changing. This time it was not needed.

TCCR2A |= (_BV(COM2A1) | _BV(COM2A0);

“can’t be bothered” You should give people the benefit of the doubt instead of assuming they are
are malicious, unless you know for sure.

Refering to Table 19-4. Compare Output Mode, Fast PWM in the data sheet it shows that OC2A can be
cleared or set but I don’t think that is true based on what I tried but I could be wrong.

Since you said the data sheet explains the mode quite clearly maybe you can explain how to set or clear
OC2A pin.

Here is a thread about this same question. I guess they didn't see the verbage for mode 7 as
"explained quite completely" as you JR.

Agreed, the wording concerning output 2A is unclear, even though the "special case" is duly noted.

Since only one output is possible from the timer in this mode, why should one care whether it is A or B?