From 678cccbd9521174d3261298c7656099a5ee0da23 Mon Sep 17 00:00:00 2001 From: Asbelos Date: Wed, 2 Mar 2022 15:34:01 +0000 Subject: [PATCH] Add DC signal generation code. --- MotorDriver.cpp | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/MotorDriver.cpp b/MotorDriver.cpp index a20bf0d..348a954 100644 --- a/MotorDriver.cpp +++ b/MotorDriver.cpp @@ -167,10 +167,17 @@ int MotorDriver::getCurrentRaw() { } void MotorDriver::setDCSignal(byte speedcode) { - // spedcxode is a dcc speed /direction - // TODO jiggle the DC speed pin PWMs - + // spedcoode is a dcc speed /direction + byte tSpeed=speedcode & 0x7F; + // DCC Speed with 0,1 stop and speed steps 2 to 127 + byte brake; + if (tSpeed <= 1) brake = 255; + else if (tSpeed >= 127) brake = 0; + else brake = 2 * (128-tSpeed); + analogWrite(brakePin,brake); + setSignal(speedcode & 0x80); } + int MotorDriver::getCurrentRawInInterrupt() { // IMPORTANT: This function must be called in Interrupt() time within the 56uS timer