mbed library sources. Supersedes mbed-src. GR-PEACH runs on RAM.
Fork of mbed-dev by
Revision 82:98895dd43cc3, committed 2016-03-05
- Comitter:
- mbed_official
- Date:
- Sat Mar 05 06:00:11 2016 +0000
- Parent:
- 81:8b5f63428415
- Child:
- 83:a036322b8637
- Commit message:
- Synchronized with git revision abf43a33ced3bd9088802574c4d56480c16bc143
Full URL: https://github.com/mbedmicro/mbed/commit/abf43a33ced3bd9088802574c4d56480c16bc143/
[LPC11U68, LPC1549] Fixed PwmOut SCT Bugs
Changed in this revision
--- a/targets/hal/TARGET_NXP/TARGET_LPC11U6X/pwmout_api.c Fri Mar 04 11:30:11 2016 +0000
+++ b/targets/hal/TARGET_NXP/TARGET_LPC11U6X/pwmout_api.c Sat Mar 05 06:00:11 2016 +0000
@@ -137,16 +137,23 @@
uint32_t t_on = (uint32_t)((float)(pwm->MATCHREL0 + 1) * value);
if (t_on > 0) {
pwm->MATCHREL1 = t_on - 1;
- pwm->CTRL &= ~(1 << 2);
+
+ // Un-halt the timer and ensure the new pulse-width takes immediate effect if necessary
+ if (pwm->CTRL & (1 << 2)) {
+ pwm->MATCH1 = pwm->MATCHREL1;
+ pwm->CTRL &= ~(1 << 2);
+ }
} else {
+ // Halt the timer and force the output low
pwm->CTRL |= (1 << 2) | (1 << 3);
pwm->OUTPUT = 0x00000000;
}
}
float pwmout_read(pwmout_t* obj) {
- uint32_t t_off = obj->pwm->MATCHREL0 + 1;
- uint32_t t_on = obj->pwm->MATCHREL1 + 1;
+ LPC_SCT0_Type* pwm = obj->pwm;
+ uint32_t t_off = pwm->MATCHREL0 + 1;
+ uint32_t t_on = (!(pwm->CTRL & (1 << 2))) ? pwm->MATCHREL1 + 1 : 0;
float v = (float)t_on/(float)t_off;
return (v > 1.0f) ? (1.0f) : (v);
}
@@ -163,17 +170,27 @@
void pwmout_period_us(pwmout_t* obj, int us) {
LPC_SCT0_Type* pwm = obj->pwm;
uint32_t t_off = pwm->MATCHREL0 + 1;
- uint32_t t_on = pwm->MATCHREL1 + 1;
+ uint32_t t_on = (!(pwm->CTRL & (1 << 2))) ? pwm->MATCHREL1 + 1 : 0;
float v = (float)t_on/(float)t_off;
uint32_t period_ticks = (uint32_t)(((uint64_t)SystemCoreClock * (uint64_t)us) / (uint64_t)1000000);
uint32_t pulsewidth_ticks = period_ticks * v;
pwm->MATCHREL0 = period_ticks - 1;
if (pulsewidth_ticks > 0) {
pwm->MATCHREL1 = pulsewidth_ticks - 1;
- pwm->CTRL &= ~(1 << 2);
+
+ // Un-halt the timer and ensure the new period & pulse-width take immediate effect if necessary
+ if (pwm->CTRL & (1 << 2)) {
+ pwm->MATCH0 = pwm->MATCHREL0;
+ pwm->MATCH1 = pwm->MATCHREL1;
+ pwm->CTRL &= ~(1 << 2);
+ }
} else {
+ // Halt the timer and force the output low
pwm->CTRL |= (1 << 2) | (1 << 3);
pwm->OUTPUT = 0x00000000;
+
+ // Ensure the new period will take immediate effect when the timer is un-halted
+ pwm->MATCH0 = pwm->MATCHREL0;
}
}
@@ -189,8 +206,14 @@
LPC_SCT0_Type* pwm = obj->pwm;
if (us > 0) {
pwm->MATCHREL1 = (uint32_t)(((uint64_t)SystemCoreClock * (uint64_t)us) / (uint64_t)1000000) - 1;
- pwm->CTRL &= ~(1 << 2);
+
+ // Un-halt the timer and ensure the new pulse-width takes immediate effect if necessary
+ if (pwm->CTRL & (1 << 2)) {
+ pwm->MATCH1 = pwm->MATCHREL1;
+ pwm->CTRL &= ~(1 << 2);
+ }
} else {
+ // Halt the timer and force the output low
pwm->CTRL |= (1 << 2) | (1 << 3);
pwm->OUTPUT = 0x00000000;
}
--- a/targets/hal/TARGET_NXP/TARGET_LPC15XX/pwmout_api.c Fri Mar 04 11:30:11 2016 +0000
+++ b/targets/hal/TARGET_NXP/TARGET_LPC15XX/pwmout_api.c Sat Mar 05 06:00:11 2016 +0000
@@ -118,16 +118,23 @@
uint32_t t_on = (uint32_t)((float)(pwm->MATCHREL0 + 1) * value);
if (t_on > 0) {
pwm->MATCHREL1 = t_on - 1;
- pwm->CTRL &= ~(1 << 2);
+
+ // Un-halt the timer and ensure the new pulse-width takes immediate effect if necessary
+ if (pwm->CTRL & (1 << 2)) {
+ pwm->MATCH1 = pwm->MATCHREL1;
+ pwm->CTRL &= ~(1 << 2);
+ }
} else {
+ // Halt the timer and force the output low
pwm->CTRL |= (1 << 2) | (1 << 3);
pwm->OUTPUT = 0x00000000;
}
}
float pwmout_read(pwmout_t* obj) {
- uint32_t t_off = obj->pwm->MATCHREL0 + 1;
- uint32_t t_on = obj->pwm->MATCHREL1 + 1;
+ LPC_SCT0_Type* pwm = obj->pwm;
+ uint32_t t_off = pwm->MATCHREL0 + 1;
+ uint32_t t_on = (!(pwm->CTRL & (1 << 2))) ? pwm->MATCHREL1 + 1 : 0;
float v = (float)t_on/(float)t_off;
return (v > 1.0f) ? (1.0f) : (v);
}
@@ -144,17 +151,27 @@
void pwmout_period_us(pwmout_t* obj, int us) {
LPC_SCT0_Type* pwm = obj->pwm;
uint32_t t_off = pwm->MATCHREL0 + 1;
- uint32_t t_on = pwm->MATCHREL1 + 1;
+ uint32_t t_on = (!(pwm->CTRL & (1 << 2))) ? pwm->MATCHREL1 + 1 : 0;
float v = (float)t_on/(float)t_off;
uint32_t period_ticks = (uint32_t)(((uint64_t)SystemCoreClock * (uint64_t)us) / (uint64_t)1000000);
uint32_t pulsewidth_ticks = period_ticks * v;
pwm->MATCHREL0 = period_ticks - 1;
if (pulsewidth_ticks > 0) {
pwm->MATCHREL1 = pulsewidth_ticks - 1;
- pwm->CTRL &= ~(1 << 2);
+
+ // Un-halt the timer and ensure the new period & pulse-width take immediate effect if necessary
+ if (pwm->CTRL & (1 << 2)) {
+ pwm->MATCH0 = pwm->MATCHREL0;
+ pwm->MATCH1 = pwm->MATCHREL1;
+ pwm->CTRL &= ~(1 << 2);
+ }
} else {
+ // Halt the timer and force the output low
pwm->CTRL |= (1 << 2) | (1 << 3);
pwm->OUTPUT = 0x00000000;
+
+ // Ensure the new period will take immediate effect when the timer is un-halted
+ pwm->MATCH0 = pwm->MATCHREL0;
}
}
@@ -170,8 +187,14 @@
LPC_SCT0_Type* pwm = obj->pwm;
if (us > 0) {
pwm->MATCHREL1 = (uint32_t)(((uint64_t)SystemCoreClock * (uint64_t)us) / (uint64_t)1000000) - 1;
- pwm->CTRL &= ~(1 << 2);
+
+ // Un-halt the timer and ensure the new pulse-width takes immediate effect if necessary
+ if (pwm->CTRL & (1 << 2)) {
+ pwm->MATCH1 = pwm->MATCHREL1;
+ pwm->CTRL &= ~(1 << 2);
+ }
} else {
+ // Halt the timer and force the output low
pwm->CTRL |= (1 << 2) | (1 << 3);
pwm->OUTPUT = 0x00000000;
}
