How to change Arduino nano 33 ble sense pwm frequency?

The analogWrite frequency of nano 33 ble sense is 500HZ.However,I need 330HZ.
How can I change the pwm frequency?
I have noticed that by using <Servo.h>,we can change servos’ pos from 0 to 180.That means <Servo.h> can change pwm frequency less than 500Hz.
Thanks!

Hi @jaxdgskvemvemx. You can do this using the Mbed OS API:

https://os.mbed.com/docs/mbed-os/v6.15/apis/pwmout.html

The core library for the Arduino Nano 33 BLE Sense is built on Mbed OS, so you have all its API available for use in your sketches.

Thanks for your reply!I will read it carefully!Thanks!

You are welcome. Please let us know if you run into any problems.

I usually am satisfied with the standard Arduino API, but I did play around with PwmOut a couple of years ago. This is a sketch I wrote at that time using Mbed OS to set the PWM frequency to 500 kHz and duty cycle to 50%.

const byte PWMPin = 5; // Arduino pin number
const unsigned int PWMPeriod = 2; // us (minimum value is 2)
const float PWMDutyCycle = 0.5; // ratio

void setup() {
  // set up the pwm object for PWMPin
  mbed::PwmOut* pwm = new mbed::PwmOut(digitalPinToPinName(PWMPin));
  digitalPinToPwmObj(PWMPin) = pwm;

  // set the PWM period to PWMPeriod
  pwm->period_us(PWMPeriod);

  // start the PWM signal with the duty cycle set to PWMDutyCycle
  pwm->write(PWMDutyCycle);
}

void loop() {}