Shop OBEX P1 Docs P2 Docs Learn Events
H-bridge control I'm trying to convert bs1 text to bs2 — Parallax Forums

H-bridge control I'm trying to convert bs1 text to bs2

LanceLance Posts: 2
edited 2005-10-04 04:58 in BASIC Stamp
' {$STAMP BS2}
··········· ' Program Listing 23.1 BS1 Program to Demonstrate Mondo-Tronics H-bridge
' Program: MONDOMOT.BAS (Demonstrate Mondo-Tronics H-bridge)
' This program demonstrates the Mondo motor controller to
' control the direction and speed of a DC motor. Connect
' input A of the controller to Stamp pin 0; B to pin 1; and
' GND to GND. Run the program. The motor will slowly accelerate
' to top speed, then stop and repeat the acceleration in
' reverse. This program uses a carry-the-1 method of generating
' duty cycle control of motor speed. When you add a number to an
' "accumulator" (a memory location of fixed size), the accumulator
' will overflow if the result is bigger than it can hold. The
' larger the number added, the more likely an overflow or "carry"
' is. This program adds the desired motor duty cycle to an
' accumulator, and turns the motor on only when there's a carry.
' Higher duty cycles make the motor run faster. This method works
' well with the Stamp because it is more or less independent of
' speed.
motAcc VAR Byte··· ' Motor-speed "accumulator.
motDir VAR Byte····· ' Motor direction: 0=fwd; 1=reverse.
spd VAR Byte···· ' Motor speed, 0 (off) to 15 (full on).
cycles VAR Byte··· ' Number of loops at a given speed.
A CON 0····· ' Controller A input.
B CON 1····· ' Controller B input.
INPUT 0
INPUT 1
DIRS = %11······ ' Set pins 0 and 1 to output.
again:
· FOR cycles = 0 TO 255·· ' Turn 255 cycles at each speed.
·· GOSUB motor···· ' Output to motor.
· NEXT
· spd = spd +1···· ' Increase speed.
· IF spd <= 15 THEN again·· ' If speed is > 15, then..
· spd = 0······ ' ..turn motor off..
· motDir = motDir ^ 1···· ' ..and reverse direction.
GOTO again·· ' Loop forever.
motor:
· motAcc = motAcc & %1111·· ' Limit motAcc to 4 bits.
· motAcc = motAcc + spd·· ' Add speed.
· IF motAcc >= 16 THEN motOn·· ' If carry, then turn on motor.
·A = B ' Otherwise, motor off.
' GOTO again
· RETURN
' If you look at the table accompanying the H-bridge, you'll
' see that the motor is on only when inputs A and B are opposite.
' Programming shorthand for this is to set A to the motor
' direction, and make B = NOT A. PBASIC1 does not have a NOT
' function per se (see LET in the manual), so we make do by
' XORing A with 1, which has the same effect: B = A ^ 1.
motOn:
· A = motDir: B = A ^ 1
RETURN
· ' GOTO again

Comments

  • Ryan ClarkeRyan Clarke Posts: 738
    edited 2005-09-28 18:48
    Hi Lance,

    Converting from BS1 to BS2 code is really easy to do, not much work involved really.

    Is the BS1 code running like you need it to/want it to?

    Ryan

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Ryan Clarke
    Parallax Tech Support

    RClarke@Parallax.com
  • LanceLance Posts: 2
    edited 2005-09-28 19:41
    Yes as far as I know.

    Lance
  • Russ FergusonRuss Ferguson Posts: 206
    edited 2005-10-04 04:58
    Lance:

    It may be that you received some code in private by email which answered this thread. Don't know why there was nothing more posted.
    ·
    The·idea of controlling an H-Bridge directly with a stamp has had my interest for a while so I finally experimented with some small 6v motors on a "Professional Development Board".·The circuit used the BS2, all 8 dip switches, and the L293D (the new PDB is great!). There is an·ASCII·drawing of the circuit in the code.
    ·
    I suppose that this circuit and code could be used in hobby robotics, but if I were to use it I would dedicate a BS2OEM as a slave to a main controller. A pin multiplexer could be used to send the two 4 bit speed signals to the BS2OEM so that the main controller would have plenty of free pins and be able to do the sensor work.
    ·
    The PWM frequency needs to be much faster than the 39Hz that this PWM cycle was measured at.
    ·
    The attached PBasic BS2 code is not a conversion of the code that was posted for the BS1. It is a redesign.

    Post Edited (Russ) : 10/4/2005 5:13:15 AM GMT
Sign In or Register to comment.