XIAO ESP32C2 ~5 ms pause/freeze every 2 seconds


i have a problem with the XIAO ESP32c3. In my setup, I use a AS5600 absolute angle sensor that is connected to the ESP32 via I2C. I use this sensor to measure the angle of a motor shaft. The motor is controlled with a DRV8833 motor driver an I use PWM to set the motor speed.

Now to the problem: The senor readings have jumps repeatable jumps. Between every two jumps there is exactly 2000 ms time passing.
To show this behavior, I used PuTTY to log the serial output. In the next figure you see the plot of the angle measurement with the jump in angle value:

(As a new user I’m only allowed to upload one picture per post, so i will continue in the next post)

But not only the angle measurement shows a jump, also if i plot millis() there is a jump every 2 seconds:

In this figure you can see that the millis() on the Y-axis jump about 5 ms between measurement point 2311 and measurement point 2312 whereas normally the difference is only 1 ms.

(As a new user I’m only allowed to upload one picture per post, so i will continue in the next post)

Here you see millis() again on the y-axis over the measuring points but more zoomed out. At every blue circle a jump is happening. By comparing the Y-values, it’s clear that there is always 2000 ms between to jumps:

First, I thought it was a problem with the used AS5600 library and I opened an issue on GitHub (Link). I recommend reading the issue to see the tests I did to solve the problem. But in short I tried:

  • Changing baud rate → no difference
  • Trying another AS5600 board → no difference
  • Using the Seeed AS5600 library → no difference
  • calling yield() in void loop() → no difference
  • calling delay(1) in void loop() → no difference
  • Setting i2c clock to 1000000 → no difference
  • Measuring at motor standstill → no difference

Then i tested the same code on an ESP8266 and the problem was not present anymore.
Is there a function that stops/blocks/pauses/interrupts/etc. the XIAO ESP32 every 2 seconds and how can I solve my problem?

Thank you for your help!

Here is the sketch is use:

#include <Wire.h>
#include "AS5600.h"

AS5600 as5600;


const int in1 = D1; // Steuer-Pins für den drv8833
const int in2 = D2;
const int frequency = 1000; // 5000 Hz
const int pwmChannel1 = 1;
const int pwmChannel2 = 2;
const int resolution = 8; // 8-bit resolution

int motorSpeed = 200;

int ang = 0;
int raw_ang = 0;
int old_ang = 0;
int revs = 0;
int abs_ang = 0;

int counter = 1;

int t_start = 0;
int t_end = 0;

int t = 0;

void setup() {
Serial.println("DRV Test");


ledcSetup(pwmChannel1, frequency, resolution);
ledcSetup(pwmChannel2, frequency, resolution);

ledcAttachPin(in1, pwmChannel1);
ledcAttachPin(in2, pwmChannel2);

as5600.setDirection(AS5600_CLOCK_WISE);  // default, just be explicit
int b = as5600.isConnected();
Serial.print("Connect: ");

ang = as5600.rawAngle();
ang = ang * AS5600_RAW_TO_DEGREES;
old_ang = ang;


void loop() {

  ledcWrite(pwmChannel1, motorSpeed);
  ledcWrite(pwmChannel2, 0);
  raw_ang = as5600.rawAngle();

  ang = raw_ang * AS5600_RAW_TO_DEGREES;

  if (old_ang > 340 && ang < 20)
   if (old_ang < 20 && ang > 340)

  abs_ang = revs * 360 + ang;
  if (counter == 3)
    t = millis();
    counter = 0;
  old_ang = ang;


Hi , Very interesting issue , I would like to know Have you tried changing the SPEED of the motor?
How do you use the Interrupt? Only the PWM function.
GL :slight_smile:

Some more tests i did in the meantime:

  • changing motor speed from 200 to 100
  • testing another program to log the serial data
  • disabling ledcSetup, ledcAttachPin and ledcWrite so that no PWM signal is created and the motor is at standstill
    Nothing changed, the problem is still there.

What do you mean by that? I only use the code posted in post 3

I just tried with another XIAO ESP32C2 board - still the same problem every 2000 milliseconds.