Skip to content

Commit 4d4db9c

Browse files
author
Owen
authored
Merge pull request #229 from sparkfun/pwmSegmentFix
Fix for sequential PWM pin setting
2 parents 2fbddb2 + cfa8713 commit 4d4db9c

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

cores/arduino/ard_sup/analog/ap3_analog.cpp

+4-4
Original file line numberDiff line numberDiff line change
@@ -538,7 +538,8 @@ ap3_err_t ap3_pwm_output(uint8_t pin, uint32_t th, uint32_t fw, uint32_t clk)
538538

539539
// if timer is running wait for timer value to roll over (will indicate that at least one pulse has been emitted)
540540
AM_CRITICAL_BEGIN // critical section when reading / writing config registers
541-
if (*((uint32_t *)CTIMERADDRn(CTIMER, timer, CTRL0)) & (CTIMER_CTRL0_TMRA0EN_Msk | CTIMER_CTRL0_TMRB0EN_Msk))
541+
if ((segment == AM_HAL_CTIMER_TIMERA && *((uint32_t *)CTIMERADDRn(CTIMER, timer, CTRL0)) & (CTIMER_CTRL0_TMRA0EN_Msk)) ||
542+
(segment == AM_HAL_CTIMER_TIMERB && *((uint32_t *)CTIMERADDRn(CTIMER, timer, CTRL0)) & (CTIMER_CTRL0_TMRB0EN_Msk)))
542543
{
543544
uint32_t current = 0;
544545
uint32_t last = 0;
@@ -548,11 +549,10 @@ ap3_err_t ap3_pwm_output(uint8_t pin, uint32_t th, uint32_t fw, uint32_t clk)
548549
current = am_hal_ctimer_read(timer, segment);
549550
} while (current >= last);
550551
}
551-
552552
AM_CRITICAL_END // end critical section
553553

554-
// clear timer (also stops the timer)
555-
am_hal_ctimer_clear(timer, segment);
554+
// clear timer (also stops the timer)
555+
am_hal_ctimer_clear(timer, segment);
556556

557557
// Configure the repeated pulse mode with our clock source
558558
am_hal_ctimer_config_single(timer,

0 commit comments

Comments
 (0)