Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[LPC11XX] Fixed PwmOut spike pulse issue #371

Merged
merged 1 commit into from Jun 24, 2014
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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