Is the PWM value independent foreach pin?

On the docs it was pointed that only the timer was shared, but when I declare the value of 2 different pins the same value is being written on the 2 pins:
(Value of 15 on 15&3 and value of 14 on 14&2)

analogWrite( 2, 0, 1000);
analogWrite( 3, 0, 1000);

analogWrite(14, 0, 1000);
analogWrite(15, 15, 1000);

If I erase the 2 first lines declaring the outputs, then the output is correct (it doesn't write the value in two pins)

And if i swap the lines it writes the last value of the pair (The alue of 3 on 15&3 and the value of 2 of 14&2).

Are the documents wrong and they share timer and VALUE ?

The syntax with using anonymous pin numbers instead of the dedicated pin labels (a better practice adivice for Particle devices) does not lend itself to the notion that this forum is focused on Particle devices.
You also don’t state which device you are asking this for, so we can’t provide a definitive answer to your question.

1 Like

I am using photon (firmware version 1.4.2)

In my program I was using my own labels, and I thought this way would be more understandable

const int Onda_pv = A4; // PWM same timer Group D2/D3/A4/A5/
const int Onda_pr = A5; // PWM same timer Group D2/D3/A4/A5/

const int Onda_mv = D3; // PWM same  timer Group D2/D3/A4/A5/.
const int Onda_mr = D2; // PWM same timer Group D2/D3/A4/A5/.`
    analogWrite( Onda_mv, 0, 1000);/
    analogWrite( Onda_mr, 2, 1000);
    
    analogWrite( Onda_pv , 50, 1000);
    analogWrite( Onda_pr, 15, 1000);

Could you post more of your code? Are you ensuring the pins are initialized as OUTPUTs with pinMode before writing to them?

Also, what are you driving with the PWM pins / how are you testing the output?

Yes. I initialize them all as OUTPUTs at the begining of the code.

The PWM drive LEDS but furthermore of the visual test (they change both LEDs bright together) I have also check the output with the oscilloscope. And I can see that the outputs are linked.

#include <clickButton.h>
void orange(void );

int x=0;
void setup() {
    pinMode(Onda_pv, OUTPUT);
    pinMode(Onda_pr, OUTPUT);    
    pinMode(Onda_mv, OUTPUT);
    pinMode(Onda_mr, OUTPUT);  
    pinMode(Onda_gr, OUTPUT);

    orange();

    while (x<4){
        button.Update();
        if (button.clicks != 0){
            x+=1;
            switch (arranque)
            {
                case 1:
                    green();
                    Log.info("v");
                    break;
                case 2:
                    orange();
                    Log.info("a");
                    break;
                case 3:
                    red();
                    Log.info("r");
                    break;
                case 4:
                    off();

                    Suma_ps = 0; 
                    adcDMA.start(SAMPLE_RATE);
                    SM_time=millis();
                    break;
            }
        }
    }
}

void orange(void ){
    analogWrite(Onda_mv, 0, 1000);
    analogWrite(Onda_mr, 2, 1000);
    
    analogWrite( Onda_pv , 50, 1000);
    analogWrite( Onda_pr , 15, 1000);
}

Since the timer is responsible for the PWM pulse-pause ratio the value is directly tied to the timer - virtually the same thing in this respect.
So no, the docs are not wrong and even states the fact explicitly

2 Likes