[STM32F3] Fix for pmw period change

The new period needs to be saved before the duty cycle is updated as
the period is used in pwmout_write function.

Also presclaer shall better be initiliazed properly.
pull/2103/head
Laurent MEUNIER 2016-06-28 16:16:58 +02:00
parent e56b9d06b7
commit fd4941f3f4
1 changed files with 4 additions and 3 deletions

View File

@ -69,6 +69,7 @@ void pwmout_init(pwmout_t* obj, PinName pin)
obj->pin = pin;
obj->period = 0;
obj->pulse = 0;
obj->prescaler = 1;
pwmout_period_us(obj, 20000); // 20 ms per default
}
@ -188,12 +189,12 @@ void pwmout_period_us(pwmout_t* obj, int us)
error("Cannot initialize PWM");
}
// Set duty cycle again
pwmout_write(obj, dc);
// Save for future use
obj->period = us;
// Set duty cycle again
pwmout_write(obj, dc);
__HAL_TIM_ENABLE(&TimHandle);
}