I figured it must be doable from the Sparkulator, so I set off tonight to try and make it possible to change the PWM frequency to whatever you want. Default in the Spark Core is 500Hz and I tested this up to 64000Hz on all 8 PWM outputs. It works flawlessly and I’m sure it can go higher. You’ll notice in the comments I also have fixed the PWM glitch by keying off of the fact that if the pin_mode is set to AF_OUTPUT_PUSHPULL it is already setup as a PWM. If this mode is only used for PWM, we’re good… if not, some other state variable will have to be used. When the PWM is already set up, we just update the duty cycle on successive calls to analowWrite2(). PWM also achieves true 100% because there is no glitch now.
Because it’s so easy to change the frequency, maybe we can gain access to this in an easier way?