Hi everyone, this is yet another 25kHz PWM question. I would like to use 3 PWM pins at 25kHz (other PWM pins are empty), I have read that it is doable with UNO by modifying the timer(s). However, since Nano 33 BLE Sense has a different microcontroller, I am not sure how to tweak the timer(or is it even possible).
tl;dr How can I change the PWM requency of Nano 33 BLE Sense?
Please note: You cannot have more than 4 PWM pins at the same time, because the PWM module has four channels only. If you create more than 4, mbedOS will crash (shown by strange blink pattern of the LED, kind of SOS, not quite). You can however free a PWM channel and then assign the channel to another pin.
reefwing:
Do you know where it is documented that you can only use 4 pins for PWM using Mbed OS for the Nano 33 BLE?
The PWM module of the Arduino Nano 33 BLE only has 4 channels (see datasheet). The PWM signal is created by hardware and not software. I think some older Arduino use software PWM and therefore can create PWM signals on more pins. But this has its own limitation (CPU load, jitter, lower max frequency). You can do this as well, but you would need to write your own software. For slow frequencies and resolution software PWM is fine e.g. to control LEDs.
reefwing:
How do you free a PWM channel? I can't find a destructor for PwmOut.
Here are two examples. They create a PWM signal on a different pin every second.
Note: The delay() function has only been used to limit the example to the necessary. In real application, delay should be avoided. The same is true for the while(1) in loop.