Skip to content

Commit db0adf1

Browse files
authored
Merge pull request micropython#5025 from DavePutz/issue_5016
Turn off PWM pin during PulseOut construct
2 parents ce73015 + 8fe4fa0 commit db0adf1

File tree

1 file changed

+11
-6
lines changed

1 file changed

+11
-6
lines changed

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

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,15 @@ volatile uint16_t current_duty_cycle;
4747
static uint32_t min_pulse = 0;
4848
static alarm_id_t cur_alarm;
4949

50+
void turn_off(uint8_t slice) {
51+
pwm_hw->slice[slice].ctr = 0;
52+
pwm_hw->slice[slice].cc = 0;
53+
pwm_hw->slice[slice].top = 0;
54+
pwm_hw->slice[slice].div = 1u << PWM_CH0_DIV_INT_LSB;
55+
pwm_hw->slice[slice].csr = PWM_CH0_CSR_EN_BITS;
56+
pwm_hw->slice[slice].csr = 0;
57+
}
58+
5059
void pulse_finish(pwmio_pwmout_obj_t *carrier) {
5160
pulse_index++;
5261
// Turn pwm pin off by setting duty cyle to 1.
@@ -88,6 +97,7 @@ void common_hal_pulseio_pulseout_construct(pulseio_pulseout_obj_t *self,
8897
pwmout_obj = (pwmio_pwmout_obj_t *)carrier;
8998
current_duty_cycle = common_hal_pwmio_pwmout_get_duty_cycle(pwmout_obj);
9099
pwm_set_enabled(carrier->slice,false);
100+
turn_off(carrier->slice);
91101
common_hal_pwmio_pwmout_set_duty_cycle(pwmout_obj,1);
92102
self->pin = carrier->pin->number;
93103
self->slice = carrier->slice;
@@ -132,11 +142,6 @@ void common_hal_pulseio_pulseout_send(pulseio_pulseout_obj_t *self, uint16_t *pu
132142
RUN_BACKGROUND_TASKS;
133143
}
134144
// Ensure pin is left low
135-
pwm_hw->slice[self->slice].ctr = 0;
136-
pwm_hw->slice[self->slice].cc = 0;
137-
pwm_hw->slice[self->slice].top = 0;
138-
pwm_hw->slice[self->slice].div = 1u << PWM_CH0_DIV_INT_LSB;
139-
pwm_hw->slice[self->slice].csr = PWM_CH0_CSR_EN_BITS;
140-
pwm_hw->slice[self->slice].csr = 0;
145+
turn_off(self->slice);
141146
pwm_set_enabled(self->slice,false);
142147
}

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy