NRF52 mbed PWM limited frequency

Hi! I'm trying to get between 1-2 MHz hardware PWM output using the Xiao NRF52840 on mbed.
Using the NRF52_mbed_pwm library I can only get up to 500 kHz.
So I've tried to switch to non-mbed and used adafruit hwpwm.

void setup()
{  
  HwPWM0.addPin(3);

  // Enable PWM modules with 15-bit resolutions(max) but different clock div
  HwPWM0.begin();
  HwPWM0.setResolution(2);
  HwPWM0.setClockDiv(PWM_PRESCALER_PRESCALER_DIV_1); // freq = 16Mhz

  const int maxValue = bit(2) - 1;
  HwPWM0.writePin(3,maxValue/2);

}

By changing the prescaler division and PWM resolution I can even get 5.3 MHz, which is I believe the practical maximum I can get from this chip.

Anyone managed to create this on mbed? I've tried but couldn't find the parameters for changing the prescaler and resolution.

Thanks.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.