RaspberryKitten
Posts: 7
Joined: Thu Jul 03, 2014 7:26 am

Controlling motor with pi

Sun Jul 06, 2014 8:29 am

Do you have to use the L298N motor drive to control motors

If not please provide instructions on how to.

Thanks :roll:

User avatar
joan
Posts: 14174
Joined: Thu Jul 05, 2012 5:09 pm
Location: UK

Re: Controlling motor with pi

Sun Jul 06, 2014 8:39 am

A L298N or L9110S motor driver board make your life a lot simpler. You could use a L293D chip instead and you could build your own from discrete components.

You can get all these from eBay for a few GBP.

Lot's of tutorials on-line. If you do follow an on-line tutorial please post a link. Some are outdated and some are downright dangerous.

ame
Posts: 3172
Joined: Sat Aug 18, 2012 1:21 am
Location: Korea

Re: Controlling motor with pi

Sun Jul 06, 2014 9:07 am

RaspberryKitten wrote:Do you have to use the L298N motor drive to control motors
No.
If not please provide instructions on how to.
How to what?

mikerr
Posts: 2774
Joined: Thu Jan 12, 2012 12:46 pm
Location: UK
Contact: Website

Re: Controlling motor with pi

Sun Jul 06, 2014 9:10 am

Ready made L298 makes things easier, but very much a "black box" to many people
If you want to learn by going back to basics (important IMO) you can use a single transistor and resistor:
Image
http://www.davidhunt.ie/howto-switching ... pberry-pi/
Of course that's only good for one direction.


For reverse,then you need a H-bridge (4 transistors), at which point its easier to use a ready made L298 or similar.
Android app - Raspi Card Imager - download and image SD cards - No PC required !

User avatar
Burngate
Posts: 5967
Joined: Thu Sep 29, 2011 4:34 pm
Location: Berkshire UK Tralfamadore
Contact: Website

Re: Controlling motor with pi

Sun Jul 06, 2014 9:39 am

Mikerr: Do you mind if I complain rather bitterly that the diagram is not very good?

On the page from which you grabbed the diagram, there's a comment describing precisely the problem: when GPIO Pin 7 goes high, it only reaches 3v3 above Pin 6 (the ground pin)
So the motor will only have about 2v7 across it, despite using a 12v supply - all the rest is across the transistor.

So move the motor into the collector
Or equivalently move the Pin 6 (ground) connection from the [motor-12v supply negative] junction to the [emitter-motor] junction

User avatar
joan
Posts: 14174
Joined: Thu Jul 05, 2012 5:09 pm
Location: UK

Re: Controlling motor with pi

Sun Jul 06, 2014 9:55 am

Does using the transistor remove the need for a fly-back diode?

mikerr
Posts: 2774
Joined: Thu Jan 12, 2012 12:46 pm
Location: UK
Contact: Website

Re: Controlling motor with pi

Sun Jul 06, 2014 10:43 am

Burngate wrote:Mikerr: Do you mind if I complain rather bitterly that the diagram is not very good?
Agreed - the perils of a quick google :oops:
I just wanted a simple bare bones circuit, didn't look too closely.
Android app - Raspi Card Imager - download and image SD cards - No PC required !

User avatar
Burngate
Posts: 5967
Joined: Thu Sep 29, 2011 4:34 pm
Location: Berkshire UK Tralfamadore
Contact: Website

Re: Controlling motor with pi

Sun Jul 06, 2014 6:23 pm

joan wrote:Does using the transistor remove the need for a fly-back diode?
YES EDIT actually NO - the diode is still required.

A motor is essentially an inductor*

In the original diagram:
At the point when the GPIO goes low, current through the inductor continues to flow, pulling its positive terminal negative. That drives the emitter below ground, and will tend to keep the transistor on, though that relies on the GPIO being able to supply current even when low, and that relies on there being a protective diode to prevent negative voltages reaching the GPIO.
Far better to put your own diode across the motor - that stops the motor-positive terminal going below -0.7v, so not drawing current from the GPIO

In the modified scenario, with the motor in the collector and its positive terminal at 12v:
At the point when the GPIO goes low, current through the inductor continues to flow, pulling its negative terminal positive. Unlike above, the transistor isn't kept on - its base and emitter are both at ground - so the positive voltage rise isn't limited except by parasitic capacitances charging up. If the voltage ries far enough, the transistor's collector-base junction will break down like a zener, and can destroy the transistor.

* with the added complication that it's also got mass which is moving, so storing kinetic energy in addition to the energy stored in the magnetic field, and acts as a generator
Once it's running at constant speed, a perfect motor - no friction - doesn't take any current, because the voltage being generated exactly balances the power supply
However, no motor is perfect, so there'll be some current flowing to replace the energy lost through friction.
Stop that current, and the motor will slow down, so the generated voltage gradually dies.
However the generated voltage is always in such a direction as to cancel the power supply, so we can ignore it here.
Hand-waving physics is a lot easier than the real stuff ;)
Last edited by Burngate on Tue Jul 08, 2014 11:31 am, edited 1 time in total.

User avatar
joan
Posts: 14174
Joined: Thu Jul 05, 2012 5:09 pm
Location: UK

Re: Controlling motor with pi

Sun Jul 06, 2014 7:44 pm

Burngate wrote:
joan wrote:Does using the transistor remove the need for a fly-back diode?
YES

A motor is essentially an inductor*

In the original diagram:
At the point when the GPIO goes low, current through the inductor continues to flow, pulling its positive terminal negative. That drives the emitter below ground, and will tend to keep the transistor on, though that relies on the GPIO being able to supply current even when low, and that relies on there being a protective diode to prevent negative voltages reaching the GPIO.
Far better to put your own diode across the motor - that stops the motor-positive terminal going below -0.7v, so not drawing current from the GPIO

In the modified scenario, with the motor in the collector and its positive terminal at 12v:
At the point when the GPIO goes low, current through the inductor continues to flow, pulling its negative terminal positive. Unlike above, the transistor isn't kept on - its base and emitter are both at ground - so the positive voltage rise isn't limited except by parasitic capacitances charging up. If the voltage ries far enough, the transistor's collector-base junction will break down like a zener, and can destroy the transistor.

* with the added complication that it's also got mass which is moving, so storing kinetic energy in addition to the energy stored in the magnetic field, and acts as a generator
Once it's running at constant speed, a perfect motor - no friction - doesn't take any current, because the voltage being generated exactly balances the power supply
However, no motor is perfect, so there'll be some current flowing to replace the energy lost through friction.
Stop that current, and the motor will slow down, so the generated voltage gradually dies.
However the generated voltage is always in such a direction as to cancel the power supply, so we can ignore it here.
Hand-waving physics is a lot easier than the real stuff ;)
All the words go in, and I can understand most of them individually, but somehow the whole never makes sense to me. I think I'll have to try out a few simple circuits. Perhaps that'll magically make everything fall into place. :(

User avatar
Burngate
Posts: 5967
Joined: Thu Sep 29, 2011 4:34 pm
Location: Berkshire UK Tralfamadore
Contact: Website

Re: Controlling motor with pi

Mon Jul 07, 2014 10:20 am

joan wrote:All the words go in, and I can understand most of them individually, but somehow the whole never makes sense to me.
Somewhat like explaining cricket's offside rule.

Many years ago, when a grasshopper looked large and dangerous, I attempted to understand how a TV EHT system worked - today's youngsters won't have a clue what I'm on about.
After lots of hand-waving by all the experts, I came to the conclusion it was just magic, a bit like how a gas fridge manages to use a hot flame to cool something down.
But I eventually got there, at least with the TV, though not the gas fridge.

There's two possible areas of confusion.
Most people can get their heads round voltages, resistances, and even capacitances - apply a voltage, current is driven by it, and the thicker the pipe the more current flows.
But current appears different, particularly in inductances. It can flow with or without any voltage, and strange voltages appear in seemingly random directions and in alarmingly large amounts in the most benign situations.

It would be straight forward if we could imagine current as the movement of bits of charge - which it actually is. But unfortunately it's the movement of negative charges, in the opposite direction to what we want.

But let's pretend for a bit that everything is the other way up. So at the bottom is ground, and we have one end of a battery connected to it. The other end of the battery is up in the air, and it's a source of electrons. Just 'cos everyone calls them negative doesn't stop them wanting to reach ground.

If we put a resistance between the top end and ground, electrons will fall through it, and the less resistance the quicker they'll do that.
Interestingly, if they were divers on a diving board, having nothing in the way, they'd fall quicker. So to an electron, nothing - open air - acts like a brick wall to a diver, while a solid lump of copper to an electron is like a vacuum to a diver.
A capacitance just holds electrons. They flow in until it's full, then nothing more happens - a pile of would-be divers, on a brick wall above the water. We now need the wall to be horizontal, but that's not impossible.

So what's with an inductance?
It's just a mechanism for adding mass to the electrons.
(And the maths works exactly like that. If we transform voltage to force and current to velocity, then resistance becomes friction, an open circuit becomes a brick wall, a short circuit an empty space, a capacitance is a spring, and an inductance a mass.
We can do that differently by transforming current to force and voltage to velocity, which swaps open with closed circuits and swaps capacitances with inductances. But we don't need to know that)

So instead of our divers suddenly rushing into the water, it takes them a while to cotton on to the idea that there's somewhere to go.
Equally, when we open the switch (put a brick wall in the way) they can't stop suddenly, so we get a pile of divers on top of the wall. Depending on how much room there is on the wall (how much capacitance) the pile can grow quite high, enough so that the wall can collapse, or maybe it grows high enough that they start falling back on the diving board.

I doubt whether that helped at all, but it was fun writing it.

BMS Doug
Posts: 3824
Joined: Thu Mar 27, 2014 2:42 pm
Location: London, UK

Re: Controlling motor with pi

Mon Jul 07, 2014 2:23 pm

All these analogies suffer because electrons move really slowly through most conductors (but are really tightly packed within the conductor, so that pushing an electron in at one end immediately causes another electron to fall out of the other end).

Imagine a plastic drinking straw filled with ballbearings, each time you push in a new ballbearing another one falls out the other end.

For an inductive load we can imagine that the drinking straw is slightly slightly elastic: as you keep pushing the ballbearings into the straw it gives a bit, but when you release the pressure it pushes the last few ballbearings back as the elastic returns to normal.

I had to double check that EHT meant what I thought, as I've always referred to them as CRT's. as the basis of all of the best pre-microchip technology, I thought they were fairly simple in theory (difficult to put into practice but the theory is easy enough).

A gas refrigerator isn't much different from a electric refrigerator: you put in energy to create a localised cold area and a localised hot area. there is always more heat in the hot area than was removed from the cold area. (with an electric refrigerator the heat is generated by an electric motor which pumps the coolant around, in a gas fridge the coolant is moved by convection from the flame). An electric fridge operates in 4 temperature pressure states and works by changing the pressure in the system where a Gas Fridge operates by chemical reactions and different boiling points.
(however unlike a CRT or a electric fridge I wouldn't be able to explain how a gas fridge works without referencing a description).
Doug.
Building Management Systems Engineer.

Ravenous
Posts: 1956
Joined: Fri Feb 24, 2012 1:01 pm
Location: UK

Re: Controlling motor with pi

Mon Jul 07, 2014 2:43 pm

Burngate wrote:
joan wrote:Does using the transistor remove the need for a fly-back diode?
YES

A motor is essentially an inductor*
Can I have a go? :lol:

NO - the transistor doesn't remove the need for the protection diode. The transistor needs protecting. (Unless the transistor has a diode built in - apparently some darlington trannies already do?)

My dumbed down explanation (because I'm not a proper electronic engineer, just an amateur) is:

When the power to the motor switches OFF, the magnetic field around it collapses. This takes a short time to happen. In that short time, field lines from the magnet are rushing through the coils of the motor. This generates a very short pulse of voltage, and repeated exposure to these can damage the transistor.

Note (1) the voltage surge is in the opposite direction because it's caused by the field contracting and (2) the voltage surge is NOT just the supply voltage, it could in fact be much higher. (Maybe I should try to measure one with a scope)

There's probably all sorts "wrong" with my explanation, but it's the best one I've seen that I can still comprehend :)

Ravenous
Posts: 1956
Joined: Fri Feb 24, 2012 1:01 pm
Location: UK

Re: Controlling motor with pi

Mon Jul 07, 2014 3:24 pm

By the way I just looked at Wikipedia and they give an example (admittedly running off a switch, not a transistor):
https://en.wikipedia.org/wiki/Flyback_diode
An oscilloscope trace given on that page shows a solenoid running at 24V, on switchoff it generates a 276V (negative) spike, if I'm reading their trace correctly.

That's probably at low current, but it's the voltage that harms the transistor...

To answer RaspberryKitten's question, yes the L298N, or for small motors an L293D, also look online for the Magpi magazine, it will probably have examples. It will matter what sort of power supply you have available (battery box?) and what sort of motor you've got.

User avatar
Burngate
Posts: 5967
Joined: Thu Sep 29, 2011 4:34 pm
Location: Berkshire UK Tralfamadore
Contact: Website

Re: Controlling motor with pi

Mon Jul 07, 2014 3:45 pm

Burngate wrote:
joan wrote:Does using the transistor remove the need for a fly-back diode?
YES
In the above, for YES read NO.
To misquote someone more well-known than me, I answered the question I thought was asked, rather than what was actually asked.

All the rest is correct, apart from the bits that aren't

User avatar
Burngate
Posts: 5967
Joined: Thu Sep 29, 2011 4:34 pm
Location: Berkshire UK Tralfamadore
Contact: Website

Re: Controlling motor with pi

Mon Jul 07, 2014 4:13 pm

BMS Doug wrote:I had to double check that EHT meant what I thought, as I've always referred to them as CRT's...
When I mentioned EHT, I was referring to the (upto) 25kv used to accelerate the beam in a CRT - which is normally done using the change in direction of current through the line-scan coils.
A transistor (or valve) switches off. The current charges a capacitor, and the voltage on it acts to reduce the current, first to zero then in the opposite direction.
As that reverse current grows, so the capacitor discharges, until the voltage across it reaches zero, then goes negative, at which point a diode (or the collector junction of the transistor) carries the (now slowly decaying) current.
When the current reaches zero or somewhat before, the transistor switches on, allowing the power supply to drive a growing current into the coil, ready for next time.

But (1) the current doesn't change linearly - it's more like exponential
and (2) we don't want it linear, since that would increase the speed of the spot at the edges compared to the middle
and (3) taking energy from the flyback pulse means its height would depend on the brightness of the picture, so changing picture content would change the EHT, altering focus, etc. as well as changing the current and therefore the picture width.
Also, because the top and bottom edges of a CRT are further away from the gun than the centre, we need to change the line scan current throughout the field.
Hence most of the complications.

Now does anyone know how it was done using thyristors instead of a transistor?

User avatar
Burngate
Posts: 5967
Joined: Thu Sep 29, 2011 4:34 pm
Location: Berkshire UK Tralfamadore
Contact: Website

Re: Controlling motor with pi

Mon Jul 07, 2014 4:17 pm

BMS Doug wrote:A gas refrigerator isn't much different from a electric refrigerator...
To quote joan
All the words go in, and I can understand most of them individually, but somehow the whole never makes sense to me.

drgeoff
Posts: 9724
Joined: Wed Jan 25, 2012 6:39 pm

Re: Controlling motor with pi

Mon Jul 07, 2014 7:29 pm

Burngate wrote: But (1) the current doesn't change linearly - it's more like exponential
and (2) we don't want it linear, since that would increase the speed of the spot at the edges compared to the middle
and (3) taking energy from the flyback pulse means its height would depend on the brightness of the picture, so changing picture content would change the EHT, altering focus, etc. as well as changing the current and therefore the picture width.
Also, because the top and bottom edges of a CRT are further away from the gun than the centre, we need to change the line scan current throughout the field.
.......
Now does anyone know how it was done using thyristors instead of a transistor?
(a) The EHT comes from the flyback pulse. Hence linearity or otherwise of the line scan current doesn't affect the EHT. (Line scan and flyback by definition occur at different parts of the cycle.) Yes, the scan current needs to be non-linear in a wide-angle CRT.

(b) I don't agree that the height of the flyback pulse depends on the picture brightness.

(c) In old CRT TVs (monochrome) there was no pincushion or trapezoidal correction.For a period it was performed entirely within the (passive) deflection coils and components - see pages 6 and 7 of http://www.vintagecomputer.net/fjkraan/ ... 16_CRT.pdf and mention of Mullard AT4041/03 or AT4041/05 Raster Correction Transductor in http://www.vintage-radio.net/forum/show ... hp?t=99482. Active modulation of the scan amplitudes came later.

(d) (Fortunately) I never encountered any line output stages using thyristors but I believe the operating principle was the same. The switch applies voltage across an inductance which causes a rising current that is (eventually) transferred to the line scan coils. What I'm not clear on is how the thyristor is turned off! http://www.piclist.org/techref/postbot. ... y&tgt=post and http://www.classiccmp.org/rtellason/chi ... da9400.pdf

I fear a moderator is going to stomp on all this soon as it way off the original topic and not really "beginner" level either!

User avatar
Burngate
Posts: 5967
Joined: Thu Sep 29, 2011 4:34 pm
Location: Berkshire UK Tralfamadore
Contact: Website

Re: Controlling motor with pi

Tue Jul 08, 2014 11:32 am

drgeoff wrote:I fear a moderator is going to stomp on all this soon as it way off the original topic and not really "beginner" level either!
You're right. Please ignore all of my posts.

boyoh
Posts: 1314
Joined: Fri Nov 23, 2012 3:30 pm
Location: Selby. North Yorkshire .UK

Re: Controlling motor with pi

Thu Jul 10, 2014 10:53 pm

Burngate wrote:
joan wrote:Does using the transistor remove the need for a fly-back diode?
YES EDIT actually NO - the diode is still required.

A motor is essentially an inductor*

In the original diagram:
At the point when the GPIO goes low, current through the inductor continues to flow, pulling its positive terminal negative. That drives the emitter below ground, and will tend to keep the transistor on, though that relies on the GPIO being able to supply current even when low, and that relies on there being a protective diode to prevent negative voltages reaching the GPIO.
Far better to put your own diode across the motor - that stops the motor-positive terminal going below -0.7v, so not drawing current from the GPIO

In the modified scenario, with the motor in the collector and its positive terminal at 12v:
At the point when the GPIO goes low, current through the inductor continues to flow, pulling its negative terminal positive. Unlike above, the transistor isn't kept on - its base and emitter are both at ground - so the positive voltage rise isn't limited except by parasitic capacitances charging up. If the voltage ries far enough, the transistor's collector-base junction will break down like a zener, and can destroy the transistor.

* with the added complication that it's also got mass which is moving, so storing kinetic energy in addition to the energy stored in the magnetic field, and acts as a generator
Once it's running at constant speed, a perfect motor - no friction - doesn't take any current, because the voltage being generated exactly balances the power supply
However, no motor is perfect, so there'll be some current flowing to replace the energy lost through friction.
Stop that current, and the motor will slow down, so the generated voltage gradually dies.
However the generated voltage is always in such a direction as to cancel the power supply, so we can ignore it here.
Hand-waving physics is a lot easier than the real stuff ;)
I found this write up very interesting, on the effects of the motor back EMF
Generated from the motor collapsing field.
One thing not explained, is why is the back EMF greater than the applied EMF.
This is due to the number of copper wire turns in the motor field winding.
The more copper wire turns in the motor field winding, the greater the
Back EMF generated .This back EMF is diverted through the protection
Diode, witch is then burnt up in form of heat ( Watt
BoyOh ( Selby, North Yorkshire.UK)
Some Times Right Some Times Wrong

mikerr
Posts: 2774
Joined: Thu Jan 12, 2012 12:46 pm
Location: UK
Contact: Website

Re: Controlling motor with pi

Fri Jul 11, 2014 9:02 am

What have I started ? :lol:

Have we lost the OP ? Remember it's in the beginners section ...

Better diagram and description:

Image
http://www.geekingabout.com/controlling ... -port.html
Android app - Raspi Card Imager - download and image SD cards - No PC required !

boyoh
Posts: 1314
Joined: Fri Nov 23, 2012 3:30 pm
Location: Selby. North Yorkshire .UK

Re: Controlling motor with pi

Fri Jul 11, 2014 2:29 pm

mikerr wrote:What have I started ? :lol:

Have we lost the OP ? Remember it's in the beginners section ...

Better diagram and description:

Image
http://www.geekingabout.com/controlling ... -port.html
I agree with you, the post was getting out of hand and to technical for
the beginners section.
When asked a question, We tell them what to do, and the reason why
In simple terms if possible, and with a simple diagram as you posted.

Regards Boyoh ( Keep Posting)
BoyOh ( Selby, North Yorkshire.UK)
Some Times Right Some Times Wrong

Ravenous
Posts: 1956
Joined: Fri Feb 24, 2012 1:01 pm
Location: UK

Re: Controlling motor with pi

Fri Jul 11, 2014 2:34 pm

Pity we'll never know if the original poster stayed to read the (simpler) replies. Pretty meaningless if not...

johndough
Posts: 254
Joined: Sun Jan 13, 2013 2:00 pm

Re: Controlling motor with pi

Sat Jul 12, 2014 9:12 am

Hi

Many years ago I designed and built control panels that had a DC brake mechanism attached to an AC motor.
A rectifier unit like this would be used...reissmann.com/en/produkte/elektronische-geraetetechnik/bremsgleichrichter/bremsgleichrichter.php

However I built my own to save a few pounds and found it needed a VARISTOR to cope with the back EMF generated, which could spike to a thousand volts and kill the diodes (1N5404) working half wave 96 - 120 volts.

I added a small varistor to quench any such energy from a highly inductive coil.

ame
Posts: 3172
Joined: Sat Aug 18, 2012 1:21 am
Location: Korea

Re: Controlling motor with pi

Sat Jul 12, 2014 12:06 pm

Ravenous wrote:Pity we'll never know if the original poster stayed to read the (simpler) replies. Pretty meaningless if not...
Successful troll is successful.

Return to “Beginners”