Jump to content
 

Using a PIC micro-processor to control trains


MarshLane
 Share

Recommended Posts

3 hours ago, Junctionmad said:

In real life this system can’t maintain an accurate known voltage drop which would need to be millivolt stable 

 

 the effect of a finite output impedance of the regulator would mean that such a voltage would vary at different parts of the load line and to attempt to mitigate that , you’d have to have a 10x or more current through the regulator as opposed to the motor leading to major inefficiencies 

 

The only voltage drop is along the length of the rails (in both directions) but that is " invisible" to the regulator. It is only concerned with the current received at the loco and that is held constant by the controller regardless of any drop along the rails.

Link to post
Share on other sites

23 hours ago, AndyID said:

 

The only voltage drop is along the length of the rails (in both directions) but that is " invisible" to the regulator. It is only concerned with the current received at the loco and that is held constant by the controller regardless of any drop along the rails.

Hang on , are we talking about a conventional shunt regulator , a shunt regulator maintains a constant voltage across it not a constant current 

Edited by Junctionmad
Link to post
Share on other sites

On 11/02/2020 at 17:17, AndyID said:

 

The only voltage drop is along the length of the rails (in both directions) but that is " invisible" to the regulator. It is only concerned with the current received at the loco and that is held constant by the controller regardless of any drop along the rails.

 

If I understand this correctly the controller has to be a good constant current source, with the current being monitored by a sense resistor and differential amp to set the regulation level - electrically can we call the regulator a 'programmable zener' (an analogue for possibly the simplest form of shunt regulator)?

 

One thing troubles me - I don't know about n-gauge mechanisms, but in larger scales you might have a power hungry Dublo locomotive on a heavy train and a modern loco running light engine on the same layout - for the same demand speed (current) you might have greatly different motor current requirements and your controlling current will have to accommodate the highest common denominator. Is that not inefficient if you have a low current efficient motor and the regulator is having to dump most of the current as heat? Effectively every locomotive becomes inefficient as they have to draw the same current as your most power hungry loco on a heavy train, irrespective of motor efficiency and train load. Am I missing something?

Edited by sharris
Link to post
Share on other sites

1 hour ago, sharris said:

 

If I understand this correctly the controller has to be a good constant current source, with the current being monitored by a sense resistor and differential amp to set the regulation level - electrically can we call the regulator a 'programmable zener' (an analogue for possibly the simplest form of shunt regulator)?

 

One thing troubles me - I don't know about n-gauge mechanisms, but in larger scales you might have a power hungry Dublo locomotive on a heavy train and a modern loco running light engine on the same layout - for the same demand speed (current) you might have greatly different motor current requirements and your controlling current will have to accommodate the highest common denominator. Is that not inefficient if you have a low current efficient motor and the regulator is having to dump most of the current as heat? Effectively every locomotive becomes inefficient as they have to draw the same current as your most power hungry loco on a heavy train, irrespective of motor efficiency and train load. Am I missing something?

 

First you have to accept that current monitoring is the best way to control the motor speed (for this project).  You have found one of the obvious downsides in that methodology.

 

Andy

 

 

Link to post
Share on other sites

  • RMweb Gold
3 hours ago, SHMD said:

...I thought we were discussing using a PIC to control trains!

 

Kev.

(Runs away sniggering...)

 

3 hours ago, sharris said:

Shhhh... we can't have the thread getting back on topic :D

 

NO Sniggering in this class BOY! Well that was what my teachers use to tell us!

 

Off topic? A thread on rmWeb? Nah, never!  To be honest, I have stepped back slightly, purely because of a lack of time recently, work has been somewhat overwhelming.  But I should be back on to this project shortly.  My understanding of things is coming so I hope to have some progress (I do keep saying that dont I :) ) shortly.  At the end of the day, achieving the aim of this project, means I can achieve the best realism possible on the layout - so that is my incentive to get on with it, and yes Kev I assure you, we'll get back to PIC control shortly (no, honestly, I promise!).  

 

While I am somewhat tied up with other things, I suppose to quote an old saying, the mice will play while the cat is away ... just play nicely :)

 

Rich

Link to post
Share on other sites

1 hour ago, sharris said:

 

If I understand this correctly the controller has to be a good constant current source, with the current being monitored by a sense resistor and differential amp to set the regulation level - electrically can we call the regulator a 'programmable zener' (an analogue for possibly the simplest form of shunt regulator)?

 

 

Yes, that's correct but I'm not sure I'd call it a programmable zener. It's really just a shunt voltage regulator rather than the more typical series regulator you might find in a DC controller. Using a shunt to control motor voltage is not a new idea at all although it's probably very unusual on model railways.

 

1 hour ago, sharris said:

One thing troubles me - I don't know about n-gauge mechanisms, but in larger scales you might have a power hungry Dublo locomotive on a heavy train and a modern loco running light engine on the same layout - for the same demand speed (current) you might have greatly different motor current requirements and your controlling current will have to accommodate the highest common denominator. Is that not inefficient if you have a low current efficient motor and the regulator is having to dump most of the current as heat? Effectively every locomotive becomes inefficient as they have to draw the same current as your most power hungry loco on a heavy train, irrespective of motor efficiency and train load. Am I missing something?

 

Yes, that would be a concern. It could well be necessary for the controller to have different current ranges to allow for a range of different motor types. Power dissipation at the loco is also a concern. If it's done right the power dissipation is approximately constant at a particular speed. As the motor load increases more power is diverted to the motor while less is dissipated by the shunt. There might even be a way to run the shunt in "switched-mode" to greatly reduce it's dissipation. But that might be nonsense!

 

17 minutes ago, Andy Reichert said:

First you have to accept that current monitoring is the best way to control the motor speed (for this project).  You have found one of the obvious downsides in that methodology.

 

Not sure I understand that. Monitoring current isn't difficult. Mind you, what you do with that data isn't at all simple in this case.

Link to post
Share on other sites

12 hours ago, Junctionmad said:

Hang on , are we talking about a conventional shunt regulator , a shunt regulator maintains a constant voltage across it not a constant current 

 

Yes, a shunt regulator is just another way of controlling voltage but there's nothing in the book that says it has to be constant. It can be variable just like a series regulator.

Link to post
Share on other sites

4 hours ago, AndyID said:

 

Yes, a shunt regulator is just another way of controlling voltage but there's nothing in the book that says it has to be constant. It can be variable just like a series regulator.

yes but if you vary the regulated voltage ( by using the concept of a " controlling current ")  , how do you know the voltage drop so delivered at the command station , you would have to have a very tightly calibrated shunt regulator 

 

The next issue you have is no shunt regulator is perfect , it has an output  impedance  , Hence you will get inaccuracies in the voltage regulation , 

Then you have  the overall noise floor 

 

In order to resolve what are very small changes in resistance , you need to have very accurate known voltages , The command station isnt an issue as you can measure in realtime , but the scheme you suggest has no way of accurately reporting the shunt voltage drop in the same manner 

 

I haven't   worked through the real life numbers , but I suspect the % variability in voltage will be greater the % change in resistivity 

This leaves aside issues like unexpected ( and unknown ) changes in track resistivity , due to variations in metal , the presence  of fishplates, potential unexpected return paths etc 

 

as I said previously, the theory is correct , however I dont see any real life application working  without considerable circuit sophistication and the fact is , it would be easier to simply relay the voltage drop experienced in motor circuit back via some form digital coding .

 

Edited by Junctionmad
  • Like 1
Link to post
Share on other sites

14 hours ago, Junctionmad said:

yes but if you vary the regulated voltage ( by using the concept of a " controlling current ")  , how do you know the voltage drop so delivered at the command station , you would have to have a very tightly calibrated shunt regulator 

 

The next issue you have is no shunt regulator is perfect , it has an output  impedance  , Hence you will get inaccuracies in the voltage regulation , 

Then you have  the overall noise floor 

 

In order to resolve what are very small changes in resistance , you need to have very accurate known voltages , The command station isnt an issue as you can measure in realtime , but the scheme you suggest has no way of accurately reporting the shunt voltage drop in the same manner 

 

I haven't   worked through the real life numbers , but I suspect the % variability in voltage will be greater the % change in resistivity 

This leaves aside issues like unexpected ( and unknown ) changes in track resistivity , due to variations in metal , the presence  of fishplates, potential unexpected return paths etc 

 

as I said previously, the theory is correct , however I dont see any real life application working  without considerable circuit sophistication and the fact is , it would be easier to simply relay the voltage drop experienced in motor circuit back via some form digital coding .

 

 

I still don't think you completely "get it". As the track circuit resistance increases the voltage at the controller has to increase to maintain the desired current at the loco, and vice versa.

 

We all know this is true. If it was not true we wouldn't have to add all those blinking droppers to overcome rail resistance (on DC layouts).

 

I'm not looking for millimeter positioning resolution and I'm not looking for microsecond response times either. Neither am I saying it's a "piece of cake" to implement any of this.

 

What I am saying is it might be possible to convert track resistance from a nuisance into an advantage and, on outdoor layouts for example, current regulation rather than voltage regulation might offer some advantages.

 

If you don't care to consider any of these possibilities that's up to you. I best say no more.

 

Link to post
Share on other sites

The point about measuring bemf to detect motor speed is that it's only done for a short controller off pulse at zero current. So no voltage drop between the detection circuit and the motor in the loco. Even if it's way out in the back garden. I just needed a handful of MSI chips to make both a sample and hold circuit and a few op amps for the Nyquist part, to create a full closed loop, and stable, control system. All you need is a DAC to substitute for the analog volts input speed knob and it can be driven by a PIC . I'm not sure if some pics can do the DAC part, but I'm certsin even the simplest can provide the PWM. Keeping the op amps saves trying to do 1st and second order error differentiation at high speed digitally and also provides the full 5v to plus and minus 12 v conversion for the input and output and forward and reverse.

 

Andy

Link to post
Share on other sites

9 hours ago, Andy Reichert said:

The point about measuring bemf to detect motor speed is that it's only done for a short controller off pulse at zero current.

 

 

No question that is one way to do it and it's also what DCC does. Another way to do it is to send a current "signal" down the track that represents the desired motor bemf (i.e. speed) and let the on-board electronics compensate for variations in motor load. That doesn't require any interruption of the motor current.

Link to post
Share on other sites

I'm not comparing or offering theoretical ways that might work. This was my 1970's actual implementation.  One major cost and size factor was that there weren't any on-board electronics used or needed to achieve 100% stellar performance.  I did implement a working digital voltage controller even earlier as a separate design for a university post-grad research project, so I'm familiar with the technology.

 

DCC decoders need to be on-board for other more important reasons than just stablising the set motor speed. Which is why the earlier fast to market decoders didn't offer it at all..

 

Andy

Link to post
Share on other sites

23 hours ago, Andy Reichert said:

 Keeping the op amps saves trying to do 1st and second order error differentiation at high speed digitally

 

You don't say what your sampling rate was, but I don't think the CPU would have too much trouble these days with the maths of differentiation (particularly the DSP PICs) in the time interval available.

 

Your sample-hold is giving you discrete time-sampled signals like the PIC would do, the only difference would be, particularly with the second differential, that quantisation steps in the ADC would come into play.

Link to post
Share on other sites

9 hours ago, Andy Reichert said:

I'm not comparing or offering theoretical ways that might work. This was my 1970's actual implementation.  One major cost and size factor was that there weren't any on-board electronics used or needed to achieve 100% stellar performance.  I did implement a working digital voltage controller even earlier as a separate design for a university post-grad research project, so I'm familiar with the technology.

 

Did you consider using a couple of op-amps instead? It's quite simple to compensate for a motor's internal resistance to maintain a constant BEMF. The only problem is variation in the track's resistance, but there we go again.

 

BTW, I developed a sort of DCC system in the early 70's. Unfortunately I couldn't cram all the required "stuff" into a 00 locomotive ;)

Link to post
Share on other sites

8 hours ago, sharris said:

 

You don't say what your sampling rate was, but I don't think the CPU would have too much trouble these days with the maths of differentiation (particularly the DSP PICs) in the time interval available.

 

Your sample-hold is giving you discrete time-sampled signals like the PIC would do, the only difference would be, particularly with the second differential, that quantisation steps in the ADC would come into play.

 

There's really no need for sampling. The BEMF is there all the time and the only difference between it and the applied voltage is the current through the motor's internal resistance. If you know the motor's internal resistance it's very simple to compensate for the loss across it, and a PIC or similar can easily determine the resistance before a motor starts. Once you know the resistance you can compensate for it to maintain a desired speed regardless of load in real-time.

Link to post
Share on other sites

13 hours ago, AndyID said:

 

There's really no need for sampling. The BEMF is there all the time and the only difference between it and the applied voltage is the current through the motor's internal resistance. If you know the motor's internal resistance it's very simple to compensate for the loss across it, and a PIC or similar can easily determine the resistance before a motor starts. Once you know the resistance you can compensate for it to maintain a desired speed regardless of load in real-time.

 

How many of those designs have you built and are running?

 

Andy

 

 

Link to post
Share on other sites

14 hours ago, AndyID said:

 

 a PIC or similar can easily determine the resistance before a motor starts. 

 

Easier said than done, methinks. the motor resistance will vary as it rotates depending how the brushes contact the commutator segments for 3 or 5 (or ?) poles. Additionally, the motor will be isolated from the PIC by something like a H bridge driver so you will need extra connections from the PIC to the motor. In turn these will need to be protected from the full motor voltage...

Link to post
Share on other sites

1 hour ago, Crosland said:

 

Easier said than done, methinks. the motor resistance will vary as it rotates depending how the brushes contact the commutator segments for 3 or 5 (or ?) poles. Additionally, the motor will be isolated from the PIC by something like a H bridge driver so you will need extra connections from the PIC to the motor. In turn these will need to be protected from the full motor voltage...

 

And then there is the armature winding(s) temperature which varies with load and the variable ventilation caused by the motor speed.

Link to post
Share on other sites

On 16/02/2020 at 10:58, Crosland said:

 

Easier said than done, methinks. the motor resistance will vary as it rotates depending how the brushes contact the commutator segments for 3 or 5 (or ?) poles. Additionally, the motor will be isolated from the PIC by something like a H bridge driver so you will need extra connections from the PIC to the motor. In turn these will need to be protected from the full motor voltage...

 

Yes, it has to be a conservative approximation. Essentially the controller is eliminating the motor's resistance by applying positive feedback based on the current. (My mentor at uni referred to it as "feed forward")  If you get too greedy and try to eliminate all the resistance the whole system becomes unstable and goes into oscillation! But that's common with any control system.

 

And yes, all signals into the PIC better not violate its spec.

Link to post
Share on other sites

On 16/02/2020 at 09:32, Andy Reichert said:

 

How many of those designs have you built and are running?

 

Andy

 

 

 

Quite a few actually. I made the first one while we were expecting our first daughter and she just turned 43.

 

But I haven't done it with a PIC or similar micro-controller yet. All the ones I've made are pure analog using a couple of op-amps. It's a pretty simple circuit. The idea has been around for ages.

Link to post
Share on other sites

11 hours ago, AndyID said:

 

Quite a few actually. I made the first one while we were expecting our first daughter and she just turned 43.

 

But I haven't done it with a PIC or similar micro-controller yet. All the ones I've made are pure analog using a couple of op-amps. It's a pretty simple circuit. The idea has been around for ages.

 

The US TAT IV Throttle had load current in it's speed feedback, but I don't know if it was effective at very low speeds, or ever incorporated in any commercial controllers. AFAIK, all the manufacturers of DCC chips have used bemf sampling with PWM.  The profit motive is usually most sensitive to cost and ease of implementation.

 

The DCC system is not a perfect solution, but with some personal modifications, will suit my purposes ongoing.

 

Andy

 

 

Link to post
Share on other sites

18 hours ago, Andy Reichert said:

AFAIK, all the manufacturers of DCC chips have used bemf sampling with PWM. 

 

That's not really comparing like-for-like though. 

DCC chips sit just cm away from the motor in a fixed relationship instead of being some metres away with a wiring geometry between the controller and motor that may well change as the loco is moving and at the throw of a point. The use of PWM is also an easy way not to have to manage throwing away the heat within the confines of a loco body that you might have to do with a linear amplifier DC motor controller, and intrinsically gives you an 'off' time-point to sample BEMF. 

Link to post
Share on other sites

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
 Share

×
×
  • Create New...