Problems with timer

Hey guys,

I have the problem that I have to detect the speed signal of a fan (with the functions pulseIn and pulseOut) and I also want to generate a PWM signal. For this I need 2 different timers because otherwise they will interfere each other. How can I change this or how can I find out which timer is conected to which pin or to which function.

Thanks for your help!

Just use pulseIn/pulseOut and use PWM, you don't need to worry about hardware timers...

But it doesn´t work. It only works if I have the speed detection or the PWM Output. Maybe my code is wrong:

void setup() {

Serial.begin(9600);

pinMode(10, OUTPUT); pinMode(3, INPUT); }

int Htime; //integer for storing high time int Ltime; //integer for storing low time float restime; // Htime+Ltime float frequency;

void loop() {

Htime=pulseIn(3,HIGH); //read high time Ltime=pulseIn(3,LOW); //read low time

restime = Htime + Ltime; frequency = 1000000/restime; // frequency fan

analogWrite(10, 150); // PWM Output

Serial.println(frequency); }

But it doesn´t work. It only works if I have the speed detection or the PWM Output.
Maybe my code is wrong:

Your code runs as intended when I test it. I jumper pin 3 to pin 10, and see a constant print out of a frequency close to the default frequency(490Hz) of Timer1 which controls PWM on pin 10.

Please learn how to post code using the code tags </> so that is appears like this

void setup() {

  Serial.begin(9600);

  pinMode(10, OUTPUT);
  pinMode(3, INPUT);
}


int Htime;               //integer for storing high time
int Ltime;               //integer for storing low time
float restime;           // Htime+Ltime
float frequency;

void loop() {


  Htime = pulseIn(3, HIGH);   //read high time
  Ltime = pulseIn(3, LOW);    //read low time

  restime = Htime + Ltime;
  frequency = 1000000 / restime;   // frequency fan


  analogWrite(10, 150);    // PWM Output


  Serial.println(frequency);

}

But it doesn´t work. It only works if I have the speed detection or the PWM Output.

Please elaborate on this statement... What do you define as "works" and what do you define as "doesn't work" because simply saying it doesn't work tells me nothing as to what is wrong with it.