Read signal (5v wave) get it's frequency, output converted frequency x2

motorica:
I just tried to measure the pulse within the interrupt, it doesn't work.

You are not listening, are you?

No interrupts, no libraries.

// Pulse Doubler
// Public Domain  Paul B.

#define OUT_PIN 13
#define IN_PIN 7

// Concept: Look for transitions; need state memory
byte in_was = LOW;
// Read once per cycle
byte in_now;
// Time of last transition up
unsigned long wentup = 0;
// Time of last transition down
unsigned long wentdn = 0;
// Output pulse duration
unsigned long pulsetime = 0;
// Time last pulse started
unsigned long pulseis = 0;

// Initiate an output pulse
void pulseon(unsigned long length) {
  digitalWrite(OUT_PIN, HIGH);
  pulsetime = length >> 2;  // A quarter of the last interval
  pulseis = micros();
}

void setup(){ 
  pinMode(OUT_PIN, OUTPUT);
  pinMode(IN_PIN, INPUT);
  digitalWrite(IN_PIN, HIGH);  // Input pullup
}

void loop()
{ 
  // Read pin once
  in_now = digitalRead(IN_PIN);
  // Now, were we high or low?
  if (in_was == LOW) {
    if (in_now == HIGH) {
      // So, has transitioned from low to high
      in_was = HIGH;
      pulseon(micros() - wentup);
      wentup = micros();
    }
  }
  else {
    if (in_now == LOW) {
      // So, has transitioned from high to low
      in_was = LOW;      
      pulseon(micros() - wentdn);
      wentdn = micros();
    }
  }

  delay(15); // Very crude debounce for proof of concept only
  // Now perform the pulse delay
  if (pulsetime != 0) {
    if (micros() - pulseis >= pulsetime) { 
      pulsetime = 0;
      digitalWrite(OUT_PIN, LOW);
    }
  }
}

So, here is some proven code written - especially for you! :astonished:

Note it is test code; proof of concept using a crude debounce delay and an input pullup so that you can test it with a button on pin 7.

Prove it for yourself, then for your tacho, remove the delay() and do what you like with the input pullup.

One little warning, the duty cycle of the input must be between about 35 and 65% (because the pulse width is set at 25%).


Edit: First tested using millis(), but no point not using micros() for the demo anyway!