In the nearby future, I will test a DC motor and plot his current to torque ratio. Which depends on the PWM frequency due to the inductance of the motor.

For my project(inverted pendulum) I will calculate the force/torque needed for control, therefore, my idea was to use a Look Up Table and some interpolation to get the correct PWM frequency. Im thinking in an array of 100 values.

Second idea in mind is plotting the torque graph and use a fitting tool to subtract the function and use this for calculating the PWM frequency. My guess is that this will be a 4th order spline

The question is: Which would be faster? A lut or the mathematical calculation?

Thanks in advance!

Edit: More background info
The pendulum is on a linear rail and moved with a timing belt and a reduction to the DC motor.

I want to measure the torque because I've noticed that when I run at high PWM frequency 10kHz+ the ON time is to short to produce a linear torque because of the motors time constant. A very low PWM frequency gives adds a lot of resistance in the coil and therefore dissipates a lot of energy and also horrible sounds. So my plan was to play with different PWM frequency's and get a full understanding of what happens.

The lut or function will be used when a low force is needed so that the corresponding PWM frequency can be determined.

In the nearby future I will test a DC motor and plot his voltage to torque ratio. Which depends on the pwm frequency due the inductance of the motor.

For my project(inverted pendulum) I will calculate the force/torque needed for control therefore my idea was to use a lut and some interpolation to get the correct pwm signal. Im thinking in an array of 100 values.

Second idea in mind is plotting the torque graph and use a fitting tool to subtract the function and use this for calculating the pwm signal. My guess is that this will be a 4th order spline

The question is:

Which would be faster? A lut or the mathematical calculation?

Thanks in advance!

First get your project properly defined. Motor torque is dependent on current, not voltage. Unless you have an extremely weak power source, the voltage should remain fairly constant.

If you are using PWM to power the motor, then you must measure the current when the voltage is high, and not continuously.

Paul_KD7HB:
First get your project properly defined. Motor torque is dependent on current, not voltage. Unless you have an extremely weak power source, the voltage should remain fairly constant.

If you are using PWM to power the motor, then you must measure the current when the voltage is high, and not continuously.

Paul

That's my bad, true that current is proportional to the torque. I'm gonna change it so that other readers won't get confused.
Secondly I will measure the output force with a strain gauge since the exact motor parameters are not known.

I don't understand how you want to apply the strain gauge and wires to a turning motor. A stalled motor has characteristics very different from a running motor.

Also consider your input (feedback) from the pendulum and its dynamic behaviour. It won't help much to interpolate values from a static table, instead you'll need a (PID...) regulator for stabilizing the pendulum.

A DC motor is an inductance, i.e. it tries to keep its current constant. That's why a high PWM frequency may not have the desired effect, because during gaps the current continues flowing through the clamping diodes of the driver board.

Also the dependency between duty cycle and torque is not fixed, it also depends on the motor rpm and load. I bet that you'll notice that yourself, when you continue with the construction and use of your table.

If the table is small enough to fit into memory, and the steps are fine enough, then a table lookup is much faster than an expression evaluation. Often a combined table and interpolation function, like used for sin(x), will match both space and accuracy requirements.