Arduino 100hz PWM output

I'm trying to get 100Hz PWM out of pin9 to drive a DC motor, and vary the duty cycle via a Pot. Here is the code i have so far. I'm VERY new to this.

Any Help would be appreciated

int sensorPin = A0; // select the input pin for the potentiometer int sensorValue = 0; // variable to store the value coming from the sensor int outputValue = 0; void setup(){ Serial.begin(19200); pinMode(9, OUTPUT); TCCR2B = TCCR2B & 0b11111000 | 0x06; } void loop(){ sensorValue = analogRead(sensorPin); outputValue = map(sensorValue, 0, 1023, 0, 255); analogWrite(9, outputValue); Serial.println(outputValue); }

Have you read this http://www.arduino.cc/playground/Main/TimerPWMCheatsheet & this? http://www.arcfn.com/2009/07/secrets-of-arduino-pwm.html

Posting code that won't compile wastes everybody's time.

PaulS: Posting code that won't compile wastes everybody's time.

really?

it would have been much easier for you to say, "Hey man, you are missing a } at the end of your setup statement"

it would have been much easier for you to

post code that compiles.

PaulS:

it would have been much easier for you to

post code that compiles.

I fixed it, if you don't have anything to say about the question i am asking, Please GTFO.

im just looking for confirmation that this line:

TCCR2B = TCCR2B & 0b11111000 | 0x06;

will give me about 125Hz on pin 9

I think you need 0x04 vs 0x06 per here

http://www.arduino.cc/playground/Main/TimerPWMCheatsheet

Pins 9 and 10: controlled by timer 1 Setting Divisor Frequency 0x01 1 31250 0x02 8 3906.25 0x03 64 488.28125 0x04 256 122.0703125 0x05 1024 30.517578125

to yield 122 Hz.

CrossRoads: I think you need 0x04 vs 0x06 per here

http://www.arduino.cc/playground/Main/TimerPWMCheatsheet

Pins 9 and 10: controlled by timer 1 Setting Divisor Frequency 0x01 1 31250 0x02 8 3906.25 0x03 64 488.28125 0x04 256 122.0703125 0x05 1024 30.517578125

to yield 122 Hz.

awesome, thanks. I'll give that a try.

i'm trying to switch a 12V load, and when i hook up 12V to the fet, it powers up the arduino. I fear i may need a diode or something on the emitter pin of the fet. Any ideas?

Sounds like you have the FET wired wrong.
Should look like this as example (from a prior discussion - right hand regulator was meant to be 7805), with a Logic Level FET.