Unable to use IRremote library and generate PWM signal at same time.

Hi,

I am unable to generate 25Khz PWM signal using timer 1 or timer 0 while using the IRemote library which by default uses timer 2.

This is the code I have written, any help will be appreciated. :-[

#include <IRremote.h>
int RECV_PIN =11;
IRrecv irrecv(RECV_PIN);
decode_results results;
int led =6;
int fan1 = 9; 
int fan2=10;
int pot1;
int pot2;
int fan1_value=1;
int fan2_value=1;

void setup()
{  
    TCCR1A = 0;
    TCCR1B = 0;
    TCNT1  = 0;
    TCCR1A = _BV(COM1A1)  | _BV(COM1B1)  | _BV(WGM11);  
    TCCR1B = _BV(WGM13)   | _BV(CS10);  
    ICR1   = 160;
    
    pinMode(fan1, OUTPUT);
    pinMode(led, OUTPUT);
    pinMode(fan2, OUTPUT);
    irrecv.enableIRIn();    
}

void loop() {
  
  if (fan1_value==1)
  {
  pot1=0;
  }
  else if(fan1_value==0)
  {
    pot1 = analogRead(A0);
  }
   else if (fan2_value==1)
  {
  pot2=0;
  }
  else if(fan2_value==0)
  {
    pot2 = analogRead(A2);
  }
  
 int fan1_speed = pot1 * (160 / 1023.0);
 int fan2_speed = pot2 * (160 / 1023.0);
 
  analogWrite(fan1,fan1_speed);
  analogWrite(fan1,fan2_speed);
 
  if (irrecv.decode(&results)) {
    if (results.value == 0x80C)
    {
      fan1_value=0;
      fan2_value=0;  
      digitalWrite(led, HIGH); 
    }
    else if (results.value == 0xC)
    {
      digitalWrite(led, LOW); 
      fan1_value=1; 
      fan2_value=1; 
    }
     irrecv.resume(); 
    
  }
}

If you look at the IRremote documentation it says you can't use PWM on pins 9 and 10 while using IRremote. Pick two other PWM pins.

Result is same when i try to generate PWM using timer 0 on pin 5.

supernova432:
Result is same when i try to generate PWM using timer 0 on pin 5.

It's possible that the IRremote library uses the millis() timer and mucking with Timer0 is disrupting that. I'm guessing that you muck with the timer registers to get some special PWM frequency that the fans require. Perhaps Timer2 on Pin 3 or Pin 11 would work? I don't know.