Skip to content

Commit 9814386

Browse files
committed
Fix for issue #4937 - Implement minimum pulseout time
1 parent c37f354 commit 9814386

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

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

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ static volatile uint16_t pulse_index = 0;
4343
static uint16_t pulse_length;
4444
pwmio_pwmout_obj_t *pwmout_obj;
4545
volatile uint16_t current_duty_cycle;
46+
static uint32_t min_pulse = 0;
4647

4748
void pulse_finish(void) {
4849
pulse_index++;
@@ -51,7 +52,12 @@ void pulse_finish(void) {
5152
if (pulse_index >= pulse_length) {
5253
return;
5354
}
54-
add_alarm_in_us(pulse_buffer[pulse_index], pulseout_interrupt_handler, NULL, false);
55+
uint64_t delay = pulse_buffer[pulse_index];
56+
if (delay < min_pulse ) {
57+
delay = min_pulse;
58+
}
59+
60+
add_alarm_in_us(delay, pulseout_interrupt_handler, NULL, false);
5561
if (pulse_index % 2 == 0) {
5662
common_hal_pwmio_pwmout_set_duty_cycle(pwmout_obj,current_duty_cycle);
5763
}
@@ -78,6 +84,7 @@ void common_hal_pulseio_pulseout_construct(pulseio_pulseout_obj_t *self,
7884
self->pin = carrier->pin->number;
7985
self->slice = carrier->slice;
8086
pwm_set_enabled(pwmout_obj->slice,false);
87+
min_pulse = (1000000 / pwmout_obj->actual_frequency) / 2;
8188
}
8289

8390
bool common_hal_pulseio_pulseout_deinited(pulseio_pulseout_obj_t *self) {
@@ -107,6 +114,6 @@ void common_hal_pulseio_pulseout_send(pulseio_pulseout_obj_t *self, uint16_t *pu
107114
RUN_BACKGROUND_TASKS;
108115
}
109116
// Short delay to give pin time to settle before disabling PWM
110-
common_hal_mcu_delay_us(25);
117+
common_hal_mcu_delay_us(min_pulse);
111118
pwm_set_enabled(pwmout_obj->slice,false);
112119
}

0 commit comments

Comments
 (0)