Minimum hardware to amplify K8055 analogue outputs?

I want to control model locomotives with K8055.

Specification follows:-

Voltage: either 0 - 12 DC analogue or 12 with PWM

Current: upto 1A : Sparkfun?, or upto 5A for large models

Speed: already variable by software I have, not a problem

Direction: either DPDT miniature latching relays wired for reversing
or using 2nd variable controller of milli-current supply
without any switches PWM/DAC1 Forward PWM/DAC2 Reverse

Hardware: MUST be absolute minimum of modern components e.g. FETs or Sparkfun
1A twin motor amplifier (postage stamp size) - not interested in old-fashioned
multiple component circuits. Need for ‘pull-up’ resistors as polarity of K8055
is wrong way round as supplied.

              I feel sure somebody has experience of building such a device and, frankly,
              am surprised Velleman has not introduced a matching motor amplifier into
              their range and rearranged the analogue/PWM outputs of K5088/K5061 so
              that independent twin-motor operation is possible with + - / + - instead of
              +/ - GND which is not really suitable for model railways.

How will you know that it is the “absolute minimum” of components? What is your fascination with Sparkfun components and why can’t it be done with a single extra component the “old fashioned” way?

Frankly, I am surprised that your preferred model locomotive manufacturer isn’t offering a complete USB solution, that fits your specs and requirements. Have you asked/complained on their forum about that? What was their reply?

Regards,
Jan

Jan

Many thanks for responding, I’ll answer your questions one by one.

I’ll know just by looking at it. Ideally, somebody would e-mail and say “I can do that and have done - it’s easy - drop by and I’ll show you!” In the real world we don’t do this - I could have a hidden agenda, hence my opening statement.

By old-fashioned - I mean solutions that use 20 or 30 components on veroboard. I was hugely impressed by the Sparkfun TB6612FNG but it defeated me when I bought one because I am not sufficiently experienced at practical electronics. However, as a one component + pull-up resistors solution it is both impressive and cheap at $10.

As for my preferred model railway supplier; nobody there would even understand what I want, never mind be able to help. Why else would I be appealing here? This is a matter for Velleman K8055 enthusiasts, like me and maybe you. The respondent with the answer in a parcel may also be a member of MERG [Model Railway Electronics Group] and/or skilled in Visual Basic computer programming applied to small motor control.

John

John,

[quote=“John Broadley”]Jan

Many thanks for responding, I’ll answer your questions one by one.

I’ll know just by looking at it. Ideally, somebody would e-mail and say “I can do that and have done - it’s easy - drop by and I’ll show you!” In the real world we don’t do this - I could have a hidden agenda, hence my opening statement.[/quote]

Unfortunately the globalization of user/interest groups over the internet has caused us to stop doing this in the real world. I remember that we did it that way back in the 80’s and early 90’s when I was part of a CP/M user group and later the founder of a Minix user group in my hometown (back in the old country). If you’re anywhere within reasonable driving distance of Philadelphia, you can still drop by and we’ll figure it out together.

No, I haven’t done it yet. And I’m lacking the 12V 1A or 5A motors to rig up a test case. I have all the electronic components though. Plenty of 10-30A power transistors floating around and the average components (like resistors, capacitors and diodes) are available in big zip-lock bags.

Fair enough. I will try to keep it below 10 components.

I am busy this evening, so my actual follow up with specifics will come later tonight or even tomorrow.

Regards,
Jan

Jan,

That’s really cool!

By an astonishing coincidence, although I live in the U.K. I do have blood relatives in PA because of Mr Hitler, so it is by no means impossible that I could do just that as I’m not without the price of a cheap air ticket. Yes, a solution to this problem is that important to me.

OK, I could compromise with the < 10 components spec. but wouldn’t it be better in the long run to get in the specified component from Sparkfun as it is much cheaper for you than for me and only $7 to somebody already in the States. Then, we have a joint stake in what could turn out to be a commercial proposition that would earn dollars as well being fun.

The component I specified almost certainly is the answer but ‘beggars can’t be choosers’ so go ahead and do your intellect thing instead of a no brainer like I really want.

Ok, here is the “minimum component” yet “old fashioned” version.

Disclaimer: I do electronics as a hobby. I am confident enough in my electronics skills to put this together on a breadboard and connect it all to my K8055 and then a very expensive laptop. But I am no expert and this comes AS IS, without any warranty.

Lacking the relay and a separate 1A motor, I only tested R1+Q1+D1 with an old (defective) hard drive in a docking station as load. The drive surges about 2A during spin up and cruises at 0.8A, so it should be fairly equivalent to a small electric locomotive. A small 12V fan connected in parallel made sure that the speed control actually works as intended. The hard drive isn’t so happy when the duty cycle goes below 70%.

The resistor R1 got warm at 100% duty cycle, but not hot. That’s expected when running 3W through it. None of the other components used nor T1 of the K8055 got even warm.

The components used were chosen because they were floating around in my hobby parts box. There is certainly room for optimization here.

About the circuit itself: It should be good for a 12V motor up to 1A, maybe more. The power transistor TIP42 is rated for 10A, so it can easily handle this. If you increase the load beyond 1A, I expect that transistor to get a bit warm and maybe need a heat sink. The resistor R1 is not your little 1/4W film resistor, but a wire wound ceramic 5W version. I only had a 10W at hand, but 5W is enough. Make sure that such a resistor is not mounted flush on the PCB, but a couple mm above it for air flow! The TIP42 has a minimum DC gain of 20, so we need to hammer 240mA into its base to saturate it. At 12V that is almost 3W. The BC337 on the K8055-PWM1/2 can handle up to 800mA, so this should be no problem. The example relay is an Omron G5V-2, which is rated 12V 2A switching and has a coil resistance of 288 Ohms at 12V. That puts about 40mA load on the K8055 output O1. No problem there either. In fact, the K8055 is able to handle a a much bigger relay. And since the ULN2803 on the K8055 already has a protecting diode on board, we don’t need to add one to the circuit.

Warning! The circuit does not protect against direction reversal under load. Make sure that the software ramps down the motor before changing the direction.

Cost of the components:
[ul][li]Relay G5V-2: $2.02[/li][li]Transistor TIP42: $0.55[/li][li]Resistor 50 Ohms 5W: $0.44[/li][li]Diode 1N4007: $0.14[/li][/ul]

That is $3.15 total for single component order from mouser.com. I know in Germany there is Conrad … don’t know what you’d use in the UK. You usually save 20% or more when ordering 50 or 100 at a time. Add a little experiment PCB and the whole thing is 4 components plus PCB for under $5.

With two of those you can control two locomotives and still have 6 digital output ports to switch tracks, signals and so on (get enough relays).

Regards,
Jan

PS: I hope there will be a CHAR(13) conference next year in Cambridge. That would put me on a National Express Coach from London to Cambridge and back somewhere around July, which is a beautiful time to be in the British country side. I wouldn’t mind adding another day to meet and have a pint or two.

Jan,

I am, as some say in these parts “gobsmacked” at your brilliant solution which is so well described and illustrated, I think even I can assemble it!
What’s more, I believe I stock some of the parts you list TIP42C for sure and a TIP41C. Is it possible to make do with one loco per K8055 card and do without the changeover relays? I say this because the ability to run 2 locos per card may not be worth having as they would need to run on 2 completely independent circuits without hope of a crossover. Hence my criticism of the K8055 card for being +/+/-/-/GND instead of +/-, +/-. +/-, +/-. However, I guess I should be glad K8055 and its siblings exist as they are. After all, Velleman did not set out to cater to the model railroad trade and it’s not their fault that, as I said, the model railroad trade would turn deaf ears to the suggestion you offered. The publishers who support it are scared people will get more interested in computers and electronics than trains, I guess.

Great idea about Cambridge, I will write the date on my calendar and will let you have my telephone number nearer the day so we can indeed meet and have a pint.

Thanks again.

John

John,

if I had to design an electric train control system, the tracks would simply carry the 12V supply voltage full bore. The locomotives would then have a PIC and a speed control system similar to the above on board. And they would communicate with the computer via another PIC based interface using some serial signal like I2C, modulated on top of the 12V supply.

That way, I could have multiple independent locomotives on the same track. I remember that Merklin developed something similar many years ago. I forgot what they called that system.

One could extend that by putting sensors on the locomotive, like IR photo diodes that could “see” a signal state ahead (assuming the signal has an IR diode “showing” its current state). The locomotive could use that info to override the current speed setting and come to a stop, even though the computer said “go”. Or communicate the “I see signal 15 showing STOP” back to the computer. I2C is a bidirectional bus protocol, so the locomotive could send all sorts of information. Painting some infrared bar codes onto the tracks and have infrared LED/PhotoTransistor combo on the underside for example, so the locomotive can tell the computer “I just passed point X”.

Just thinking outside Pandora’s box, you know?

Jan

Jan,

Stick to the day job old son - all you describe and much, much more is already in the shops - look for DCC and the MERG organisation has an expert group working on the bar code idea which they call R.F.I.D. and even sell a kit to members to construct them.

Is there any mileage in my idea of dispensing with the reversing relay? Although my software has the means to prevent full speed motor reversal already, it seems sensible to exploit K8055 to its design maximum rather than moan about its imagined deficiencies. It has two analogue outputs each offering both DAC and PWM. You have opted for the latter and I have to tell you that some of the more expensive British trains will suffer from a diet of PWM, preferring the taste of DAC. Surely, one output can be for moving Forward and the other for moving in Reverse. The DAC option will provide much greater compliance than any PWM solution could, popular though PWM is for some modern motors.

John

Not surprising, John. I haven’t paid much attention to the model train world for more than two decades, so I guess I’m a little behind at this point. Nevertheless, what I am proposing would be Open Source down to the PIC firmware. Is that available in the shops too?

As for the idea of using the two PWM outputs for the two directions, I’m not sure what you expect. We don’t have GND and separate +12V, -12V supply, do we? I assumed so far we just have +12V and GND. One can certainly replace the functionality of the relay with more transistors, but it’s going to be a lot more components and not getting any cheaper.

Note that the PIC on the K8055 only has two PWM outputs (or to be precise, two CCP modules). That PWM signal is routed through a BC337 NPN transistor as PWM1 and PWM2. The DAC1 and DAC2 outputs of the K8055 are nothing but a quarter TLV274 Op-Amp in voltage follower configuration together with a capacitor, connected to that same PWM signal. The resulting “slew” turns the square PWM signal into something that looks like +0…5V level. The PIC itself doesn’t have any DAC.

Jan

Jan,

Effectively “Yes”. Everything you feel should be in place has been in place for nearly a decade. There really is nothing new under the sun but I am learning more about electronics from your spiel - are you a retired electronics lecturer by any chance?

There is a German protocol called ‘XpressNet’ that I follow, another British one (doomed in my inflated opinion) called ‘CBUS’ and both are striving to dominate the market. The first is purely commercial, the 2nd purely open source invented by we Brits and promulgated by the MERG organisation.

Now : to give you a little insight into railway, sorry railroad modelling standards and give you an idea of the comparative strength of the two threads, British and American. The British one is called B.R.M.S.B. and covers flange depth and a host of other standards to keep the rolling stock on the track. That’s British Railway Modelling Standards Bureau and I guess it remains what it started as, a roll-top desk! By comparison the American equivalent is called N.M.R.A. which stands for National Model Railroad Association and is quite literally a 3-story block! Check them out on Wikipaedia.

The N.M.R.A. has gathered together a set of standards for D.C.C., that’s Digital Command Control and awards a seal of approval to all hardware and software that meets its standards that looks like a Civil War cannon. The protocol I follow conforms to this standard but CBUS does not, hence my opinion that it will not prevail in its present form but must submit itself for approval to the N.M.R.A. eventually and will have to evolve further to do so and maybe lose its identity in the process. So, just as I.B.M. dominates computers because of its vast market share, so ‘XpressNet’ will win. Moreover the reason I bought into it is because its German parent LENZ was the only DCC hardware supplier that could be bothered to make its protocol open-source and publish it so geeks like me can command their trains while thumbing their noses at what’s in the shops - if they so wish.

How’s that for starters. I bet a lot of other readers who are still with me think I write the most utter rubbish but they haven’t spent 11 years full-time devising a control software ‘SMARTRAX’ that stands on the ‘XpressNet’ platform and can serve any operator in any gauge DC or DCC - or both at once!

John,

no, I’m neither retired nor an electronics lecturer. As a matter of fact back in the 80’s I was a certified bank clerk in Germany. Electronics and related things are hobbies (I also hold an Extra Class Radio Amateur License). As was programming computers back then. The computer hobby eventually grew into a day (and night) job and ultimately moved me to the other side of the Atlantic. Today I make my living developing open source software inside and around the PostgreSQL database system. I designed and implemented the Slony replication system for PostgreSQL for example.

Electronics is still a hobby and with the ever more powerful growing micro controllers, programming and electronics get closer and closer. There is a pattern in what I do. I exchanged the PIC on my K8055 and create my own open source firmware for that. I have modified the open source firmware for the dsPIC inside my short wave radio. I have modified the open source firmware of my digital storage oscilloscope (ARM based). I have not yet flashed and recompiled the firmware in the Turnigy 9x remote control of my model helicopter, but I do have the programmer for Atmel chips already. I really love to modify electronic gadgets and toys.

I read up a little on DCC and that seems to be precisely what I was envisioning. It is always a good sign when one comes up independently with similar or identical solutions.

If I understand this right (correct me if I’m wrong), then the DCC control station provides the supply power (depending on scale anything between 7V and 22V) and encodes the command bits by reversing polarity. The decoders are connected to that power source, listen to the commands and output several rectified signals, eventually including a voltage regulated or PWM signal for a motor. Different decoder types exist for switching signals or tracks and so on. The decoders can be retrofitted into existing locomotives or cars. Most of the command stations seem to have some computer interface too. That is so exactly what I was thinking of.

The K8055 analog/PWM output boost, that started this discussion, doesn’t seem to fit into that DCC world, so I presume you want that for a separate, single locomotive section of track.

What would eventually fit into the computer controlled railway world is a modified K8055 with the faster PIC and the open source firmware, I am maintaining. I was able to teach that thing to control standard hobby servos, like the ones used in RC models. I can see raising/lowering of a draw bridge, moving a construction crane, controlling a silo and so on in your railway world via that. Or is there a DCC decoder that can control a standard PWM hobby servo already?

The other thing possible would be to develop a custom firmware for the modified K8055 and/or the K8055N. It would output the DCC protocol on a digital port. The latency of USB communication doesn’t allow you to switch the ports fast enough with the stock K8055/K8055N firmware, but the PIC itself is absolutely capable of doing that. Add some power transistor based polarity reversal circuit and a power supply to that, and you have a relatively cheap USB DCC controller. One where you are 100% in control of all the software involved. How does that sound as a project?

Jan

Pretty impressive. Only snag is, once again MERG were there before you with their non-NMRA ratified system CBUS (based on motor car electronics) parallel to the NMRA ratified (commercial) system known as XpressNet owned by LENZ of Germany. As I said, I bought LENZ Set 100, incidentally it was the most expensive of the lot but I think you get what you pay for up to a point.

What you describe is exciting! A K8055N+ for model railroaders could be just what the market needs and I don’t think Velleman would be unsupportive either unless you went for it alone in which case why should they worry if more K8055/8061 are being sold as a result?

BUT. I believe you should leave DCC out of this all together. It needs nothing from anybody that is not either done or being done. Believe me, there’s an awful lot of meat on that bone and LENZ, who invented it, are well aware of this. I should mention the British firm HORNBY whose ZERO1 concept made history in the 1980’s but has now largely disappeared.

What I want is, as you imply, a souped-up K8061 (the 8 digital inputs are excellent as a basic way of reporting train movement and can be expanded to 64 quite easily by constructing a matrix. Do. the K8055 will expand in the same way to 25 inputs - you just stick 8 or 5 diodes in each screw terminal and your computer program does the rest, just as it does for the digital outputs which give you a staggering 255 solenoid triggers using only one byte.
Infinitely expandable if more used - you just have to wait for the buffer to empty. SMARTRAX offers all this and will be on the market as soon as possible so there is room for collaboration here which can be discussed over British real ale in a Cambridge pub next July.

regards,

John

John,

you have no idea what kind of memory cavity you opened. I had a lot of Märklin stuff back in the 70’s as a boy. It all was lost when I moved to America. I also was tinkering with a Tcl/TK based widget set, implementing track block diagrams, during the 90’s. I somehow see a potential to bring all this full circle and combine it with modern micro controllers. Now that would be cool.

Jan

Attaboy! My first experience of computer programming at 18, was at Harwell [Atomic Energy Research] but the dime never dropped until 1993 and the arrival in Britain of Amstrad microcomputers (PCW 9512] when I taught myself MALLARD BASIC.
The compiler I used was based on the CP/M platform you mentioned and the software was devised by Locomotive Software Ltd, a very British company. Having quickly developed a penchant for what I saw as virtual ‘Meccano’ (still do) I took myself to college and gained an Ordinary National Certificate in Computer Studies (with Programming) moving up a link with a brand new Amstrad 7486 in order to carry on with MALLARD in a more powerful environment, which swiftly introduced me to the mysteries of Microsoft QBASIC from which I advanced to VBASIC. I was careful from then on never to clutter my mind with other platforms (as the mugs did) but am still in BASIC and always will be. VBASIC is now a legacy language that had millions of dollars thrown at it before being dumped, just like the British Avro Vulcan jet bomber - and see how big in the sky that is today. VBASIC is now the software of choice for robotics enthusiasts and robotics can be computer-programmed trains can’t it? Any scale, any gauge. How powerful? Very powerful indeed all ye scoffers.

John

Since 1987 I’m doing pretty much everything in C. Except for graphics, those I’m doing in Tcl/Tk. Not the most popular language, but I don’t care.

The PIC18F2550 I’m using on my K8055 is programmed in C. The PIC18F24J55 used on the K8055N is almost identical. So now I’m on my home turf … watch out!

I did some math on the DCC protocol specifications. A “1” bit is 116µs long (2×58µs) and a “0” is ≥ 200µs. A Baseline Packet consists of a Preamble of 12 “1” bits, 3 bytes, each preceded by a “0” bit, and a final “1” stop bit. The first byte is the address, the second the actual command and the third a trivial XOR check sum of the previous two. Assuming an equal distribution of 1s and 0s, this makes a Baseline Packet 5900µs long on average. The Extended Packet Format allows up to 6 bytes length, but they still follow that same pattern; Preamble of 12 “1” bits, 3-6 bytes consisting of “0” plus 8 data bits each, “1” stop bit.

The firmware of my modified K8055 currently uses an internal 100µs Ticker, triggered by a timer interrupt. Using that timer interrupt instead to toggle the state of an output port, so that it outputs DCC packets, would be absolutely no problem at all. However, since the timer is also used to do the precise on/off timing for the Servo Pulses, these two features may be mutually exclusive on a single board. But that is no big deal since the “DCC->Servo” decoder, I envisioned earlier, apparently exists already. tamvalleydepot.com/products/ … coder.html

So here is how the entire thing would work:

[ol][li]One gets either a K8055N/VM110N or does the hardware modification of a K8055/VM110 to the PIC18F2550 chip. I have a K8055N on my Xmas shopping list. Might have to order that one early, plus a spare PIC18F24J55.[/li]
[li]Create a new firmware branch that starts with the original K8055 compatible code.[/li]
[li]Extend the protocol and firmware. A status bit in the cards report will show that the K8055 is ready to receive a new DCC packet. A new command message type sends a DCC packet of 3-6 bytes length to the card. The card starts sending that packet on output port O8. During that the status bit is off and another DCC send command will be ignored. When done, the status bit comes back on. [/li]
[li]Flash the new firmware into a PIC and put it onto the K8055(N).[/li][/ol]

The K8055(N) would be completely ignorant of the actual content of the packets. Those byte values are entirely up to the controlling PC software. This K8055(N) would be capable of controlling anything that conforms to the DCC packet format of 12x"1", “0” 8-bits, … , “1”. I didn’t read up on that MERG CBUS stuff. Is that using a different packet format? If so, well, maybe not supported in version 1.0.

What is missing is some circuitry that, controlled by the K8055(N) output port O8, will reverse a DC voltage. Probably power transistor based. That shouldn’t be terribly difficult and only cost about $10-$20 in parts. A suitable PIC to replace the one coming with a K8055(N)/VM110(N) costs less than $5.

Here is the problem: End users don’t regularly flash PICs. They don’t have PIC programmers. This is why almost nobody has ever done the K8055 hardware modifications, I described here: viewtopic.php?f=3&t=7480#p28184

End users also don’t regularly build custom circuits on breadboards. And with the voltage and currents we are talking about here, this may actually be a good thing. Wiring that stuff the wrong way can cause some serious damage.

If this should be used by other RR model enthusiasts, you would have to offer the voltage reversal circuit together with a pre-programmed PIC and your control software as a bundle. The user then only has to get a regular K8055N/VM110N board, exchange the PIC (which is in a socket, so that’s easy enough), connect the wires and be ready to go. From there, new firmware updates can be flashed via USB bootloader. The user doesn’t even have to touch the hardware any more.

This custom K8055 could still do up to two of the PWM controlled trains, we discussed initially. And have 5 digital inputs, 2 analog inputs and 5 digital outputs spare so far. I can see an analog input sensing a photo resistor, so that your model world reacts to dimming down the lights. I know, I’m evil.

Regards,
Jan

Jan,

Evil? You’re positively satanic.

Keep at it though, we have the makings of a partnership here that could make us rich and even if we stay poor we’ll have fun and spread it. Only please remember: the bottom line is keeping out of DCC. It would be plain wrong to stand against the NMRA, totally counter-productive. This is for the poor old DC enthusiast who likes to twist a real knob - occasionally. My software takes care of the track routing, signals, section feeds, sounds if you want them (and smells) and, in theory, prevents collisions. All this is inherent in the architecture of the Velleman product. If you published your e-mail address in your profile I could send you the executable to play with FREE. Send it via the Moderator to avoid unwanted problems.

regards,

John

John,

I must be missing something. I don’t think one can “stay out of DCC” at this point in the game.

Granted, I haven’t looked at the model railway world for over 20 years, but actively “not supporting” something like DCC today simply doesn’t make any sense to me. I understand that you want to drive things, that can’t be controlled by DCC. But that doesn’t mean that one has to exclude DCC by design.

Regards,
Jan

Jan,

Actually, my good friend, it does mean just that. You just need to go around the block a few more pillion times to find out. “Aha!” I hear you say, “But what is a pillion?” I can’t say how you have it over the pond being only half-American and spent nearly all my life on this side, bar a couple of visits to Coaldale PA to see my dear father’s other kids and their kids … and their kids and stand by his grave on Thanksgiving Day to salute his memory and all the incredibly brave lads and lassies of the 8th Air Force who laid down their lives for us all in the face of the most monstrous evil the world had ever seen.

Well, the answer’s the back seat of a motorbike.

Just take it from me there are perhaps hundreds of thousands for whom computers are things they have to put up with whether they like it or not and they just want leaving alone with their old-fashioned block-sections and DC.

So, come on, wise up and help me give them a reason to keep having a chuckle as they read this!

regards,

John

John,

I guess that excursion into all the DCC stuff added some confusion on my side.

Let’s clear this up. What you are looking for is just an Electronic Speed Control, probably for a Brushed DC motor. You want to be able to control that with a K8055, either via PWM or DAC output. The output to the motor is preferably a regulated voltage rather than a PWM signal. In other words, you want to control old school, pre-DCC locomotives running on a classic block-section track layout.

Is that correct?

Regards,
Jan