@@ -43,6 +43,7 @@ static volatile uint16_t pulse_index = 0;
43
43
static uint16_t pulse_length ;
44
44
pwmio_pwmout_obj_t * pwmout_obj ;
45
45
volatile uint16_t current_duty_cycle ;
46
+ static uint32_t min_pulse = 0 ;
46
47
47
48
void pulse_finish (void ) {
48
49
pulse_index ++ ;
@@ -51,7 +52,12 @@ void pulse_finish(void) {
51
52
if (pulse_index >= pulse_length ) {
52
53
return ;
53
54
}
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);
55
61
if (pulse_index % 2 == 0 ) {
56
62
common_hal_pwmio_pwmout_set_duty_cycle (pwmout_obj ,current_duty_cycle );
57
63
}
@@ -78,6 +84,7 @@ void common_hal_pulseio_pulseout_construct(pulseio_pulseout_obj_t *self,
78
84
self -> pin = carrier -> pin -> number ;
79
85
self -> slice = carrier -> slice ;
80
86
pwm_set_enabled (pwmout_obj -> slice ,false);
87
+ min_pulse = (1000000 / pwmout_obj -> actual_frequency ) / 2 ;
81
88
}
82
89
83
90
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
107
114
RUN_BACKGROUND_TASKS ;
108
115
}
109
116
// 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 );
111
118
pwm_set_enabled (pwmout_obj -> slice ,false);
112
119
}
0 commit comments