File tree Expand file tree Collapse file tree 1 file changed +9
-2
lines changed
ports/raspberrypi/common-hal/pulseio Expand file tree Collapse file tree 1 file changed +9
-2
lines changed Original file line number Diff line number Diff line change @@ -44,9 +44,12 @@ static uint16_t pulse_length;
44
44
pwmio_pwmout_obj_t * pwmout_obj ;
45
45
volatile uint16_t current_duty_cycle ;
46
46
static uint32_t min_pulse = 0 ;
47
+ static alarm_id_t cur_alarm ;
47
48
48
49
void pulse_finish (void ) {
49
50
pulse_index ++ ;
51
+ // Turn off the current alarm
52
+ cancel_alarm (cur_alarm );
50
53
// Turn pwm pin off by setting duty cyle to 1.
51
54
common_hal_pwmio_pwmout_set_duty_cycle (pwmout_obj ,1 );
52
55
if (pulse_index >= pulse_length ) {
@@ -56,8 +59,12 @@ void pulse_finish(void) {
56
59
if (delay < min_pulse ) {
57
60
delay = min_pulse ;
58
61
}
59
-
60
- add_alarm_in_us (delay , pulseout_interrupt_handler , NULL , false);
62
+ cur_alarm = 0 ;
63
+ // if the alarm cannot be set, try again with a longer delay
64
+ while (cur_alarm == 0 ) {
65
+ cur_alarm = add_alarm_in_us (delay , pulseout_interrupt_handler , NULL , false);
66
+ delay = delay + 1 ;
67
+ }
61
68
if (pulse_index % 2 == 0 ) {
62
69
common_hal_pwmio_pwmout_set_duty_cycle (pwmout_obj ,current_duty_cycle );
63
70
}
You can’t perform that action at this time.
0 commit comments