Inverting PWM

I have found this excellent piece of code and it sure works fine.
My problem is that I need to be able to invert several pwm outputs, in this case pin 6, 9 and 10.

Can anyone help me decoding the two rows under analogWrite(pin, value);?

void invertAnalogWrite(int pin, int value)
{
    analogWrite(pin, value);
   TCCR1A = TCCR1A & ~B00110000; //switch off output B
   TCCR1A |= B00110000;  //switch on the B output with inverted output
}

void loop()
{
    invertAnalogWrite(10, value);
}

Click the top link here.

:stuck_out_tongue:

OMFG!

Google, how on earth could I have missed that site?!
It is truly remarkable that I have been on the net since '93 without ever noticing that search engine.

Thank you PeterH, your comment really learned me a lot.

Can anyone help me decoding the two rows under analogWrite(pin, value);?

Sure. Go to http://web.alfredstate.edu/weimandn and scroll down to the Atmel ATmega Subsystem Diagrams. Click on the Reference Diagrams For Programmers link and check out the diagrams for Timer/Counter1. You may not be using the Compare Match A or B functions but the diagrams should help you anyway.

Don

Okay, so why is it a problem to invert all 3 PWM’s using 3 function calls? Or 2 analogWrites and 1 function call?

I can run 6 PWM’s now and I only have 3 timers so I don’t expect there’s a 1 PWM to 1 timer relation.

I can run 6 PWM's now and I only have 3 timers so I don't expect there's a 1 PWM to 1 timer relation.

There is an absolute relationship between the six Arduino PWM outputs and the three ATMega328 Timers. The PWM pins on D5 and D6 are controlled by Timer0, the PWM pins on D9 and D10 are controlled by Timer1, and the PWM pins on D3 and D11 are controlled by Timer2.

Don