PWM frequency settings for XIAO MG24 (sense)

My project on XIAO MG24 sense includes steering Motors via PWM, coding in the arduino IDE.

The PWM-frequency effects the loudness and torque of the motors, but I can not find out, what settings are used on the MG24 and how I could change them.

There seems to be a difference compared to the ESP32-C3, motors have less torque.

Can you help, where to find this?

Silicon Labs provides an SDK with direct timer and PWM configuration APIs. If you switch your development from Arduino to using the EMLIB/SILABS SDK (or Zephyr), you can:


CMU_ClockEnable(cmuClock_TIMER0, true);
TIMER_TopSet(TIMER0, topValue);      // set PWM frequency
TIMER_CompareSet(TIMER0, chan, duty); // set duty cycle
...

This same approach applies to EFR32MG24 timers. But from Arduino you’d have to drop to register level or include parts of the SDK. Sun May Sky: How to generate PWM on EFR32

1 Like

Thank you, for the good hint on how to change settings.
I want to use the arduino IDE, to keep it simple for me, and firstly find out, what setting for PWM frequency is used in “default”, then how to change it (using register level).

How could I find out?

As far as I understand, the MG24 Board is installed in the Arduino IDE and therefor the PWM Information should be there. I don’t know where to look. How do I find the file with the code that defines the default setting for PWM in the Arduino IDE?

Open the MG24 board folder in VSCode or Notepad++

Search entire folder for:

analogWrite

Then also search for:

TIMER_

That will take you directly to the timer configuration.

1 Like

I’m on Mac and could not find the board folder.

I tried to work around that and look up github, from whre the boardmanager is loaded and found:

In line 56: “used for analogWrite” !

In line 122: static const int duty_cycle_mode_default_freq = 1000;

I suppose frequency is in Hz, so this would be 1 kHz as the default setting for PWM. I think this part is solved.

.. leaving the question how to change the frequency in Arduino IDE.