Having some trouble. Here’s the code I’m debugging. Don’t worry about the timed action just yet, I’m still working on proper pulse time calculation. I moved the values around as you suggested, and it does appear to work at slow speeds:

```
#include <TimedAction.h>
long TimeNow;
long LastPulseTime;
long PulseTime;
long TotalPulseTime;
int PulseCount;
long RPM;
TimedAction timedAction = TimedAction(100,CalculateRPM);
void setup()
{
Serial.begin(9600);
attachInterrupt(0, TimeStamp, RISING); // Attaches interrupt to Digi Pin 2
LastPulseTime=millis();
PulseCount=0;
}
void TimeStamp()
{
TimeNow=millis();
Serial.print("TimeNow:");
Serial.print(TimeNow);
PulseTime=TimeNow-LastPulseTime; //Takes difference between current timestamp and last timestamp
Serial.print(" PulseTime:");
Serial.print(PulseTime);
LastPulseTime=TimeNow; //Puts current timestamp into temp variable to use next time
Serial.print(" LastPulseTime:");
Serial.print(LastPulseTime);
TotalPulseTime+=PulseTime; //Accumulate total
Serial.print(" TotalPulseTime:");
Serial.print(TotalPulseTime);
PulseCount++; //Accumulate count
Serial.print( "PulseCount:");
Serial.println(PulseCount);
}
void loop()
{
timedAction.check();
}
void CalculateRPM(){
// PulseCount=0;
// TotalPulseTime=0;
}
```

The problem is this. At high speeds, the time stamp stamps the same value. Here is the output:

```
TimeNow:27777 PulseTime:907 LastPulseTime:27777 TotalPulseTime:27776PulseCount:229
TimeNow:28528 PulseTime:751 LastPulseTime:28528 TotalPulseTime:28527PulseCount:230
TimeNow:28946 PulseTime:418 LastPulseTime:28946 TotalPulseTime:28945PulseCount:231
TimeNow:29553 PulseTime:607 LastPulseTime:29553 TotalPulseTime:29552PulseCount:232
TimeNow:30371 PulseTime:818 LastPulseTime:30371 TotalPulseTime:30370PulseCount:233
TimeNow:30568 PulseTime:197 LastPulseTime:30568 TotalPulseTime:30567PulseCount:234
TimeNow:30755 PulseTime:187 LastPulseTime:30755 TotalPulseTime:30754PulseCount:235
TimeNow:31419 PulseTime:664 LastPulseTime:31419 TotalPulseTime:31418PulseCount:236
TimeNow:31560 PulseTime:141 LastPulseTime:31560 TotalPulseTime:31559PulseCount:237
TimeNow:32209 PulseTime:649 LastPulseTime:32209 TotalPulseTime:32208PulseCount:238
TimeNow:32280 PulseTime:71 LastPulseTime:32280 TotalPulseTime:32279PulseCount:239
TimeNow:32294 PulseTime:14 LastPulseTime:32294 TotalPulseTime:32293PulseCount:240
TimeNow:32942 PulseTime:648 LastPulseTime:32942 TotalPulseTime:32941PulseCount:241
TimeNow:33078 PulseTime:136 LastPulseTime:33078 TotalPulseTime:33077PulseCount:242
TimeNow:33187 PulseTime:109 LastPulseTime:33187 TotalPulseTime:33186PulseCount:243
TimeNow:33227 PulseTime:40 LastPulseTime:33227 TotalPulseTime:33226PulseCount:244
TimeNow:33785 PulseTime:558 LastPulseTime:33785 TotalPulseTime:33784PulseCount:245
TimeNow:33881 PulseTime:96 LastPulseTime:33881 TotalPulseTime:33880PulseCount:246
TimeNow:34420 PulseTime:539 LastPulseTime:34420 TotalPulseTime:34419PulseCount:247
TimeNow:34525 PulseTime:105 LastPulseTime:34525 TotalPulseTime:34524PulseCount:248
TimeNow:35949 PulseTime:1424 LastPulseTime:35949 TotalPulseTime:35948PulseCount:249
TimeNow:35949 PulseTime:0 LastPulseTime:35949 TotalPulseTime:35948PulseCount:250
TimeNow:35949 PulseTime:0 LastPulseTime:35949 TotalPulseTime:35948PulseCount:251
TimeNow:35949 PulseTime:0 LastPulseTime:35949 TotalPulseTime:35948PulseCount:252
TimeNow:35949 PulseTime:0 LastPulseTime:35949 TotalPulseTime:35948PulseCount:253
TimeNow:35949 PulseTime:0 LastPulseTime:35949 TotalPulseTime:35948PulseCount:254
TimeNow:35949 PulseTime:0 LastPulseTime:35949 TotalPulseTime:35948PulseCount:255
TimeNow:35949 PulseTime:0 LastPulseTime:35949 TotalPulseTime:35948PulseCount:256
TimeNow:35949 PulseTime:0 LastPulseTime:35949 TotalPulseTime:35948PulseCount:257
TimeNow:35949 PulseTime:0 LastPulseTime:35949 TotalPulseTime:35948PulseCount:258
TimeNow:35949 PulseTime:0 LastPulseTime:35949 TotalPulseTime:35948PulseCount:259
TimeNow:35949 PulseTime:0 LastPulseTime:35949 TotalPulseTime:35948PulseCount:260
TimeNow:35949 PulseTime:0 LastPulseTime:35949 TotalPulseTime:35948PulseCount:261
TimeNow:35949 PulseTime:0 LastPulseTime:35949 TotalPulseTime:35948PulseCount:262
TimeNow:35949 PulseTime:0 LastPulseTime:35949 TotalPulseTime:35948PulseCount:263
TimeNow:35949 PulseTime:0 LastPulseTime:35949 TotalPulseTime:35948PulseCount:264
TimeNow:35949 PulseTime:0 LastPulseTime:35949 TotalPulseTime:35948PulseCount:265
TimeNow:35949 PulseTime:0 LastPulseTime:35949 TotalPulseTime:35948PulseCount:266
TimeNow:35949 PulseTime:0 LastPulseTime:35949 TotalPulseTime:35948PulseCount:267
TimeNow:35949 PulseTime:0 LastPulseTime:35949 TotalPulseTime:35948PulseCount:268
TimeNow:35949 PulseTime:0 LastPulseTime:35949 TotalPulseTime:35948PulseCount:269
TimeNow:35949 PulseTime:0 LastPulseTime:35949 TotalPulseTime:35948PulseCount:270
TimeNow:35949 PulseTime:0 LastPulseTime:35949 TotalPulseTime:35948PulseCount:271
TimeNow:35949 PulseTime:0 LastPulseTime:35949 TotalPulseTime:35948PulseCount:272
```

The top part is being rotated by hand, and it seems to work properly. When I put power on the motor, the TimeNow value freezes and just prints the same one. I figured this is probably because of all the Serial printing done in the interrupt loop. So, I took it all out and put it in the TimedAction loop so it would only print ever 100ms

```
#include <TimedAction.h>
long TimeNow;
long LastPulseTime;
long PulseTime;
long TotalPulseTime;
int PulseCount;
long RPM;
TimedAction timedAction = TimedAction(100,CalculateRPM);
void setup()
{
Serial.begin(9600);
attachInterrupt(0, TimeStamp, RISING); // Attaches interrupt to Digi Pin 2
LastPulseTime=millis();
PulseCount=0;
}
void TimeStamp()
{
TimeNow=millis();
PulseTime=TimeNow-LastPulseTime; //Takes difference between current timestamp and last timestamp
LastPulseTime=TimeNow; //Puts current timestamp into temp variable to use next time
TotalPulseTime+=PulseTime; //Accumulate total
PulseCount++; //Accumulate count
}
void loop()
{
timedAction.check();
}
void CalculateRPM(){
Serial.print("TotalPulseTime:");
Serial.print(TotalPulseTime);
Serial.print(" PulseCount:");
Serial.println(PulseCount);
PulseCount=0;
TotalPulseTime=0;
}
```

Now here’s the output with the motor running at about 6kRPM

```
TotalPulseTime:82 PulseCount:53
TotalPulseTime:81 PulseCount:56
TotalPulseTime:80 PulseCount:58
TotalPulseTime:82 PulseCount:60
TotalPulseTime:82 PulseCount:60
TotalPulseTime:80 PulseCount:58
TotalPulseTime:82 PulseCount:55
TotalPulseTime:82 PulseCount:51
TotalPulseTime:80 PulseCount:49
TotalPulseTime:79 PulseCount:49
TotalPulseTime:82 PulseCount:52
TotalPulseTime:82 PulseCount:57
TotalPulseTime:81 PulseCount:59
TotalPulseTime:82 PulseCount:59
TotalPulseTime:81 PulseCount:59
TotalPulseTime:82 PulseCount:55
TotalPulseTime:81 PulseCount:50
TotalPulseTime:83 PulseCount:50
TotalPulseTime:81 PulseCount:50
TotalPulseTime:80 PulseCount:54
TotalPulseTime:81 PulseCount:58
TotalPulseTime:82 PulseCount:59
TotalPulseTime:79 PulseCount:59
TotalPulseTime:82 PulseCount:57
TotalPulseTime:81 PulseCount:52
TotalPulseTime:81 PulseCount:49
TotalPulseTime:82 PulseCount:49
TotalPulseTime:81 PulseCount:51
TotalPulseTime:80 PulseCount:54
TotalPulseTime:81 PulseCount:58
TotalPulseTime:81 PulseCount:59
TotalPulseTime:81 PulseCount:59
TotalPulseTime:81 PulseCount:60
TotalPulseTime:81 PulseCount:61
TotalPulseTime:80 PulseCount:60
TotalPulseTime:82 PulseCount:60
TotalPulseTime:82 PulseCount:60
TotalPulseTime:80 PulseCount:59
TotalPulseTime:80 PulseCount:58
TotalPulseTime:82 PulseCount:54
TotalPulseTime:80 PulseCount:51
TotalPulseTime:81 PulseCount:51
TotalPulseTime:80 PulseCount:49
TotalPulseTime:81 PulseCount:49
TotalPulseTime:81 PulseCount:49
TotalPulseTime:80 PulseCount:54
TotalPulseTime:83 PulseCount:60
TotalPulseTime:81 PulseCount:60
TotalPulseTime:81 PulseCount:59
TotalPulseTime:82 PulseCount:60
TotalPulseTime:80 PulseCount:60
TotalPulseTime:80 PulseCount:60
TotalPulseTime:82 PulseCount:60
TotalPulseTime:82 PulseCount:60
TotalPulseTime:80 PulseCount:59
TotalPulseTime:80 PulseCount:59
TotalPulseTime:82 PulseCount:55
TotalPulseTime:80 PulseCount:52
TotalPulseTime:81 PulseCount:52
TotalPulseTime:81 PulseCount:51
TotalPulseTime:81 PulseCount:50
TotalPulseTime:82 PulseCount:51
TotalPulseTime:82 PulseCount:52
TotalPulseTime:81 PulseCount:57
TotalPulseTime:80 PulseCount:60
TotalPulseTime:82 PulseCount:60
TotalPulseTime:80 PulseCount:59
TotalPulseTime:81 PulseCount:60
TotalPulseTime:82 PulseCount:60
TotalPulseTime:81 PulseCount:59
TotalPulseTime:81 PulseCount:60
TotalPulseTime:82 PulseCount:60
TotalPulseTime:82 PulseCount:60
TotalPulseTime:81 PulseCount:60
TotalPulseTime:81 PulseCount:59
TotalPulseTime:82 PulseCount:60
TotalPulseTime:82 PulseCount:60
TotalPulseTime:81 PulseCount:60
TotalPulseTime:81 PulseCount:60
TotalPulseTime:82 PulseCount:60
TotalPulseTime:80 PulseCount:59
TotalPulseTime:81 PulseCount:60
TotalPulseTime:82 PulseCount:60
TotalPulseTime:82 PulseCount:60
TotalPulseTime:81 PulseCount:60
TotalPulseTime:82 PulseCount:60
TotalPulseTime:80 PulseCount:59
TotalPulseTime:81 PulseCount:60
TotalPulseTime:81 PulseCount:60
TotalPulseTime:80 PulseCount:60
TotalPulseTime:82 PulseCount:60
TotalPulseTime:82 PulseCount:60
TotalPulseTime:80 PulseCount:59
TotalPulseTime:82 PulseCount:60
```

I was loading it down with my fingers, you can see the pulse count drop down to 51 from about 60, but total pulse time stays the same