+ Reply to Thread
Results 1 to 11 of 11

Thread: Motor Controller MC7 PWM Need Help with code...

  1. #1

    Default Motor Controller MC7 PWM Need Help with code...

    Hi all I am having trouble getting 1 motor to go ccw and 1 motor to go cw at the same time
    Below is the code that I am using, it works fine otherwise. I have tried making·· high fwd_portleft· and·high rev_portright and the others low but it seems to lock up there.. Please any help would be appreciated.

    '-----------------------------pwm1mc7mtr.bs2px-----------------------------
    '· written by Carl A. Kollar modified by FV

    'Purpose:· control by BS2px of the MC7 motor Controller
    ·Can be used with
    '·either 12 or 24 volt models.
    '
    'Motor action: The motor (1) Gradually increases in speed in the forward
    '· direction until it reaches full speed. (2) Gradually
    '· reduces speed until it stops. (3) Gradually increases speed
    '· in the reverse direction until it reaches full rev. speed
    '· (4) Gradually decreases speed until it comes to a stop.
    '· (5) Does it all over again.

    '---------------------Define Constants & Variables-------------------------
    enable_portleft con 0: low enable_portleft 'disable MC7 while initializing
    pwm_out_portleft con 1
    fwd_portleft con 2
    rev_portleft con 3
    enable_portright con 4: low enable_portright 'disable MC7 while initializing
    pwm_out_portright con 5
    fwd_portright con 6
    rev_portright con 7
    duty var byte
    cycles var byte: cycles = 10

    min_speed var byte: min_speed = 52 'pwm value for 1.0V out
    max_speed var byte: max_speed = 165 'pwm value for 3.2V out
    x var byte: x = 0· 'counter variable
    pause_time var word: pause_time = 15 'pause between counter increments
    max_speed_time var byte: max_speed_time = 150

    '------------------------Initialize----------------------------------------
    low fwd_portleft 'Put MC7 in "neutral" by making both direction ports low
    low rev_portleft
    high enable_portleft 'enable the left controller
    low fwd_portright 'Put MC7 in "neutral" by making both direction ports low
    low rev_portright
    high enable_portright 'enable the right controller

    '----------------------------The Main Program-----------------------------
    '· (All sub-routine names are self-explanatory)
    main:
    ·gosub set_forward_direction
    ·gosub min_to_max
    ·gosub max_to_min
    ·gosub set_reverse_direction
    ·gosub min_to_max
    ·gosub max_to_min
    ·gosub set_right_direction
    ·gosub min_to_max
    goto main

    '***************************Sub-Routines**********************************

    'Bring motor speed gradually from a stop to full speed
    min_to_max:
    ·for x = min_speed to max_speed 'gradually increase speed
    ·pwm pwm_out_portleft,x,cycles

    ·pwm pwm_out_portright,x,cycles

    ·pause pause_time 'wait specified time
    ·next
    ·for x = 1 to max_speed_time 'stay at max. speed for awhile
    ·pwm pwm_out_portleft,max_speed,cycles
    ·pwm pwm_out_portright,max_speed,cycles

    ·next
    ·return
    '-------------------------------------------------------------------------

    'Bring motor speed gradually to a stop from full speed
    max_to_min:
    ·for x = max_speed to min_speed 'gradually decrease speed
    ·pwm pwm_out_portleft,x,cycles

    ·pwm pwm_out_portright,x,cycles

    ·pause pause_time 'wait specified time
    ·next
    ·return
    '------------------------------------------------------------------------
    set_forward_direction:
    ·high fwd_portleft 'enable forward
    ·high fwd_portright 'enable forward

    ·low rev_portleft 'reverse not enabled

    ·low rev_portright 'reverse not enabled

    ·return
    '-------------------------------------------------------------------------
    set_reverse_direction:
    ·low fwd_portleft 'forward not enabled
    ·high rev_portleft 'enable reverse

    ·low fwd_portright 'forward not enabled
    ·high rev_portright 'enable reverse
    ·return

    '-------------------------------------------------------------------------
    set_right_direction:
    high·fwd_portleft 'Left motor forward· enabled
    low·rev_portleft ' left motor reverse not enabled
    low fwd_portright 'Right motor forward not enabled
    high rev_portright 'right motor enable reverse
    ·return

    Post Edited (Bozook) : 12/15/2005 12:57:07 PM GMT
    Last edited by ForumTools; 10-01-2010 at 12:03 PM. Reason: Forum Migration

  2. #2

    Default

    If you are using PWM to power your motors, you will only get one running at a time. The PWM function will have to complete for one motor before the other one starts up. To get simultaneosly running motors, you will need a dedicated motor controller, or you will need to "roll your own" using a faster processor such as the SX.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Truly Understand the Fundamentals and the Path will be so much easier...

    Post Edited (Tom Walker) : 12/13/2005 7:17:22 PM GMT
    Last edited by ForumTools; 10-01-2010 at 12:03 PM. Reason: Forum Migration

  3. #3

    Default

    Hi Tom thanks for the reply. I am using 2 MC7 Motor Controllers made by Diverse electronics www.DiverseElectronicServices.com. On there site they show a BS2 hooked up to 1 motor and a sample code to test the motor. I have the code working on both motors forward and backward. I just cannot get one motor to go in rev while the other motor goes in forward.
    Last edited by ForumTools; 10-01-2010 at 12:03 PM. Reason: Forum Migration

  4. #4

    Default

    Looking at page 3 of the docs for the MC7 ( http://www.diverseelectronicservices.com/mc7_package.pdf ) which has a DPDT switch to control the direction. You would need to replace that switch with an electronic one using transistors and have the stamp turn on which ever one you want for the direction you want to go.

    JJ
    Last edited by ForumTools; 10-01-2010 at 12:03 PM. Reason: Forum Migration

  5. #5

    Default

    Hi Gearhead thanks for the reply. Page 5 in the ( http://www.diverseelectronicservices.com/mc7_package.pdf ) Shows how to use the stamp with the controller. I have the motors working forward and backwards with the controllers the way they are. I have talked to Diverse Electronics and they say it's in the stamps coding .. They say (Diverse) that they sell allot of them and other customers make the controllers do what I want them to do. It's just a matter how's its coded Diverse says. (racking my Brains)..

    Post Edited (Bozook) : 12/14/2005 12:40:37 AM GMT
    Last edited by ForumTools; 10-01-2010 at 12:03 PM. Reason: Forum Migration

  6. #6

    Default

    Here is a link to a Picture of the controllers and hook up to the BS2px

    http://bozooka.markv.net/images/IMG_0320.JPG

    and the·schematic NOTE! The schematic only shows one controller

    http://bozooka.markv.net/images/mc7schematic.gif

    Post Edited (Bozook) : 12/14/2005 1:55:29 AM GMT
    Last edited by ForumTools; 10-01-2010 at 12:03 PM. Reason: Forum Migration

  7. #7

    Default

    Bozook,

    Looking at the code for your set_left_direction should look something like this.

    set_left_direction:

    ' Set left motor MC7 to reverse
    low fwd_portleft 'forward not enabled
    high rev_portleft 'enable reverse

    ' Set right motor MC7 to forward
    high fwd_portright 'enable forward
    low rev_portright 'reverse not enabled
    return

    If you set high rev_portleft and high fwd_portright should make it turn to the left. Your code posted above looks like it would turn to the right.

    When it reaches the set_left_direction sub, what does it do?
    Last edited by ForumTools; 10-01-2010 at 12:03 PM. Reason: Forum Migration

  8. #8

    Default

    GearHead: When it reaches the set_left_direction sub, what does it do?

    When it gets to that gosub it stops or freez's and don't do noting. Thats my problem. I have changed the ports around and all and it just freez's at that point.
    Last edited by ForumTools; 10-01-2010 at 12:03 PM. Reason: Forum Migration

  9. #9

    Default

    I was having a look at this, because it seems there should be a simple solution if both motors work fine in one direction. For one thing, i have no idea why the constants are there? Is that supposed to be " pin connections" ? Hope you have a pin directive set for the outputs. And, as far as the code goes, if you look at the input states of the controllers in reverse, when you go back to the turn right sub, you are trying to drive an input high, when it is already in a high state. This could be locking up the contoller or the stamp.I would try either driving all the contoller inputs low before going to the turn sub, or try it at the start of the program, to see if that may be the trouble. Or even omit the code for the motor that is already programmed to move in the proper direction already in the sub. I don't know if i am right on this, but it would be worth a shot. Never used a px, may be issues with that also.

    kelvin
    Last edited by ForumTools; 10-01-2010 at 12:03 PM. Reason: Forum Migration

  10. #10

    Default

    Hi Kelvin thanks for the reply. In answer to your question "Is that supposed to be " pin connections" Yes con 1-7 are the pin directives. I have tried putting the sub set_right_direction first and have tried it by its self. does the same thing anywhich way ..freeze's up..

    Post Edited (Bozook) : 12/15/2005 1:10:34 PM GMT
    Last edited by ForumTools; 10-01-2010 at 12:03 PM. Reason: Forum Migration

  11. #11

    Default

    Someone can correct me if i am wrong, but i would dump the pin constant thing, and try a regular pin definition, stating the proper direction of the pins.

    kelvin
    Last edited by ForumTools; 10-01-2010 at 12:03 PM. Reason: Forum Migration

+ Reply to Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts