summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorScott Shawcroft <scott.shawcroft@gmail.com>2017-04-13 14:47:34 -0700
committerScott Shawcroft <scott.shawcroft@gmail.com>2017-04-13 14:47:34 -0700
commitf0e24bd81270227fff63644b3a12444b5d0e5a4f (patch)
tree66070a7b11a7e8973b2d16e7b71e18dbe0d3aff3
parentd1b15cf1a3070581a781a80fd55a346e4849950b (diff)
atmel-samd: Account for pending ticks in PulseIn. Fixes #116.
-rw-r--r--atmel-samd/common-hal/pulseio/PulseIn.c4
1 files changed, 3 insertions, 1 deletions
diff --git a/atmel-samd/common-hal/pulseio/PulseIn.c b/atmel-samd/common-hal/pulseio/PulseIn.c
index de40ff036..920b7f34d 100644
--- a/atmel-samd/common-hal/pulseio/PulseIn.c
+++ b/atmel-samd/common-hal/pulseio/PulseIn.c
@@ -78,7 +78,9 @@ static void pulsein_set_config(pulseio_pulsein_obj_t* self, bool first_edge) {
static void pulsein_callback(void) {
// Grab the current time first.
uint16_t current_us = tc_get_count_value(&ms_timer);
- uint64_t current_ms = ticks_ms;
+ // Add the overflow flag to account for tick interrupts that are blocked by
+ // this interrupt.
+ uint64_t current_ms = ticks_ms + TC5->COUNT16.INTFLAG.bit.OVF;
pulseio_pulsein_obj_t* self = active_pulseins[extint_get_current_channel()];
current_us = current_us * 1000 / self->ticks_per_ms;
if (self->first_edge) {