analog changing duty ratio and frequency in PWM mode

I have a problem in designing a PWM programme that required me to analog changing the duty ratio and frequency.

I want to set the frequency to become <1.5 kHz, 1.5 kHz, 2kHz and 3kHz

and duty ratio of 0, 20%, 40%, 50%, 60%, 80% and 100%.

right now i have done the pwm coding of:

int sensorPin = A0; // select the input pin for the potentiometer
int sensorValue = 0; // variable to store the value coming from the sensor

void setup() {

}
void loop() {
// read the value from the sensor:
val01=sensorValue/4
analogWrite(val01); //490Hz
delay(10);

but that is when the frequency is stated.

my question is;

1. how can I set the frequency using anolog 4 analog button?
2. what should I put in the previous coding for that desired frequency?

hopefully you can help me =(

faisalirshad: 1) how can I set the frequency using anolog 4 analog button?

I don't know what this means. If you want to select between four possible values, one option is to use a rotary switch to select between different resistance paths through a voltage divider so the Arduino analogue input see four different voltages. Another is to provide four momentary switches each connected to an input; when a switch is pressed, change to the corresponding frequency. In that case it would be helpful to show the current frequency, for example by associating an LED with each switch.

[u]Another is to provide four momentary switches each connected to an input; when a switch is pressed, change to the corresponding frequency. In that case it would be helpful to show the current frequency, for example by associating an LED with each switch.[/u] [/quote]

this is exactly what i want! so, how to programme it in such a way?? I mean, coding for that? right now I confuse how to put coding of that inside the previous coding.

I mean, coding for that?

Your exact code depends on the hardware you have. Basically you do an analogue read of the pin and use the map function to reduce it to a value between 0 and 3. Then you use a switch statement on this value to set the appropriator registers on the PWM counting chain. For changing the frequency then see:- http://www.arduino.cc/playground/Code/PwmFrequency and http://arduino.cc/en/Tutorial/SecretsOfArduinoPWM