I am using a PWM output to control a high power LED by an LPC11U35. The LED is turned on by a N MOSFET when the PWM output is high. Also, the output pin is pulled down externally by 3K3 to make sure the MOSFET is stays off until the output is initialized.
If I this minimal program that does nothing:
static PwmOut led_r(P0_8); should set PWM value to 0
void main() {
for(;;) {}
}
The LED flickers once upon startup even though the initialization of the PWM output is supposed to initialize it to zero.
Looking at the PWM code at https://developer.mbed.org/users/mbed_official/code/mbed-src/file/a11c0372f0ba/targets/hal/TARGET_NXP/TARGET_LPC11UXX/pwmout_api.c it seems that the flicker happens because it enables the initialization code enables the output before the timer completed the first cycle which is the point where it resets the output pin.
Original code
default to 20ms: standard for servos, and fine for e.g. brightness control
pwmout_period_ms(obj, 20);
pwmout_write (obj, 0);
Wire pinout
pinmap_pinout(pin, PinMap_PWM);
Changing the pinout statement such that it occurs when the timer is held on zero fixes the problem
timer->TCR = TCR_RESET; new
pinmap_pinout(pin, PinMap_PWM);
timer->TCR = TCR_CNT_EN; new
Is this a reasonable fix?
What would be the process to have it integrated with the main mbed code line?
Thanks,
Zapta
I am using a PWM output to control a high power LED by an LPC11U35. The LED is turned on by a N MOSFET when the PWM output is high. Also, the output pin is pulled down externally by 3K3 to make sure the MOSFET is stays off until the output is initialized.
If I this minimal program that does nothing:
static PwmOut led_r(P0_8); should set PWM value to 0
void main() { for(;;) {} }
The LED flickers once upon startup even though the initialization of the PWM output is supposed to initialize it to zero.
Looking at the PWM code at https://developer.mbed.org/users/mbed_official/code/mbed-src/file/a11c0372f0ba/targets/hal/TARGET_NXP/TARGET_LPC11UXX/pwmout_api.c it seems that the flicker happens because it enables the initialization code enables the output before the timer completed the first cycle which is the point where it resets the output pin.
Original code
default to 20ms: standard for servos, and fine for e.g. brightness control pwmout_period_ms(obj, 20); pwmout_write (obj, 0);
Wire pinout pinmap_pinout(pin, PinMap_PWM);
Changing the pinout statement such that it occurs when the timer is held on zero fixes the problem
timer->TCR = TCR_RESET; new pinmap_pinout(pin, PinMap_PWM); timer->TCR = TCR_CNT_EN; new
Is this a reasonable fix?
What would be the process to have it integrated with the main mbed code line?
Thanks,
Zapta