From e26d17219a006d64fb3661bdf735a1c6ba6e8abc Mon Sep 17 00:00:00 2001 From: dean Date: Mon, 25 Jun 2018 13:32:01 -0400 Subject: [PATCH] DM: fix PWMs --- bsp/bsp_timer.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/bsp/bsp_timer.cpp b/bsp/bsp_timer.cpp index 75ca3319..25888f16 100644 --- a/bsp/bsp_timer.cpp +++ b/bsp/bsp_timer.cpp @@ -42,7 +42,7 @@ void initTimerPWM( Tc *TCx ) TCx->COUNT16.CTRLA.bit.ENABLE = 0; syncTC_16(TCx); // Set Timer counter Mode to 16 bits, normal PWM, prescaler 1/16 - TCx->COUNT16.CTRLA.reg |= TC_CTRLA_MODE_COUNT16 | TC_CTRLA_WAVEGEN_NPWM | TC_CTRLA_PRESCALER_DIV16; + TCx->COUNT16.CTRLA.reg = TC_CTRLA_MODE_COUNT16 | TC_CTRLA_WAVEGEN_NPWM | TC_CTRLA_PRESCALER_DIV1; syncTC_16(TCx); // Set the initial values @@ -90,7 +90,7 @@ void PWMWrite( uint8_t pwm, uint16_t value) #ifdef USE_TCC_TIMERS } else{ - uint32_t top = p.tcc->PER.reg; + uint32_t top = p.tcc->PER.reg + 1; uint32_t val = (uint32_t)value * top / 65535UL; //map to current top value while (p.tcc->SYNCBUSY.bit.CTRLB); while (p.tcc->SYNCBUSY.bit.CC0 || p.tcc->SYNCBUSY.bit.CC1);