1
0
mirror of https://github.com/DCC-EX/CommandStation-EX.git synced 2024-11-30 03:26:13 +01:00

STM32 reinstate 100% duty cycle PWM

This commit is contained in:
pmantoine 2023-10-04 14:54:06 +08:00
parent 7afd4443d6
commit 2ff1619ad1

View File

@ -306,18 +306,18 @@ void DCCTimer::DCCEXanalogWrite(uint8_t pin, int value) {
// Calculate percentage duty cycle from value given // Calculate percentage duty cycle from value given
uint32_t duty_cycle = (value * 100 / 256) + 1; uint32_t duty_cycle = (value * 100 / 256) + 1;
if (pin_timer[pin] != NULL) { if (pin_timer[pin] != NULL) {
if (duty_cycle == 100) // if (duty_cycle == 100)
{ // {
pin_timer[pin]->pauseChannel(pin_channel[pin]); // pin_timer[pin]->pauseChannel(pin_channel[pin]);
DIAG(F("DCCEXanalogWrite::Pausing timer channel on pin %d"), pin); // DIAG(F("DCCEXanalogWrite::Pausing timer channel on pin %d"), pin);
} // }
else // else
{ // {
pinmap_pinout(digitalPinToPinName(pin), PinMap_TIM); // ensure the pin has been configured! pinmap_pinout(digitalPinToPinName(pin), PinMap_TIM); // ensure the pin has been configured!
pin_timer[pin]->resumeChannel(pin_channel[pin]); // pin_timer[pin]->resumeChannel(pin_channel[pin]);
pin_timer[pin]->setCaptureCompare(pin_channel[pin], duty_cycle, PERCENT_COMPARE_FORMAT); // DCC_EX_PWM_FREQ Hertz, duty_cycle% dutycycle pin_timer[pin]->setCaptureCompare(pin_channel[pin], duty_cycle, PERCENT_COMPARE_FORMAT); // DCC_EX_PWM_FREQ Hertz, duty_cycle% dutycycle
DIAG(F("DCCEXanalogWrite::Pin %d, value %d, duty cycle %d"), pin, value, duty_cycle); DIAG(F("DCCEXanalogWrite::Pin %d, value %d, duty cycle %d"), pin, value, duty_cycle);
} // }
} }
else else
DIAG(F("DCCEXanalogWrite::Pin %d is not configured for PWM!"), pin); DIAG(F("DCCEXanalogWrite::Pin %d is not configured for PWM!"), pin);