PWM HELP Please

Hello all,
I have been looking all over this forum and the arduino website. I still cannot figure it out. I am a looking for a way to generate a PWM signal of about 20 to 30 kHz. Can anybody point me to where I might find a good explanation. Or perhaps help directly.

Thankyou in advance.

Have you come across this article in the Playground?
http://www.arduino.cc/playground/Main/TimerPWMCheatsheet

I hadn't run across that one yet. Problem is im not sure what to do with this info. ie how to code it.

Could you please advise.

0x01 1 31250 // this would be a good frequency for my purposes

TCCR1B = TCCR1B & 0b11111000 | ; // This is the code that was directly below the previous line.

I'm not sure how to interpret all of this.

Please help

Also how would go about which pins to run to the fet?

TCCR1B is the name of an internal register, a sort of variable that is already set up.

TCCR1B & 0b11111000 - is a bitwise operation between the value in the TCCR1B register and the binary value that follows it. Basically it sets all those bit in the TCCR1B to zero that have a zero in the binary number. In other words it sets the three least significant bits to zero.

| ; - the | is a bitwise or operation that adds in the bits in to the TCCR1B register. You replace with the number you want to use. It will be a number between 0 and 7.

Can you tell me if this will work?

void setup()
{
TCCR1B = 0x01;
TCCR1B = TCCR1B & 0b11111000 | 7;
OCR2B = 159; // I got this line from another forum, not sure what it means
pinMode(3, OUTPUT); // enable the PWM output (you now have a PWM signal on digital pin 3)
}

void loop()
{
OCR2B = 60; // set the PWM to 50% duty cycle

}

OCR2B = 60; // set the PWM to 50% duty cycle

That is not the way to set a PWM output, for 250% duty cycle on pin 3 use:-

analogWrite(3, 128);

the line TCCR1B = 0x01; - is wrong it is rendered useless by the line that follows, remove it.
As to the rest drop the OCR2B = 159; line and try it.

Here is the Modified code as you suggested, it compiles nicley. I will test it this evening when I get home,

Thank you Kind sir.

void setup()
{
TCCR1B = TCCR1B & 0b11111000 | 7;

pinMode(10, OUTPUT); // enable the PWM output (you now have a PWM signal on digital pin 10)
}

void loop()
{
analogWrite(10,128); // set the PWM to 50% duty cycle on pin 10

}

The code seems to work well for now. Although upon imperical testing, I noticed the frequency dropped off from what I orginally set it to. Perhaps Its my mutli meter. I will keep working on it.

Thank you for your assistance.

Perhaps Its my mutli meter.

You measure frequency with a multi meter?

You measure frequency with a multi meter?

Why not?