From dc7155634a454ee93c28a28a1393abfe46e4ea41 Mon Sep 17 00:00:00 2001 From: Sissors Date: Mon, 21 Jul 2014 19:03:07 +0200 Subject: [PATCH] Bugfix for KLxx/K20 pwm period Period is MOD + 1, so needs to add/substract 1 in the correct places --- .../targets/hal/TARGET_Freescale/TARGET_K20D5M/pwmout_api.c | 6 +++--- .../targets/hal/TARGET_Freescale/TARGET_KLXX/pwmout_api.c | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/libraries/mbed/targets/hal/TARGET_Freescale/TARGET_K20D5M/pwmout_api.c b/libraries/mbed/targets/hal/TARGET_Freescale/TARGET_K20D5M/pwmout_api.c index bc417ee900..0966e2d795 100644 --- a/libraries/mbed/targets/hal/TARGET_Freescale/TARGET_K20D5M/pwmout_api.c +++ b/libraries/mbed/targets/hal/TARGET_Freescale/TARGET_K20D5M/pwmout_api.c @@ -99,11 +99,11 @@ void pwmout_write(pwmout_t* obj, float value) { value = 1.0; } - *obj->CnV = (uint32_t)((float)(*obj->MOD) * value); + *obj->CnV = (uint32_t)((float)(*obj->MOD + 1) * value); } float pwmout_read(pwmout_t* obj) { - float v = (float)(*obj->CnV) / (float)(*obj->MOD); + float v = (float)(*obj->CnV) / (float)(*obj->MOD + 1); return (v > 1.0) ? (1.0) : (v); } @@ -118,7 +118,7 @@ void pwmout_period_ms(pwmout_t* obj, int ms) { // Set the PWM period, keeping the duty cycle the same. void pwmout_period_us(pwmout_t* obj, int us) { float dc = pwmout_read(obj); - *obj->MOD = (uint32_t)(pwm_clock * (float)us); + *obj->MOD = (uint32_t)(pwm_clock * (float)us) - 1; pwmout_write(obj, dc); } diff --git a/libraries/mbed/targets/hal/TARGET_Freescale/TARGET_KLXX/pwmout_api.c b/libraries/mbed/targets/hal/TARGET_Freescale/TARGET_KLXX/pwmout_api.c index 3a7be521da..ddefd05b59 100644 --- a/libraries/mbed/targets/hal/TARGET_Freescale/TARGET_KLXX/pwmout_api.c +++ b/libraries/mbed/targets/hal/TARGET_Freescale/TARGET_KLXX/pwmout_api.c @@ -78,12 +78,12 @@ void pwmout_write(pwmout_t* obj, float value) { value = 1.0; } - *obj->CnV = (uint32_t)((float)(*obj->MOD) * value); + *obj->CnV = (uint32_t)((float)(*obj->MOD + 1) * value); *obj->CNT = 0; } float pwmout_read(pwmout_t* obj) { - float v = (float)(*obj->CnV) / (float)(*obj->MOD); + float v = (float)(*obj->CnV) / (float)(*obj->MOD + 1); return (v > 1.0) ? (1.0) : (v); } @@ -98,7 +98,7 @@ void pwmout_period_ms(pwmout_t* obj, int ms) { // Set the PWM period, keeping the duty cycle the same. void pwmout_period_us(pwmout_t* obj, int us) { float dc = pwmout_read(obj); - *obj->MOD = (uint32_t)(pwm_clock * (float)us); + *obj->MOD = (uint32_t)(pwm_clock * (float)us) - 1; pwmout_write(obj, dc); }