Theoretical max RPM tachometer


hi!
i have built tachometer using ir led , receiver. reflection of led on whatever being measured triggers interrupt via ir receiver. pretty sure works accurately, question rpm (or interupt per second) can expect reliable readings?

this code:
code: [select]
#include <wire.h>
#include <lcd.h>
#include <liquidcrystal_i2c.h>

#define i2c_addr    0x27 // <<----- add address here.  find i2c scanner
#define backlight_pin     3
#define en_pin  2
#define rw_pin  1
#define rs_pin  0
#define d4_pin  4
#define d5_pin  5
#define d6_pin  6
#define d7_pin  7

liquidcrystal_i2c lcd(i2c_addr,en_pin,rw_pin,rs_pin,d4_pin,d5_pin,d6_pin,d7_pin);

unsigned int passes = 0;
unsigned long first = 0;
unsigned long last = 0;
unsigned long updatelcd = 0;

float numblades = 2.0;

void blade_pass(){
  passes++;
  if (passes == 1){
    first = millis();
  }
  else if (passes >= 10){
    last = millis();
  }
}

void setup(){
  serial.begin(115200);
  lcd.begin (16,2);
  lcd.setbacklightpin(backlight_pin,positive);
  lcd.setbacklight(high);
  lcd.home ();
  lcd.clear();
  //lcd.print("hello!");
 
  attachinterrupt(0,blade_pass,falling);
 
}


void loop(){
  if (passes >= 10){
    float passespersecond = (float)passes / ((float)last - (float)first) * 1000.0;
    float rpm = passespersecond * 60.0 / numblades;
    serial.print("passes: ");
    serial.print(passes);
    serial.print(" time: ");
    serial.print(last-first);
    serial.print(" pps: ");
    serial.print(passespersecond);
    serial.print(" rpm: ");
    serial.println(rpm);
   
    if (updatelcd < millis()){
      lcd.clear();
      lcd.home();
      lcd.print("rpm:");
      lcd.setcursor(5,0);
      lcd.print(rpm);
      updatelcd = millis() + 500;
    }
   
    passes = 0;
    delay(100);
  }
}

code: [select]
float numblades = 2.0;
you might change in future have 3.14159 blades?

passes used in isr , in loop(), not volatile. why not?

what happens, in isr, when passes gets 11, 12, 13, etc.?


Arduino Forum > Using Arduino > Programming Questions > Theoretical max RPM tachometer


arduino

Comments

Popular posts from this blog

VIDIOC_S_FMT error 16, Device or resource busy - Raspberry Pi Forums

using a laptop skeleton to build a pi laptop - Raspberry Pi Forums

Forum for Joomla? - Joomla! Forum - community, help and support