Skip to content

[LPC812] Fix PwmOut conflict issue #1758

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

Merged
merged 1 commit into from
May 23, 2016
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -152,10 +152,18 @@ void pwmout_write(pwmout_t* obj, float value) {
uint32_t t_off = (uint32_t)((float)(obj->pwm->MATCHREL[0].U) * value);
obj->pwm->MATCHREL[(obj->pwm_ch) + 1].U = t_off; // New endtime

// Clear OxRES (conflict resolution register) bit first, effect of simultaneous set and clear on output x
int offset = (obj->pwm_ch * 2);
obj->pwm->RES &= ~(0x3 << offset);

if (value == 0.0f) { // duty is 0%
// Clear output
obj->pwm->RES |= (0x2 << offset);
// Set CLR event to be same as SET event, makes output to be 0 (low)
obj->pwm->OUT[(obj->pwm_ch)].CLR = (1 << 0);
} else {
// Set output
obj->pwm->RES |= (0x1 << offset);
// Use normal CLR event (current SCT ch + 1)
obj->pwm->OUT[(obj->pwm_ch)].CLR = (1 << ((obj->pwm_ch) + 1));
}
Expand Down