From 9d9c6edc2fab9e600492db7cda8f48c98568e9ca Mon Sep 17 00:00:00 2001 From: Harald Barth Date: Fri, 10 Jul 2020 01:03:47 +0200 Subject: [PATCH] Pololu on Mega seems OK --- Config.h | 18 +++++++++++------- DCCWaveform.cpp | 1 + Hardware.cpp | 2 ++ 3 files changed, 14 insertions(+), 7 deletions(-) diff --git a/Config.h b/Config.h index aaf1d9e..597eff4 100644 --- a/Config.h +++ b/Config.h @@ -3,19 +3,23 @@ // This hardware configuration would normally be setup using a bunch of #ifdefs. -const byte MAIN_POWER_PIN = 3; -const byte MAIN_SIGNAL_PIN = 12; +const byte MAIN_POWER_PIN = 4; +const byte MAIN_SIGNAL_PIN = 7; const byte MAIN_SIGNAL_PIN_ALT = 0; // for hardware that flipflops signal pins const byte MAIN_SENSE_PIN = A0; const byte MAIN_BRAKE_PIN = 9; -const float MAIN_SENSE_FACTOR=1.717; // analgRead(MAIN_SENSE_PIN) * MAIN_SENSE_FACTOR = milliamps -const byte PROG_POWER_PIN = 11; -const byte PROG_SIGNAL_PIN = 13; +const int MAIN_MAX_MILLIAMPS=2000; +const float MAIN_SENSE_FACTOR=18; // analgRead(MAIN_SENSE_PIN) * MAIN_SENSE_FACTOR = milliamps + +const byte PROG_POWER_PIN = 2; +const byte PROG_SIGNAL_PIN = 8; const byte PROG_SIGNAL_PIN_ALT = 0; // for hardware that flipflops signal pins const byte PROG_SENSE_PIN = A1; -const byte PROG_BRAKE_PIN = 8; -const float PROG_SENSE_FACTOR=1.717; // analgRead(PROG_SENSE_PIN) * PROG_SENSE_FACTOR = milliamps +const byte PROG_BRAKE_PIN = 10; + +const int PROG_MAX_MILLIAMPS=250; +const float PROG_SENSE_FACTOR=18; // analgRead(PROG_SENSE_PIN) * PROG_SENSE_FACTOR = milliamps // Allocations with memory implications..! // Base system takes approx 900 bytes + 8 per loco. Turnouts, Sensors etc are dynamically created diff --git a/DCCWaveform.cpp b/DCCWaveform.cpp index c696575..e162555 100644 --- a/DCCWaveform.cpp +++ b/DCCWaveform.cpp @@ -73,6 +73,7 @@ POWERMODE DCCWaveform::getPowerMode() { void DCCWaveform::setPowerMode(POWERMODE mode) { powerMode = mode; Hardware::setPower(isMainTrack, mode == POWERMODE::ON); + Hardware::setBrake(isMainTrack, mode == POWERMODE::OFF); if (mode == POWERMODE::ON) delay(200); } diff --git a/Hardware.cpp b/Hardware.cpp index 04bf3d5..6bd189d 100644 --- a/Hardware.cpp +++ b/Hardware.cpp @@ -15,11 +15,13 @@ void Hardware::init() { pinMode(MAIN_POWER_PIN, OUTPUT); + pinMode(MAIN_BRAKE_PIN, OUTPUT); pinMode(MAIN_SIGNAL_PIN, OUTPUT); if (MAIN_SIGNAL_PIN_ALT) pinMode(MAIN_SIGNAL_PIN_ALT, OUTPUT); pinMode(MAIN_SENSE_PIN, INPUT); pinMode(PROG_POWER_PIN, OUTPUT); + pinMode(PROG_BRAKE_PIN, OUTPUT); pinMode(PROG_SIGNAL_PIN, OUTPUT); if (PROG_SIGNAL_PIN_ALT) pinMode(PROG_SIGNAL_PIN_ALT, OUTPUT); pinMode(PROG_SENSE_PIN, INPUT);