Skip to content

Commit

Permalink
Merge pull request #371 from toyowata/master
Browse files Browse the repository at this point in the history
[LPC11XX] Fixed PwmOut spike pulse issue
  • Loading branch information
0xc0170 committed Jun 24, 2014
2 parents f5d3245 + 27a7514 commit fb26733
Showing 1 changed file with 9 additions and 2 deletions.
Expand Up @@ -109,11 +109,15 @@ void pwmout_write(pwmout_t* obj, float value) {
} else if (value > 1.0f) {
value = 1.0;
}

timer_mr tid = pwm_timer_map[obj->pwm];
LPC_TMR_TypeDef *timer = Timers[tid.timer];
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->MR[tid.mr] = t_off;
timer->TCR = TCR_CNT_EN;
Expand All @@ -124,6 +128,9 @@ float pwmout_read(pwmout_t* obj) {
LPC_TMR_TypeDef *timer = Timers[tid.timer];

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);
}

Expand Down

0 comments on commit fb26733

Please sign in to comment.