Considering that the motor slows down a bit between pulses, your graph appears perfect. The closer the pulses are to each other, the less time to slow down.
When I count the RPM of the motor shaft at a Motor Speed of 20 I get 37 RPM. This is quite a bit higher than the serial.print of 28. Any idea why this is the case?
This code is extracted from a program I use to control a small DC motor. I have an optical sensor that produces one pulse per revolution. It is not complete but it should give the idea. It simply measures the time between pulses.
volatile unsigned long isrMicros;
unsigned long latestIsrMicros;
unsigned long previousIsrMicros;
volatile boolean newISR = false;
void loop() {
if (newISR == true) {
previousIsrMicros = latestIsrMicros; // save the old value
noInterrupts(); // pause interrupts while we get the new value
latestIsrMicros = isrMicros;
newISR = false;
interrupts();
microsThisRev = latestIsrMicros - previousIsrMicos;
}
void myISR() {
isrMicros = micros();
newISR = true;
}