PWM capabilities

Not sure if one can use two different PWM frequencies on 2 different outputs?!
If so, how to approach it?
Thank you.

Look here.

That is in fact the default situation for an Arduino... four pins at ~490 Hz, two (pins 5 and 6) on ~980Hz.

Thank you!

Thanks again for the links.
I am experiencing difficulties using the ATmega PWM registers directly, as in the link above:

pinMode(3, OUTPUT);
  pinMode(11, OUTPUT);
  TCCR2A = _BV(COM2A1) | _BV(COM2B1) | _BV(WGM21) | _BV(WGM20);
  TCCR2B = _BV(CS22);
  OCR2A = 180;
  OCR2B = 50;

I am trying to control a fan's speed varying the output duty cycle and frequency; but it doesn't make a difference in speed if the output is set to 10% or to 90%.
I am using the digitalWrite() function to set the pins .

The analogWrite() function and the Timer/Counter registers work fine.

I tried the code on an Arduino UNO and NANO.
I would appreciate some feedback since I'm not sure what I did wrong.
Thanks.

kwhunter:
I am trying to control a fan's speed varying the output duty cycle and frequency; but it doesn't make a difference in speed if the output is set to 10% or to 90%.
I am using the digitalWrite() function to set the pins .

digitalWrite() does not set PWM duty cycles.

I don't know what digitalWrite() is doing with a PWM setting on the same pin - it would make sense that this is overridden, but you'll have to check the source code of digitalWrite() function to be sure.

I read the whole article again and still I'm confused; digitalWrite() is not the function to use, however analogWrite() sets the duty cycle itself and thus negates the registry settings. The author is ambiguous relative to the function he used; he lists frequencies and duty cycles for each output but does not disclose which function and value he used to achieve those outputs...
my guess is he used analogWrite( pin, value) but which value?
I don't have an oscilloscope to look at the wave.

When manipulating the timer registers directly you don’t use either analog or digitalWrite.
You set duty cycle in the output compare register(OCRx) and You can enable/disable it in the register or simply use pinMode to set the pin as input thus disabling pwm. Either way is acceptable and described in this article. Secrets of Arduino PWM

EDIT: Been awhile so I may not have the details quite correct. read the article.

Hutkikz:
When manipulating the timer registers directly you don't use either analog or digitalWrite.
You set duty cycle in the output compare register(OCRx) and You can enable/disable it in the register or simply use pinMode to set the pin as input thus disabling pwm. Either way is acceptable and described in this article. Secrets of Arduino PWM

EDIT: Been awhile so I may not have the details quite correct. read the article.

That is what I used as reference; however, if what you say it's true and probably it is, how do I use the output in a logic? how do I turn the pin output on or off? pinMode sets the pin but does not turn it on/off.
Thank you.

kwhunter:
pinMode sets the pin but does not turn it on/off.

To be clear, you inserted code pinMode (3,Input) when you wanted to turn PWM output on pin 3 off and it still was going?

Slumpert:
To be clear, you inserted code pinMode (3,Input) when you wanted to turn PWM output on pin 3 off and it still was going?

No.

pinMode(3, OUTPUT);
  TCCR2A = _BV(COM2A1) | _BV(COM2B1) | _BV(WGM21) | _BV(WGM20);
  TCCR2B = _BV(CS22);
  OCR2A = 180;
  OCR2B = 50;

and it was not going

I don't have an oscilloscope to look at the wave.

and it was not going

How do you determine what is "going"?

cattledog:
How do you determine what is "going"?

Quite easy: the LED connected to pin 3 was off. Any idea why?

How is the led connected? Have you confirmed the correct polarity? What serial resistance do you use?

If you use digitalWrite on pin 3 can you turn the LED on and off?

cattledog:
How is the led connected? Have you confirmed the correct polarity? What serial resistance do you use?

If you use digitalWrite on pin 3 can you turn the LED on and off?

Turns on with both digitalWrite and analogWrite; analogWrite works for me to control the speed, however I was trying to replicate the technique presented here:https://www.arduino.cc/en/Tutorial/SecretsOfArduinoPWM
Unfortunately does not seem to work but if it does, I don't know how to turn the output On because it's not On.

I'm not certain of your issue, but your code works correctly for me. An LED on pin 3 is lit up, and I can vary the intensity of the output with OCR2B

OP posted only snippets, so it's probably such a typical case of "the problem is in the part you didn't post".

I copied your code into setup() and put this in loop()
result == blinky light

void loop() {
  pinMode(3, OUTPUT); // turn on 
  delay(1000);
  pinMode(3, INPUT); // turn off
  delay(1000);
}

Thank you everybody. I must admit I did not figure it out that pinMode(x, INPUT) will turn the signal off.
Learning something new every day...

I don't know how to turn the output On because it's not On.

I must admit I did not figure it out that pinMode(x, INPUT) will turn the signal off.

I thought the issue was that there was no output on pin 3 with pinMode(3,OUTPUT).