Committed on the Free edition of March Hare Software CVSNT Server.
Upgrade to CVS Suite for more features and support:
http://march-hare.com/cvsnt/
}
async command uint32_t Atm128Calibrate.calibrateMicro(uint32_t n) {
- return scale32(n + MAGIC / 2, cycles, MAGIC);
+ return scale32(n, cycles, MAGIC);
}
async command uint32_t Atm128Calibrate.actualMicro(uint32_t n) {
- return scale32(n + (cycles >> 1), MAGIC, cycles);
+ return scale32(n, MAGIC, cycles);
}
async command uint8_t Atm128Calibrate.adcPrescaler() {
* @param x Number to scale
* @param a Numerator of scaling value
* @param b Denominator of scaling value
- * @return x * a/b
+ * @return round(x * a/b)
*/
inline uint32_t scale32(uint32_t x, uint32_t a, uint32_t b)
{
uint32_t x_mod_b = x % b;
x_mod_b *= a; // on a separate line just in case some compiler goes weird
- return x_over_b * a + x_mod_b / b;
+ return x_over_b * a + (x_mod_b + (b>>1)) / b;
}
#endif