# Count RPM's with encoders

I’m programming a flywheel for an AP Physics project, the program works fine but for shits and giggles I wanted to know how many RPM’s the final output is. So I put an encoder on the output shaft and realized I have no idea how I would program that. Any ideas/suggestions? I’m programming with PROS but tell me how you would do it with anything else and I can probably figure the rest out.

To measure RPM, you must have a measurement of distance/time. The units can be anything, but it must be a measure of distance (or rotations, degrees, etc.) / time. You already have an encoder, which would give you distance (specifically degrees), so now all you need is a measure of time. As long as you calculate the RPM at a constant rate, you can use that rate to figure out how fast it is going, which would be the time factor. I don’t know what else you’re doing in your code, so I’ll give an example that would run in a different task so it won’t interfere.

``````
int prev = 0;
void calcRPM() {

int enc = encoderGet(encoder); // gets the encoder value
int change = enc - prev; // determines how much the encoder has moved since the last update
printf("RPM: %f\n", change * 0.17f); // convert to RPM (assuming a 1000ms update interval) and print
prev = enc; // update the previous encoder variable for next update

}

``````

Then you just have to call

``````