Single Frequency, variable duty cycle PWM

hi, i am working on a project in which frequency is constant and i have to vary duty cycle using arduino's serial monitor, i wrote this code which works perfect for an led but when i connect oscilloscope it doesnot show the correct frequency and duty cycle which i have input through serial monitor. here is my code, please help me

#include <PWM.h>
int led = 9;
int x=0;
void duty();

void setup()
{
pinMode(9, OUTPUT);
Serial.begin(9600); // Sets up communication with the serial monitor
duty();
}

void duty()
{
SetPinFrequency(led, 500);

}
void loop()
{
if (Serial.available()>0) // Checks for a character in the serial monitor
{
int x = Serial.parseInt();
Serial.println(x);
pwmWrite(led,x);
}
}

PWM.h is not a built-in library so you should say where you got it from.

If SetPinFrequency() is not working you should investigate the third-party PWM library that contains it.

What frequency do you get on the 'scope?

Mark