Independent 25KHz PWM duty Cycle on Timer1

Hi everyone

I’m new in the topic on modifying timers and it would be great if someone had some tipps on the following:

I want to operate two pumps which both need a PWM signal at 25KHz. So far I tried to use Timer1 (since it was used in the code snippet I found first :wink:
I can operate Pin 9 (OC1A) perfectly well, however Pin 10 (OC1B) I can’t get to work.

I’m working with the following code:

const byte OC1A_PIN = 9;
const byte OC1B_PIN = 10;

const word PWM_FREQ_HZ = 25000; //Adjust this value to adjust the frequency
const word TCNT1_TOP = 16000000 / (2 * PWM_FREQ_HZ);

int dutyCycle = 0;

void setup() {

  pinMode(OC1A_PIN, OUTPUT);
  pinMode(OC1B_PIN, OUTPUT);

  // Clear Timer1 control and count registers
  TCCR1A = 0;
  TCCR1B = 0;
  TCNT1  = 0;

  // Set Timer1 configuration
  // COM1A(1:0) = 0b10   (Output A clear rising/set falling)
  // COM1B(1:0) = 0b00   (Output B normal operation)
  // WGM(13:10) = 0b1010 (Phase correct PWM)
  // ICNC1      = 0b0    (Input capture noise canceler disabled)
  // ICES1      = 0b0    (Input capture edge select disabled)
  // CS(12:10)  = 0b001  (Input clock select = clock/1)

  TCCR1A |= (1 << COM1A1) | (1 << WGM11);
  TCCR1B |= (1 << WGM13) | (1 << CS10);
  ICR1 = TCNT1_TOP;
 
  OCR1A = (word) (20 * TCNT1_TOP) / 100;
  OCR1B = (word) (80 * TCNT1_TOP) / 100;
}

With this code, the duty cycle of Pin 9 is at 20, as expected, while Pin 10 remains at 0 duty cycle. As I said, I’m new to timers and there might be obvious mistakes or even a deep misunderstanding on the whole concept within my code.
Can anyone help me?

Thank you in advance.

// COM1A(1:0) = 0b10   (Output A clear rising/set falling)
  // COM1B(1:0) = 0b00   (Output B normal operation)

You need to set for output B similar to what you do for output A

//TCCR1A |= (1 << COM1A1) | (1 << WGM11);

TCCR1A |= (1 << COM1A1) |(1 << COM1B1)| (1 << WGM11);

That makes sense, I'll try it as soon as possible. Thank you very much so far.

It worked perfectly, thank you very much.