Tachometer til Puls-tæller
http://www.pyroelectro.com/tutorials/tachometer_rpm_arduino/software.html (http://www.pyroelectro.com/tutorials/tachometer_rpm_arduino/software.html)
Har fået Tachometer til, at køre på em Mega 2660 Display I2C
Skal havde Puls-tælleren til, at kunne måle hvor mange pulser der tælles ved, at Solartrackeren køre 180grader.
Vil du være behjælpelig med, at rette koderne herunder til en Puls-tæller?
Info: signal fra Hall sensor er 24Hz
Ville også kunne bruge Puls-tæller til vinmåler!
/*
Author: Chris @ PyroElectro.com
Date: 4/03/2015
Description:
This project is meant to capture interrupt counts from an IR breakbeam circuit
and display them as an RPM number on a 20x4 I2C LCD module.
Full Project Details:
http://www.pyroelectro.com/tutorials/tachometer_rpm_arduino/
*/
//Arduino Mega 2660
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x20, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE);
volatile float time = 0;
volatile float time_last = 0;
volatile int rpm_array[5] = {0,0,0,0,0};
void setup()
{
//Digital Pin 2 Set As An Interrupt
attachInterrupt(0, fan_interrupt, FALLING);
// set up the LCD's number of columns and rows:
lcd.begin(16, 2);
// Print a message to the LCD.
lcd.print("Current RPM:");
}
void loop()
{
int rpm = 0;
while(1){
//Slow Down The LCD Display Updates
delay(400);
//Clear The Bottom Row
lcd.setCursor(0, 1);
lcd.print(" ");
//Update The Rpm Count
lcd.setCursor(0, 1);
lcd.print(rpm);
////lcd.setCursor(4, 1);
////lcd.print(time);
//Update The RPM
if(time > 0)
{
//5 Sample Moving Average To Smooth Out The Data
rpm_array[0] = rpm_array[1];
rpm_array[1] = rpm_array[2];
rpm_array[2] = rpm_array[3];
rpm_array[3] = rpm_array[4];
rpm_array[4] = 60*(1000000/(time*7));
//Last 5 Average RPM Counts Eqauls....
rpm = (rpm_array[0] + rpm_array[1] + rpm_array[2] + rpm_array[3] + rpm_array[4]) / 5;
}
}
}
void fan_interrupt()
{
time = (micros() - time_last);
time_last = micros();
}
Med venlig hilsen
Monie