Timer1 PWM 25kHz

I've been trying to control timer1 on the Arduino UNO to output at 25kHz to control some fans with some interesting and unexpected results. Here is the code I am using:

int controlPin = 10;
void setup()
{
  Serial.begin(9600);
  TCCR1A = 0x23;
  TCCR1B = 0x02;  // select clock
  ICR1 = 639;  // aiming for 25kHz
  pinMode(controlPin, OUTPUT);  // enable the PWM output (you now have a PWM signal on digital pin 3)
  OCR1B = 320;  // set the PWM duty cycle
}

void loop()
{
  OCR1B = 160;
  Serial.println(OCR1B);
  delay(10000);
  OCR1B = 639;
  Serial.println(OCR1B);
  delay(10000);
}

This code is sort of working to control the PWM on pin 10 (goes from around 0.7 V to 3 V). The problem in OCR1B should correspond to pin 9. Pin 9 does not work for either OCR2B or OCR2A. Any thoughts or suggestions would be greatly appreciated! Thanks in advance!

OC1A corresponds to PB1, which is D9, and OC1B corresponds to PB2, which is D10.

OC2A and OC2B are not connected to Timer 1.

--
The Ruggeduino: compatible with Arduino UNO, 24V operation, all I/O's fused and protected

Typo, my bad. Yes, I am using OCR1A and OCR1B. I guess I could have been misinformed as to which one corresponds to which pin, but pin 9 will not work for either OCR1A or B. Any ideas as to why?

Because you have set TCCR1A to 0x23 you are not connecting OCR1A to the hardware output on pin 9. You have only connected OCR1B to the hardware output. You need to set the upper 2 bits of TCCR1A according to Section 16.11 of the ATmega328P datasheet.

You also have not used pinMode() to make pin 9 an output pin.

--
The QuadRAM shield: add 512 kilobytes of external RAM to your Arduino Mega/Mega2560

Thanks a lot! I looked at the datasheet, though, and that stuff is all pretty far over my head. I just want to be able to control the both pins 9 and 10 at the same time using ICR1 as top. Here is the code that I would like to use:

int controlPin1 = 9;
int controlPin2 = 10;

void setup()
{
  Serial.begin(9600);
  TCCR1A = 0x23;
  TCCR1B = 0x02;  // select clock
  ICR1 = 639;  // aiming for 25kHz
  pinMode(controlPin1, OUTPUT);  
  pinMode(controlPin2, OUTPUT);
  OCR1B = 320;  // set the PWM duty cycle
  OCR1A = 320;
}

void loop()
{
  OCR1B = 160;
  OCR1A = 160;
  Serial.println(OCR1B);
  delay(10000);
  OCR1B = 639;
  OCR1A = 639;
  Serial.println(OCR1B);
  delay(10000);
}

But it seems that I have the wrong value for TCCR1A. Do you know what that value should be?

If this stuff is over your head I'd suggest using the Timer1 library which wraps all this up in library functions:

http://arduino.cc/playground/Code/Timer1

--
The Rugged Motor Driver: two H-bridges, more power than an L298, fully protected