Is there any way to adjust the PWM frequency on the XIAO NRF52840, I am trying get the frequency up to 20KHZ so that my motor driver doesn’t make any audible noise.
I found this in the library folder
AppData\Local\Arduino15\packages\Seeeduino\hardware\mbed\2.9.1\cores\arduino\wiring_analog.cpp
I figured it out somewhat
C:\Users\Matt\AppData\Local\Arduino15\packages\Seeeduino\hardware\mbed\2.9.1\cores\arduino\mbed\drivers\include\drivers\PwmOut.h
/** Set the PWM period, specified in seconds (float), keeping the duty cycle the same.
*
* @param seconds Change the period of a PWM signal in seconds (float) without modifying the duty cycle
* @note
* The resolution is currently in microseconds; periods smaller than this
* will be set to zero.
*/
void period(float seconds);
/** Set the PWM period, specified in milliseconds (int), keeping the duty cycle the same.
* @param ms Change the period of a PWM signal in milliseconds without modifying the duty cycle
*/
void period_ms(int ms);
/** Set the PWM period, specified in microseconds (int), keeping the duty cycle the same.
* @param us Change the period of a PWM signal in microseconds without modifying the duty cycle
*/
void period_us(int us);
/** Read the PWM period
* @returns
* The PWM period, specified in microseconds (int)
*/
So in the wiring_analog.cpp from above I changed the period from period_ms(2) to period_us(50). No more motor noise from my motor driver. I have not verified the actual frequency with a scope, but It’s out of my hearing range now.