Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding Support for DCC++ HAT #22

Open
wants to merge 13 commits into
base: master
Choose a base branch
from
3 changes: 2 additions & 1 deletion DCCpp_Uno/Config.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,9 @@ Part of DCC++ BASE STATION for the Arduino
//
// 0 = ARDUINO MOTOR SHIELD (MAX 18V/2A PER CHANNEL)
// 1 = POLOLU MC33926 MOTOR SHIELD (MAX 28V/3A PER CHANNEL)
// 2 = CESM DCC++ HAT (MAX 28V/5A PER CHANNEL)

#define MOTOR_SHIELD_TYPE 0
#define MOTOR_SHIELD_TYPE 2

/////////////////////////////////////////////////////////////////////////////////////
//
Expand Down
2 changes: 1 addition & 1 deletion DCCpp_Uno/CurrentMonitor.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ Part of DCC++ BASE STATION for the Arduino
#define CURRENT_SAMPLE_SMOOTHING 0.01
#define CURRENT_SAMPLE_MAX 300

#ifdef ARDUINO_AVR_UNO // Configuration for UNO
#ifdef ARDUINO_AVR_UNO // Configuration for UNO/DCC++ HAT
#define CURRENT_SAMPLE_TIME 10
#else // Configuration for MEGA
#define CURRENT_SAMPLE_TIME 1
Expand Down
29 changes: 25 additions & 4 deletions DCCpp_Uno/DCCpp_Uno.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ Part of DCC++ BASE STATION for the Arduino
// RELEASE VERSION
/////////////////////////////////////////////////////////////////////////////////////

#define VERSION "1.2.1+"
#define VERSION "1.2.2+"

/////////////////////////////////////////////////////////////////////////////////////
// AUTO-SELECT ARDUINO BOARD
Expand All @@ -28,14 +28,22 @@ Part of DCC++ BASE STATION for the Arduino

#if defined ARDUINO_AVR_UNO

#define ARDUINO_TYPE "UNO"
#if MOTOR_SHIELD_TYPE == 3

#define ARDUINO_TYPE "DCC++ HAT"

#else

#define ARDUINO_TYPE "UNO"

#endif

#define DCC_SIGNAL_PIN_MAIN 10 // Ardunio Uno - uses OC1B
#define DCC_SIGNAL_PIN_PROG 5 // Arduino Uno - uses OC0B

#if COMM_INTERFACE != 0 // Serial was not selected

#error CANNOT COMPILE - DCC++ FOR THE UNO CAN ONLY USE SERIAL COMMUNICATION - PLEASE SELECT THIS IN THE CONFIG FILE
#error CANNOT COMPILE - DCC++ FOR THE UNO/DCC++ HAT CAN ONLY USE SERIAL COMMUNICATION - PLEASE SELECT THIS IN THE CONFIG FILE

#endif

Expand All @@ -48,7 +56,7 @@ Part of DCC++ BASE STATION for the Arduino

#else

#error CANNOT COMPILE - DCC++ ONLY WORKS WITH AN ARDUINO UNO OR AN ARDUINO MEGA 1280/2560
#error CANNOT COMPILE - DCC++ ONLY WORKS WITH AN ARDUINO UNO, DCC++ HAT, OR AN ARDUINO MEGA 1280/2560

#endif

Expand Down Expand Up @@ -82,6 +90,19 @@ Part of DCC++ BASE STATION for the Arduino
#define DIRECTION_MOTOR_CHANNEL_PIN_A 7
#define DIRECTION_MOTOR_CHANNEL_PIN_B 8

#elif MOTOR_SHIELD_TYPE == 2

#define MOTOR_SHIELD_NAME "DCC++ HAT - INTEGRATED MOTOR DRIVER"

#define SIGNAL_ENABLE_PIN_MAIN 3
#define SIGNAL_ENABLE_PIN_PROG 11

#define CURRENT_MONITOR_PIN_MAIN A0
#define CURRENT_MONITOR_PIN_PROG A1

#define DIRECTION_MOTOR_CHANNEL_PIN_A 10
#define DIRECTION_MOTOR_CHANNEL_PIN_B 5

#else

#error CANNOT COMPILE - PLEASE SELECT A PROPER MOTOR SHIELD TYPE
Expand Down
30 changes: 20 additions & 10 deletions DCCpp_Uno/DCCpp_Uno.ino
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@ COPYRIGHT (c) 2013-2016 Gregg E. Berman
DCC++ BASE STATION is a C++ program written for the Arduino Uno and Arduino Mega
using the Arduino IDE 1.6.6.

It allows a standard Arduino Uno or Mega with an Arduino Motor Shield (as well as others)
to be used as a fully-functioning digital command and control (DCC) base station
for controlling model train layouts that conform to current National Model
It allows a standard Arduino Uno or Mega with an Arduino Motor Shield (as well as others),
or a DCC++ Raspberry Pi HAT, to be used as a fully-functioning digital command and control
(DCC) base station for controlling model train layouts that conform to current National Model
Railroad Association (NMRA) DCC standards.

This version of DCC++ BASE STATION supports:
Expand All @@ -46,11 +46,18 @@ This version of DCC++ BASE STATION supports:
DCC++ BASE STATION is controlled with simple text commands received via
the Arduino's serial interface. Users can type these commands directly
into the Arduino IDE Serial Monitor, or can send such commands from another
device or computer program.
device or computer program. On the DCC++ HAT, serial commands are sent directly through
the UART port available on the GPIO haeder of the Raspberry Pi.

When compiled for the Arduino Mega, an Ethernet Shield can be used for network
communications instead of using serial communications.

When the DCC++ HAT is used, programming must be carried out by the ICSP header. The programmer
cab be most any arduino board. Upload the ArduinoISP program from the examples to the Arduino,
connect the ISP header to the Arduino as specified in the example code, and then plug the
Arduino into your computer and select Sketch>Upload using Programmer. Ensure that you have selected
the "Arduino/Genuino Uno" option and "Arduino as ISP" from the Tools menu.

DCC++ CONTROLLER, available separately under a similar open-source
license, is a Java program written using the Processing library and Processing IDE
that provides a complete and configurable graphic interface to control model train layouts
Expand Down Expand Up @@ -79,8 +86,8 @@ REFERENCES:

BRIEF NOTES ON THE THEORY AND OPERATION OF DCC++ BASE STATION:

DCC++ BASE STATION for the Uno configures the OC0B interrupt pin associated with Timer 0,
and the OC1B interupt pin associated with Timer 1, to generate separate 0-5V
DCC++ BASE STATION for the Uno/DCC++ HAT configures the OC0B interrupt pin associated
with Timer 0, and the OC1B interupt pin associated with Timer 1, to generate separate 0-5V
unipolar signals that each properly encode zero and one bits conforming with
DCC timing standards. When compiled for the Mega, DCC++ BASE STATION uses OC3B instead of OC0B.

Expand Down Expand Up @@ -129,11 +136,14 @@ For the Mega, the OC1B output is produced directly on pin 12, so no jumper is ne
Motor Shield's DIRECTION A input. However, one small jumper wire is needed to connect the Mega's OC3B output (pin 2)
to the Motor Shield's DIRECTION B input (pin 13).

For the DCC++ HAT, all pins are properly connected to the motor driver chip (5A), and no jumpers are required.

Other Motor Shields may require different sets of jumper or configurations (see Config.h and DCCpp_Uno.h for details).

When configured as such, the CHANNEL A and CHANNEL B outputs of the Motor Shield may be
connected directly to the tracks. This software assumes CHANNEL A is connected
to the Main Operations Track, and CHANNEL B is connected to the Programming Track.
to the Main Operations Track, and CHANNEL B is connected to the Programming Track. The
Programming Track and the Main Operations Track are labelled on the DCC++ HAT.

DCC++ BASE STATION in split into multiple modules, each with its own header file:

Expand Down Expand Up @@ -234,7 +244,7 @@ void setup(){
if(!digitalRead(A5))
showConfiguration();

Serial.print("<iDCC++ BASE STATION FOR ARDUINO "); // Print Status to Serial Line regardless of COMM_TYPE setting so use can open Serial Monitor and check configurtion
Serial.print("<iDCC++ BASE STATION"); // Print Status to Serial Line regardless of COMM_TYPE setting so user can open Serial Monitor and check configurtion
Serial.print(ARDUINO_TYPE);
Serial.print(" / ");
Serial.print(MOTOR_SHIELD_NAME);
Expand Down Expand Up @@ -309,7 +319,7 @@ void setup(){

// CONFIGURE EITHER TIMER_0 (UNO) OR TIMER_3 (MEGA) TO OUTPUT 50% DUTY CYCLE DCC SIGNALS ON OC0B (UNO) OR OC3B (MEGA) INTERRUPT PINS

#ifdef ARDUINO_AVR_UNO // Configuration for UNO
#ifdef ARDUINO_AVR_UNO // Configuration for UNO/DCC++ HAT

// Directon Pin for Motor Shield Channel B - PROGRAMMING TRACK
// Controlled by Arduino 8-bit TIMER 0 / OC0B Interrupt Pin
Expand Down Expand Up @@ -458,7 +468,7 @@ ISR(TIMER1_COMPB_vect){ // set interrupt service for OCR1B of TIMER
DCC_SIGNAL(mainRegs,1)
}

#ifdef ARDUINO_AVR_UNO // Configuration for UNO
#ifdef ARDUINO_AVR_UNO // Configuration for UNO/DCC++ HAT

ISR(TIMER0_COMPB_vect){ // set interrupt service for OCR1B of TIMER-0 which flips direction bit of Motor Shield Channel B controlling Prog Track
DCC_SIGNAL(progRegs,0)
Expand Down
2 changes: 1 addition & 1 deletion DCCpp_Uno/SerialCommand.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -458,7 +458,7 @@ void SerialCommand::parse(char *com){
bitSet(TCCR1B,CS11);
bitClear(TCCR1B,CS10);

#ifdef ARDUINO_AVR_UNO // Configuration for UNO
#ifdef ARDUINO_AVR_UNO // Configuration for UNO/DCC++ HAT

bitSet(TCCR0B,CS02); // set Timer 0 prescale=256 - SLOWS NORMAL SPEED BY A FACTOR OF 4
bitClear(TCCR0B,CS01);
Expand Down
Binary file added Hardware/BOM.pdf
Binary file not shown.
Loading