Step 1 to remove float from the code. LUT table can be perfect build by
fixed point math.
lut[i] = (float)i / ((float)255 / ((float)pwm_max - (float)pwm_min)) +
pwm_min;
can be converted to:
lut[i] = (float)i ((float)pwm_max - (float)pwm_min) / (float)255 +
pwm_min;
can be futher convert to:
lut[i] = i (pwm_max - pwm_min) / 255 + pwm_min;
The second convertion is validated by a small test code. The first
convertion has slight difference on lut[255] of some combinition of
pwm_max and pwm_min, which I believe second fomula is more accurate.
Step 1 to remove float from the code. LUT table can be perfect build by fixed point math.
lut[i] = (float)i / ((float)255 / ((float)pwm_max - (float)pwm_min)) + pwm_min; can be converted to: lut[i] = (float)i ((float)pwm_max - (float)pwm_min) / (float)255 + pwm_min; can be futher convert to: lut[i] = i (pwm_max - pwm_min) / 255 + pwm_min;
The second convertion is validated by a small test code. The first convertion has slight difference on lut[255] of some combinition of pwm_max and pwm_min, which I believe second fomula is more accurate.