Imagine you were trying to write a C routine for an 8bit microcontroller that converted a desired timespan (be it seconds, milliseconds, hertz, etc). to the corresponding hardware timer preload value (taking into account the clock source and frequency of the timer). The goal is to make the function as easy as possible to use, with as few arguments as possible. What would this function look like?
Would you pass in a uint32_t representing the desired hertz of the timer (0 = 0Hz, 1000 = 1kHz, etc.):
void set_timer(uint32_t hz);
Would you prefer using a uint16_t representing kHz instead (0 = 0Hz, 1 = 1KHz, 10 = 10Khz)?
void set_timer(uint16_t khz);
Or would a 32bit fixed point argument be more desirable (to be able to represent fraction of hertz)?
void set_timer(q15_16_t hz);
Or would this fixed point value represent seconds instead of Hz?
void set_timer(q15_16_t sec);
Or would you use a 16bit fixed point instead of a 32bit fixed point.
Or would you even dare want to use a floating point? Or what about a half-precision float?
What do you think?