Using PWM Output Pins

To set the PWM period on any pin which can be used for PWM use the following:

  analogWrite(3, 127);      //PinId, PWM period from 0 to 255

There is no need to set the pin as an output as it will be automatically set as one. The PWM frequency is fixed at approximately 490 Hz.

Boards With > 8 Bit PWM Resolution

Most boards are 8bit. Some can use higher resolutions on some of the pins by using special commands. A few Arduinos support analogWriteResolution() function to set the resolution in use.

https://www.arduino.cc/reference/en/language/functions/zero-due-mkr-family/analogwriteresolution/