# A Simple Motor Control Circuit FWD RVS OFF

#### T.Jackson

Joined Nov 22, 2011
328
Thanks for that.

It just goes straight down the emitter through to base as I can see.

#### SgtWookie

Joined Jul 17, 2007
22,220
You were thinking of the emitter follower configuration when wired for class AB operation.

In that configuration, if the diodes have constant current sources/sinks across them, are thermally coupled to the transistors, are adjusted carefully, and have the same temperature coefficient, they can nearly eliminate the crossover distortion.

#### T.Jackson

Joined Nov 22, 2011
328
Yeah I am a bit rusty. I haven't really done very much in years besides a couple of MCU-based projects. Oh, and a half-baked metal detector that was a massive disappoint.

#### thatoneguy

Joined Feb 19, 2009
6,359
The H-Bridge I had in my schematic, with high side drivers, is good for rail to rail power to the motor at several amps, with practically no heat dissipation relative to the BJT solution.

Independent control of all 4 transistors also allows all off to be coast, and either the top two or bottom two to act as a fast brake.

Drivers like your second one (PNP on bottom) are seen where cost is a major factor and dissipation isn't. Some MOSFET drivers even use BJTs if their internal charge pump creates enough voltage.

All is not lost. we all took something away from the exercise. If the motor was a linear actuator with a cone attached, your second design would have been much better for the application.

Switching is different than amplification, just driving an amp stage into saturation isn't exactly the same as efficient switching of loads.

#### T.Jackson

Joined Nov 22, 2011
328
Either way, mosfet or BJT -- this is the basic schema that I would personally go with in a real world project:

Rich (BB code):
/*
* Project name:
Custom Motor Controller FWD, RWD STOP

None

* Description:
A start switch is pressed and the motor begins to rotate forwards until a
limit switch is hit, then the motor reverses back to initial position
*/

#define motorCtrlLineA GPIO.F0
#define motorCtrlLineB GPIO.F1
#define startSwitch GPIO.F2
#define limitSwitch GPIO.F3

// Global scope vars
char motorRun = 0;
char lSWCount = 0;

void main()
{
ANSEL  = 0;                   // Configure AN pins as digital
CMCON  = 7;                   // Turn off the comparators
TRISIO = 0b00001100;          // configure pins of GPIO
GPIO   = 0;                   // Clear port ...

while(1)
{
if (motorRun == 0)          // Flag set denoting that motor is on?
{
if (startSwitch == 0)    // User press start switch?
{
motorRun = 1;         // Flag on denoting that motor is running
}
}
else     // :: Motor running FORWARDS until limit switch is hit :: //
{
if (lSWCount == 0)
{
// Rotate motor forwards
motorCtrlLineA = 1;
motorCtrlLineB = 0;

// Limit switch it?
if (limitSwitch == 0)
{
lSWCount = 1; // Set flag denoting that motor is to be reversed
}
}
else   // :: Motor running BACKWARDS until limit switch is hit :: //
{
// Reverse motor
motorCtrlLineA = 0;
motorCtrlLineB = 1;

// Limit switch it? Cease operation if so
if (limitSwitch == 0)
{
// Motor off
motorCtrlLineA = 0;
motorCtrlLineB = 0;

// reset vars ready for next cycle
motorRun = 0;
lSWCount = 0;
}
}
}
}
}

#### Attachments

• 89.4 KB Views: 39

#### T.Jackson

Joined Nov 22, 2011
328
A 16F629 is like a 2-cent part if you know the right people?

#### SgtWookie

Joined Jul 17, 2007
22,220
A 16F629 is like a 2-cent part if you know the right people?
What's a 16F629? Microchip doesn't make one of those.

A PIC12F629-I/SN costs $0.70/ea if you have a commercial account and are buying them in lots of 5,000. It has an internal oscillator that can be used in lieu of an xtal or ceramic resonator, saving two pins. The internal oscillator has a range of 32kHz to 4MHz. #### T.Jackson Joined Nov 22, 2011 328 That works out overall being so much cheaper. That software took me like 30 mins to write. Much faster. Much easier. Far more manageable. You'd have to have rocks in your head to do it any other way. #### SgtWookie Joined Jul 17, 2007 22,220 If you were doing a one-off and had no experience programming, it would be madness to spring for$35 or more for a programmer, then spend weeks trying to learn how to program the thing.

Don't get me wrong - microcontrollers are great, but I don't have the time to teach someone brand-new to electronics and microcontrollers how to program them from the get-go.

#### T.Jackson

Joined Nov 22, 2011
328
I agree 100% with that. Micros are no simple affair requiring much time and money to be able to implement.

I have spent years as a programmer to get to this stage. I am fluent now, but I never used to be very good I can tell you.

#### T.Jackson

Joined Nov 22, 2011
328
The PIC12F625-I/SN is a bit cheaper again?

#### sheldons

Joined Oct 26, 2011
613
plus you havnt taken switch bounce into consideration......

#### T.Jackson

Joined Nov 22, 2011
328
plus you havnt taken switch bounce into consideration......
There is logically no need with the way in which it is coded.

Rich (BB code):
  while(1)
{
if (motorRun == 0)          // Flag set denoting that motor is on?
{
if (startSwitch == 0)    // User press start switch?
{
motorRun = 1;         // Flag on denoting that motor is running
}
}
It can bounce all it likes with that!

The other switch is the same, it sets a flag and changes program flow.

No need for delays and stuff if you can code the right way.

#### strantor

Joined Oct 3, 2010
5,369
That works out overall being so much cheaper. That software took me like 30 mins to write. Much faster. Much easier. Far more manageable.

You'd have to have rocks in your head to do it any other way.
here's the parts list for my design:
2 relays @ 2.10$ea = 4.20$
2 diodes @ 10c = 20c
total = 4.40\$, less than an angus burger
OP could build mine in less time than it took you to write your program, with no electronics experience at all, just by looking at the little symbols on the side of the relays.

But I guess I must (?) admit that things always become at least 10X cooler when you unnecessarily throw a microcontroller into the mix.

#### T.Jackson

Joined Nov 22, 2011
328
But I guess I must (?) admit that things always become at least 10X cooler when you unnecessarily throw a microcontroller into the mix.
It is a different way of thinking altogether. You lose one old skill set and gain a new when you cross over. I used to be better with discrete and not so good with micros, now it is the other way around!

#### strantor

Joined Oct 3, 2010
5,369
It is a different way of thinking altogether. You lose one old skill set and gain a new when you cross over. I used to be better with discrete and not so good with micros, now it is the other way around!
I've played around with arduino plenty and I like it alot. I have been on the cusp of buying a PIC programmer for over a year now; I keep getting to the point where I think my arduino won't handle the application and I have no choice, and then I find another way.
I consider myself a decent amatuer at programming; I can fumble my way through visual basic and some C. Basically, I don't know jack, but I have a foundation to build on so I can figure things out, which I've heard is the most important part.

#### T.Jackson

Joined Nov 22, 2011
328
You should be alright. Just make sure that your projects have clear goals and so on. I started off as a laughable programmer contributing projects to a site where I copped a lot of ridicule. Around 5-years down the track had one of the offenders e-maling me saying "holly crap Trent I cannot get my head around your Pacman game, how did you manage to migrate from VB6 to .net?"

People who live in glass houses simply shouldn't throw stones. If you're determined enough; you will eventually come to grips with most of it.

#### ElectroDFW

Joined Sep 2, 2011
15
I really think you guys are over-thinking this.

Check out "The Incredibly Useless Machine"
I do believe it fills his requirements:
Hit a switch, mostor starts in one direction until it hits a limit;
Motor goes in other direction until it hits the other limit, then stops.
Can't get much simpler.

Circuit diagrams are available online.

--Electro-
aka The Other David
---------------------
The proof that there is Intelligent Life in the Universe
---------------------

#### Flux007

Joined Dec 5, 2011
2
Thank you all very much for your replies, sorry for my late reply. I will try and bang out these circuits on Proteous and get making. I think Sgt. Wookies initial circuit looks as though it will do the job nicely.

T Jackson the circuit you posted is very similar to mine as I too used an h bridge and 4017 but I couldnt get it to quite work so I'll probably make this too.

Many thanks.