What is the fastest way to do division in C for 8bit MCUs?

Posted by Jordan S on Stack Overflow See other posts from Stack Overflow or by Jordan S
Published on 2010-04-30T13:46:20Z Indexed on 2010/04/30 13:47 UTC
Read the original article Hit count: 255

Filed under:
|
|
|

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;
}

© Stack Overflow or respective owner

Related posts about binary

Related posts about division