Marlin FW - Analogwrite for PWM control
Posted: Sat Aug 29, 2020 2:38 pm
Hello,
I am currently playing with my 3D printer to add some LED strip. In the Marlin FW, the RGBW leds are controlled with an Analogwrite function such as in the standard arduino example:
Although this method kind of works, the brightness of the led strip is at max roughly 50% of the max possible (ie connected to +12V). I don't understand why fully (I don't have an oscilloscope to look at the output) but it is what it is.
I tried a small program based on the page
https://github.com/stm32duino/wiki/wiki ... er-library
In that case, I am getting the full brightness at max.
Without rewriting the Marlin FW, what would you recommend to do?
Optimal solution: analogwrite directly using the PWM hardwaretimer of the STM32
Thank you for your feedback
I am currently playing with my 3D printer to add some LED strip. In the Marlin FW, the RGBW leds are controlled with an Analogwrite function such as in the standard arduino example:
Code: Select all
void loop() {
// fade in from min to max in increments of 5 points:
for (int fadeValue = 0 ; fadeValue <= 255; fadeValue += 5) {
// sets the value (range from 0 to 255):
analogWrite(ledPin, fadeValue);
// wait for 30 milliseconds to see the dimming effect
delay(30);
}
// fade out from max to min in increments of 5 points:
for (int fadeValue = 255 ; fadeValue >= 0; fadeValue -= 5) {
// sets the value (range from 0 to 255):
analogWrite(ledPin, fadeValue);
// wait for 30 milliseconds to see the dimming effect
delay(30);
}
}
I tried a small program based on the page
https://github.com/stm32duino/wiki/wiki ... er-library
Code: Select all
void setup() {
TIM_TypeDef *Instance = (TIM_TypeDef *)pinmap_peripheral(digitalPinToPinName(ledPin), PinMap_PWM);
uint32_t channel = STM_PIN_CHANNEL(pinmap_function(digitalPinToPinName(ledPin), PinMap_PWM));
// Instantiate HardwareTimer object. Thanks to 'new' instantiation, HardwareTimer is not destructed when setup() function is finished.
HardwareTimer *MyTim = new HardwareTimer(Instance);
// Configure and start PWM
// MyTim->setPWM(channel, pin, 5, 10, NULL, NULL); // No callback required, we can simplify the function call
MyTim->setPWM(channel, ledPin, 5000, 10);
delay(5000);
for (;;){
for (int fadeValue = 0 ; fadeValue <= 100; fadeValue += 2) {
MyTim->setPWM(channel, ledPin, 10000, fadeValue);
delay(100);
}
for (int fadeValue = 100 ; fadeValue >= 0; fadeValue -= 2) {
MyTim->setPWM(channel, ledPin, 10000, fadeValue);
delay(100);
}
}
}
Without rewriting the Marlin FW, what would you recommend to do?
Optimal solution: analogwrite directly using the PWM hardwaretimer of the STM32
Thank you for your feedback