Shop OBEX P1 Docs P2 Docs Learn Events
HB-25 w/ Propeller Issues [Revised name] — Parallax Forums

HB-25 w/ Propeller Issues [Revised name]

John BoardJohn Board Posts: 371
edited 2012-04-21 20:44 in Propeller 1
Hi.. I'm back - with my new HB-25's and my robot... and my dreaded motors....

Yeap, even with the fancy-pants HB's I'm still having trouble, I believe it is to do with the code

Some pics are attached anyway.
CON
  _clkmode = xtal1 + pll16x
  _xinfreq = 5_000_000


  UpperLimit    = 2100            'Set Maximum allowed pulse width
  LowerLimit    =  900            'Set Minimum allowed pulse width
                                  '910 is full bore one way
                                  '2090 is full bore the other way
                                  '1600 is stop

pub start
   repeat
    pulsout (0,2100)              'pin & speed,direction 900-2100

PRI PULSOUT(Pin,Duration) | ClkCycles
    Duration := LowerLimit #> ||Duration <# UpperLimit 
    ClkCycles := Duration * (clkfreq / 1_000_000) - 1050
    dira[pin]~~
    waitcnt(ClkCycles + cnt)
    outa[pin]~~                                 
    waitcnt(ClkCycles + cnt)                             
    outa[pin]~   

{

[COLOR=#000000][FONT=sans-serif]MIT LICENSE[/FONT][/COLOR]

[COLOR=#000000][FONT=sans-serif]Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:[/FONT][/COLOR]

[COLOR=#000000][FONT=sans-serif]The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.[/FONT][/COLOR]

[COLOR=#000000][FONT=sans-serif]THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.[/FONT][/COLOR]

[COLOR=#000000][FONT=sans-serif]}[/FONT][/COLOR]
                              

So, I'm using the demo board which is connected to mains power. I've got the motor driver connected to my battery (7.4v, 3.6AH) and I have connected the grounds. I am using a multimeter to check the voltage, I have no motor connected to the driver. I am aiming to get my code to get the output voltage around the 1.5v - 3.3v.

1. How can I achieve this
2. What have I done wrong in my code/wiring
3. Help!

Thanks for helping my constant stream of questions,

John

[Edit] This is some new code I've tried, it looks promising, but it always goes from 0v to 8v, I need it to go from 0v to 3v (or less)

Driver:
{

}
CON
  _clkmode = xtal1 + pll16x
  _xinfreq = 5_000_000


  UpperLimit    = 2100            'Set Maximum allowed pulse width
  LowerLimit    =  900            'Set Minimum allowed pulse width

  HoldTimeM1M2  = 1500            'Minimum Hold time from Motor1 to Motor2
  HoldTimeM2M1  = 5500            'Minimum Hold time from Motor2 to Motor1

VAR
long    cog,HB25_Stack[20]
long    Motor1WidthNew,Motor1WidthOld,Motor1WidthTemp
long    Motor2WidthNew,Motor2WidthOld,Motor2WidthTemp
long    Motor1Rate, Motor1RateTemp
long    Motor2Rate, Motor2RateTemp

PUB stop                                                'Stop HB25 motor controller if started 
    if cog
       cogstop(cog)

PUB start(Pin)                                          'Start HB25 motor controller
    cog := cognew(HB25(Pin),@HB25_Stack)
    
PUB SetMotor1(Motor1WidthNew_)                          'Note: A negative Width value indicates Ramp mode
    Motor1WidthNew := Motor1WidthNew_                   '      A positive Width value indicates Immediate mode
        
PUB SetMotor2(Motor2WidthNew_)                          'Note: A negative Width value indicates Ramp mode
    Motor2WidthNew := Motor2WidthNew_                   '      A positive Width value indicates Immediate mode
                                                        '      A "Zero" Width value deselects Motor2 
PUB SetMotorS(Motor1WidthNew_,Motor2WidthNew_)      
    SetMotor1(Motor1WidthNew_)                                            
    SetMotor2(Motor2WidthNew_)                   

PUB SetRamp(Motor1Rate_,Motor2Rate_)                    'Note: A negative Rate value will cause the motor to
    Motor1Rate := Motor1Rate_                           '      exponentially ramp.  A positive Rate value will                         
    Motor2Rate := Motor2Rate_                           '      cause the motor to linearly ramp.

PUB Pulse(Pin,Motor1Width_,Motor2Width_)
    PULSOUT(Pin,Motor1Width_)                           'Send first Pulse (Motor 1)
    If Motor2WidthTemp <> 0
       Pause(HoldTimeM1M2)                              'If Motor 2 selected wait minimum hold time between motor 1&2
       PULSOUT(Pin,Motor2Width_)                        'If Motor 2 selected send second Pulse (Motor 2)
    Pause(HoldTimeM2M1)                                 'wait minimum hold time between motor 2&1 

PRI HB25(Pin)
    repeat
'---------------------------------------------Motor 1 Ramp logic--------------------------------------------
      If Motor1WidthNew < 0 
         if ||Motor1WidthNew <> Motor1WidthOld
         
            if Motor1Rate < 0                           'Detect Proportional Rate mode...
               Motor1RateTemp := (||(||Motor1WidthNew - ||Motor1WidthOld))* ||Motor1Rate
               Motor1RateTemp /= ((UpperLimit - LowerLimit)/2)
            else                                        '...or Linear Rate mode
               Motor1RateTemp := Motor1Rate

            Motor1RateTemp := 1 #> Motor1RateTemp   

            if ||Motor1WidthNew > ||Motor1WidthOld      'Detect Width increase...
               Motor1WidthOld += Motor1RateTemp
            else                                        '...or Width decrease
               Motor1WidthOld -= Motor1RateTemp
               
         Motor1WidthTemp := Motor1WidthOld
      else
         Motor1WidthTemp := Motor1WidthOld := Motor1WidthNew      
               
'---------------------------------------------Motor 2 Ramp logic--------------------------------------------
      If Motor2WidthNew < 0 
         if ||Motor2WidthNew <> Motor2WidthOld
         
            if Motor2Rate < 0                           'Detect Proportional Rate mode...
               Motor2RateTemp := (||(||Motor2WidthNew - ||Motor2WidthOld))* ||Motor2Rate
               Motor2RateTemp /= ((UpperLimit - LowerLimit)/2) 
            else                                        '...or Linear Rate mode
               Motor2RateTemp := Motor2Rate

            Motor2RateTemp := 1 #> Motor2RateTemp    

            if ||Motor2WidthNew > ||Motor2WidthOld      'Detect Width increase...
               Motor2WidthOld += Motor2RateTemp
            else                                        '...or Width decrease
               Motor2WidthOld -= Motor2RateTemp
               
         Motor2WidthTemp := Motor2WidthOld
      else
         Motor2WidthTemp := Motor2WidthOld := Motor1WidthNew      


      Pulse(Pin,Motor1WidthTemp,Motor2WidthTemp)         

PRI PULSOUT(Pin,Duration) | ClkCycles
    Duration := LowerLimit #> ||Duration <# UpperLimit 
    ClkCycles := Duration * (clkfreq / 1_000_000) - 1050
    dira[pin]~~
    outa[pin]~~                                 
    waitcnt(ClkCycles + cnt)                             
    outa[pin]~                                 

PUB Pause(Duration) | ClkCycles
    ClkCycles := ||Duration * (clkfreq / 1_000_000) - 1050
    waitcnt(ClkCycles + cnt)             

{

[COLOR=#000000][FONT=sans-serif]MIT LICENSE[/FONT][/COLOR]

[COLOR=#000000][FONT=sans-serif]Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:[/FONT][/COLOR]

[COLOR=#000000][FONT=sans-serif]The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.[/FONT][/COLOR]

[COLOR=#000000][FONT=sans-serif]THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.[/FONT][/COLOR]

[COLOR=#000000][FONT=sans-serif]}[/FONT][/COLOR]
                

Demo:
CON
  _clkmode = xtal1 + pll16x
  _xinfreq = 5_000_000


OBJ
    HB25        : "HB-25"
 
PUB Demo
    HB25.SetMotorS(1500,1500)
    HB25.SetRamp(-20,20)
    HB25.start(0)
    HB25.Pause(4000000)

repeat
    HB25.SetMotorS(-2000,-2000)
    HB25.Pause(4000000)
    HB25.SetMotorS(-1500,-1500)
    HB25.Pause(4000000)
    
{

[COLOR=#000000][FONT=sans-serif]MIT LICENSE[/FONT][/COLOR]

[COLOR=#000000][FONT=sans-serif]Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:[/FONT][/COLOR]

[COLOR=#000000][FONT=sans-serif]The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.[/FONT][/COLOR]

[COLOR=#000000][FONT=sans-serif]THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.[/FONT][/COLOR]

[COLOR=#000000][FONT=sans-serif]}[/FONT][/COLOR]


EDIT 2:

G'day,

I would just like to note that I believe I copied some of this code from another person's source which may have been covered by the MIT license, and since I removed the MIt license before, I wish to edit the post to have it in now.
1024 x 681 - 79K
1024 x 681 - 80K
1024 x 681 - 104K
1024 x 681 - 100K
1024 x 681 - 94K

Comments

  • John BoardJohn Board Posts: 371
    edited 2012-04-20 17:44
    Tried some different code - My mutimeter readings are like this:

    0.0
    *2 seconds later*
    8.0
    -Looping-

    In my mind it should go something like this:

    0.0
    0.1

    Because the pulse width is going from 1500 (Halt) to 1510..

    Here is the code:
    CON
      _clkmode = xtal1 + pll16x
      _xinfreq = 5_000_000
    
    
      UpperLimit    = 2100            'Set Maximum allowed pulse width
      LowerLimit    =  900            'Set Minimum allowed pulse width
                                      '910 is full bore one way
                                      '2090 is full bore the other way
                                      '1600 is stop
    
    pub start
       repeat
        pulsout (0,1510)              'pin & speed,direction 900-2100
        waitcnt(clkfreq*2+cnt)
        pulsout (0,1500)              'pin & speed,direction 900-2100
        waitcnt(clkfreq*2+cnt)
        
    
    PRI PULSOUT(Pin,Duration) | ClkCycles
        Duration := LowerLimit #> ||Duration <# UpperLimit 
        ClkCycles := Duration * (clkfreq / 1_000_000) - 1050
        dira[pin]~~
        waitcnt(ClkCycles + cnt)
        outa[pin]~~                                 
        waitcnt(ClkCycles + cnt)                             
        outa[pin]~                                 
    
              
    
  • W9GFOW9GFO Posts: 4,010
    edited 2012-04-20 19:32
    You may not be getting good voltage readings with the motor outputs disconnected.
  • John BoardJohn Board Posts: 371
    edited 2012-04-20 19:37
    Would I be able to connect to anything BUT the motors? I don't want to add in the motors because the motors are rated for 3.3v, not the 8v that is getting outputed.

    -John
  • TubularTubular Posts: 4,706
    edited 2012-04-20 20:09
    John, just connect the two motors in series, and run them 'unloaded' until you're confident.

    That way they won't see more than about 4V each, so you won't damage them.
  • John BoardJohn Board Posts: 371
    edited 2012-04-20 20:16
    Okay, thanks for the idea. I don't think it will fix the problem... but thanks anyway,

    John
  • John BoardJohn Board Posts: 371
    edited 2012-04-20 20:42
    Hmm, I'm not really confortable with that approach, would a resistor do?

    [Edit] New idea, I've got a big daddy motor that I can hook up, it will be able to cope with the high voltage, and it won't burn out the drivers because the drivers are rated at 25A and the motor draws about 1-2 amps.

    -John
  • John BoardJohn Board Posts: 371
    edited 2012-04-20 21:12
    Righto, flash update! I got the wheels working! Ahh, what a good feeling, after quite a few months its finally working! Well, now I got the job of doing everything else....
  • jmgjmg Posts: 15,183
    edited 2012-04-20 22:12
    John Board wrote: »
    Would I be able to connect to anything BUT the motors? I don't want to add in the motors because the motors are rated for 3.3v, not the 8v that is getting outputed.

    Err, I'd be rather nervous doing any project that had hardware that could throw 8V into 3.3V motors, and only the Magic Software Fairies were preventing that from happening ??
    A "50% hardware watchdog" should be easy enough - a FF and a monostable ?
  • John BoardJohn Board Posts: 371
    edited 2012-04-20 22:56
    jmg wrote: »
    Err, I'd be rather nervous doing any project that had hardware that could throw 8V into 3.3V motors, and only the Magic Software Fairies were preventing that from happening ??
    A "50% hardware watchdog" should be easy enough - a FF and a monostable ?

    Hmm, thanks, but I got it working never the less ;) It feels great, finally I can press forward and start work on the logic!

    -John
  • Peter JakackiPeter Jakacki Posts: 10,193
    edited 2012-04-21 04:59
    Isn't the motor driver doing what it's supposed to be doing? You are measuring with a meter, without a load etc. Normally motor drivers will pulse the output with the supply voltage and it is up to you to specify the duty cycle. At no time do PWM drivers EVER output an analog voltage. If you are running from 7.4V batteries (forget your meter "reading" for the moment, it won't be accurate in this circuit) then you will get a little less than 7.4V peak pulses to the motor and if you set your duty cycle for 25% than you will still get 7.4V pulse except they will be on for 25% of the time thereby delivering 25% of the "voltage" <= 1.85V. Remember too that motors are inductive and generate back-EMF.

    BTW: Forum etiquette (perhaps even the rules) would really require that you choose a thread title that bears directly on the subject. You would agree that thread titles such as "Hi" and "Help" are not very descriptive or catalogable and neither is "It's me again...." even though some of us at this present moment understand the connection. The forum posts become a searchable (barely sometimes) database so thread titles are important.
  • John BoardJohn Board Posts: 371
    edited 2012-04-21 13:52
    Okay, sorry, will pick a better title next time. Well, what you were decribing with the meter, is true, it always read just under what the batt read, except when it had < 25% duty. Well, I got the code fine honed with the big motor, and then when I attached the small ones - contrary to what I thought would happen (burning out) - they worked! I don't know why they were working before, and not now, maybe it was because I was using an arduino, and the arduino starts with all pins on or something, I don't know, but it is working fine now ;) Hehe, I was so excited to see 'dem wheels turning!

    -John
  • John BoardJohn Board Posts: 371
    edited 2012-04-21 15:50
    Hmm, I wired it up this morning, and tried a few things, but it didn't work, here is my code & schematics:
    CON
      _clkmode = xtal1 + pll16x
      _xinfreq = 5_000_000
    
    
      UpperLimit    = 2100            'Set Maximum allowed pulse width
      LowerLimit    =  900            'Set Minimum allowed pulse width
                                      '910 is full bore one way
                                      '2090 is full bore the other way
                                      '1600 is stop
    
      TOP = 1500
      MPIN = 4
    
    OBJ
    
    Serial: "FullDuplexSerial"
    
    pub start | counter
    
      Serial.start(31,30,0,9600)
    
      repeat
        pulsout(MPIN, 1700)
    
        waitcnt(clkfreq/100+cnt)
        serial.str(string("W"))
      
        
    
    PRI PULSOUT(Pin,Duration) | ClkCycles
        Duration := LowerLimit #> ||Duration <# UpperLimit 
        ClkCycles := Duration * (clkfreq / 1_000_000) - 1050
        dira[pin]~~
        waitcnt(ClkCycles + cnt)
        outa[pin]~~                                 
        waitcnt(ClkCycles + cnt)                             
        outa[pin]~      
     
    {
    
    [COLOR=#000000][FONT=sans-serif]MIT LICENSE[/FONT][/COLOR]
    
    [COLOR=#000000][FONT=sans-serif]Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:[/FONT][/COLOR]
    
    [COLOR=#000000][FONT=sans-serif]The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.[/FONT][/COLOR]
    
    [COLOR=#000000][FONT=sans-serif]THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.[/FONT][/COLOR]
    
    [COLOR=#000000][FONT=sans-serif]}[/FONT][/COLOR]
                              
    

    schem.jpg


    (Sorry for my somewhat sketchy schematic quality)

    -John
    1024 x 969 - 52K
  • jmgjmg Posts: 15,183
    edited 2012-04-21 15:55
    John Board wrote: »
    Okay, sorry, will pick a better title next time.

    You can change your own title anytime. Just go Edit Advanced, and the title text is an option.
  • John BoardJohn Board Posts: 371
    edited 2012-04-21 19:49
    Hmm... I pulled it back to scratch again, and it started working... Hmm....

    I'll keep y'all posted.
  • John BoardJohn Board Posts: 371
    edited 2012-04-21 20:13
    Okey dokey, well, I've isolated the problem now, but I need some help in correcting it. Problem:

    When I turned the MCU and the HB on at the same time, it didn't work, when I turn on the prop, then wait for it to init, then turn in the HB's, then it works - why? And how would I fix it apart from having 2 switches on my robot, one for the motors, and one for the MCU. Also I tried turning on the HB's first, then the prop - which worked, but the motors turned really fast for about 1/4 second, then went back to the normal speed. My guess is, is that the init proccess of the chip somehow triggers the HB's - like the manual said it would.

    Thanks,

    John
  • W9GFOW9GFO Posts: 4,010
    edited 2012-04-21 20:17
    This is a known "feature" of the HB-25s. Power on either one before the other and it should work 100% of the time. Power them on together and it is hit or miss.

    Use two switches or one switch and a relay.
  • John BoardJohn Board Posts: 371
    edited 2012-04-21 20:44
    Huh.. some feature...

    Well anyway, I figured as much, so I've got a plan to put 2 matching toggle switches on the top of the robot :)
Sign In or Register to comment.