XIAO - Output pins linked?

I have a very simple program: drive PWM outputs to LEDs on 8 channels. The problem is - output 4 appears to override output 1.

During testing, I drive pin 1 to 255, but then the pin output is limited by pin 4 output. So, pin 1 can never be ‘higher’ than pin 4. Here is my code:

void setup() {
  // put your setup code here, to run once:
  //Starting serial monitor communications
  Serial.begin(9600);
  delay(2000);
}

void loop() {
  // put your main code here, to run repeatedly:
Serial.println("Driving Outputs at:  " + String(millis()));
analogWrite(1,255);
analogWrite(4,10);
delay(2000);
}

When this runs, pin 1 will only be at PWM output level 10 (whatever is assigned to pin 4).

P.S. - I determined output was limited by looking at the brightness of LEDs attached to each pin. It might be beyond me to hook up an oscilloscope to see the actual switching…

I believe this is also occurring on another set of outputs also, but haven’t completely validated that yet.

Any ideas?

Thanks in advance… DJG
New user to both Arduino and XIAO…

Did you forget to assign the 1st and 4th pin pinMode on the setup?

It should.

 void setup() {
  pinMode(1, OUTPUT);
  pinMode(4, OUTPUT);
  Serial.begin(9600);
  delay(2000);
}

void loop() {

  Serial.println("Driving Outputs at: " + String(millis()));
  analogWrite(1, 255);
  analogWrite(4, 10);
  delay(2000);
}

Thank you for responding.

At one point I had those pinMode statements, with no change in how it worked. I also read on the Seeed site that you did not need to issue pinMode commands to XIAO. Maybe I read that wrong.

Here is a little more detail on what I did this morning, and the results:

I removed every wire and rebuilt the circuit from scratch to make sure there were no wiring issues. It is now simply the micro and two LED’s (I had dropping resistors, also made no difference. Took them out for testing).

I tested it with and without pinMode statements - they made no difference.I made the code a little more complex to see the actual interactions. Both my expected results and the actual results are in the comments of the code below.

Thanks again for looking. I have no idea what could be happening… I have not tested further, but I think the same thing maybe happening to outputs 3 & 8.
DJG

void setup() {
  // put your setup code here, to run once:
  pinMode(1,OUTPUT);
  pinMode(4,OUTPUT);
 //Starting serial monitor communications 
  Serial.begin(9600);
  delay(2000);
}

void loop() {
  // put your main code here, to run repeatedly:
  Serial.println("Restarting cycle at:  " + String(millis()));
  
    //Step 1 - Expected = both LEDs should turn off.
    analogWrite(1,0);
    analogWrite(4,0);
    Serial.println("Step 1 - Expected = both LEDs should turn off.");
    delay(5000);
    //Step 1 - Actual = OK. both led's turn off.  
    
    //Step 2 - Expected = Only LED1 should turn on, full brightness.
    analogWrite(1,255);
    Serial.println("Step 2 - Expected = Only LED1 should turn on, full brightness.");
    delay(5000);
    //Step 2 - Actual = FAIL. both led's turn on at full brightness. 
    
    //Step 3 - Expected = LED4 should now come on at a low brightness.  LED1 should not change.
    analogWrite(4,20);
    Serial.println("Step 3 - Expected = LED4 should now come on at a low brightness.  LED1 should not change.");
    delay(5000);
    //Step 3 - Actual = FAIL.  Both led's dim down.
      
    //Step 4 - Expected = LED4 should increase to full brightness.  LED1 should not change.
    analogWrite(4,255);
    Serial.println("Step 4 - Expected = LED4 should increase to full brightness.  LED1 should not change.");
    delay(5000);
    //Step 4 - Actual = FAIL.  Both led's increase to full brightness.
    
    //Step 5 - Expected = LED1 should turn off.  LED4 should remain on.
    analogWrite(1,0);
    Serial.println("Step 5 - Expected = LED1 should turn off.  LED4 should remain on.");
    delay(5000);
    //Step 5 - Actual = FAIL.  Both led's turn off.
}

Even more data, and the stranger it gets…

I rewired all 11 outputs to LEDs. Defined all as OUTPUT. I use a chaser program (very simple) to step through the outputs, one at a time, every second.

If I use digitalWrite statements to drive the outputs, it works great. Just as expected.

If I use analogWrite statements to drive the LEDs, then all heck breaks out. The FIRST time the program runs, outputs 1, 2, & 3 are fine, but when 4 turns on, it also turns on 1. Then, each time AFTER that first pass, whenever it turns on output 1 it also turns on output 4. Outputs 2 & 10 are linked. Outputs 3 & 8 are linked. Outputs 5 & 9 are linked. In fact, the only outputs that do not interact with others in analog mode appears to be outputs 0, 6 & 7.

Code I used below.

I look forward to a really simple answer that makes me look stupid… please.

Thanks,
DJG

My sample code:
    void setup() {
      // put your setup code here, to run once:
      pinMode(1,OUTPUT);
      pinMode(2,OUTPUT);
      pinMode(3,OUTPUT);
      pinMode(4,OUTPUT);
      pinMode(5,OUTPUT);
      pinMode(6,OUTPUT);
      pinMode(7,OUTPUT);
      pinMode(8,OUTPUT);
      pinMode(9,OUTPUT);
      pinMode(10,OUTPUT);
      pinMode(0,OUTPUT);
        
     //Starting serial monitor communications 
      Serial.begin(9600);
      delay(2000);
    }

    void loop() {
      // put your main code here, to run repeatedly:
      Serial.println("Restarting cycle at:  " + String(millis()));

    int Brightness = 255;
    int StepDelay = 1000;


    //This section drives the outputs using analog statements.
    // Comment it out to run the digital section below
    analogWrite(0,0);
    analogWrite(1,Brightness);
    delay(StepDelay);

    analogWrite(1,0);
    analogWrite(2,Brightness);
    delay(StepDelay);

    analogWrite(2,0);
    analogWrite(3,Brightness);
    delay(StepDelay);

    analogWrite(3,0);
    analogWrite(4,Brightness);
    delay(StepDelay);

    analogWrite(4,0);
    analogWrite(5,Brightness);
    delay(StepDelay);

    analogWrite(5,0);
    analogWrite(6,Brightness);
    delay(StepDelay);

    analogWrite(6,0);
    analogWrite(7,Brightness);
    delay(StepDelay);

    analogWrite(7,0);
    analogWrite(8,Brightness);
    delay(StepDelay);

    analogWrite(8,0);
    analogWrite(9,Brightness);
    delay(StepDelay);

    analogWrite(9,0);
    analogWrite(10,Brightness);
    delay(StepDelay);

    analogWrite(10,0);
    analogWrite(0,Brightness);
    delay(StepDelay);



    //This code drives the outs with digital statements.  Comment it out to use the analog section above.
    /*
    digitalWrite(0,false);
    digitalWrite(1,true);
    delay(StepDelay);

    digitalWrite(1,false);
    digitalWrite(2,true);
    delay(StepDelay);

    digitalWrite(2,false);
    digitalWrite(3,true);
    delay(StepDelay);

    digitalWrite(3,false);
    digitalWrite(4,true);
    delay(StepDelay);

    digitalWrite(4,false);
    digitalWrite(5,true);
    delay(StepDelay);

    digitalWrite(5,false);
    digitalWrite(6,true);
    delay(StepDelay);

    digitalWrite(6,false);
    digitalWrite(7,Brightness);
    delay(StepDelay);

    digitalWrite(7,false);
    digitalWrite(8,true);
    delay(StepDelay);

    digitalWrite(8,false);
    digitalWrite(9,true);
    delay(StepDelay);

    digitalWrite(9,false);
    digitalWrite(10,true);
    delay(StepDelay);

    digitalWrite(10,false);
    digitalWrite(0,true);
    delay(StepDelay);
    */
    }

Blockquote

Any updates? I won’t be able to use XIAO without this being resolved.

Thanks,
DJG

I tested and I facing the same issue, @ansonhe97 @Baozhu can you take a look!

Hi @salman @laddg

Let us test this also and get back to you

2 Likes

Hi @laddg
I tested it again and the result is the same. This is because the Pin 1 and PIN 4 use the same PWM clock. Our software engineer is doing research on whether can change the PWM channel.

1 Like

Hi @laddg
We have updated the Arduino core variant.cpp file, now only OUTPUT 4 & 10, 5&8 are linked.
You can replace the original with the updated one. Besides, the I2C port is not recommended for PWM use.
My variant.cpp located here.
C:\Users\LJC\AppData\Local\Arduino15\packages\Seeeduino\hardware\samd\1.7.9\variants\XIAO_m0
We will update the Arduino core later.

1 Like

Hi,

I have a similar issue on my XIAO when using analogWrite() for PWM.

When using analogWrite() to pin 3, the same output appears on pin 8.
When using analogWrite() to pin 5, the same output appears on pin 9.
Vice-versa.

And yet digitalWrite() works as expected with no pin ‘binding’.

#include <Arduino.h>

int speed = 500;

void setup() {
}

void loop() {

for (int i = 3; i <= 10; i++) {
analogWrite(i, 255);
delay(speed);
analogWrite(i, 0);
delay(10);
};
}

analogWrite() Example Video Clip

Is individual but simultaneous PWM control of 8x pins possible?

Can you confirm which pins are linked because the comment above confuses matters more…

now only OUTPUT 4 & 10, 5&8 are linked.

The same results appear when compiling/uploading in the Arduino IDE and PlatformIO for VScode.

Help appreciated please!

Thanks,
Alex

Can we use Arduino.h for xiao as Arduino.h is for AVR and xiao has samd21 chip?

For PlatformIO:

[env:seeed_xiao]
platform = atmelsam
board = seeed_xiao
framework = arduino

I am using arduino IDE , I think all pins are correctly taken care of in <variant.h>