Shop OBEX P1 Docs P2 Docs Learn Events
PWM Motor Driver (H Bridge) Object from OBEX — Parallax Forums

PWM Motor Driver (H Bridge) Object from OBEX

JeremyJJeremyJ Posts: 30
edited 2012-04-11 20:29 in Propeller 1
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

Comments

  • StefanL38StefanL38 Posts: 2,292
    edited 2012-04-11 13:41
    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
  • idbruceidbruce Posts: 6,197
    edited 2012-04-11 13:56
    And if it is a stepper motor, did you also use the L297?
  • Duane DegnDuane Degn Posts: 10,588
    edited 2012-04-11 14:28
    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 article about driving a stepper motor with a Prop. It's the last article listed #136.
  • JeremyJJeremyJ Posts: 30
    edited 2012-04-11 16:51
    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.
  • pedwardpedward Posts: 1,642
    edited 2012-04-11 17:01
    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.
  • JeremyJJeremyJ Posts: 30
    edited 2012-04-11 17:15
    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?
  • pedwardpedward Posts: 1,642
    edited 2012-04-11 17:37
    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.
  • JeremyJJeremyJ Posts: 30
    edited 2012-04-11 18:06
    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
  • idbruceidbruce Posts: 6,197
    edited 2012-04-11 18:15
    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
  • JeremyJJeremyJ Posts: 30
    edited 2012-04-11 18:30
    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.
  • idbruceidbruce Posts: 6,197
    edited 2012-04-11 19:47
    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
  • pedwardpedward Posts: 1,642
    edited 2012-04-11 20:29
    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.
Sign In or Register to comment.