RE: DCC Function Decoder for Arduino and ATtiny

#1 von RudyB , 26.10.2015 11:51

DCC Function Decoder for Arduino and ATtiny

In previous posts on Arduino DCC Decoders I have been using the word 'function decoder', which has led to some confusion. The decoders posted so far are what I should have called accessory decoders.

An accessory decoder listens to a DCC accessory address and switches an output or drives a servo. One Arduino DCC decoder can be configured to listen to max 16 DCC addresses.

A function decoder listens to one address (a locomotive address, or as the NMRA calls it, a multi-function decoder) and it switches locomotive functions, which are called F1, F2, etc. on command stations or handheld controllers.

Now that this is cleared up ... here it is ... an Arduino and ATtiny DCC Function Decoder.

And, if you like it small enough to fit in an HO wagon (with a diode bridge and a capacitor as a power supply), this code also works with the 22x18 mm ATtiny boards that can be had for under $1,50 here.

Of course DCC needs to be fed to the Arduino / ATtiny. For that I use this opto coupler circuit. If it needs to be smaller to fit inside a wagon, it is also possible to use a Zener diode and a resistor.

Configuration is easy. In line 1 of the code state the loc address you want it to listen to. In the lines that follow, define the output pins for F0, F1, F2 ... up to F12. Not all need to be defined, just the ones that you want to use. On the Arduino outputs 3-19 (14-19 are A0-A5) are available. On the Attiny P0, P1, P3, P4, P5.

int decoderAddress = 1830; // This is the decoder address, change into the number you want.
#define F0_pin 13 // Define the output pin for every Function number in use. 13 has on board LED.
#define F1_pin 0 // Available pin numbers: 3-19
#define F2_pin 0
...
#define F12_pin 0



Click here to go the blog post on the Arduino and ATtiny DCC Function Decoder that has the download link.




..


Youtube channel on Model Railway, Traincontroller, Arduino and more


RudyB  
RudyB
InterRegioExpress (IRE)
Beiträge: 268
Registriert am: 20.09.2014
Homepage: Link
Gleise Peco 75
Spurweite H0
Steuerung TrainController
Stromart Digital


RE: DCC Function Decoder for Arduino and ATtiny

#2 von tom75 , 28.10.2015 16:30

Hello Rudy,

i want to test your Code on a ATTINY44 because i have a lot of them here. I think it would be no problem to do so, but can you tell me which clock i have to use when i write it to the attiny? I can use the 1 Mhz or the 8 Mhz internal clock, or do i need an 20 Mhz external clock ?

Best regards

Tom75


Schaut doch auch mal bei mir vorbei ;)

Aktuelle Anlage:
http://stummiforum.de/viewtopic.php?f=64&t=123785

Alte Anlage Kellerhausen
viewtopic.php?f=64&t=87438


tom75  
tom75
InterCity (IC)
Beiträge: 625
Registriert am: 08.01.2013
Gleise Märklin K-Gleis
Spurweite H0
Stromart AC


RE: DCC Function Decoder for Arduino and ATtiny

#3 von RudyB , 30.10.2015 12:07

New versions of Arduino and ATtiny DCC Function- and Accessory Decoders are available.

DCC Function Decoder
The possibility to use the direction of travel of the loc (forward or reverse) to switch two outputs has been added. This makes it possible to switch head and tail lights depending on the loc direction.

DCC Accessory Decoder
A mode has been added to switch signals using two pins. The outputs are inverse, if pin1 is HIGH, then pin 2 is LOW. Four modes are available now:
mode 1 - Continuous output. OFF at startup.
mode 2 - One shot, with a timer. OFF at startup.
mode 3 - Flasher with 2 outputs that alternate based on 2 timers in ms. OFF at startup.
mode 4 - Signal with 2 outputs that always are inverse. At startup one of them is ON.

IMPORTANT:
The output logic has been changed with respect to the previous versions. In the new versions, the Arduino output pin is LOW when accessory or function is switched ON, and vice versa.

If you need it the other way around ... it is not difficult to edit this in the code, just do a 'find' for all 'digitalWrite' instructions and change them.

The download link is available on the software page. The download contains all Aduino decoder versions, S88-, sniffer- and sound software.

Link to the blog with a download link to the software package


Youtube channel on Model Railway, Traincontroller, Arduino and more


RudyB  
RudyB
InterRegioExpress (IRE)
Beiträge: 268
Registriert am: 20.09.2014
Homepage: Link
Gleise Peco 75
Spurweite H0
Steuerung TrainController
Stromart Digital


RE: DCC Function Decoder for Arduino and ATtiny

#4 von KTH ( gelöscht ) , 31.10.2015 14:43

Hi Rudy,

in your Blog you state that you use a diode bridge an a capacitor as 5V Power Supply for the Attiny.
You still need a voltage regulater for 5V, am I right with that?
Unless you use a zener diode.

Maybe you can tell me how you do it. I want to use all that in an H0 Wagon.


Thanks for your help.


KTH

   


  • Ähnliche Themen
    Antworten
    Zugriffe
    Letzter Beitrag
Xobor Einfach ein eigenes Forum erstellen
Datenschutz