Compare commits
11 Commits
Author | SHA1 | Date | |
---|---|---|---|
|
dafa1c9964 | ||
|
dcbd20ef7e | ||
|
e622a596d7 | ||
|
4c1d5fd6e4 | ||
|
3a5986d10d | ||
|
9035e55930 | ||
|
3eee73f6cd | ||
|
d3059d2f4e | ||
|
0c3385b27d | ||
|
e0d46ff9b9 | ||
|
0bab98c838 |
107
NmraDcc.cpp
107
NmraDcc.cpp
@@ -20,6 +20,8 @@
|
||||
// Experimental Version to support 14 speed steps
|
||||
// and new signature of notifyDccSpeed and notifyDccFunc
|
||||
// 2015-12-16 Version without use of Timer0 by Franz-Peter Müller
|
||||
// 2016-07-16 handle glitches on DCC line
|
||||
// 2016-08-20 added ESP8266 support by Sven (littleyoda)
|
||||
//
|
||||
//------------------------------------------------------------------------
|
||||
//
|
||||
@@ -29,7 +31,12 @@
|
||||
//------------------------------------------------------------------------
|
||||
|
||||
#include "NmraDcc.h"
|
||||
|
||||
#if defined(ESP8266)
|
||||
#include <EEPROM.h>
|
||||
#else
|
||||
#include <avr/eeprom.h>
|
||||
#endif
|
||||
|
||||
//------------------------------------------------------------------------
|
||||
// DCC Receive Routine
|
||||
@@ -60,14 +67,14 @@
|
||||
//
|
||||
// |<-----116us----->|
|
||||
// DCC 1: _________XXXXXXXXX_________XXXXXXXXX_________
|
||||
// |<--------138us------>|
|
||||
// |<--------146us------>|
|
||||
// ^-INTx ^-INTx
|
||||
// less than 138us: its a one-Bit
|
||||
//
|
||||
//
|
||||
// |<-----------------232us----------->|
|
||||
// DCC 0: _________XXXXXXXXXXXXXXXXXX__________________XXXXXXXX__________
|
||||
// |<--------138us------->|
|
||||
// |<--------146us------->|
|
||||
// ^-INTx ^-INTx
|
||||
// greater than 138us: its a zero bit
|
||||
//
|
||||
@@ -76,8 +83,12 @@
|
||||
//
|
||||
//------------------------------------------------------------------------
|
||||
#define MAX_ONEBITFULL 146
|
||||
#define MAX_PRAEAMBEL 146 //138
|
||||
#define MAX_PRAEAMBEL 146
|
||||
#define MAX_ONEBITHALF 82
|
||||
#define MIN_ONEBITFULL 82
|
||||
#define MIN_ONEBITHALF 35
|
||||
#define MAX_BITDIFF 18
|
||||
|
||||
|
||||
// Debug-Ports
|
||||
//#define debug // Testpulse for logic analyser
|
||||
@@ -192,7 +203,7 @@ struct countOf_t countOf;
|
||||
#endif
|
||||
|
||||
static byte ISREdge; // RISING or FALLING
|
||||
static word bitMax;
|
||||
static word bitMax, bitMin;
|
||||
|
||||
typedef enum
|
||||
{
|
||||
@@ -228,6 +239,7 @@ typedef struct
|
||||
#ifdef DCC_DEBUG
|
||||
uint8_t IntCount;
|
||||
uint8_t TickCount;
|
||||
uint8_t NestedIrqCount;
|
||||
#endif
|
||||
}
|
||||
DCC_PROCESSOR_STATE ;
|
||||
@@ -240,19 +252,38 @@ void ExternalInterruptHandler(void)
|
||||
uint8_t DccBitVal;
|
||||
static int8_t bit1, bit2 ;
|
||||
static word lastMicros;
|
||||
static byte halfBit;
|
||||
static byte halfBit, DCC_IrqRunning;
|
||||
unsigned int actMicros, bitMicros;
|
||||
if ( DCC_IrqRunning ) {
|
||||
// nested DCC IRQ - obviously there are glitches
|
||||
// ignore this interrupt and increment glitchcounter
|
||||
CLR_TP3;
|
||||
#ifdef DCC_DEBUG
|
||||
DccProcState.NestedIrqCount++;
|
||||
#endif
|
||||
SET_TP3;
|
||||
return; //>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> abort IRQ
|
||||
}
|
||||
SET_TP3;
|
||||
actMicros = micros();
|
||||
bitMicros = actMicros-lastMicros;
|
||||
if ( bitMicros < bitMin ) {
|
||||
// too short - my be false interrupt due to glitch or false protocol -> ignore
|
||||
CLR_TP3;
|
||||
SET_TP4;
|
||||
SET_TP4;
|
||||
CLR_TP4;
|
||||
return; //>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> abort IRQ
|
||||
}
|
||||
DccBitVal = ( bitMicros < bitMax );
|
||||
lastMicros = actMicros;
|
||||
//#ifdef debug
|
||||
if(DccBitVal) {SET_TP2} else {CLR_TP2};
|
||||
if(DccBitVal) {SET_TP2;} else {CLR_TP2;};
|
||||
//#endif
|
||||
DCC_IrqRunning = true;
|
||||
sei(); // time critical is only the micros() command,so allow nested irq's
|
||||
#ifdef DCC_DEBUG
|
||||
DccProcState.TickCount++;
|
||||
DccProcState.TickCount++;
|
||||
#endif
|
||||
|
||||
switch( DccRx.State )
|
||||
@@ -269,6 +300,7 @@ void ExternalInterruptHandler(void)
|
||||
attachInterrupt( DccProcState.ExtIntNum, ExternalInterruptHandler, CHANGE);
|
||||
halfBit = 0;
|
||||
bitMax = MAX_ONEBITHALF;
|
||||
bitMin = MIN_ONEBITHALF;
|
||||
CLR_TP1;
|
||||
}
|
||||
} else {
|
||||
@@ -299,12 +331,13 @@ void ExternalInterruptHandler(void)
|
||||
halfBit = 0;
|
||||
bit2=bitMicros;
|
||||
DccRx.BitCount++;
|
||||
if( abs(bit2-bit1) > 14 ) {
|
||||
// the length of the 2 halbits differ too much -> wrong protokoll
|
||||
if( abs(bit2-bit1) > MAX_BITDIFF ) {
|
||||
// the length of the 2 halfbits differ too much -> wrong protokoll
|
||||
CLR_TP2;
|
||||
CLR_TP3;
|
||||
DccRx.State = WAIT_PREAMBLE;
|
||||
bitMax = MAX_PRAEAMBEL;
|
||||
bitMin = MIN_ONEBITFULL;
|
||||
DccRx.BitCount = 0;
|
||||
attachInterrupt( DccProcState.ExtIntNum, ExternalInterruptHandler, ISREdge );
|
||||
SET_TP3;
|
||||
@@ -320,6 +353,7 @@ void ExternalInterruptHandler(void)
|
||||
// its a '1' halfbit -> we got only a half '0' bit -> cannot be DCC
|
||||
DccRx.State = WAIT_PREAMBLE;
|
||||
bitMax = MAX_PRAEAMBEL;
|
||||
bitMin = MIN_ONEBITFULL;
|
||||
DccRx.BitCount = 0;
|
||||
} else {
|
||||
// we got two '0' halfbits -> it's the startbit
|
||||
@@ -327,6 +361,7 @@ void ExternalInterruptHandler(void)
|
||||
if ( ISREdge == RISING ) ISREdge = FALLING; else ISREdge = RISING;
|
||||
DccRx.State = WAIT_DATA ;
|
||||
bitMax = MAX_ONEBITFULL;
|
||||
bitMin = MIN_ONEBITFULL;
|
||||
DccRx.PacketBuf.Size = 0;
|
||||
DccRx.PacketBuf.PreambleBits = 0;
|
||||
for(uint8_t i = 0; i< MAX_DCC_MESSAGE_LEN; i++ )
|
||||
@@ -345,11 +380,13 @@ void ExternalInterruptHandler(void)
|
||||
// second halfbit is 1 -> unknown protokoll
|
||||
DccRx.State = WAIT_PREAMBLE;
|
||||
bitMax = MAX_PRAEAMBEL;
|
||||
bitMin = MIN_ONEBITFULL;
|
||||
DccRx.BitCount = 0;
|
||||
} else {
|
||||
// we got the startbit
|
||||
DccRx.State = WAIT_DATA ;
|
||||
bitMax = MAX_ONEBITFULL;
|
||||
bitMin = MIN_ONEBITFULL;
|
||||
DccRx.PacketBuf.Size = 0;
|
||||
DccRx.PacketBuf.PreambleBits = 0;
|
||||
for(uint8_t i = 0; i< MAX_DCC_MESSAGE_LEN; i++ )
|
||||
@@ -378,6 +415,7 @@ void ExternalInterruptHandler(void)
|
||||
{
|
||||
DccRx.State = WAIT_PREAMBLE ;
|
||||
bitMax = MAX_PRAEAMBEL;
|
||||
bitMin = MIN_ONEBITFULL;
|
||||
DccRx.BitCount = 0 ;
|
||||
}
|
||||
else
|
||||
@@ -395,6 +433,7 @@ void ExternalInterruptHandler(void)
|
||||
CLR_TP3;
|
||||
DccRx.State = WAIT_PREAMBLE ;
|
||||
bitMax = MAX_PRAEAMBEL;
|
||||
bitMin = MIN_ONEBITFULL;
|
||||
DccRx.PacketCopy = DccRx.PacketBuf ;
|
||||
DccRx.DataReady = 1 ;
|
||||
SET_TP3;
|
||||
@@ -407,6 +446,7 @@ void ExternalInterruptHandler(void)
|
||||
}
|
||||
CLR_TP1;
|
||||
CLR_TP3;
|
||||
DCC_IrqRunning = false;
|
||||
}
|
||||
|
||||
void ackCV(void)
|
||||
@@ -415,6 +455,32 @@ void ackCV(void)
|
||||
notifyCVAck() ;
|
||||
}
|
||||
|
||||
uint8_t readEEPROM( unsigned int CV ) {
|
||||
#if defined(ESP8266)
|
||||
return EEPROM.read(CV) ;
|
||||
#else
|
||||
return eeprom_read_byte( (uint8_t*) CV );
|
||||
#endif
|
||||
}
|
||||
|
||||
void writeEEPROM( unsigned int CV, uint8_t Value ) {
|
||||
#if defined(ESP8266)
|
||||
EEPROM.write(CV, Value) ;
|
||||
EEPROM.commit();
|
||||
#else
|
||||
eeprom_write_byte( (uint8_t*) CV, Value ) ;
|
||||
#endif
|
||||
}
|
||||
|
||||
bool readyEEPROM() {
|
||||
#if defined(ESP8266)
|
||||
return true;
|
||||
#else
|
||||
return eeprom_is_ready();
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
uint8_t validCV( uint16_t CV, uint8_t Writable )
|
||||
{
|
||||
if( notifyCVResetFactoryDefault && (CV == CV_MANUFACTURER_ID ) && Writable )
|
||||
@@ -425,7 +491,7 @@ uint8_t validCV( uint16_t CV, uint8_t Writable )
|
||||
|
||||
uint8_t Valid = 1 ;
|
||||
|
||||
if( CV > E2END )
|
||||
if( CV > MAXCV )
|
||||
Valid = 0 ;
|
||||
|
||||
if( Writable && ( ( CV ==CV_VERSION_ID ) || (CV == CV_MANUFACTURER_ID ) ) )
|
||||
@@ -441,8 +507,7 @@ uint8_t readCV( unsigned int CV )
|
||||
if( notifyCVRead )
|
||||
return notifyCVRead( CV ) ;
|
||||
|
||||
Value = eeprom_read_byte( (uint8_t*) CV ) ;
|
||||
|
||||
Value = readEEPROM(CV);
|
||||
return Value ;
|
||||
}
|
||||
|
||||
@@ -451,14 +516,14 @@ uint8_t writeCV( unsigned int CV, uint8_t Value)
|
||||
if( notifyCVWrite )
|
||||
return notifyCVWrite( CV, Value ) ;
|
||||
|
||||
if( eeprom_read_byte( (uint8_t*) CV ) != Value )
|
||||
if( readEEPROM( CV ) != Value )
|
||||
{
|
||||
eeprom_write_byte( (uint8_t*) CV, Value ) ;
|
||||
writeEEPROM( CV, Value ) ;
|
||||
|
||||
if( notifyCVChange )
|
||||
notifyCVChange( CV, Value) ;
|
||||
}
|
||||
return eeprom_read_byte( (uint8_t*) CV ) ;
|
||||
return readEEPROM( CV ) ;
|
||||
}
|
||||
|
||||
uint16_t getMyAddr(void)
|
||||
@@ -946,6 +1011,9 @@ void NmraDcc::initAccessoryDecoder( uint8_t ManufacturerId, uint8_t VersionId, u
|
||||
|
||||
void NmraDcc::init( uint8_t ManufacturerId, uint8_t VersionId, uint8_t Flags, uint8_t OpsModeAddressBaseCV )
|
||||
{
|
||||
#if defined(ESP8266)
|
||||
EEPROM.begin(MAXCV);
|
||||
#endif
|
||||
// Clear all the static member variables
|
||||
memset( &DccRx, 0, sizeof( DccRx) );
|
||||
|
||||
@@ -955,6 +1023,7 @@ void NmraDcc::init( uint8_t ManufacturerId, uint8_t VersionId, uint8_t Flags, ui
|
||||
MODE_TP4;
|
||||
ISREdge = RISING;
|
||||
bitMax = MAX_ONEBITFULL;
|
||||
bitMin = MIN_ONEBITFULL;
|
||||
attachInterrupt( DccProcState.ExtIntNum, ExternalInterruptHandler, RISING);
|
||||
|
||||
DccProcState.Flags = Flags ;
|
||||
@@ -990,8 +1059,7 @@ uint8_t NmraDcc::isSetCVReady(void)
|
||||
{
|
||||
if(notifyIsSetCVReady)
|
||||
return notifyIsSetCVReady();
|
||||
|
||||
return eeprom_is_ready();
|
||||
return readyEEPROM();
|
||||
}
|
||||
|
||||
#ifdef DCC_DEBUG
|
||||
@@ -1005,6 +1073,11 @@ uint8_t NmraDcc::getTickCount(void)
|
||||
return DccProcState.TickCount;
|
||||
}
|
||||
|
||||
uint8_t NmraDcc::getNestedIrqCount(void)
|
||||
{
|
||||
return DccProcState.NestedIrqCount;
|
||||
}
|
||||
|
||||
uint8_t NmraDcc::getState(void)
|
||||
{
|
||||
return DccRx.State;
|
||||
|
@@ -89,7 +89,13 @@ typedef struct
|
||||
#define CV_VERSION_ID 7
|
||||
#define CV_MANUFACTURER_ID 8
|
||||
#define CV_29_CONFIG 29
|
||||
|
||||
#if defined(ESP8266)
|
||||
#include <spi_flash.h>
|
||||
#define MAXCV SPI_FLASH_SEC_SIZE
|
||||
#else
|
||||
#define MAXCV E2END // the upper limit of the CV value currently defined to max memory.
|
||||
#endif
|
||||
|
||||
typedef enum {
|
||||
CV29_LOCO_DIR = 0b00000001, /** bit 0: Locomotive Direction: "0" = normal, "1" = reversed */
|
||||
@@ -203,6 +209,7 @@ class NmraDcc
|
||||
uint8_t getTickCount(void);
|
||||
uint8_t getBitCount(void);
|
||||
uint8_t getState(void);
|
||||
uint8_t getNestedIrqCount(void);
|
||||
#endif
|
||||
|
||||
};
|
||||
|
@@ -1,5 +1,5 @@
|
||||
// Production 17 Function DCC Decoder
|
||||
// Version 5.1 Geoff Bunza 2014,2015,2016
|
||||
// Version 5.4 Geoff Bunza 2014,2015,2016
|
||||
// NO LONGER REQUIRES modified software servo Lib
|
||||
// Software restructuring mods added from Alex Shepherd and Franz-Peter
|
||||
// With sincere thanks
|
||||
@@ -16,7 +16,7 @@
|
||||
#include <NmraDcc.h>
|
||||
#include <SoftwareServo.h>
|
||||
|
||||
SoftwareServo servo[16];
|
||||
SoftwareServo servo[17];
|
||||
#define servo_start_delay 50
|
||||
#define servo_init_delay 7
|
||||
#define servo_slowdown 3 //servo loop counter limit
|
||||
@@ -299,7 +299,7 @@ void loop() //****************************************************************
|
||||
// from the Arduino loop() function for correct library operation
|
||||
Dcc.process();
|
||||
SoftwareServo::refresh();
|
||||
delay(8);
|
||||
delay(4);
|
||||
for (int i=0; i < numfpins; i++) {
|
||||
if (ftn_queue[i].inuse==1) {
|
||||
|
||||
|
@@ -16,7 +16,7 @@
|
||||
#include <NmraDcc.h>
|
||||
#include <SoftwareServo.h>
|
||||
|
||||
SoftwareServo servo[16];
|
||||
SoftwareServo servo[17];
|
||||
#define servo_start_delay 50
|
||||
#define servo_init_delay 7
|
||||
#define servo_slowdown 3 //servo loop counter limit
|
||||
@@ -299,7 +299,7 @@ void loop() //****************************************************************
|
||||
// from the Arduino loop() function for correct library operation
|
||||
Dcc.process();
|
||||
SoftwareServo::refresh();
|
||||
delay(8);
|
||||
delay(4);
|
||||
for (int i=0; i < numfpins; i++) {
|
||||
if (ftn_queue[i].inuse==1) {
|
||||
|
||||
|
@@ -1,5 +1,5 @@
|
||||
// Production 17 Function DCC Decoder
|
||||
// Version 5.1 Geoff Bunza 2014,2015,2016
|
||||
// Version 5.4 Geoff Bunza 2014,2015,2016
|
||||
// NO LONGER REQUIRES modified software servo Lib
|
||||
// Software restructuring mods added from Alex Shepherd and Franz-Peter
|
||||
// With sincere thanks
|
||||
@@ -16,7 +16,7 @@
|
||||
#include <NmraDcc.h>
|
||||
#include <SoftwareServo.h>
|
||||
|
||||
SoftwareServo servo[16];
|
||||
SoftwareServo servo[17];
|
||||
#define servo_start_delay 50
|
||||
#define servo_init_delay 7
|
||||
#define servo_slowdown 3 //servo loop counter limit
|
||||
@@ -293,7 +293,7 @@ void loop() //****************************************************************
|
||||
// from the Arduino loop() function for correct library operation
|
||||
Dcc.process();
|
||||
SoftwareServo::refresh();
|
||||
delay(8);
|
||||
delay(4);
|
||||
for (int i=0; i < numfpins; i++) {
|
||||
if (ftn_queue[i].inuse==1) {
|
||||
|
||||
|
@@ -1,5 +1,5 @@
|
||||
// Production 17 Function DCC Decoder
|
||||
// Version 5.1 Geoff Bunza 2014,2015,2016
|
||||
// Version 5.4 Geoff Bunza 2014,2015,2016
|
||||
|
||||
// ******** UNLESS YOU WANT ALL CV'S RESET UPON EVERY POWER UP
|
||||
// ******** AFTER THE INITIAL DECODER LOAD REMOVE THE "//" IN THE FOOLOWING LINE!!
|
||||
|
@@ -1,5 +1,5 @@
|
||||
// Production 17 Function DCC Decoder
|
||||
// Version 5.1 Geoff Bunza 2014,2015,2016
|
||||
// Version 5.4 Geoff Bunza 2014,2015,2016
|
||||
// NO LONGER REQUIRES modified software servo Lib
|
||||
// Software restructuring mods added from Alex Shepherd and Franz-Peter
|
||||
// With sincere thanks
|
||||
@@ -16,7 +16,7 @@
|
||||
#include <NmraDcc.h>
|
||||
#include <SoftwareServo.h>
|
||||
|
||||
SoftwareServo servo[16];
|
||||
SoftwareServo servo[17];
|
||||
#define servo_start_delay 50
|
||||
#define servo_init_delay 7
|
||||
#define servo_slowdown 3 //servo loop counter limit
|
||||
@@ -299,7 +299,7 @@ void loop() //****************************************************************
|
||||
// from the Arduino loop() function for correct library operation
|
||||
Dcc.process();
|
||||
SoftwareServo::refresh();
|
||||
delay(8);
|
||||
delay(4);
|
||||
for (int i=0; i < numfpins; i++) {
|
||||
if (ftn_queue[i].inuse==1) {
|
||||
|
||||
|
@@ -1,5 +1,5 @@
|
||||
// Production 17 Function DCC Decoder
|
||||
// Version 5.1 Geoff Bunza 2014,2015,2016
|
||||
// Version 5.4 Geoff Bunza 2014,2015,2016
|
||||
// NO LONGER REQUIRES modified software servo Lib
|
||||
// Software restructuring mods added from Alex Shepherd and Franz-Peter
|
||||
// With sincere thanks
|
||||
@@ -19,7 +19,7 @@
|
||||
#include <NmraDcc.h>
|
||||
#include <SoftwareServo.h>
|
||||
|
||||
SoftwareServo servo[16];
|
||||
SoftwareServo servo[17];
|
||||
#define servo_start_delay 50
|
||||
#define servo_init_delay 7
|
||||
#define servo_slowdown 3 //servo loop counter limit
|
||||
@@ -302,7 +302,7 @@ void loop() //****************************************************************
|
||||
// from the Arduino loop() function for correct library operation
|
||||
Dcc.process();
|
||||
SoftwareServo::refresh();
|
||||
delay(8);
|
||||
delay(4);
|
||||
for (int i=0; i < numfpins; i++) {
|
||||
if (ftn_queue[i].inuse==1) {
|
||||
|
||||
|
@@ -1,5 +1,5 @@
|
||||
// Production 17 Function DCC Decoder
|
||||
// Version 5.1 Geoff Bunza 2014,2015,2016
|
||||
// Version 5.4 Geoff Bunza 2014,2015,2016
|
||||
// NO LONGER REQUIRES modified software servo Lib
|
||||
// Software restructuring mods added from Alex Shepherd and Franz-Peter
|
||||
// With sincere thanks
|
||||
@@ -16,7 +16,7 @@
|
||||
#include <NmraDcc.h>
|
||||
#include <SoftwareServo.h>
|
||||
|
||||
SoftwareServo servo[16];
|
||||
SoftwareServo servo[17];
|
||||
#define servo_start_delay 50
|
||||
#define servo_init_delay 7
|
||||
#define servo_slowdown 3 //servo loop counter limit
|
||||
@@ -299,7 +299,7 @@ void loop() //****************************************************************
|
||||
// from the Arduino loop() function for correct library operation
|
||||
Dcc.process();
|
||||
SoftwareServo::refresh();
|
||||
delay(8);
|
||||
delay(4);
|
||||
for (int i=0; i < numfpins; i++) {
|
||||
if (ftn_queue[i].inuse==1) {
|
||||
|
||||
|
@@ -1,5 +1,5 @@
|
||||
// Production 17 Function DCC Decoder
|
||||
// Version 5.1 Geoff Bunza 2014,2015,2016
|
||||
// Version 5.4 Geoff Bunza 2014,2015,2016
|
||||
// NO LONGER REQUIRES modified software servo Lib
|
||||
// Software restructuring mods added from Alex Shepherd and Franz-Peter
|
||||
// With sincere thanks
|
||||
@@ -16,7 +16,7 @@
|
||||
#include <NmraDcc.h>
|
||||
#include <SoftwareServo.h>
|
||||
|
||||
SoftwareServo servo[16];
|
||||
SoftwareServo servo[17];
|
||||
#define servo_start_delay 50
|
||||
#define servo_init_delay 7
|
||||
#define servo_slowdown 3 //servo loop counter limit
|
||||
@@ -295,7 +295,7 @@ void loop() //****************************************************************
|
||||
// from the Arduino loop() function for correct library operation
|
||||
Dcc.process();
|
||||
SoftwareServo::refresh();
|
||||
delay(8);
|
||||
delay(4);
|
||||
for (int i=0; i < numfpins; i++) {
|
||||
if (ftn_queue[i].inuse==1) {
|
||||
|
||||
|
@@ -1,5 +1,5 @@
|
||||
// Production 17 Function DCC Decoder
|
||||
// Version 5.1 Geoff Bunza 2014,2015,2016
|
||||
// Version 5.4 Geoff Bunza 2014,2015,2016
|
||||
// NO LONGER REQUIRES modified software servo Lib
|
||||
// Software restructuring mods added from Alex Shepherd and Franz-Peter
|
||||
// With sincere thanks
|
||||
@@ -16,7 +16,7 @@
|
||||
#include <NmraDcc.h>
|
||||
#include <SoftwareServo.h>
|
||||
|
||||
SoftwareServo servo[16];
|
||||
SoftwareServo servo[17];
|
||||
#define servo_start_delay 50
|
||||
#define servo_init_delay 7
|
||||
#define servo_slowdown 3 //servo loop counter limit
|
||||
@@ -295,7 +295,7 @@ void loop() //****************************************************************
|
||||
// from the Arduino loop() function for correct library operation
|
||||
Dcc.process();
|
||||
SoftwareServo::refresh();
|
||||
delay(8);
|
||||
delay(4);
|
||||
for (int i=0; i < numfpins; i++) {
|
||||
if (ftn_queue[i].inuse==1) {
|
||||
|
||||
|
@@ -1,5 +1,5 @@
|
||||
// Production 17 Function DCC Decoder
|
||||
// Version 5.1 Geoff Bunza 2014,2015,2016
|
||||
// Version 5.4 Geoff Bunza 2014,2015,2016
|
||||
// NO LONGER REQUIRES modified software servo Lib
|
||||
// Software restructuring mods added from Alex Shepherd and Franz-Peter
|
||||
// With sincere thanks
|
||||
@@ -16,7 +16,7 @@
|
||||
#include <NmraDcc.h>
|
||||
#include <SoftwareServo.h>
|
||||
|
||||
SoftwareServo servo[16];
|
||||
SoftwareServo servo[17];
|
||||
#define servo_start_delay 50
|
||||
#define servo_init_delay 7
|
||||
#define servo_slowdown 3 //servo loop counter limit
|
||||
@@ -295,7 +295,7 @@ void loop() //****************************************************************
|
||||
// from the Arduino loop() function for correct library operation
|
||||
Dcc.process();
|
||||
SoftwareServo::refresh();
|
||||
delay(8);
|
||||
delay(4);
|
||||
for (int i=0; i < numfpins; i++) {
|
||||
if (ftn_queue[i].inuse==1) {
|
||||
|
||||
|
@@ -1,5 +1,5 @@
|
||||
// Production 17 Function DCC Decoder
|
||||
// Version 5.1 Geoff Bunza 2014,2015,2016
|
||||
// Version 5.4 Geoff Bunza 2014,2015,2016
|
||||
|
||||
// ******** UNLESS YOU WANT ALL CV'S RESET UPON EVERY POWER UP
|
||||
// ******** AFTER THE INITIAL DECODER LOAD REMOVE THE "//" IN THE FOOLOWING LINE!!
|
||||
@@ -33,7 +33,7 @@ const int FunctionPin15 = 18; //A4
|
||||
const int FunctionPin16 = 19; //A5
|
||||
NmraDcc Dcc ;
|
||||
DCC_MSG Packet ;
|
||||
|
||||
uint8_t CV_DECODER_MASTER_RESET = 120;
|
||||
#define This_Decoder_Address 24
|
||||
|
||||
struct CVPair
|
||||
@@ -47,6 +47,7 @@ CVPair FactoryDefaultCVs [] =
|
||||
{CV_ACCESSORY_DECODER_ADDRESS_MSB, 0},
|
||||
{CV_MULTIFUNCTION_EXTENDED_ADDRESS_MSB, 0},
|
||||
{CV_MULTIFUNCTION_EXTENDED_ADDRESS_LSB, 0},
|
||||
{CV_DECODER_MASTER_RESET, 0},
|
||||
};
|
||||
|
||||
uint8_t FactoryDefaultCVIndex = 4;
|
||||
|
@@ -1,5 +1,5 @@
|
||||
// Production 17 Function DCC Decoder
|
||||
// Version 5.1 Geoff Bunza 2014,2015,2016
|
||||
// Version 5.4 Geoff Bunza 2014,2015,2016
|
||||
// NO LONGER REQUIRES modified software servo Lib
|
||||
// Software restructuring mods added from Alex Shepherd and Franz-Peter
|
||||
// With sincere thanks
|
||||
@@ -15,7 +15,7 @@
|
||||
#include <NmraDcc.h>
|
||||
#include <SoftwareServo.h>
|
||||
|
||||
SoftwareServo servo[16];
|
||||
SoftwareServo servo[17];
|
||||
#define servo_start_delay 50
|
||||
#define servo_init_delay 7
|
||||
#define servo_slowdown 3 //servo loop counter limit
|
||||
@@ -295,7 +295,7 @@ void loop() //****************************************************************
|
||||
// from the Arduino loop() function for correct library operation
|
||||
Dcc.process();
|
||||
SoftwareServo::refresh();
|
||||
delay(8);
|
||||
delay(4);
|
||||
for (int i=0; i < numfpins; i++) {
|
||||
if (ftn_queue[i].inuse==1) {
|
||||
|
||||
|
@@ -1,5 +1,5 @@
|
||||
// Production 17 Function DCC Decoder
|
||||
// Version 5.1 Geoff Bunza 2014,2015,2016
|
||||
// Version 5.4 Geoff Bunza 2014,2015,2016
|
||||
// NO LONGER REQUIRES modified software servo Lib
|
||||
// Software restructuring mods added from Alex Shepherd and Franz-Peter
|
||||
// With sincere thanks
|
||||
@@ -15,7 +15,7 @@
|
||||
#include <NmraDcc.h>
|
||||
#include <SoftwareServo.h>
|
||||
|
||||
SoftwareServo servo[12];
|
||||
SoftwareServo servo[13];
|
||||
#define servo_start_delay 50
|
||||
#define servo_init_delay 7
|
||||
#define servo_slowdown 3 //servo loop counter limit
|
||||
|
@@ -1,5 +1,5 @@
|
||||
// Production 17 Function DCC Decoder
|
||||
// Version 5.1 Geoff Bunza 2014,2015,2016
|
||||
// Version 5.4 Geoff Bunza 2014,2015,2016
|
||||
// NO LONGER REQUIRES modified software servo Lib
|
||||
// Software restructuring mods added from Alex Shepherd and Franz-Peter
|
||||
// With sincere thanks
|
||||
@@ -16,7 +16,7 @@
|
||||
#include <NmraDcc.h>
|
||||
#include <SoftwareServo.h>
|
||||
|
||||
SoftwareServo servo[16];
|
||||
SoftwareServo servo[17];
|
||||
#define servo_start_delay 50
|
||||
#define servo_init_delay 7
|
||||
#define servo_slowdown 3 //servo loop counter limit
|
||||
@@ -295,7 +295,7 @@ void loop() //****************************************************************
|
||||
// from the Arduino loop() function for correct library operation
|
||||
Dcc.process();
|
||||
SoftwareServo::refresh();
|
||||
delay(8);
|
||||
delay(4);
|
||||
for (int i=0; i < numfpins; i++) {
|
||||
if (ftn_queue[i].inuse==1) {
|
||||
|
||||
|
@@ -1,5 +1,5 @@
|
||||
// Production 17 Function DCC Decoder
|
||||
// Version 5.1 Geoff Bunza 2014,2015,2016
|
||||
// Version 5.4 Geoff Bunza 2014,2015,2016
|
||||
// LED control is dependent on direction of travel
|
||||
// ******** UNLESS YOU WANT ALL CV'S RESET UPON EVERY POWER UP
|
||||
// ******** AFTER THE INITIAL DECODER LOAD REMOVE THE "//" IN THE FOOLOWING LINE!!
|
||||
@@ -44,6 +44,7 @@ const int FunctionPin15 = 18; //A4
|
||||
const int FunctionPin16 = 19; //A5
|
||||
NmraDcc Dcc ;
|
||||
DCC_MSG Packet ;
|
||||
uint8_t CV_DECODER_MASTER_RESET = 120;
|
||||
|
||||
#define This_Decoder_Address 24
|
||||
struct CVPair
|
||||
@@ -57,6 +58,7 @@ CVPair FactoryDefaultCVs [] =
|
||||
{CV_ACCESSORY_DECODER_ADDRESS_MSB, 0},
|
||||
{CV_MULTIFUNCTION_EXTENDED_ADDRESS_MSB, 0},
|
||||
{CV_MULTIFUNCTION_EXTENDED_ADDRESS_LSB, 0},
|
||||
{CV_DECODER_MASTER_RESET, 0},
|
||||
};
|
||||
uint8_t FactoryDefaultCVIndex = 0;
|
||||
void notifyCVResetFactoryDefault()
|
||||
|
@@ -1,5 +1,5 @@
|
||||
// Production 17 Function DCC Decoder
|
||||
// Version 5.1 Geoff Bunza 2014,2015,2016
|
||||
// Version 5.4 Geoff Bunza 2014,2015,2016
|
||||
// NO LONGER REQUIRES modified software servo Lib
|
||||
// Software restructuring mods added from Alex Shepherd and Franz-Peter
|
||||
// With sincere thanks
|
||||
@@ -66,6 +66,7 @@ const int FunctionPin15 = 18; //A4
|
||||
const int FunctionPin16 = 19; //A5
|
||||
NmraDcc Dcc ;
|
||||
DCC_MSG Packet ;
|
||||
uint8_t CV_DECODER_MASTER_RESET = 120;
|
||||
|
||||
#define This_Decoder_Address 24
|
||||
|
||||
@@ -80,6 +81,7 @@ CVPair FactoryDefaultCVs [] =
|
||||
{CV_ACCESSORY_DECODER_ADDRESS_MSB, 0},
|
||||
{CV_MULTIFUNCTION_EXTENDED_ADDRESS_MSB, 0},
|
||||
{CV_MULTIFUNCTION_EXTENDED_ADDRESS_LSB, 0},
|
||||
{CV_DECODER_MASTER_RESET, 0},
|
||||
};
|
||||
|
||||
uint8_t FactoryDefaultCVIndex = 0;
|
||||
|
@@ -1,12 +1,13 @@
|
||||
{\rtf1\ansi\ansicpg1252\deff0\deflang1033{\fonttbl{\f0\fswiss\fprq2\fcharset0 Calibri;}}
|
||||
{\*\generator Msftedit 5.41.15.1515;}\viewkind4\uc1\pard\sl276\slmult1\b\f0\fs24 Decoder Configuration Details\par
|
||||
{\rtf1\ansi\ansicpg1252\deff0\nouicompat\deflang1033{\fonttbl{\f0\fswiss\fprq2\fcharset0 Calibri;}}
|
||||
{\*\generator Riched20 10.0.10586}\viewkind4\uc1
|
||||
\pard\sl276\slmult1\b\f0\fs24 Decoder Configuration Details\par
|
||||
\par
|
||||
\b0 The multfunction decoder examples all for 4 functions to be assigned to any of the 17 available pins: on/off control, single line blinking with variable rate, servo control with start position/stop position/transit rate CV setting and end to end control via the function (on/off), and paired line blinking with variable rate.\par
|
||||
\b0 The multfunction decoder examples all for 6 functions to be assigned to any of the 17 available pins: on/off control, single line blinking with variable rate, servo control with start position/stop position/transit rate CV setting and end to end control via the function (on/off), and paired line blinking with variable rate.\par
|
||||
\par
|
||||
When first loaded the decoder is set to short DCC address 24 (or 17 in Decoder_17LED_1Function). The decoder can be reset to the original parameters by loading CV 120 with 120 (decimal). This will reset everything including the decoder address, when the pushbutton on the Pro Mini is pushed (reset) or by powering the decoder off then on. You will know when the default CV setting are being reset as the decoder will flash Digital Pin 14 (A0) for one second.\par
|
||||
The decoder address can be changed to another \ul\b short\ulnone\b0 DCC address by changing CV 1.\par
|
||||
\par
|
||||
\b The 7 Servo 10 LED decoder configuration\par
|
||||
\b Example Only: 7 Servo 10 LED decoder configuration\par
|
||||
\par
|
||||
\b0 Arduino Pro Mini Pins are set as follows: 3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19\par
|
||||
\ul\b Pro Mini Pin\ulnone\b0\tab \ul\b Function\par
|
||||
@@ -151,7 +152,8 @@ For example \b F0\b0 is initially set for \b servo\b0 control:\par
|
||||
\par
|
||||
Before changing the CV settings take a look at the initial settings and make small changes first to observe the effects. This should give modelers a starting point, and a better understanding for customizing their decoders.\par
|
||||
\par
|
||||
Please also note there is a new 17 LED (On/Off) decoder configuration (Decoder_17LED_4Function), which while providing the 17 LED on/off control like the very first decoder (Decoder_17LED_1Function) introduced in this project, whichh ONLY has on/off control. However, this new version can be reconfigured via CV control to perform the other functions too.\par
|
||||
Please also note there is a new 17 LED (On/Off) decoder configuration (Dec_17LED_6Ftn), which while providing the 17 LED on/off control like the very first decoder (Dec_17LED_1Ftn) introduced in this project, which ONLY has on/off control. However, this new version can be reconfigured via CV control to perform the other functions too.\par
|
||||
|
||||
\pard\par
|
||||
}
|
||||
|