Unable to import PWM module in Nano 33 BLE Sense

I’m following the example code on the site below on a nano sense ble board.

from machine import Pin, PWM, ADC

pwm = PWM(Pin(15))
duty = 30000 #between 0-65000


while True:

This is the execution output.
Traceback (most recent call last):
   File "<stdin>", line 3, in <module>
ValueError: PWM period must be within 16000 cycles
MicroPython: v1.18-omv OpenMV: v4.3.0 HAL: v2.0.0 BOARD: Arduino Nano 33 BLE SENSE-NRF52840
Type "help()" for more information.

In the module import syntax, Pin and ADC are colored, but PWM is the default text color.
Even if I change the pwm duty value from 30000 to 16000, the result is the same.

Try this example:


Actually you know what that example wouldn’t work either, for some reason you need to provide the period to PWM, example:

PWM(Pin(15), period=x)

I’m also having some PWM issues. With PWM(Pin(pin), period = X). I don´t get any error, but the code won’t execute. Tried a very simple code just to try it, but the program stops/hangs and won’t continue. Has anyone succesfully coded PWM on Nano BLE 33?

So note that period here is actually used for the top_value of the NRF PWM driver, and freq is the base_clock. The final PWM output frequency is:

F(pwm) = base_clock / top_value

For example, try this and you should see an output:

PWM(Pin(n), freq=1_000_000, period=1000)