Shop OBEX P1 Docs P2 Docs Learn Events
Motor Controller - Need some Help — Parallax Forums

Motor Controller - Need some Help

merlinmerlin Posts: 40
edited 2007-03-02 05:13 in Robotics
Dear friends:

I am on a nightmare controlling my motors. Afte a very bad experience with Pololu controllers, commented earlier on this forum, I have purchased two HB-25 for my two motors.
After the wiring setup using only one motor, I have working with the code example provided on HB-25 documentation:

(this is portion of the code)
PAUSE 20 ' Wait 20 mS Before Ramping
FOR index = 0 TO 250 ' Ramp Up To Full Speed
PULSOUT HB25, 750 + index ' Motor 1 Forward
PAUSE 20 ' 20 mS Smoothing Delay
NEXT
Running the code I get some strange behavior, because the motor begins to run· only near to the end of the loop, when the index value is about to 230. The motor start running at full speed during short period and I can´t get the Rampu Up effect.
Any suggestion or comments will be very appreciated.
Thanks a lot

merlin

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔


Visit my Personal Home Page:

http://darnoff.vtrbandaancha.net/
«1

Comments

  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2006-06-15 16:35
    Merlin,

    ·· Since the part you posted seems to be slightly modified from the original I would suggest attaching (not pasting) the exact piece of code you are running so I can run it on my end and see what might be happening.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Chris Savage
    Parallax Tech Support
    csavage@parallax.com
  • merlinmerlin Posts: 40
    edited 2006-06-16 14:28
    Tks for fast reply, here is the exact code I am using on my test:

    ' {$STAMP BS2}
    ' {$PBASIC 2.5}

    HB25 PIN 7

    index VAR Word

    DO:LOOP UNTIL HB25=1
    LOW HB25
    PAUSE 5
    PULSOUT HB25, 750

    Main:
    PAUSE 20
    FOR index=0 TO 250
    PULSOUT HB25, 750+index
    DEBUG 1, DEC index
    PAUSE 20
    NEXT

    PAUSE 3000

    FOR index=250 TO 0
    PULSOUT HB25, 750+index
    DEBUG 1, DEC index
    PAUSE 20
    NEXT

    STOP

    I run the code using two typical DC motors, from differents brands, previously tested.
    With the first motor, as I mention above, the motor start running at full speed only when the index value is near to 240 in the first For-Next cycle. Second For-Next have no effect on the motor.
    Trying the second motor, the effect is even more weird: when the index value goes to 240 in the first cycle, the Stamp program interrupts the execution and begin from the start of the For-Next loop, again and again.
    Pls give me some advise, I am little lost here.
    Thanks in advance

    merlin

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔


    Visit my Personal Home Page:

    http://darnoff.vtrbandaancha.net/
  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2006-06-16 14:52
    merlin,

    ·· You wouldn't happen to be using the same power supply for both the BASIC Stamp and the HB-25 would you?· Also, how are you powering both devices?


    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Chris Savage
    Parallax Tech Support
    csavage@parallax.com


    Post Edited (Chris Savage (Parallax)) : 6/16/2006 3:03:00 PM GMT
  • Tom WalkerTom Walker Posts: 509
    edited 2006-06-16 18:13
    Is that a "useful" form of "DO - LOOP"?

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Truly Understand the Fundamentals and the Path will be so much easier...
  • merlinmerlin Posts: 40
    edited 2006-06-16 18:46
    Actually I am using only one 7v battery for powering. One wire from battery goes directly to the HB25 motor power connectors and other wire goes to a LM7805 to obtain 5v regulated, who are used to powering the Stamps and other components of the project.

    Do you suspect a power issue here?

    And yes, the DO-LOOP form described above working fine if you are using PBasic 2.5



    Thanks and best regards

    merlin

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔


    Visit my Personal Home Page:

    http://darnoff.vtrbandaancha.net/
  • merlinmerlin Posts: 40
    edited 2006-06-16 19:12
    I have try on this last minutes powering the Stamp with a 9v battery using the LM7805 as regulator and powering the HB25 with the 7v battery. The results are the same reported earlier.
    Tks

    merlin

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔


    Visit my Personal Home Page:

    http://darnoff.vtrbandaancha.net/
  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2006-06-16 19:39
    merlin,

    ·· What is most likely happening is that when the motor goes to engage it draws enough current to sag the power supply.· What this happens the BASIC Stamp is browning out, and resetting.· In most cases where you would use an HB-25 you would have a separate power supply for the HB-25 from the BASIC Stamp OR you have to have the source voltage high enough that it won't reset the BASIC Stamp during peak current consumption when the voltage sags.· For example, I am using a 12V system on a robot and powering everything from that supply.· But even at peak current draw my supply never sags down below 9 volts and it would need to hit 4.8 to affect the BASIC Stamp.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Chris Savage
    Parallax Tech Support
    csavage@parallax.com
  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2006-06-16 19:41
    Tom Walker said...
    Is that a "useful" form of "DO - LOOP"?
    Tom,

    ·· That is a terse way of saying, "Loop until this condition is met", without doing anything inside the loop.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Chris Savage
    Parallax Tech Support
    csavage@parallax.com
  • bennettdanbennettdan Posts: 614
    edited 2006-06-16 20:55
    The recomended min voltage on the HB-25 is 6v do you have a larger battery to try?
  • Bruce BatesBruce Bates Posts: 3,045
    edited 2006-06-16 21:38
    Chris -

    And the advantage of doing that over IF ... THEN is what, since it obviously must take up more code space?

    Regards,

    Bruce Bates

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    <!--StartFragment -->
  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2006-06-17 01:22
    Bruce,

    ·· You are correct in a sense.· One context of the command does use more program space.· What I should have done was:

    DO : LOOP WHILE HB25 = 0
    

    Which would be the equivalent of:

    Main:
      IF HB25 = 0 THEN Main
    

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Chris Savage
    Parallax Tech Support
    csavage@parallax.com
  • Tom WalkerTom Walker Posts: 509
    edited 2006-06-19 17:50
    Chris,
    I am familiar with the DO:LOOP construct but I haven't used the HB-25 and wasn't aware that it apparently provided a "Ready" signal. It just seemed odd to be looking for something FROM the HB-25. I though perhaps he actually meant to be looking for a switch closure or something...

    My bad...

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Truly Understand the Fundamentals and the Path will be so much easier...
  • merlinmerlin Posts: 40
    edited 2006-06-19 23:51
    Dear friends:
    Despite the interesting conversation about programming, I wish to return to the main problem I have with my two HB25 units, that is, the motor begins to run at full speed only when the counter is about 240 and the motor stops when is reached the end of the first loop. The second loop has no effect on the motor.
    I have follow the advices and I have separated the power sources, giving a common ground, I have used also a 9v battery to energize the motor, and the result is exactly the same.
    This is the problem here and I really I will appreciatte any guidance, due my two units works on the same way.
    Thanks in advance, best regards

    merlin

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔


    Visit my Personal Home Page:

    http://darnoff.vtrbandaancha.net/
  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2006-06-20 15:29
    merlin,

    ·· Above you stated you were using a 9V battery and· 7V battery.· If you're using a 9V transistor battery this will provide insufficient current to run the motors and the HB-25.· I don't know what your 7V motor is.· What is it's current capacity?

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Chris Savage
    Parallax Tech Support
    csavage@parallax.com
  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2006-06-20 15:31
    Tom Walker said...(trimmed)
    I am familiar with the DO:LOOP construct but I haven't used the HB-25 and wasn't aware that it apparently provided a "Ready" signal. It just seemed odd to be looking for something FROM the HB-25. I though perhaps he actually meant to be looking for a switch closure or something...
    Tom,

    ·· It's not that we're getting a "ready" signal, per se.· The HB-25 signal line is pulled high.· We can use this to detect that it's powering-up/connected.· Just a little trick since often the motor control/power is turned on after the controller in many systems.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Chris Savage
    Parallax Tech Support
    csavage@parallax.com
  • merlinmerlin Posts: 40
    edited 2006-06-20 16:44
    Chris:
    I am using the follow powering for the robot system:
    For the logical voltage I am using a 9v battery regulated via an LM7805 in order to get the 5v requeried. This voltage is applied to the BS2p.
    For power voltage of motor I am using a 7v dry battery with 1Amp H. The leads of this battery are connected to the HB25 Power input terminal. Both grounds of power supplies are connected, so the whole system has only one common ground.
    The servo pulse input requiered by HB25 comes from one I/O line of the BS2p
    Thanks in advance

    merlin

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔


    Visit my Personal Home Page:

    http://darnoff.vtrbandaancha.net/
  • bennettdanbennettdan Posts: 614
    edited 2006-06-21 02:44
    What voltage does the 7v battery read when the code is trying to run? It may be dropping below the 6v min of the HB-25
  • merlinmerlin Posts: 40
    edited 2006-06-21 12:57
    The battery voltage is about 6,75 when the code is running. I have tried with a 12v battery , wich gives about 11,25v during th code execution and and the effect is exactly the same.
    As I posted before, I have two motors in my tests, both toys motors but one smaller than the other. The small one begins to run when the loop counter reach the 240 value. The second motor does not respond at any moment.
    Thanks in advance

    merlin

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔


    Visit my Personal Home Page:

    http://darnoff.vtrbandaancha.net/
  • merlinmerlin Posts: 40
    edited 2006-06-22 02:20
    Dear folks:
    I am very happy to share with you I have found the real source of this problem: it doesn't the Powering, it doesn't the code...it was the Microprocessor!!
    From the very beginning on this thread I have post that I am using a BS2, wich is a major error. The fact is that I am using for my robot the new BS2px Microcontroller, but I assumed the behavior of one BS2px should be identical to one BS2...the asumption was not correct, because I have changed the BS2px for a simple BS2 and all runs in perfectly way. I have two BS2px chips, and the two experiments the errors I have posted, so I assume the difference is related to the microsprocessor.
    I have read carefully the specific documentation about the BS2px and the PULSOUT command is mentioned, but I can figure out what changes has to be made on the main code to get on work this new chips. All help about this issue will be very appreciatted and thanks for all your time spended on this case.
    Best regards


    merlin

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔


    Visit my Personal Home Page:

    http://darnoff.vtrbandaancha.net/
  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2006-06-22 04:21
    merlin,

    ·· Looks like you beat me to what I was going to say.· Now that I know you're using a BS2px I can tell you that the code won't work as listed just because the PULSOUT values are different.· If you look in the Help File it will tell you the differences and you should be able to make the changes based on that information.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Chris Savage
    Parallax Tech Support
    csavage@parallax.com
  • merlinmerlin Posts: 40
    edited 2006-06-22 18:29
    Chris
    I have checked the most recent Help file and I didn't find anything specifically related to BS2px regarding the Pulsout, Pulsin, Serout and Serin commands. In fact, the example used in the Help file in Pulsout is a BS2 code example, wich should be aplicable to any BS2 member family Stamps without changes.
    So I guess I need "a little help from my friends" to go further in order to migrate my code from BS2 to BSpx.
    Pls give me some initial guidance and I will follow for my own, thanks again.
    Best regards


    merlin

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔


    Visit my Personal Home Page:

    http://darnoff.vtrbandaancha.net/
  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2006-06-22 22:34
    merlin,

    ·· Please update your software...The help file included with all recent version contains the following table, which does contain the information I referred to.· As you can see, the PULSOUT on the BS2sx, BS2p and BS2px has different timing from the BS2, so in fact the example code will not work for you.

    attachment.php?attachmentid=73805


    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Chris Savage
    Parallax Tech Support
    csavage@parallax.com
    549 x 133 - 6K
  • bennettdanbennettdan Posts: 614
    edited 2006-06-23 01:11
    Chris so what you are saying is that when he uses the BS2p for his zero position for the HB-25 should be PWM HB-25 1600 and he should very the PWM in the For next loops from 0-600 and 600-0 because the BS2p is running a little over twice as fast?
  • merlinmerlin Posts: 40
    edited 2006-06-23 04:07
    Chris:
    I spend almost all day seeking for aditional information about the issues you have noted.
    In fact, on this forum are many many post around this issue and you, support guys, had given thousand of answers about.
    So at the end of my seek I have tons of info and in the meantime I have corrected some portions of my code and voil
  • bennettdanbennettdan Posts: 614
    edited 2006-06-23 05:53
    merlin do you mind posting the corrected code?
  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2006-06-23 14:56
    bennettdan said...
    Chris so what you are saying is that when he uses the BS2p for his zero position for the HB-25 should be PWM HB-25 1600 and he should very the PWM in the For next loops from 0-600 and 600-0 because the BS2p is running a little over twice as fast?
    No, what I am saying is that due to the different resolution of the BS2sx, BS2p and BS2px their center position is 1875 rather than 750 as on the BS2.· From there he would calculate his range from 1260 through 2500.· On the BS2 the resolution is 2us, as per the table I posted.· So from 1.0 ms through 2.0 ms the BS2 would be 500 through 1000 with 750 being the center.· That is calculated by 1000/2 (500) and 2000/2 (1000) giving a center position of 750 (1500/2).· With a BS2sx, BS2p or BS2px you would do 1500 (center) / .8 and get 1875.· I hope this helps.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Chris Savage
    Parallax Tech Support
    csavage@parallax.com
  • bennettdanbennettdan Posts: 614
    edited 2006-06-23 17:53
    Yes I think I was thinking the same way you was but did not know the math to work it out. Thanks again.
  • robonutrobonut Posts: 3
    edited 2007-03-02 04:48
    What would be the translation of the following code to a bs2sx:


    ' {$PBASIC 2.5}
    HB25 PIN 0 ' I/O Pin For HB-25

    index VAR Word ' Counter For Ramping
    '
    [noparse][[/noparse] Initialization ]
    DO : LOOP UNTIL HB25 = 1 ' Wait For HB-25 Power Up
    LOW HB25 ' Make I/O Pin Output/Low
    PAUSE 5 ' Wait For HB-25 To Initialize
    PULSOUT HB25,·750 ' Stop Motor 1
    PAUSE 1 ' 1 mS Delay
    PULSOUT HB25,·750 ' Stop Motor 2 (If Connected)
    ' The Above 2 Lines May Be Removed
    ' If You Are Using Single Mode
    '
    [noparse][[/noparse] Program Code ]
    top:
    Main:
    PAUSE 20 ' Wait 20 mS Before Ramping
    FOR index = 0 TO 250 ' Ramp Up To Full Speed
    PULSOUT HB25,·750 + index ' Motor 1 Forward
    PAUSE 1 ' 1 mS Delay For Motor 2 Pulse
    PULSOUT HB25,·750 - index ' Motor 2 Reverse
    PAUSE 20 ' 20 mS Smoothing Delay
    NEXT
    PAUSE 3000 ' Wait 3 Seconds
    FOR index = 250 TO 0 ' Ramp Back Down
    PULSOUT HB25,·750 + index ' Motor 1 Forward Slowing
    PAUSE 1 ' 1 mS Delay For Motor 2
    PULSOUT HB25,·750 - index ' Motor 2 Reverse Slowing
    PAUSE 20 ' 20 mS Smoothing Delay
    NEXT
    'STOP ' Use STOP To Prevent State
    GOTO top
  • FranklinFranklin Posts: 4,747
    edited 2007-03-02 05:10
    Robonut, if you have a question you need to start your own thread not hijack someone elses.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    - Stephen
  • robonutrobonut Posts: 3
    edited 2007-03-02 05:13
    Im powering them separetly, I tested with a bs2 and works fine, im pretty sure you need to change the code since a bs2sx is 2.5 times faster than a bs2. From previous posts it seems i need to change 750 in the code to 1875. I tried this but no luck.
Sign In or Register to comment.