Solved: Newbie trying to get PWM frequency to work

I can’t figure out why this doesn’t work on my Arduino UNO. It’s probably some stupid mistake, but I’ve haven’t figured it out. Pin 9 goes high and there is no PWM frequency out at pin 11. I would appreciate any help I can get. Thanks.


#include <PWM.h>

int32_t frequency = 1000;

void setup() {

InitTimersSafe ();

bool success = SetPinFrequencySafe (11, frequency);

if(success) {

pinMode(8, OUTPUT);
digitalWrite(8, HIGH);}

else {

pinMode(9, OUTPUT);
digitalWrite(9, HIGH);

void loop() {


bool SetPinFrequencySafe(int8_t pin, uint32_t frequency)
	uint8_t timer = digitalPinToTimer(pin);
	if(timer == TIMER1A || timer == TIMER1B)
		return Timer1_SetFrequency(frequency);
	else if(timer == TIMER2B)
		return Timer2_SetFrequency(frequency);
		return false;

Pin 11 is Output A on Timer 2 and is not one of the pins available with SetPinFrequencySafe(). I would think that the OCR2A value is reserved for a PWM top value when setting up the timer at custom frequencies and is not available for output on pin A.

You should be able to use SetPinFrequencySafe with pin D3 Output B.

Thanks. About 15 minutes ago I got it working using a different pin. It's just my luck that I would get everything right except something like this. It works well with many other pins. Thanks again.

Please edit your original post to include [SOLVED] in the subject line so I (and others) don't keep coming back to check on your progress. Thanks.