aikopras / AP_DCC_Decoder_Core

Core library for DCC accessory decoders that use the RS-Bus for feedback. PoM feedback messages use (instead of RailCom) the RS-Bus with address 128.
GNU General Public License v3.0
0 stars 0 forks source link

The DCC decoder core

Direct links:

Purpose

Implements the common core functions and objects needed by every DCC decoder that supports Configuration Variables (CVs) and feedback via RS-Bus messages. It builds upon the AP_DCC_library and the RSBus library.

The DCC decoder core initialises the DCC and RS-Bus hardware, by using the pin and USART settings as defined in boards.h.

The core functions handle most of the Programming on the Main (PoM) and Service Mode (Programming track) messages and support Configuration Variables (CVs) for different kind of decoders; these CVs can be remotely accessed via SM and PoM. A speciality is that PoM feedback messages will not be send via RailCom, but via the RS-Bus using address 128. Dedicated MAC programs are available that use this setup to configure these CVs; these programs can be downloaded from:

If the user pushes the programming button, the core functions respond by initialising the decoder's DCC and/or RS-Bus addresses based on the next DCC address that is received. The core functions provide an onboard LED object, to signal events to the user, and an onboard button object, to allow the user to configure a new address.

The library has been tested on traditional ATMega processors, such as the ATMega 16A, ATMega 328 (UNO, Nano) and ATMega2560 (Mega), but also on the newer MegaAVR processors, such as 4808 (Thinary), 4809 (Nano Every) and the AVR128DA. For the design of new boards the use of these newer processors is recommended. Note that dedicated "boards" may need to be installed in the Arduino IDE to support these processors, such as MightyCore, MegaCore, MegaCoreX and DxCore. For each board the mapping between external (DCC and RS-Bus) signals and Arduino pin numbers is defined in the boards.h file.


Using the DCC Decoder Core

The only library file that needs to be included by the main sketch is AP_Accessory_Common.h. This header file includes the following header files and libraries: CvValues.h, AP_DCC_library, RSbus, AP_DccButton, AP_DccLED and AP_DccTimer. Instead of AP_Accessory_Common.h, it is also possible to include individual header files if limited functionality is needed only.

DCC decoder objects and classes

The following objects and classes become available to the user sketch:


Example

A skeleton that shows the basic usage of the core functions (without RS-Bus feedback) is shown below.
Each decoder should call in setup() cvValues.init() as well as decoderHardware.init(). The main loop should call dcc.input() to check if a new DCC message has been received, and decoderHardware.update() to update the onboard LED and check if the programming button was pushed.

#include <AP_DCC_Decoder_Core.h>

void setup() {
  cvValues.init(SwitchDecoder, 20);
  decoderHardware.init();
}

void loop() {
  // Do something with the DCC message received ...
  if (dcc.input()) {};
  // Check if the programming button is pushed; handle CV PoM and SM messages
  decoderHardware.update();
}

A more elaborate example, which includes feedback via the RS_Bus, is shown BasicDecoder.md.