PDA

View Full Version : PWM Motor Driver (H Bridge) Object from OBEX



JeremyJ
04-11-2012, 05:39 PM
Hello all,

I just soldered up an eval board with a L298 full bridge driver and I found this software in the Propeller OBEX:
http://obex.parallax.com/objects/455/

I loaded in onto my Propeller and I see that the pwm object initiates signals to drive one of the two bridges on the L298. I checked the signal output on an O-scope and it looks good. I looked at the code a little and it wasn't apparent to me how you would get the object to work with a two phase, bipolar motor, which is what I'd like to drive.

Has anyone worked with this object before or something similar? The switching of the "Enable" pin for the two phases has to be 180 degrees out of phase for it to work.

Thanks

StefanL38
04-11-2012, 08:41 PM
Hi,

2-phase bipolar motor sounds like a stepper-motor which were driven completely different than dc-motors.

Can you post a schematic of the motor?
best regards
Stefan

idbruce
04-11-2012, 08:56 PM
And if it is a stepper motor, did you also use the L297?

Duane Degn
04-11-2012, 09:28 PM
Yeah, I don't think that object will work with a stepper motor (I assume a "two phase, bipolor motor" is a stepper).

Besides possible objects in the OBEX, you might want to check out JonnyMac's Spin Zone (http://www.parallax.com/Resources/NutsVoltsColumns/TheSpinZone/tabid/781/Default.aspx)article about driving a stepper motor with a Prop. It's the last article listed #136.

JeremyJ
04-11-2012, 11:51 PM
It's definitely a stepper motor - more specifically a bipolar, 2-phase permanent magnet stepper. I'd guestimate it to be on the order of 1A - it's something that I salvaged from a scanner.

StefanL38 - I'm not sure why you think that the L298 can't drive a bipolar stepper. Can you explain? The IC should be able to drive one small (up to 2A per bridge, per spec) DC motor per bridge or a single bipolar, 2 phase stepper (I'm sure you could wire up a unipolar stepper also, but I'd have to think about the wiring a little on that one...)

idBruce - the L297 is shown as a possible application on the spec sheet, but I don't see why it can't be driven directly from the Propeller with the referenced object. The signals look good....I just need a Phase B that sends a Enable signal out of phase with Phase A.

So what I'm thinking you need to do to drive this motor using said pwm object is to get EnableA and EnableB shifted...so the sequence is something like this.

1: EnA - high | EnB - low
2: EnA - low | EnB - high
3: EnA - high | EnB - low
4: EnA - low | EnB - high
.....etc

I'd be happy to get the referenced object to give me that output for the enable pins. The direction of revolution is controlled by the Input 1,2,3,4 pins. 1 and 3 high with 2 and 4 low with be one direction and the opposite will correspond to the reverse direction. You can follow the logic of the IC's internal bridge schematic on the first page of the IC specification - http://www.sparkfun.com/datasheets/Components/General/L298N.pdf

OK....I will mention as a caveat that I have some doubt as to the stepping required by this motor, since it is of the permanent magnet type and not the variable relucance type (for which current direction in the coil is inconsequential). I'm not sure if it is:

Option 1:
Phase A pulse
Phase B pulse
Phase A pulse
Phase B pulse

or

Option 2:
Phase A Pos pulse (current sent in positive direction through coil)
Phase B Pos pulse (current sent in positive direction through coil)
Phase A Neg pulse (current sent in negative direction through coil)
Phase B Neg pulse (current sent in negative direction through coil)
Phase A Pos pulse....etc.

I have no experience with steppers, and know they are designed differently from standard PM and SR motors that are used for motion rather than precision stepping.

pedward
04-12-2012, 12:01 AM
The L298 is a dumb high power transistor quad H bridge. Without external current limiting or PWM driving the inputs, the L298 will saturate the motor. The L297 is a chopping current regulated driver, it will cap the current at 2 amps, you can limit the current further by adjusting the duty cycle.

JeremyJ
04-12-2012, 12:15 AM
pedward

So then what are the two sense resistors and Vsense outputs doing on the L298? My understanding per the spec is that they are controlling the chopping to do exactly what you say....to limit the current to 2A, and you can as mentioned adjust the duty cycle further (once Vsense exceeds some value, your IC knows to limit duty cycle based on current consideration vs input into the Enable pins).

I didn't hook these up, as I didn't see them critical to basic (rough or "jerky") operation.

Oh wow....it just dawned on me that you are right. Sometimes you look at these things and look at these things and just don't get it....of course you need to connect these outputs to another chip...nothing is reading them!

Regardless, my setup should work just fine without the L297, since I am limiting current on the power supply. Thoughts?

pedward
04-12-2012, 12:37 AM
The sense resistors are the ground path for both H bridges, the voltage drop across the resistor is fed to the L297 so it knows the current being drawn. The L297 then chops the inputs to the L298 to effect current control. The duty cycle is controlled with jumpered inputs to the L297 IIRC. You should hook up the sense resistors, the L298 won't work without them.

JeremyJ
04-12-2012, 01:06 AM
OK, I'll bite on that.

Won't work why?

You're the one that said the L298 was dumb, right? How does it know if I have a 0.05Ohm wire path to ground or a short ground path with the 0.5Ohm resistor. The useful information in this scenario is being transmitted by the inputs (Vsenses) into the L298, as you mention. This is just going to be I(phase) x R(sense) <= 2V (at which point the L298 will being its current-limiting, PWM magic).

Also, since you have some knowledge on the subject, do you have any feedback on my stepping question?

Here's what I asked....

OK....I will mention as a caveat that I have some doubt as to the stepping required by this motor, since it is of the permanent magnet type and not the variable relucance type (for which current direction in the coil is inconsequential). I'm not sure if it is:

Option 1:
Phase A pulse
Phase B pulse
Phase A pulse
Phase B pulse

or

Option 2:
Phase A Pos pulse (current sent in positive direction through coil)
Phase B Pos pulse (current sent in positive direction through coil)
Phase A Neg pulse (current sent in negative direction through coil)
Phase B Neg pulse (current sent in negative direction through coil)
Phase A Pos pulse....etc.

Thanks

idbruce
04-12-2012, 01:15 AM
JeremyJ

The L297 is just a controller, which makes life a whole lot easier for controlling a stepper. You should be able to control the stepper with a dual h-bridge like the L298, but it is much more difficult without the L297 to back it up.

Bruce

JeremyJ
04-12-2012, 01:30 AM
Thanks guys,

I should add that I'm not really trying to build a serious stepper motor controller here. I'm actually taking a course at the moment on embedded systems design and I need to give a presentation to my class tomorrow. We've been working on an ARM microcontroller platform. It can be a bit cumbersome programming on that platform, so I wanted to demo a simple .spin program to control a stepper motor to show how a propeller MCU masks a lot of the complexity required to build a simple motor driver, particularly the issues of dealing with timer registers all all that fun stuff. Therefore, it's not absolutely critical that I have a finished product - I would, however, like to get one of these objects working. I'll try the Spin Zone article too.

idbruce
04-12-2012, 02:47 AM
JeremyJ

If that is the case, it would be a lot easier to just use a ULN2803 and a unipolar stepper motor. One SpinZone article and you would be ready for a demonstration.

Bruce

pedward
04-12-2012, 03:29 AM
The L293 is a nice DIP quad half h-bridge chip too. You can experiment without worrying about a lot of current. I have written code to control stepper motors with microstepping, using the L293. If you search the forum for microstepping, you should find some code I posted. This will get you started. To control current you basically adjust the dead time of the PWM -- if your range is 0-255, the dead time is increased by keeping the input 0-255, but increasing the loop from 255 to 512. I found values such as 290 and 300 to be useful.

You said you omitted the sense resistors, but didn't say you simply jumpered them to ground; the statement I made was to ensure you have the sense pins connected to ground somehow.