1
0
mirror of https://github.com/DCC-EX/CommandStation-EX.git synced 2024-11-27 01:56:14 +01:00

ESP32 rewrite PWM LEDC inrush duty fix

This commit is contained in:
Harald Barth 2024-04-05 01:10:10 +02:00
parent fdc956576b
commit 6d7d2325da
3 changed files with 4 additions and 4 deletions

View File

@ -68,7 +68,7 @@ class DCCTimer {
static void DCCEXanalogWrite(uint8_t pin, int value); static void DCCEXanalogWrite(uint8_t pin, int value);
static void DCCEXledcDetachPin(uint8_t pin); static void DCCEXledcDetachPin(uint8_t pin);
static void DCCEXanalogCopyChannel(uint8_t frompin, uint8_t topin); static void DCCEXanalogCopyChannel(uint8_t frompin, uint8_t topin);
static void DCCEXInrushControlOn(uint8_t pin); static void DCCEXInrushControlOn(uint8_t pin, int duty);
// Update low ram level. Allow for extra bytes to be specified // Update low ram level. Allow for extra bytes to be specified
// by estimation or inspection, that may be used by other // by estimation or inspection, that may be used by other
// called subroutines. Must be called with interrupts disabled. // called subroutines. Must be called with interrupts disabled.

View File

@ -245,10 +245,10 @@ void DCCTimer::DCCEXanalogWrite(uint8_t pin, int value) {
ledcWrite(pin_to_channel[pin], value); ledcWrite(pin_to_channel[pin], value);
} }
} }
void DCCTimer::DCCEXInrushControlOn(uint8_t pin) { void DCCTimer::DCCEXInrushControlOn(uint8_t pin, int duty) {
ledcSetup(0, 62500, 8); ledcSetup(0, 62500, 8);
ledcAttachPin(pin, 0); ledcAttachPin(pin, 0);
ledcWrite(0, 207); ledcWrite(0, duty);
} }
int ADCee::init(uint8_t pin) { int ADCee::init(uint8_t pin) {

View File

@ -411,7 +411,7 @@ void MotorDriver::throttleInrush(bool on) {
duty = 255-duty; duty = 255-duty;
#if defined(ARDUINO_ARCH_ESP32) #if defined(ARDUINO_ARCH_ESP32)
if(on) { if(on) {
DCCTimer::DCCEXInrushControlOn(brakePin); DCCTimer::DCCEXInrushControlOn(brakePin, duty);
} else { } else {
ledcDetachPin(brakePin); // not DCCTimer::DCCEXledcDetachPin() as we have not ledcDetachPin(brakePin); // not DCCTimer::DCCEXledcDetachPin() as we have not
// registered the pin in the pin to channel array // registered the pin in the pin to channel array