Skip to content

Commit b395dd5

Browse files
committed
Merge branch 'toyowata-master'
2 parents f74fc12 + 9c525e2 commit b395dd5

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

hal/targets/hal/TARGET_NXP/TARGET_LPC81X/pwmout_api.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,10 +152,18 @@ void pwmout_write(pwmout_t* obj, float value) {
152152
uint32_t t_off = (uint32_t)((float)(obj->pwm->MATCHREL[0].U) * value);
153153
obj->pwm->MATCHREL[(obj->pwm_ch) + 1].U = t_off; // New endtime
154154

155+
// Clear OxRES (conflict resolution register) bit first, effect of simultaneous set and clear on output x
156+
int offset = (obj->pwm_ch * 2);
157+
obj->pwm->RES &= ~(0x3 << offset);
158+
155159
if (value == 0.0f) { // duty is 0%
160+
// Clear output
161+
obj->pwm->RES |= (0x2 << offset);
156162
// Set CLR event to be same as SET event, makes output to be 0 (low)
157163
obj->pwm->OUT[(obj->pwm_ch)].CLR = (1 << 0);
158164
} else {
165+
// Set output
166+
obj->pwm->RES |= (0x1 << offset);
159167
// Use normal CLR event (current SCT ch + 1)
160168
obj->pwm->OUT[(obj->pwm_ch)].CLR = (1 << ((obj->pwm_ch) + 1));
161169
}

0 commit comments

Comments
 (0)