threeme3 / usdx

Simple and experimental (class-E driven) SSB transceiver.
616 stars 221 forks source link

Build LUT by fixed point math #27

Closed howard0su closed 3 years ago

howard0su commented 3 years ago

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.