#include "KMotionDef.h"
#define TMP 10 // which spare persist to use to transfer data
#include "KflopToKMotionCNCFunctions.c"

void DoRate(void);

/*
void main(void)
{
	for (;;)
	{
		WaitNextTimeSlice();
		DoRate();
	}
}
*/

#define CNTS_PER_REV 3200.0
#define DT 0.1
#define SPINDLEAXIS 3

void DoRate(void)
{
	static double LastTime=0, LastS=0;
	double t=Time_sec(), dt, S;
	char s[80];
	
	if (t > LastTime + DT)
	{
		S = ch3->Position * (1.0/CNTS_PER_REV);
		
		// round to TIMEBASE
		dt = ((int)(((t-LastTime)*(1.0/TIMEBASE))+0.5))*TIMEBASE;

		LastTime=t;
		
		sprintf(s,"%8.0f rpm\n",(S-LastS)/dt*60.0);
		
		LastS = S;
		
		// Put it onto the Screen
		DROLabel(1000, 162, s);
	}
}

