Skip to content

Commit 91739de

Browse files
committed
Increased max pulse to 65535 us
1 parent 5bd1da2 commit 91739de

File tree

1 file changed

+11
-6
lines changed
  • ports/raspberrypi/common-hal/pulseio

1 file changed

+11
-6
lines changed

ports/raspberrypi/common-hal/pulseio/PulseIn.c

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -39,11 +39,11 @@
3939
pulseio_pulsein_obj_t *save_self;
4040

4141
#define NO_PIN 0xff
42-
#define MAX_PULSE 32678
42+
#define MAX_PULSE 65535
4343
#define MIN_PULSE 10
4444
volatile bool last_level;
45-
volatile uint16_t level_count = 0;
46-
volatile uint16_t result = 0;
45+
volatile uint32_t level_count = 0;
46+
volatile uint32_t result = 0;
4747
volatile uint16_t buf_index = 0;
4848

4949
uint16_t pulsein_program[] = {
@@ -140,14 +140,19 @@ void common_hal_pulseio_pulsein_interrupt() {
140140
result = level_count;
141141
last_level = level;
142142
level_count = 1;
143-
// ignore pulses that are too long and too short
144-
if (result < MAX_PULSE && result > MIN_PULSE) {
145-
self->buffer[buf_index] = result;
143+
// Pulses that are londger than MAX_PULSE will return MAX_PULSE
144+
if (result > MAX_PULSE ) {
145+
result = MAX_PULSE;
146+
}
147+
// ignore pulses that are too short
148+
if (result <= MAX_PULSE && result > MIN_PULSE) {
149+
self->buffer[buf_index] = (uint16_t) result;
146150
buf_index++;
147151
self->len++;
148152
}
149153
}
150154
}
155+
151156
// check for a pulse thats too long (MAX_PULSE us) or maxlen reached, and reset
152157
if ((level_count > MAX_PULSE) || (buf_index >= self->maxlen)) {
153158
pio_sm_set_enabled(self->state_machine.pio, self->state_machine.state_machine, false);

0 commit comments

Comments
 (0)