A math problem / challenge (PIC32)

I'm trying to come up with a simple function to do basically frequency division / multiplication. This will be written in C running on a PIC32, but doesn't really effect the basic math.
Inputs to the function are:
- Integer variable "Frame" that increments on an constant time base.
- Integer "Speed" in 1/16 increment (Rate * 16 for integer math).

What I want the function to return is "increment". Think of this as an animation.
A few examples of what I want the function to do:

Speed = 16 (16/16 = 1, thus function should increment on every Frame)
Frame = 0, 1, 2, 3, 4, 5, ....
Result = 1, 1, 1, 1, 1, 1, ....

Speed = 32 (32/16 = 2, thus function should increment twice on every Frame)
Frame = 0, 1, 2, 3, 4, 5, ....
Result = 2, 2, 2, 2, 2, 2, ....

Speed = 8 (8/16 = 1/2, thus function should increment on every 2nd Frame)
Frame = 0, 1, 2, 3, 4, 5, ....
Result = 0, 1, 0, 1, 0, 1, ....

Speed = 20 (20/16 = 5/4, thus function should increment on every Frame, twice on every 4th frame)
Frame = 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 ....
Result = 1, 1, 1, 2, 1, 1, 1, 2, 1, 1 ....

Speed = 12 (12/16 = 3/4, thus function should increment on every Frame, except for every 4th)
Frame = 0, 1, 2, 3, 4, 5, 6, ....
Result = 0, 1, 1, 1, 0, 1, 1, ....

I hope I'm making sense. I think this should be possible using the modulo operator but having a brain fart coming up with a function.
If ((Frame*16)%(Speed*16) == 0) ?

Thank you,

Boris.
Topic archived. No new replies allowed.