38
38
#include "src/rp2_common/hardware_pwm/include/hardware/pwm.h"
39
39
#include "src/common/pico_time/include/pico/time.h"
40
40
41
- static uint8_t refcount = 0 ;
42
41
volatile alarm_id_t cur_alarm = 0 ;
43
42
44
- void turn_off (uint8_t slice ) {
45
- // Set the current counter value near the top so that the output is low. The
46
- // - 2 gives us a little wiggle room for enabling and disabling the slice.
47
- // The top + 1 ensure we don't end up lower than the cc (and therefore high.)
48
- uint32_t top = MAX (pwm_hw -> slice [slice ].cc + 1 , pwm_hw -> slice [slice ].top - 2 );
49
- // Disable interrupts so this happens as fast as possible.
50
- common_hal_mcu_disable_interrupts ();
51
- pwm_hw -> slice [slice ].ctr = top ;
52
- // Enable for at least one cycle so that the new counter value takes effect.
53
- pwm_hw -> slice [slice ].csr = PWM_CH0_CSR_EN_BITS ;
54
- pwm_hw -> slice [slice ].csr = 0 ;
55
- common_hal_mcu_enable_interrupts ();
56
- }
57
-
58
43
void pulse_finish (pulseio_pulseout_obj_t * self ) {
59
44
self -> pulse_index ++ ;
60
- // Turn pwm pin off by setting duty cyle to 1 .
61
- common_hal_pwmio_pwmout_set_duty_cycle (& self -> carrier , 1 );
45
+ // Turn pwm pin off by setting duty cyle to 0 .
46
+ common_hal_pwmio_pwmout_set_duty_cycle (& self -> carrier , 0 );
62
47
if (self -> pulse_index >= self -> pulse_length ) {
63
48
return ;
64
49
}
@@ -91,15 +76,12 @@ void common_hal_pulseio_pulseout_construct(pulseio_pulseout_obj_t *self,
91
76
uint16_t duty_cycle ) {
92
77
93
78
pwmout_result_t result = common_hal_pwmio_pwmout_construct (
94
- & self -> carrier , pin , duty_cycle , frequency , false);
79
+ & self -> carrier , pin , 0 , frequency , false);
95
80
96
81
// This will raise an exception and not return if needed.
97
82
common_hal_pwmio_pwmout_raise_error (result );
98
83
99
84
self -> current_duty_cycle = duty_cycle ;
100
- pwm_set_enabled (self -> carrier .slice , false);
101
- turn_off (self -> carrier .slice );
102
- common_hal_pwmio_pwmout_set_duty_cycle (& self -> carrier , 1 );
103
85
self -> pin = self -> carrier .pin -> number ;
104
86
self -> slice = self -> carrier .slice ;
105
87
self -> min_pulse = (1000000 / self -> carrier .actual_frequency );
@@ -123,7 +105,6 @@ void common_hal_pulseio_pulseout_send(pulseio_pulseout_obj_t *self, uint16_t *pu
123
105
self -> pulse_length = length ;
124
106
125
107
common_hal_pwmio_pwmout_set_duty_cycle (& self -> carrier , self -> current_duty_cycle );
126
- pwm_set_enabled (self -> slice , true);
127
108
uint64_t delay = self -> pulse_buffer [0 ];
128
109
if (delay < self -> min_pulse ) {
129
110
delay = self -> min_pulse ;
@@ -140,7 +121,4 @@ void common_hal_pulseio_pulseout_send(pulseio_pulseout_obj_t *self, uint16_t *pu
140
121
// signal.
141
122
RUN_BACKGROUND_TASKS ;
142
123
}
143
- // Ensure pin is left low
144
- turn_off (self -> slice );
145
- pwm_set_enabled (self -> slice ,false);
146
124
}
0 commit comments