# PWM timing preferences



## KVBarkley (Jan 9, 2009)

I am just starting to breadboard my PWM power supply. (I am currently using my Heathkit DC power supply as a stopgap...).

This may be a bit *too* technical, but is there any preferences as to the Pulse Frequency? Should it be above the audio band?

What is a good practical minimum for the duty cycle? 10%? 

Any other pearls of wisdom?


----------



## dbodnar (Jan 2, 2008)

KV - when I am using PWM with my microcontrollers I generally keep the frequency around 30000, well above where folks can hear it.

I drop the duty cycle to 0 to stop a motor. Leaving it at 10% when you want it to be off could cause some troubles.

How are you generating the PWM pulses? 




dave


----------



## KVBarkley (Jan 9, 2009)

Right now I am using a couple of 555's. I will probably switch to the 7555 for faster switching and fewer transients. 

I was thinking along the lines of a "brake" switch that will turn everything off and once the brake is "released" start at the minimum duty cycle. This will probably be adjusted by trim pot which will set the minimum voltage to the 555 modulation input. 

So far this is all analog, microcontroller control can come in the future.


----------



## Torby (Jan 2, 2008)

I like AVR's for that. A $2 processor has hardware that makes controlling motors easy. The programmer is like $30.


----------



## krs (Feb 29, 2008)

I assume you're using the PMW supply to control your trains and you have thought about the downside of using PMW for that specifically if your locos or cars have any electronics in them. 

Knut


----------



## eheading (Jan 5, 2008)

I am about as far from being an expert on this as one can be, but I do have two data points. I believe the 27 MHz trackside Aristo Train Engineer runs at about 20,000 Hz. I also believe the new Revolution TE runs in the 7000 Hz range. I cannot hear any frequency noise from the Revolution, although I must admit my hearing is not the best. However, my wife cannot hear anything either, and she has very acute hearing.

WIth my 27 MHz receiver, my Phoenix board misbehaves occasionally when running in the PWC mode. I now have used the Revolution TE with two Phoenix boards, one of them for well over 20 hours, and it has never misbehaved once - long enough that I am convinced it will not misbehave. 

So - is a lower frequency better? Wiser minds than mine will have to answer that!

Ed


----------



## KVBarkley (Jan 9, 2009)

Torby: 
I want some direct on-the-fly control - which will be a little easier with a trim pot rather than a programmer. 8^) 

Knut: I assume you mean that the DC is no longer constant. PWM This is the way my Basic Train engineer works - when it does work - and it does not seem to wreak havoc on the sound system in the tender. So I guess I am OK.


----------



## krs (Feb 29, 2008)

I occasionally run analogue and use the 27MHz Aristo TE. 
I now always use it in the linear mode, never in the PWM mode for a couple of reasons. 

For one, many of the LGB sound cars and sound engines seem to have a capacitive input with a relatively large discharge time constant. So the PWM Pulses charge the capacitor up to the maximum voltage and if the sound module is designed to be controlled by the DC voltage on the track, it sounds as if the loco is always going full speed even if it's just crawling along. 
Switching to linear solves that problem. 

I also found that applying pulses to drive the motor causes fairly large back EMF spikes which are usually not suppressed at the engine, especially the older ones. So any electronics connected across the track will see these spikes and can be damaged. I have had a few of my friends loose their LGB sound board that way. 

It all depends if the electronic circuitry in your trains is designed to handle PWM on the tracks.


----------



## George Schreyer (Jan 16, 2009)

those spikes are not BEMF but 1/2 L di/dt transients due to inductance in the motor. BEMF would be a DC voltage that is proportional to the motor's rotation.


----------



## KVBarkley (Jan 9, 2009)

I have the Orange Basic Train Engineer, it seems to work fine with my cars, and it has no analog mode.


----------



## krs (Feb 29, 2008)

Posted By George Schreyer on 04/27/2009 5:31 PM
those spikes are not BEMF but 1/2 L di/dt transients due to inductance in the motor. BEMF would be a DC voltage that is proportional to the motor's rotation.



Those voltage transients caused by the inductance of relays (or a motor) were always referred to as Back EMF when I worked at a design engineer at Bell Labs and Bell-Northern Research.
I never heard of a different name for those spikes and they are still called that today:
http://www.google.ca/search?hl=en&q=back+emf+relay&btnG=Search&meta=

I suppose having the same name for two somewhat different phenomena is a bit confusing.


Knut


----------



## Greg Elmassian (Jan 3, 2008)

bemf is usually explained as the reverse (back) voltage (electromotive force) that is created by the rapid collapse of a magnetic field. 

Since field is collapsing, current flows in the opposite direction as when it was applied to make the device operate (right hand rule of electric current and magnetic lines of flux) 

The current through resistance/inductance creates a voltage. 

Since the collapse of the magnetic field can be very fast, the bemf voltage can be higher than the steady voltage applied. 

That's why you put much higher voltage "snubbing" diodes across relay contacts. 

BEMF is created during the collapse of the magnetic field, i.e. when power is removed, and it is proportional to the current that was in the winding before. 

(because the strength of the magnetic field was generated by the current) 

Regards, Greg


----------



## Semper Vaporo (Jan 2, 2008)

Posted By Greg Elmassian on 04/27/2009 7:24 PM
bemf is usually explained as the reverse (back) voltage (electromotive force) that is created by the rapid collapse of a magnetic field. 

Since field is collapsing, current flows in the opposite direction as when it was applied to make the device operate (right hand rule of electric current and magnetic lines of flux) 

The current through resistance/inductance creates a voltage. 

Since the collapse of the magnetic field can be very fast, the bemf voltage can be higher than the steady voltage applied. 

That's why you put much higher voltage "snubbing" diodes across relay contacts. 

BEMF is created during the collapse of the magnetic field, i.e. when power is removed, and it is proportional to the current that was in the winding before. 

(because the strength of the magnetic field was generated by the current) 

Regards, Greg


Methinks you have it backwards.

When current starts to flow in a wire the magnetic field increases and if the wire is coiled up such that the field crosses other windings it induces a voltage opposite the direction of current flow. Once the current flow stabilizes the field is no longer moving and no more voltage is induced. This is why an inductor has high resistance when current is applied, but lower resistance when the current stabilizes. But that is not usually called "Back EMF", which is more often applied to motor physics.

When the current stops flowing the field collapses and that is now moving in the other direction across the coil windings and that induces a current flow in the same direction as the formerly applied current. This is why you put a diode across the input to a coil so that when the field collapses the Forward EMF generated, which can be hundreds of volts more than the applied voltage, is shorted back to the other end of the coil and does not burn-out the circuitry that is controlling the current in the coil (the coil driver)... this is especially necessary when semiconductors are used as the driver. Sometimes the diode is hundreds of times more voltage tollerant than the driver circuit, but the current that is generated is so small that the diode does not have to conduct all that much, whereas the driver circuit might be able to handle lots of current but not the voltage spike induced when the current ceases to flow so abruptly.

"Back EMF" is generated in a motor when the magnetic field generated by the passage of current causes the coil to move against/through a stationary magnetic field, (e.g.: the motor rotates). That movement then generates a voltage (EMF- Electro-Motive Force) opposite the flow of the current that is generating the initial field... thus the term "Back" in conjunction with EMF. The faster the motor spins the more BEMF will be generated until an equalibrium is reached where the forward voltage cannot move enough current to overcome the BEMF to sustain the speed of the motor.

EDIT: I said "sustain the speed of the motor" and that is wrong... I mean, "continue to increase the speed of the motor, and it maintains that speed until the applied voltage changes." Sorry.


----------



## Greg Elmassian (Jan 3, 2008)

I guess I cut to the chase of how BEMF is used in decoders. Yes there is a bemf resisting the voltage/current running the motor. Yes it is there resisting the current powering the coil. In fact it is always present WHENEVER the magnetic field is changing, thus the phenomenon of inductance. 

But you cannot "read it" during that time.... it merely manifests itself as a change in the voltage, and you don't have a reference, because you cannot solve 2 variables (load/current and the BEMF component ) 

But if you briefly interrupt the power applied to the motor you can read BEMF, so some systems do exactly that, briefly interrupt the power and read the bemf, which at that time IS a result of the magnetic field collapsing BECAUSE you have interrupted the power. 

And another more clever way to do this is measure the BEMF during the transitions on commutator segments in a motor, a NATURAL interruption of the power to a motor winding without any additional circuitry required. 

This also has the added benefit of allowing you to precisely determine the rpm of the motor. This is how the QSI decoder precisely can synchronize chuffs to the rpm of a motor. 

I guess I jumped ahead too far on how it's implemented. I thought most people knew this was the typical "Trick" to easily read bemf ... sorry. 

Regards, Greg


----------



## Westcott (Feb 17, 2009)

So, given that back EMF has been discussed enough, what *are* your PWM timing preferences?

I've gone for 20 KHz with my PICAXE controller, because it makes the duty cycle sums easier!

On a related note, does anyone know how to drive an H-bridge of MOSFETs from an 8-pin PICAXE?

Hamish


----------



## Torby (Jan 2, 2008)

For controlling, I found the cutest switch at Mouser. P/N 688-SLLB120200 Hmm. What did I do with the silly thing?


----------



## KVBarkley (Jan 9, 2009)

Westcott: 
Check out the LMD18200 (Thanks George!). For 14$ US (from Digikey). It is a full 5 A H bridge comprised of DMOS power transistors (integral reverse diode protection!) with short circut protection, over temperature compensation and current sensing. Check out National Semiconductor data sheet and AN-694 

It has 3 inputs: PWM, direction and brake (for emergency stops) - pretty much a complete package. 

I just got mine in the mail yesterday, which is what brought up this discussion.


----------



## dbodnar (Jan 2, 2008)

Posted By Westcott on 04/28/2009 4:06 AM
So, given that back EMF has been discussed enough, what *are* your PWM timing preferences?

I've gone for 20 KHz with my PICAXE controller, because it makes the duty cycle sums easier!

On a related note, does anyone know how to drive an H-bridge of MOSFETs from an 8-pin PICAXE?

Hamish






Hamish - if your current draw is low you can also use the LM293D (up to 1/2 amp) or sn754410ne (up to 1 amp) - they are very easy to use, inexpensive and readily available. I use them to control LGB 0-4-0 locomotives without any problems. I also find them to work well to throw switch motors under PIC or PICAXE control.




There is an article on how to interface them with a PICAXE 18X on my web page at:


Robot Train Article

There are details on using them with switch motors using a PICAXE 08M at:

Switch Motors 


dave


----------



## krs (Feb 29, 2008)

Posted By Westcott on 04/28/2009 4:06 AM
So, given that back EMF has been discussed enough, what *are* your PWM timing preferences?

I've gone for 20 KHz with my PICAXE controller, because it makes the duty cycle sums easier!

On a related note, does anyone know how to drive an H-bridge of MOSFETs from an 8-pin PICAXE?

Hamish




If you want to be on the safe side, the PWM frequency should be 16 KHz or higher.
Any frequency much lower than that will overheat coreless motors, like the Faulhaber which are used by some manufacturers.

DCC decoders typically use 16, 20, 22 and even 32KHz. but the higher the frequency the higher the power dissipation - depends a lot on the rise and fall time.


----------



## Torby (Jan 2, 2008)

Pickaxe? 

I'm an AVR freak. "Pickaxe" is a fighting word


----------



## Westcott (Feb 17, 2009)

Thanks all.

Torby - an AVR - is that by any chance an Atmel 8-bit RISC microprocessor? Just a wild guess.

KVBarkley (and George) - yes that is one cool device.
3A continuous, 6 peak.
There's an Ebay seller in Hong Kong.

Hamish

P.S. This LMD18200 chip also has a current sensing output which tells you how much current the load is taking.
This could be an answer to the "Detecting engine load" topic in the Sound Systems forum.


----------



## KVBarkley (Jan 9, 2009)

Thanks everyone, I guess I will go with 22.05 kHz since that is the official digital upper end for the audio band. 8^) 

I used to be able to hear the 15kHz flyback noise in a TV. I can't hear anything from my new flatscreen, I guess my hearing is going. 8^) 

And I will play around with the minimum duty cycle with a trim pot.


----------

