analogWriteResolution and the SAMD21

The Arduino documentation states that the maximum resolution of the PWM analogWrite (not the DAC analogWrite) is 12 bits. However the SAMD21 has 16-bit timer/counters and the actual resolution is 16 bits. So you can call analogWriteResolution(16) successfully.

Because of the high resolution, the PWM frequency is a fairly low 732Hz, being 48MHz/65536. If the high resolution is not necessary, it is possible by configuring the timer/counter directly to have a much faster frequency by reducing the period (which also reduces the resolution).

The analogWrite function has a “gotcha” in the way it does scaling. Considering the default 8-bit resolution, the PWM duty cycle for a setting of n is 100n/256 %. This means that 100% high is not obtainable with the maximum n=255. Setting a value n=256 actually gives a duty cycle of 0%. The PWM generation is always single-slope and some channels are not double buffered, which can cause glitching. Which channels are “good” is dependent on the board model — look for channels that use the TCC (timer/counters for control).