# Is the PWM value independent foreach pin?

**URL:** <https://community.particle.io/t/is-the-pwm-value-independent-foreach-pin/53435>\
**Category:** Hardware\
**Created:** [November 22, 2019, 11:59am UTC](https://community.particle.io/t/is-the-pwm-value-independent-foreach-pin/53435 "2019-11-22T11:59:53Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Rikardov](https://avatars.discourse-cdn.com/v4/letter/r/90ced4/32.png) [@Rikardov](https://community.particle.io/u/Rikardov)\
**Post date:** [November 22, 2019, 11:59am UTC](https://community.particle.io/t/is-the-pwm-value-independent-foreach-pin/53435/1 "2019-11-22T11:59:53Z")

</div>

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 ?

---

<div class="post-metadata">

**Author:** ![ScruffR](https://sea2.discourse-cdn.com/flex026/user_avatar/community.particle.io/scruffr/32/6952_2.png) [@ScruffR](https://community.particle.io/u/ScruffR)\
**Post date:** [November 22, 2019, 12:44pm UTC](https://community.particle.io/t/is-the-pwm-value-independent-foreach-pin/53435/2 "2019-11-22T12:44:30Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Rikardov](https://avatars.discourse-cdn.com/v4/letter/r/90ced4/32.png) [@Rikardov](https://community.particle.io/u/Rikardov)\
**Post date:** [November 22, 2019, 12:49pm UTC](https://community.particle.io/t/is-the-pwm-value-independent-foreach-pin/53435/3 "2019-11-22T12:49:47Z")

</div>

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

```auto
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/.`

```

```auto
    analogWrite( Onda_mv, 0, 1000);/
    analogWrite( Onda_mr, 2, 1000);
    
    analogWrite( Onda_pv , 50, 1000);
    analogWrite( Onda_pr, 15, 1000);

```

---

<div class="post-metadata">

**Author:** ![nrobinson2000](https://sea2.discourse-cdn.com/flex026/user_avatar/community.particle.io/nrobinson2000/32/15624_2.png) [@nrobinson2000](https://community.particle.io/u/nrobinson2000)\
**Post date:** [November 22, 2019, 2:56pm UTC](https://community.particle.io/t/is-the-pwm-value-independent-foreach-pin/53435/4 "2019-11-22T14:56:47Z")

</div>

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

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

---

<div class="post-metadata">

**Author:** ![Rikardov](https://avatars.discourse-cdn.com/v4/letter/r/90ced4/32.png) [@Rikardov](https://community.particle.io/u/Rikardov)\
**Post date:** [November 22, 2019, 4:44pm UTC](https://community.particle.io/t/is-the-pwm-value-independent-foreach-pin/53435/5 "2019-11-22T16:44:49Z")

</div>

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.

```auto
#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);
}

```

---

<div class="post-metadata">

**Author:** ![ScruffR](https://sea2.discourse-cdn.com/flex026/user_avatar/community.particle.io/scruffr/32/6952_2.png) [@ScruffR](https://community.particle.io/u/ScruffR)\
**Post date:** [November 22, 2019, 11:01pm UTC](https://community.particle.io/t/is-the-pwm-value-independent-foreach-pin/53435/6 "2019-11-22T23:01:55Z")

</div>

> [@Rikardov](#):
>
> Are the documents wrong and they share timer and VALUE ?

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

> [@](#):
>
> A5 and D2 cannot be used as independently controlled PWM outputs at the same time.
