Skip to content

Commit f214d6b

Browse files
authored
Merge pull request adafruit#7649 from jepler/improve-pwmio-documentation
Improve pwmio documentation
2 parents 96ab9ff + 07b3bd6 commit f214d6b

File tree

1 file changed

+26
-3
lines changed

1 file changed

+26
-3
lines changed

shared-bindings/pwmio/PWMOut.c

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,27 @@ void common_hal_pwmio_pwmout_raise_error(pwmout_result_t result) {
6969
}
7070

7171
//| class PWMOut:
72-
//| """Output a Pulse Width Modulated signal on a given pin."""
72+
//| """Output a Pulse Width Modulated signal on a given pin.
73+
//|
74+
//| .. note:: The exact frequencies possible depend on the specific microcontroller.
75+
//| If the requested frequency is within the available range, one of the two
76+
//| nearest possible frequencies to the requested one is selected.
77+
//|
78+
//| If the requested frequency is outside the range, either (A) a ValueError
79+
//| may be raised or (B) the highest or lowest frequency is selected. This
80+
//| behavior is microcontroller-dependent, and may depend on whether it's the
81+
//| upper or lower bound that is exceeded.
82+
//|
83+
//| In any case, the actual frequency (rounded to 1Hz) is available in the
84+
//| ``frequency`` property after construction.
85+
//|
86+
//| .. note:: The frequency is calculated based on a nominal CPU frequency.
87+
//| However, depending on the board, the error between the nominal and
88+
//| actual CPU frequency can be large (several hundred PPM in the case of
89+
//| crystal oscillators and up to ten percent in the case of RC
90+
//| oscillators)
91+
//|
92+
//| """
7393
//|
7494
//| def __init__(
7595
//| self,
@@ -134,7 +154,9 @@ void common_hal_pwmio_pwmout_raise_error(pwmout_result_t result) {
134154
//| pwm = pwmio.PWMOut(board.D13, duty_cycle=2 ** 15, frequency=440, variable_frequency=True)
135155
//| time.sleep(0.2)
136156
//| pwm.frequency = 880
137-
//| time.sleep(0.1)"""
157+
//| time.sleep(0.1)
158+
//|
159+
//| """
138160
//| ...
139161
STATIC mp_obj_t pwmio_pwmout_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args) {
140162
enum { ARG_pin, ARG_duty_cycle, ARG_frequency, ARG_variable_frequency };
@@ -234,7 +256,8 @@ MP_PROPERTY_GETSET(pwmio_pwmout_duty_cycle_obj,
234256
//| for the PWM's duty cycle may need to be recalculated when the frequency
235257
//| changes. In these cases, the duty cycle is automatically recalculated
236258
//| from the original duty cycle value. This should happen without any need
237-
//| to manually re-set the duty cycle."""
259+
//| to manually re-set the duty cycle. However, an output glitch may occur during the adjustment.
260+
//| """
238261
//|
239262
STATIC mp_obj_t pwmio_pwmout_obj_get_frequency(mp_obj_t self_in) {
240263
pwmio_pwmout_obj_t *self = MP_OBJ_TO_PTR(self_in);

0 commit comments

Comments
 (0)