Shop OBEX P1 Docs P2 Docs Learn Events
stamp too slow? — Parallax Forums

stamp too slow?

mikeamikea Posts: 283
edited 2012-07-08 09:22 in BASIC Stamp
I'm trying to use an r/c remote and reciever to control 2 wheelchair motors. i have 2 h-bridges made from 12 volt auto relays switched by the stamp and n-channel mosfets. everything worked ok on the desk switching 1 bridge so i installed everything on the project buggy (now 2 h-bridges) and when i hold the remote stick over the activate fwd for example the relay clicks on /off. everything acts like it should except the relays dont hold they keep clicking on/off. i was wondering if the stamp is too slow to read in 2 channels and run 8 relays(need a ninth for a safety shut off). any advice would be appreciated-mike
' {$STAMP BS2}
' {$PBASIC 2.5}
channel9 VAR Word
channel10 VAR Word
channel9 = 750
channel10 = 750
 main:
receiver:
HIGH 0
LOW 1    'rev off
LOW 2   'rev off
LOW 3    'fwd off
LOW 4   'fwd off
LOW 5
LOW 6
LOW 7
LOW 8
DO
PULSIN 9,1,channel9                             'read output from receiver channels "9" and "10"
PULSIN 10,1,channel10
DEBUG "channel9=",DEC ? channel9,CR                       'display pusles for each channel in debug terminal
DEBUG HOME            'display range+/- 550-950
DEBUG "channel10=", DEC ? channel10,CR

IF channel9<400 THEN IF channel9>1100 THEN         ' pin 0 can kill power to motors if radio signal is out of normal parameters
LOW 0                                              '
ENDIF                                              '
IF channel10<400 THEN IF channel10>1100 THEN       '
LOW 0                                              '
ENDIF
IF channel9>800 THEN                             'fwd motor 1
 GOSUB for1
  ENDIF
IF channel9<700 THEN IF channel9>401 THEN                             'bwd motor 1
 GOSUB back1
  ENDIF
 
IF channel9<=770 THEN IF channel9 >= 700 THEN      'deadstick range center position
   GOSUB nogo
   ENDIF

IF channel10<=770 THEN IF channel9 >= 700 THEN      'deadstick range center position
   GOSUB nogo
   ENDIF
IF channel10<700 THEN                              'bwd motor 2
  GOSUB back2
  ENDIF
IF channel10>770 THEN                             'fwd motor 2
  GOSUB for2
  ENDIF

LOOP
  '-----------------------------------------------------------------------------------
     for1:
     LOW 2   'rev off
     LOW 3  ' rev off
     PAUSE 250
     HIGH 1    'f on
     HIGH 4    'f on
     RETURN
     back1:
     LOW 1  'fwd off
     LOW 4 'fwd off
     PAUSE 250
     HIGH 2      'b on
     HIGH 3      'b on
     RETURN
     back2:
     LOW 5       'f off
     LOW 8       'f off
     PAUSE 250
     HIGH 6      'b on
     HIGH 7      'b on
     RETURN
     for2:
     LOW 6       'b off
     LOW 7       'b off
     PAUSE 250
     HIGH 5      'f on
     HIGH 8      'f on
     RETURN
     nogo:
     LOW 1       'shut off all relays
     LOW 2
     LOW 3
     LOW 4
     LOW 5
     LOW 6
     LOW 7
     LOW 8

     RETURN

Comments

  • Mike GreenMike Green Posts: 23,101
    edited 2012-07-06 10:02
    The Stamp is fast enough, but it can't do several things at a time. In particular, when it does a PULSIN, it can't do anything else until the PULSIN completes. The DEBUG statements also slow things down, about 1ms for each character sent. Try first commenting out the DEBUG statements and see what happens. It's also faster to set groups of I/O pins. For example, OUTL sets pins 0-7 all at the same time from an 8 bit value.
  • mikeamikea Posts: 283
    edited 2012-07-06 10:20
    Thanks Mike, i've previously commented out the debugs with the same results. I will try " outl" to see if that helps. Whats odd is, one (or two) of the relays when i push fwd on one motor doesnt click off/on...it does what its supposed to. the rest of them act like theres a not so steady on command. I will post what i find out. Thanks Mike-mike
  • mikeamikea Posts: 283
    edited 2012-07-06 11:20
    I,ve commented out the "deadstick" space and everything acts like it should. Is there another way to code this deadstick space? at center stick of the r/c remote pulsin says its about 750...so i have dedicated the 700-800 range to "neutral" for the motor. Is there a way to AND the upper and lower limits of the dead space? i think it is stopping the relay every time through because fwd is above 800, and reverse is below 700.Either way it has a reason to stop.Thanks-mike

    'IF channel9<=800 THEN IF channel9 >= 700 THEN      'deadstick range center position
    '   GOSUB nogo
    '   ENDIF
    
    
  • willembadwillembad Posts: 47
    edited 2012-07-06 13:16
    How about this?
    IF channel9 > 699 AND channel9 < 801 THEN GOSUB nogo
    
  • mikeamikea Posts: 283
    edited 2012-07-06 13:46
    Thank you willembad! it works. I had to move them (2 copies of your code, one for each channel)around to make it work, i dont yet understrand why the order of it made a difference the way it did, but very happy it works.thanks again.-mike
  • willembadwillembad Posts: 47
    edited 2012-07-06 14:42
    Glad I could help :) You can also use OR like this:
    IF channel9 < 400 OR channel9 > 1100 THEN LOW 0
    

  • mikeamikea Posts: 283
    edited 2012-07-06 19:31
    Thanks willembad, i looked in the reserved word list for "and ...ect." and must have missed them. i'm glad you brought that up. -mike
  • mikeamikea Posts: 283
    edited 2012-07-07 11:46
    I was wondering if someone could take a peek at this code, it seems logical to me but isnt working correctly. the original problem was dedicating deadstick space(the 2 nogo code sections) in the middle of the pulseband. i changed it to include the AND... "IF channel9 > 699 AND channel9 < 801 THEN GOSUB nogo" and seemed to fix the relays clicking on/off, but there was no longer a deadstick space when the motors were running. i could start them independently or reverse their directions but when i let go of one stick the other would keep both motors going until i let go of both sticks. the problem centers around the deadstick space, the code seems to make sense unless the "AND" command doesnt mean anything i pbasic.-mike
    ' {$STAMP BS2}
    ' {$PBASIC 2.5}
    'full fwd is around 950
    'deadstick is 750
    'full reverse is around 550
    channel9 VAR Word
    channel10 VAR Word
    'channel11 VAR Word    'safety relay not used yet
    
     main:
    receiver:
    HIGH 0   'kill power relay ...safety not used yet
    LOW 1    'rev off  motor 1
    LOW 2   'rev off
    LOW 3    'fwd off
    LOW 4   'fwd off
    LOW 5      'motor 2
    LOW 6
    LOW 7
    LOW 8
    DO
    'PULSIN 11,1,channel11
    'DEBUG "channel9=",DEC ? channel9,CR                       'display pusles for each channel in debug terminal
    'DEBUG HOME            'display range+/- 550-950
    'DEBUG "channel10=", DEC ? channel10,CR
    'DEBUG "channel11=", DEC ? channel11,CR
    PULSIN 10,1,channel10          'read r/c reciever channel
    IF channel10>800 THEN          'fwd motor 2
      GOSUB for2
      ENDIF
    IF channel10<700 THEN        'bwd motor 2
      GOSUB back2
      ENDIF
    IF channel10 > 699 AND channel10 < 801 THEN      'if pulsin reads deadstick range 700-800...stop motor
     GOSUB nogo1
    ENDIF
     
    PULSIN 9,1,channel9             'read r/c receiver channel
    IF channel9>800 THEN                             'fwd motor 1
     GOSUB for1
      ENDIF
    IF channel9<700 THEN         'bwd motor 1
     GOSUB back1
      ENDIF
    IF channel9 > 699 AND channel9 < 801 THEN        'if pulsin reads deadstick range 700-800...stop motor
    GOSUB nogo2
    ENDIF
    LOOP
      '-----------------------------------------------------------------------------------
         for1:
         LOW 2   'rev off
         LOW 3  ' rev off
         PAUSE 250
         HIGH 1    'f on
         HIGH 4    'f on
         RETURN
         back1:
         LOW 1  'fwd off
         LOW 4 'fwd off
         PAUSE 250
         HIGH 2      'b on
         HIGH 3      'b on
         RETURN
         back2:
         LOW 5       'f off
         LOW 8       'f off
         PAUSE 250
         HIGH 6      'b on
         HIGH 7      'b on
         RETURN
         for2:
         LOW 6       'b off
         LOW 7       'b off
         PAUSE 250
         HIGH 5      'f on
         HIGH 8      'f on
         RETURN
         nogo1:
         LOW 1       'shut off motor 1 relays
         LOW 2
         LOW 3
         LOW 4
         RETURN
         nogo2:    'shut off motor 2 relays
         LOW 5
         LOW 6
         LOW 7
         LOW 8
         RETURN
    
    
  • willembadwillembad Posts: 47
    edited 2012-07-07 14:47
    Try this if it makes sense. I guessed channel 9 was left and 10 right but that's easily reversed. It also does not contain code to deal with low or high out of range inputs.
    ' {$STAMP BS2}
    ' {$PBASIC 2.5}
    
    
    ' Code follows this pinout. Adjust as needed.
    ' Pins 0 & 1      Left motor forward
    ' Pins 2 & 3      Left motor backwards
    ' Pins 4 & 5      Right motor forwards
    ' Pins 6 & 7      Right motor backwards
    ' Pin 8           Kill power
    
    
    LeftChannel   VAR   Word
    RightChannel  VAR   Word
    KillChannel   VAR   Word
    
    
    Initialize:
    HIGH 8                                                                  ' Set power on?
    GOSUB AllStop
    
    
    Main:
    DO
      PULSIN 11, 1, KillChannel
        ' if KillChannel then ?
      PULSIN 9, 1, LeftChannel
        IF LeftChannel < 700 THEN GOSUB LeftBack
        IF LeftChannel > 699 AND LeftChannel < 801 THEN GOSUB LeftStop
        IF LeftChannel > 800 THEN GOSUB LeftForward
      PULSIN 10, 1, RightChannel
        IF RightChannel < 700 THEN GOSUB RightBack
        IF RightChannel > 699 AND RightChannel < 801 THEN GOSUB RightStop
        IF RightChannel > 800 THEN GOSUB RightForward
    LOOP
    
    
    AllStop:
    OUTL = 0                                                                ' Set pins 0 - 7 low
    RETURN
    
    
    LeftBack:
    LOW 0                                                                   ' Turn left forward off
    LOW 1
    PAUSE 250
    HIGH 2                                                                  ' Turn left backward on
    HIGH 3
    RETURN
    
    
    LeftStop:
    OUTA = 0                                                                ' Set pins 0 - 3 low
    RETURN
    
    
    LeftForward:
    LOW 2
    LOW 3
    PAUSE 250
    HIGH 0
    HIGH 1
    RETURN
    
    
    RightBack:
    LOW 4                                                                   ' Turn right forward off
    LOW 5
    PAUSE 250
    HIGH 6                                                                  ' Turn right backward on
    HIGH 7
    RETURN
    
    
    RightStop:
    OUTB = 0                                                                ' Set pins 4 - 7 low
    RETURN
    
    
    RightForward:
    LOW 6
    LOW 7
    PAUSE 250
    HIGH 4
    HIGH 5
    RETURN
    
  • mikeamikea Posts: 283
    edited 2012-07-07 18:31
    Thanks Willembad i appreciate the help. I try this when i get home in the morning and post what happens.-mike
  • mikeamikea Posts: 283
    edited 2012-07-08 08:16
    It works perfectly. Thanks Willembad for helping me. I found something else out this morning unrelated. with the n-channel mosfet that i am swithcing the relays with, the back plate of two of them were touching. i thought this plate was for a heat sink and maybe they could all be tied together(i didnt intentionally). apparently there is continuity between this back plate and the drain. So this morning i kept getting a short because an extra, unintended relay was coming on at the same time from this touching.

    where do you find the info for things like outa to control only pins 0-3? i looked in the manual and help section and only found them on the reserved word list, but with no info about how to use them.
    thanks again i appreciate your time and help.-mike
  • Mike GreenMike Green Posts: 23,101
    edited 2012-07-08 08:58
    There's a section in the beginning of the manual on memory allocation, section 4 starting on page 81. This discusses the access to OUTA, INA, and DIRA as bytes, nibbles, and individual bits. A little later is the discussion on how to do this with ordinary variables as well.
  • mikeamikea Posts: 283
    edited 2012-07-08 09:22
    Thanks Mike, i skipped over that part in my search this morning.-mike
Sign In or Register to comment.