Jump to content

JNSF DIY Lighting with in-built DCC function decoder project


Martijn Meerts

Recommended Posts

Martijn Meerts

Moderator note: this was split off from another topic on the non dcc version of this lightboard here:

 

A version that allows daisy chaining could be interesting, so that if you have have custom couplers, you could theoretically control the lights of all boards with a single function decoder. It'd get really expensive to digitally control the lights in a 16 car train if each car needs a decoder, even with the cheapest function only decoders.

 

Link to comment
32 minutes ago, Martijn Meerts said:

A version that allows daisy chaining could be interesting, so that if you have have custom couplers, you could theoretically control the lights of all boards with a single function decoder. It'd get really expensive to digitally control the lights in a 16 car train if each car needs a decoder, even with the cheapest function only decoders.

 

 

You could actually do that here I would think.  Just run a bus wire to all cars through your coupler and come off it into the decoder inputs on the boards on each board.   You just need a function decoder that can handle the current of 16 cars worth of LEDs.  A real EE type would need to look at and confirm my statements.

Link to comment
Martijn Meerts

Optimally, you'd use the board itself as bus, just have 2 traces go from 1 end to the other, so you don't have to run extra wires. Of course, for Japanese models it's not much of an issue, since pretty much all cars have power pickup strips running the length of the car, but European brand cars don't have any pickup at all, and the power pickup system in them is pretty terrible anyway.

 

I've been looking at things like current conducting 3D printed couplers, or custom power pickup inspired by how the Japanese brands do it, but I haven't had the time for any of that really. Another option would be to try and manufacture very simple decoders that control lighting and not much (if anything) else. The components on them are dirt cheap, and they could be integrated in a lighting board, so you don't have to go for the smalles components either. But you do need someone who knows how to write the software to respond to DCC commands and program CVs and the like. There is OpenDCC, so it's quite possible to find code that can do all that, but it'd require a lot of time.

 

 

 

Link to comment

The Japanese style wouldn't help you with controlling it from a single decoder.   It does make it easy to run a board though since the power pickups are there already.

 

 

Link to comment
Martijn Meerts

Ah yeah, of course, wasn't really thinking it through. Although, I guess you could add traces on the board to solder a miniature connector to them, and the use those connectors to hook up the cars. Not pretty, and doesn't really work for all cars, but it's an option.

Link to comment
Martijn Meerts
46 minutes ago, cteno4 said:

 

I think that was part of the dcc stuff don was working on with trainaidsa. They wanted a simple lighting/end car decoder and starter power pack. I think do was surprised how cheap the circuit was, like you said mainly programming.

 

jeff

 

Yeah, I actually have one of their developer starter kits, but never got around to trying it. It didn't include any loco decoders or anything.

 

1 thing that makes loco decoders expensive is that their size. For N-scale they need to be really small, so you can't really solder them yourself. If you can basically integrate them with a lightboard you have a lot of space to work with. I'm pretty sure I'd be able to solder the components and get the code to work, but I'm no good at designing the actual hardware.

 

Link to comment
4 hours ago, Martijn Meerts said:

Yeah, I actually have one of their developer starter kits, but never got around to trying it. It didn't include any loco decoders or anything.

 

1 thing that makes loco decoders expensive is that their size. For N-scale they need to be really small, so you can't really solder them yourself. If you can basically integrate them with a lightboard you have a lot of space to work with. I'm pretty sure I'd be able to solder the components and get the code to work, but I'm no good at designing the actual hardware.

 

Yeah I think just the prelim work was done on the decoder side. Ardesh was keen on finding niches like a budget throttle and the odd accessory decoders as he knew the end car decoders jacked up the dcc price for most Japanese trains. Lighting decoders didn’t need to be quite as micro as loco to fit into tiny spaces.

 

Ardesh was an excellent businessman (and a very good egg), finding the niches that had little or no competition and was a big relief/fix for the customer to fill that need. I’ve still not gotten as good a screw replacement in price and quality to beat his. I should have asked his sons to buy a big box of them! Since I had lunch him every month or two I would just buy stuff as needed and he brought it to lunch. this is how we started having lunch as I realized he lived like 5 miles from me and shipping was as much as lunch so I offered to buy him lunch to deliver my first package as I was intrigued by a guy would would make 100,000 screws because he knew enough friends were frustrated buying marklin screws from Europe for very high prices. I miss him dearly.

 

jeff

Link to comment

I plan on (eventually) controlling all my lighting with DCC.    This circuit allows ON/OFF control through DCC, though when switching off, you'll get a slight delay due to anti-flicker.  

 

What it probably is not compatible with is dimming through DCC -- ie, dynamically changing the light intensity using DCC commands.   I personally don't see much use for that in N-scale internal lighting.   It would be cool to have some sort of variable resistor controlled through an input voltage.  Such things exist (through Googling) but they seem to be complicated affairs 🙂

 

 

 

Link to comment
Martijn Meerts

I came across a site that explains how to make a DCC function decoder, including which components are needed, and the source code for the PIC. I'm tempted to try and somehow make a version of this light board with the decoder integrated. The only real issue is that the PICs need to be programmed, so it does require a PIC programmer. Also, the source code is in assembly, which isn't the easiest of things to modify.

 

https://www.lydo.nl/hobby/dcc-diy-function-decoder/ has some info, custom boards and schematics of an SMD version of the decoder. There's also a HEX file for programming the PIC there. The original assembly source is located at http://usuaris.tinet.cat/fmco/home_en.htm. There's a bunch of files there, the function decoder source is 'dcc_isr.asm' (http://usuaris.tinet.cat/fmco/download/dcc_isr.asm)

 

 

  • Like 1
Link to comment
13 hours ago, Martijn Meerts said:

I came across a site that explains how to make a DCC function decoder, including which components are needed, and the source code for the PIC. I'm tempted to try and somehow make a version of this light board with the decoder integrated. The only real issue is that the PICs need to be programmed, so it does require a PIC programmer. Also, the source code is in assembly, which isn't the easiest of things to modify.

 

https://www.lydo.nl/hobby/dcc-diy-function-decoder/ has some info, custom boards and schematics of an SMD version of the decoder. There's also a HEX file for programming the PIC there. The original assembly source is located at http://usuaris.tinet.cat/fmco/home_en.htm. There's a bunch of files there, the function decoder source is 'dcc_isr.asm' (http://usuaris.tinet.cat/fmco/download/dcc_isr.asm)

 

 

 

 

It would be pretty easy to incorporate that decoder into the board I think.  There are some parts we could substitute (no need for an MB10S -- MB1S or MB6S or MB6F will work).  I'll take a gander at it in more detail once I get the generic V2 board done.  I too would like to have the decoder built-in.

 

  • Like 1
Link to comment
Martijn Meerts
14 hours ago, chadbag said:

 

 

It would be pretty easy to incorporate that decoder into the board I think.  There are some parts we could substitute (no need for an MB10S -- MB1S or MB6S or MB6F will work).  I'll take a gander at it in more detail once I get the generic V2 board done.  I too would like to have the decoder built-in.

 

 

I did have a quick look, and it doesn't seem all that difficult. However, my electronics knowledge has faded over the years. Last time I really made any circuits and boards and everything was well over 20 years ago.

 

I should be able to figure out the source code for the PIC though, and make changes where needed. I'd also be more than willing to get a PIC programmer and, depending on the volume, program PICs for people who are interested in a DCC controlled version of the board.

 

Since the function decoder of the example has 4 outputs, it would even be possible to have 1 function for the interior lights, and for coaches that have them, have a separate function output for table lamps, or red end lights in the tail car. 

Link to comment
7 hours ago, Martijn Meerts said:

 

I did have a quick look, and it doesn't seem all that difficult. However, my electronics knowledge has faded over the years. Last time I really made any circuits and boards and everything was well over 20 years ago.

 

I should be able to figure out the source code for the PIC though, and make changes where needed. I'd also be more than willing to get a PIC programmer and, depending on the volume, program PICs for people who are interested in a DCC controlled version of the board.

 

Since the function decoder of the example has 4 outputs, it would even be possible to have 1 function for the interior lights, and for coaches that have them, have a separate function output for table lamps, or red end lights in the tail car. 

 

I t would be nice to find a DIY DCC function decoder that only has 2 outputs and uses smaller programmable chips.   I'll see what I can find.   The way they have it laid out now it is pretty "big" for n-scale and especially when combined with lighting.

 

How do they program the PIC?  I would like one that when we turn the lighting off, we break the neg/gnd side of the lighting circuit to get the lights to go off immediately (or some scheme like that).

 

Random musings of a tired mind

 

Link to comment
Martijn Meerts
10 hours ago, chadbag said:

 

I t would be nice to find a DIY DCC function decoder that only has 2 outputs and uses smaller programmable chips.   I'll see what I can find.   The way they have it laid out now it is pretty "big" for n-scale and especially when combined with lighting.

 

How do they program the PIC?  I would like one that when we turn the lighting off, we break the neg/gnd side of the lighting circuit to get the lights to go off immediately (or some scheme like that).

 

Random musings of a tired mind

 

 

Yeah, not sure what the sizes of it all are. I did notice the function decoder was quite a bit bigger than for example an ESU function decoder, but miniaturisation does cost a lot of money, and at some point things get so small you can't solder them manually anymore.

 

What I can see from looking at the source of the PIC, it's basically the same as any function decoder, so F0 is light on/off, and the rest is freely programmable from F1 to Fx. There are some light effects as well, such as ditch light, fluorescents lights (the LEDs flash a few times before turning on), mars light etc.

 

I might see if I can experiment with this a bit, maybe build the circuit using non-SMD components, and try programming the PIC etc. 

  • Like 1
Link to comment
3 hours ago, Martijn Meerts said:

 

Yeah, not sure what the sizes of it all are. I did notice the function decoder was quite a bit bigger than for example an ESU function decoder, but miniaturisation does cost a lot of money, and at some point things get so small you can't solder them manually anymore.

 

What I can see from looking at the source of the PIC, it's basically the same as any function decoder, so F0 is light on/off, and the rest is freely programmable from F1 to Fx. There are some light effects as well, such as ditch light, fluorescents lights (the LEDs flash a few times before turning on), mars light etc.

 

I might see if I can experiment with this a bit, maybe build the circuit using non-SMD components, and try programming the PIC etc. 

 

I've been searching a little.  Need to spend more time.  But it might be interesting to find an "AVR" based version instead of PIC as there are C compilers for the AVR based chips 🙂

 

 

Link to comment

Here is the basic circuit for V2.  The same as previously posted but I added in more caps capacity,  removed the switch for the dimming resistor, moved which resistor is the dimming (from tests, though I need to do more), and added an optional zener diode to limit the voltage when using caps less than 25V rating (ie 16V -- should not use less than 16V).  YOu can leave the zener diode off and just always use min 25V caps.

 

I would like to add an optional transistor based switch that shuts off power to the LEDs immediately when the input power is turned off.  This should be simple (and I am looking at some transistor based switch schematics but as an electronics dummy, I get the gist of it but the operational details are not yet sunk into my thick head).  The purpose of this is to allow DCC control of the circuit, and when you switch it off, the LEDs go OFF right away instead of draining the caps and fading out slowly.
 

Schematic-V2-v0.2.pdf

Link to comment
Martijn Meerts
5 hours ago, chadbag said:

 

I've been searching a little.  Need to spend more time.  But it might be interesting to find an "AVR" based version instead of PIC as there are C compilers for the AVR based chips 🙂

 

 

 

There are compilers that turn C into a hex file for PICs as well, so that's not the problem. I just mentioned assembly since the example firmware for this thing was written in assembly. It would be very much possible, and probably preferable, to rewrite it in C though.

 

I came across the PicKit programmer, which is made by the main manufacturer of the 12F629 PIC, which allows in-circuit programming, which basically means you can program the PIC even if it's installed on the circuit board. This would obviously be very interesting since you can update them without having to de-solder them. However, I do think this needs some special connections, so it would require additional modifications to the board.

Link to comment
1 minute ago, Martijn Meerts said:

 

There are compilers that turn C into a hex file for PICs as well, so that's not the problem. I just mentioned assembly since the example firmware for this thing was written in assembly. It would be very much possible, and probably preferable, to rewrite it in C though.

 

OK, great.  A page I found listed the AVR advantage of not needing to use an assembly language with a free C compiler available.  The PIC had C available but only with a commercial compiler.

 

1 minute ago, Martijn Meerts said:

 

I came across the PicKit programmer, which is made by the main manufacturer of the 12F629 PIC, which allows in-circuit programming, which basically means you can program the PIC even if it's installed on the circuit board. This would obviously be very interesting since you can update them without having to de-solder them. However, I do think this needs some special connections, so it would require additional modifications to the board.

 

Would be interesting to see what you need for that.

Link to comment
Martijn Meerts

I've downloading the MPLab X IDE and with some additional plugins, it allows you to write C code and compile it for PICs (including 12F629). I managed to get it working with a blank main loop, although that's for PIC16F18313, which is mostly the same as 12F629, just with enhanced features and more memory I believe. It's still 8 pins and the same size. The only reason I tried with that one, is that 1 of the plugins for the IDE had a preset configuration setup for that PIC.

 

As for in circuit programming. As far as I can tell, you still need to be able to just hook up the PicKit programmer to the PIC, but it doesn't matter if the PIC is installed in a circuit. You would need an additional 5 pin header on the board to plug the PicKit into though, and that 5 pin header needs to connect to specific pins of the PIC. So, you'll still need to take the light board out of the coach, but at least the PIC can stay in place. It's not great that you have to add another header on the board though, although something like an NEM651 socket is fairly small and would to the trick.

 

Of course, I'm going by my limited knowledge of electronics here, so it might work different, but looking at https://www.instructables.com/id/make-your-own-In-circuit-programming-board-for-the/, the first image in step 4 shows the pin setup. The PIC12F629 has all those pins apart from PGM, but apparently that's not needed when using the PicKit at least.

  • Like 1
Link to comment

Regarding the DCC decoder schematic

 

For the transistor array chip in the DCC decoder schematic (the ULN2003AD), there is a different package of the same chip under ULN2003APW.  The difference is 9.90mm x 3.91mm VS 5.00 mm x 4.40 mm.  That is the largest chip in the system and using the different form factor would probably allow us to make it much smaller.

 

Link to comment

There is also an SMD package for the PIC chip (Soic-8 package) which is probably more compact, but harder to program.    There are all these "clips" you can use to attach to the chip on-board in order to program it.   

Link to comment
Martijn Meerts

The SMD version would be preferable, there are special tools.cradles to program them. Of course, it it's possible to add traces for the in circuit programming option to the board, then programming is no issue either way.

 

Link to comment
21 minutes ago, Martijn Meerts said:

The SMD version would be preferable, there are special tools.cradles to program them. Of course, it it's possible to add traces for the in circuit programming option to the board, then programming is no issue either way.

 

 

This is not the best one (someone in a forum somewhere mentioned the one from Pomona, which I found last night on eBay) but this sort of thing looks to make it easy

 

https://www.amazon.com/WINGONEER-EEPROM-circuit-programming-adapters/dp/B012VSGQ0Q/ref=sr_1_fkmr0_1?keywords=pomona+soic8+clip&qid=1554218377&s=electronics&sr=8-1-fkmr0

 

Link to comment
Martijn Meerts

That would definitely make it a lot easier, and you won't need to add a header and traces on the board for programming it. That does mean that everyone who wants these boards and program/upgrade them will need one of these, but since they're only around $10, that seems like a good investment.

 

I remember when I first worked with programming PICs, you had like only a handful of (really expensive) hardware to program the PICs, but these days it's really hard to find what you need just for some simple programming. I do think the Microchip Technologies PicKit 3 (or one of its cheaper clones) is a good option for an all purpose programmer at least. There's also a newer version, but apparently it doesn't support some of the older, but still often used PICs.

Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...