mirror of https://github.com/ARMmbed/mbed-os.git
[LPC1114] Fixed PwmOut spike pulse issue
[LPC1114] Fixed PwmOut spike pulse issue when duty is 0%.pull/371/head
parent
f5d3245fe9
commit
27a7514c6e
|
|
@ -113,6 +113,10 @@ void pwmout_write(pwmout_t* obj, float value) {
|
||||||
timer_mr tid = pwm_timer_map[obj->pwm];
|
timer_mr tid = pwm_timer_map[obj->pwm];
|
||||||
LPC_TMR_TypeDef *timer = Timers[tid.timer];
|
LPC_TMR_TypeDef *timer = Timers[tid.timer];
|
||||||
uint32_t t_off = timer->MR3 - (uint32_t)((float)(timer->MR3) * value);
|
uint32_t t_off = timer->MR3 - (uint32_t)((float)(timer->MR3) * value);
|
||||||
|
// to avoid spike pulse when duty is 0%
|
||||||
|
if (value == 0) {
|
||||||
|
t_off++;
|
||||||
|
}
|
||||||
|
|
||||||
timer->TCR = TCR_RESET;
|
timer->TCR = TCR_RESET;
|
||||||
timer->MR[tid.mr] = t_off;
|
timer->MR[tid.mr] = t_off;
|
||||||
|
|
@ -124,6 +128,9 @@ float pwmout_read(pwmout_t* obj) {
|
||||||
LPC_TMR_TypeDef *timer = Timers[tid.timer];
|
LPC_TMR_TypeDef *timer = Timers[tid.timer];
|
||||||
|
|
||||||
float v = (float)(timer->MR3 - timer->MR[tid.mr]) / (float)(timer->MR3);
|
float v = (float)(timer->MR3 - timer->MR[tid.mr]) / (float)(timer->MR3);
|
||||||
|
if (timer->MR[tid.mr] > timer->MR3) {
|
||||||
|
v = 0.0f;
|
||||||
|
}
|
||||||
return (v > 1.0f) ? (1.0f) : (v);
|
return (v > 1.0f) ? (1.0f) : (v);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue