Well that was easier than I thought, here's the code
You will find a line
rpm = 52554745/(timeNow-LastInt); //scaled for gear ratioo in head
the rather strange constant is to take account of the gear ratio in the centec vertical head. I got this by using
rpm = 60000000/(timeNow-LastInt);
for starters and using another accurate tacho triggered by a slotted wheel held in the chuck, noting the reading on the new tacho and adjusting the 60000000 to get both to read the same. If your sensor magnet is going at the same speed as the spindle is just use 60000000. If you don't have another tacho but do have a vfd then it should might be possible to drive an led off single wave rectified AC to generate a 50hz stroboscope and a painted black/white disc in the spindle
//08 feb 2014
// This version works as a tacho, counter added so that if more than n display updates happen between Interrupts the rpm is set to zero
#include "LedControl.h"
/*
pin 12 is connected to the DataIn
pin 11 is connected to the CLK
pin 10 is connected to LOAD
We have only a single MAX72XX.
*/
LedControl lc=LedControl(12,11,10,1);
unsigned long timeNow = 0;
unsigned long LastInt = 0;
int delaytime=250;
int rpm = 0;
int USLI = 0; //Updates Since Last Interrupt
unsigned int ones;
unsigned int tens;
unsigned int hundreds;
unsigned int thousands;
unsigned int tenthousands;
#define IntPin 2
void setup()
{
/*
The MAX72XX is in power-saving mode on startup,
we have to do a wakeup call
*/
lc.shutdown(0,false);
/* Set the brightness to a medium values */
lc.setIntensity(0,8);
/* and clear the display */
lc.clearDisplay(0);
//interrupt 0 (pin 2)
pinMode(IntPin, INPUT);
attachInterrupt(0, GetSpeed, FALLING); //interrupt 0 attached to pin 2
}
void DisplayDigits()
{
if (USLI > 20)
rpm = 0;
ones = rpm % 10u;
tens = (rpm/10u) % 10u;
hundreds = (rpm/100u) % 10u;
thousands = (rpm/1000u) % 10u;
tenthousands = rpm/10000u;
if (rpm == 0) {
ones = 0;
}
if(rpm > 9999) {
lc.setDigit(0,4,tenthousands,false);
lc.setDigit(0,3,thousands,false);
lc.setDigit(0,2,hundreds,false);
lc.setDigit(0,1,tens,false);
}
else if(rpm > 999) {
lc.setDigit(0,3,thousands,false);
lc.setDigit(0,2,hundreds,false);
lc.setDigit(0,1,tens,false);
}
else if (rpm > 99) {
lc.setDigit(0,2,hundreds,false);
lc.setDigit(0,1,tens,false);
}
else if (rpm > 9) {
lc.setDigit(0,1,tens,false);
}
lc.setDigit(0,0,ones,false);
delay(delaytime);
lc.clearDisplay(0);
USLI++;
}
void GetSpeed()
{noInterrupts();
timeNow = micros();
if (timeNow > LastInt)
rpm = 52554745/(timeNow-LastInt); //scaled for gear ratioo in head
// rpm = 60000000/(timeNow-LastInt);
LastInt = timeNow;
USLI = 0;
/* unsigned int i = 0;
while (i < 5000)
{
if (digitalRead(IntPin) != LOW) //not stopped bouncing start count again
i = 0;
i++;
}
rpm++;
*/ interrupts();
}
void loop()
{
DisplayDigits();
}