Merge pull request #1855 from dhalbert/frequencyin-no-double-arith

avoid double float arithmetic in FrequencyIn
This commit is contained in:
Scott Shawcroft 2019-05-08 14:40:18 -04:00 committed by GitHub
commit 9ba8191a04
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 6 additions and 1 deletions

View File

@ -103,7 +103,10 @@ void frequencyin_interrupt_handler(uint8_t index) {
// record a new event count.
if (current_ms - self->last_ms >= self->capture_period) {
float new_factor = self->last_us + (1000 - current_us);
self->factor = (current_ms - self->last_ms) + (new_factor / 1000);
// ms difference will not need 64 bits. If we use 64 bits,
// double-precision float routines are required, and we don't
// want to include them because they're very large.
self->factor = (uint32_t) (current_ms - self->last_ms) + (new_factor / 1000);
self->last_ms = current_ms;
self->last_us = current_us;

View File

@ -48,7 +48,9 @@ void shared_timer_handler(bool is_tc, uint8_t index) {
uint8_t handler = tc_handler[index];
switch(handler) {
case TC_HANDLER_PULSEOUT:
#if CIRCUITPY_PULSEIO
pulseout_interrupt_handler(index);
#endif
break;
case TC_HANDLER_PEW:
#if CIRCUITPY_PEW