Greetings, I am new to setting up PWM without analogwrite and need some help. I have been reading the help and found:
Compare Match Output A Mode bits (COMnA): these enable/disable/invert output A
Compare Match Output B Mode bits (COMnB): these enable/disable/invert output B
Setting the COM2A bits and COM2B bits to 10 provides non-inverted PWM for outputs A and B.
zippo01:
Greetings, I am new to setting up PWM without analogwrite and need some help. I have been reading the help and found:
Compare Match Output A Mode bits (COMnA): these enable/disable/invert output A
Compare Match Output B Mode bits (COMnB): these enable/disable/invert output B
Setting the COM2A bits and COM2B bits to 10 provides non-inverted PWM for outputs A and B.
How would I set one or the other? What does each of the above commands do in practice?
That code sets 4 bits in the 2A register. Go to the datasheet and look up what they do.
I normally just use hex or binary constants since you still need to go to the datasheet to workout what
bits do what and that long line of ORed constants is clumsy
Ok so I have been doing a lot of reading, just checking to make sure I understand.
TCCR2A is one of the timers available.
// I found this in the Atmel datasheet
COMnA1 COMnA0
COMnB1 COMnB0
COMnC1 COMnC0
1 0 Clear OCnA/OCnB/OCnC on compare match, set OCnA/OCnB/OCnC at BOTTOM (non-inverting mode)
1 1 Set OCnA/OCnB/OCnC on compare match, clear OCnA/OCnB/OCnC at BOTTOM (inverting mode)
So _BV(COM2A1) | _BV(COM2B1) sets this PWM to inverting. _BV(COM2A1) only would be non-inverting
_BV(WGM21) | _BV(WGM20); are what set fast PWM mode?
TCCR2B = _BV(CS22); sets the clock?
What assoiated pinMode(3, OUTPUT); pinMode(11, OUTPUT); When I look at the data sheet for various pins I only see (OC3B/INT4)PE4 I would use OC3B?
Thanks for all the help. I'm really trying to learn this, and I don't have anyone local to me that can help!