From: asterix Date: Fri, 23 Apr 2010 08:55:26 +0000 (+0000) Subject: Compute duty cycle according to pwm polarity before to set it. X-Git-Tag: 2.5.0~410 X-Git-Url: https://codewiz.org/gitweb?a=commitdiff_plain;h=c5a47da9ce42957dd0fb12dae2500b4c5852b7c5;p=bertos.git Compute duty cycle according to pwm polarity before to set it. git-svn-id: https://src.develer.com/svnoss/bertos/trunk@3498 38d2e660-2303-0410-9eaa-f027e97ec537 --- diff --git a/bertos/cpu/arm/drv/pwm_at91.c b/bertos/cpu/arm/drv/pwm_at91.c index 411f3ab6..39fd4a66 100644 --- a/bertos/cpu/arm/drv/pwm_at91.c +++ b/bertos/cpu/arm/drv/pwm_at91.c @@ -146,6 +146,16 @@ void pwm_hw_setDutyUnlock(PwmDev dev, uint16_t duty) ASSERT(duty <= (uint16_t)*pwm_map[dev].period_reg); + /* + * If polarity flag is true we must invert + * PWM polarity. + */ + if (pwm_map[dev].pol) + { + duty = (uint16_t)*pwm_map[dev].period_reg - duty; + LOG_INFO("Inverted duty[%d], pol[%d]\n", duty, pwm_map[dev].pol); + } + /* * WARNING: is forbidden to write 0 to duty cycle value, * and so for duty = 0 we must enable PIO and clear output! @@ -158,16 +168,6 @@ void pwm_hw_setDutyUnlock(PwmDev dev, uint16_t duty) } else { - /* - * If polarity flag is true we must invert - * PWM polarity. - */ - if (pwm_map[dev].pol) - { - duty = (uint16_t)*pwm_map[dev].period_reg - duty; - LOG_INFO("Inverted duty[%d], pol[%d]\n", duty, pwm_map[dev].pol); - } - PWM_PIO_PDR = pwm_map[dev].pwm_pin; PWM_PIO_ABSR = pwm_map[dev].pwm_pin;