Which pins are PWM capable via analogWrite()?

Guys,

I'm new to Arduino and I am trying to control two DC motors with a L298 motor driver.
I want to use two PWMs to control the speed of the motors.
I was expecting any of pin 3/5/6/9/10/11 can provide that function as in this tutorial.

However, I found only pin 11 is capable of doing that on my Arduino Pro Mini (5V@16MHz with a ATmega328P).
Did I get it wrong about "Digital I/O Pins 14 (of which 6 provide PWM output)" or I miss anything?

The test code is listed below.
Any comments will be appreciated.


int motor0P = 2;
int motor0N = 4;
int speed0 = 3; /* 5/6/9/10/11 */

int motor1P = 7;
int motor1N = 8;
int speed1= 11;

void setup()
{
pinMode(motor0P, OUTPUT);
pinMode(motor0N, OUTPUT);
pinMode(motor1P, OUTPUT);
pinMode(motor1N, OUTPUT);
pinMode(speed0, OUTPUT);
pinMode(speed1, OUTPUT);

Serial.begin(115200);
while (!Serial);
}

void motor0Go(int move)
{
switch (move) {
case 0:
digitalWrite(motor0P, HIGH);
digitalWrite(motor0N, LOW);
break;
case 1:
digitalWrite(motor0P, LOW);
digitalWrite(motor0N, HIGH);
break;
default:
digitalWrite(motor0P, HIGH);
digitalWrite(motor0N, HIGH);
break;
}
}

void motor1Go(int move)
{
switch (move) {
case 0:
digitalWrite(motor1P, HIGH);
digitalWrite(motor1N, LOW);
break;
case 1:
digitalWrite(motor1P, LOW);
digitalWrite(motor1N, HIGH);
break;
default:
digitalWrite(motor1P, HIGH);
digitalWrite(motor1N, HIGH);
break;
}
}

void setSpeed(int i, int power)
{
if (i = 0) {
analogWrite(speed0, power);
}
else {
analogWrite(speed1, power);
}
}

void loop()
{
Serial.println("2 seconds to go.");
delay(1000 * 2);

/* stop at start */
motor0Go(3);
motor1Go(3);

/* power on */
setSpeed(0, 255);
setSpeed(1, 255);
delay(1000);

/* go forward */
motor0Go(0);
motor1Go(0);
delay(1000 * 2);

/* stop for a second */
motor0Go(3);
motor1Go(3);
delay(1000 * 2);

/* go backward */
motor0Go(1);
motor1Go(1);
delay(1000 * 2);
}

Both your pro-mini and a Uno board use a 328P chip so same number of pins with PWM capability. However you may be not getting the 'arduino pin name' Vs pro-min physical pin number correct?

3,5,6,9,10,11 are all hardware PWM driven, and are marked on the Uno with a ~ or something.
Others can be driven with software PWM.

Part of your problem is this:

void setSpeed(int i, int power)
{
  if (i = 0) {     <<< this needs == for comparison

Oh, no! That's a terrible mistake.
With that fixed, it works.
Thank you, sir.

CrossRoads:
3,5,6,9,10,11 are all hardware PWM driven, and are marked on the Uno with a ~ or something.
Others can be driven with software PWM.

Part of your problem is this:

void setSpeed(int i, int power)

{
 if (i = 0) {     <<< this needs == for comparison