Skip to content

Fix for sequential PWM pin setting #229

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 14, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions cores/arduino/ard_sup/analog/ap3_analog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -538,7 +538,8 @@ ap3_err_t ap3_pwm_output(uint8_t pin, uint32_t th, uint32_t fw, uint32_t clk)

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

AM_CRITICAL_END // end critical section

// clear timer (also stops the timer)
am_hal_ctimer_clear(timer, segment);
// clear timer (also stops the timer)
am_hal_ctimer_clear(timer, segment);

// Configure the repeated pulse mode with our clock source
am_hal_ctimer_config_single(timer,
Expand Down