Skip to content

Commit b3e2763

Browse files
committed
[LPC11U68, LPC1549] Improved PwmOut Documentation
Improved commenting in pwmout_write(), pwmout_period_us(), and pwmout_pulsewidth_us().
1 parent 792b359 commit b3e2763

File tree

2 files changed

+24
-2
lines changed

2 files changed

+24
-2
lines changed

libraries/mbed/targets/hal/TARGET_NXP/TARGET_LPC11U6X/pwmout_api.c

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,11 +137,14 @@ void pwmout_write(pwmout_t* obj, float value) {
137137
uint32_t t_on = (uint32_t)((float)(pwm->MATCHREL0 + 1) * value);
138138
if (t_on > 0) {
139139
pwm->MATCHREL1 = t_on - 1;
140+
141+
// Un-halt the timer and ensure the new pulse-width takes immediate effect if necessary
140142
if (pwm->CTRL & (1 << 2)) {
141143
pwm->MATCH1 = pwm->MATCHREL1;
142144
pwm->CTRL &= ~(1 << 2);
143145
}
144146
} else {
147+
// Halt the timer and force the output low
145148
pwm->CTRL |= (1 << 2) | (1 << 3);
146149
pwm->OUTPUT = 0x00000000;
147150
}
@@ -174,15 +177,20 @@ void pwmout_period_us(pwmout_t* obj, int us) {
174177
pwm->MATCHREL0 = period_ticks - 1;
175178
if (pulsewidth_ticks > 0) {
176179
pwm->MATCHREL1 = pulsewidth_ticks - 1;
180+
181+
// Un-halt the timer and ensure the new period & pulse-width take immediate effect if necessary
177182
if (pwm->CTRL & (1 << 2)) {
178183
pwm->MATCH0 = pwm->MATCHREL0;
179184
pwm->MATCH1 = pwm->MATCHREL1;
180185
pwm->CTRL &= ~(1 << 2);
181186
}
182187
} else {
188+
// Halt the timer and force the output low
183189
pwm->CTRL |= (1 << 2) | (1 << 3);
184-
pwm->MATCH0 = pwm->MATCHREL0;
185190
pwm->OUTPUT = 0x00000000;
191+
192+
// Ensure the new period will take immediate effect when the timer is un-halted
193+
pwm->MATCH0 = pwm->MATCHREL0;
186194
}
187195
}
188196

@@ -198,11 +206,14 @@ void pwmout_pulsewidth_us(pwmout_t* obj, int us) {
198206
LPC_SCT0_Type* pwm = obj->pwm;
199207
if (us > 0) {
200208
pwm->MATCHREL1 = (uint32_t)(((uint64_t)SystemCoreClock * (uint64_t)us) / (uint64_t)1000000) - 1;
209+
210+
// Un-halt the timer and ensure the new pulse-width takes immediate effect if necessary
201211
if (pwm->CTRL & (1 << 2)) {
202212
pwm->MATCH1 = pwm->MATCHREL1;
203213
pwm->CTRL &= ~(1 << 2);
204214
}
205215
} else {
216+
// Halt the timer and force the output low
206217
pwm->CTRL |= (1 << 2) | (1 << 3);
207218
pwm->OUTPUT = 0x00000000;
208219
}

libraries/mbed/targets/hal/TARGET_NXP/TARGET_LPC15XX/pwmout_api.c

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,11 +118,14 @@ void pwmout_write(pwmout_t* obj, float value) {
118118
uint32_t t_on = (uint32_t)((float)(pwm->MATCHREL0 + 1) * value);
119119
if (t_on > 0) {
120120
pwm->MATCHREL1 = t_on - 1;
121+
122+
// Un-halt the timer and ensure the new pulse-width takes immediate effect if necessary
121123
if (pwm->CTRL & (1 << 2)) {
122124
pwm->MATCH1 = pwm->MATCHREL1;
123125
pwm->CTRL &= ~(1 << 2);
124126
}
125127
} else {
128+
// Halt the timer and force the output low
126129
pwm->CTRL |= (1 << 2) | (1 << 3);
127130
pwm->OUTPUT = 0x00000000;
128131
}
@@ -155,15 +158,20 @@ void pwmout_period_us(pwmout_t* obj, int us) {
155158
pwm->MATCHREL0 = period_ticks - 1;
156159
if (pulsewidth_ticks > 0) {
157160
pwm->MATCHREL1 = pulsewidth_ticks - 1;
161+
162+
// Un-halt the timer and ensure the new period & pulse-width take immediate effect if necessary
158163
if (pwm->CTRL & (1 << 2)) {
159164
pwm->MATCH0 = pwm->MATCHREL0;
160165
pwm->MATCH1 = pwm->MATCHREL1;
161166
pwm->CTRL &= ~(1 << 2);
162167
}
163168
} else {
169+
// Halt the timer and force the output low
164170
pwm->CTRL |= (1 << 2) | (1 << 3);
165-
pwm->MATCH0 = pwm->MATCHREL0;
166171
pwm->OUTPUT = 0x00000000;
172+
173+
// Ensure the new period will take immediate effect when the timer is un-halted
174+
pwm->MATCH0 = pwm->MATCHREL0;
167175
}
168176
}
169177

@@ -179,11 +187,14 @@ void pwmout_pulsewidth_us(pwmout_t* obj, int us) {
179187
LPC_SCT0_Type* pwm = obj->pwm;
180188
if (us > 0) {
181189
pwm->MATCHREL1 = (uint32_t)(((uint64_t)SystemCoreClock * (uint64_t)us) / (uint64_t)1000000) - 1;
190+
191+
// Un-halt the timer and ensure the new pulse-width takes immediate effect if necessary
182192
if (pwm->CTRL & (1 << 2)) {
183193
pwm->MATCH1 = pwm->MATCHREL1;
184194
pwm->CTRL &= ~(1 << 2);
185195
}
186196
} else {
197+
// Halt the timer and force the output low
187198
pwm->CTRL |= (1 << 2) | (1 << 3);
188199
pwm->OUTPUT = 0x00000000;
189200
}

0 commit comments

Comments
 (0)