I am working on the firmware for a device that uses an 8bit mcu (8051 architecture). I am using SDCC (Small Device C Compiler). I have a function that I use to set the speed of a stepper motor that my circuit is driving. The speed is set by loading a desired value into the reload register for a timer. I have a variable, MotorSpeed that is in the range of 0 to 1200 which represents pulses per second to the motor. My function to convert MotorSpeed to the correct 16bit reload value is shown below. I know that float point operations are pretty slow and I am wondering if there is a faster way of doing this...
void SetSpeed()
{
float t = MotorSpeed;
unsigned int j = 0;
t = 1/t ;
t = t / 0.000001;
j = MaxInt - t;
TMR3RL = j; // Set reload register for desired freq
return;
}