Hacker News new | ask | show | jobs
by unwind 1369 days ago
Very interesting project, but I must admit I raised an eyebrow when the author said it was nice to use an ATtiny25(8-bit core) instead of the usual (32-bit) ARM micro controllers, then proceeded to use float in the code all over the place.

Since the AVR core has zero support for floats, that will mean it's all software emulation, bloating the code fantastically. I guess (and understand) it doesn't matter as long as the application fits and does what it's supposed to do, it was just ... extremely jarring.

This, for example:

    void set_pwm(float voltage) {
       OCR1A = ( voltage / 5 )* 0x400;
    }
The above generates 100+ instructions, without inlining the floating-point operations that are left as library calls (see [1] for a Compiler Explorer view).

Normally you'd expect code like that to use 8-bit variables wherever possible, and perhaps stretching to 16-bit numbers when more range is needed such as when computing the above PWM value.

[1]: https://godbolt.org/z/PvP5jsrnG