Shop OBEX P1 Docs P2 Docs Learn Events
Motors do not work on BS2PX — Parallax Forums

Motors do not work on BS2PX

Hi,
Hoping someone can help me with an issue I'm having. I have been using a BS2 as my microcontroller on a BOE for a long time and all my programs work as designed on it. However, I just recently received a BS2PX and now that I'm using that microcontroller instead; now the issue I'm having is in any of my programs or any example programs that I've tried, the motors do not run on the BS2PX; everything else works fine though, sensors, LEDs, speech, etc. Everything including the motors work perfectly on the BS2.

Same program, just changed the the Stamp module in the code from ' {$STAMP BS2} to ' {$STAMP BS2px}. My robot is running two DC motors powered by a 12 volt lead acid battery and controlled by two HB25 motor controllers. Are there any commands/initialization for this type of module that need to be specified first in order for the motors to run? I've been researching the "CONFIGPIN" command, thinking maybe I need to set the motors/controllers as an output pin, but nothing yet. Below is an example of of one of my programs:

Any help would be greatly appreciated! :)

' Robot will speak a warning, then using a PIR motion sensor, Robot will detect If movement is detected or not. If movement
' is detected then robot will ramp up backwards and speak. If no movement is detected then robot will ramp up CCW and then start over
' in a infinit loop.

' {$STAMP BS2px}
' {$PBASIC 2.5}

'
[ I/O Definitions ]
EMIC_TX PIN 0 ' Serial output (connects to Emic 2 SIN)
EMIC_RX PIN 1 ' Serial input (connects to Emic 2 SOUT)
FrontLED PIN 4
RLED PIN 6
BLED PIN 8
GLED PIN 9
PIR PIN 10 ' PIR motion detector
HB25 PIN 12 ' I/O Pin For HB-25

'
[ Variables ]
i VAR Byte
pulseCount VAR Word
pulseLeft VAR Word
pulseRight VAR Word
time VAR Word
'
[ Constants ]

#SELECT $STAMP ' Select Baud constants
#CASE BS2, BS2E, BS2PE
T1200 CON 813
T2400 CON 396
T4800 CON 188
T9600 CON 84
T19K2 CON 32
#CASE BS2SX, BS2P
T1200 CON 2063
T2400 CON 1021
T4800 CON 500
T9600 CON 240
T19K2 CON 110
#CASE BS2PX
T1200 CON 3313
T2400 CON 1646
T4800 CON 813
T9600 CON 396
T19K2 CON 188
#ENDSELECT
EmicBaud CON T9600

'
[ Initialization ]

DEBUG "HB25 Controller Initializing..."
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
DEBUG "Completed!", CR

'
Emic 2
' When the Emic 2 powers on, it takes about 3 seconds for it to successfully
' intialize. it then sends a ":" character to indicate it's ready to accept
' commands. if the Emic 2 is already initialized, a CR will also cause it
' to send a ":"
DEBUG "Waiting for Emic 2..."
SEROUT EMIC_TX, EmicBaud, [CR]
SERIN EMIC_RX, EmicBaud, [WAIT(":")]
DEBUG "Ready!", CR

'
[ Program Code ]

LEDs:
HIGH FrontLED

HIGH RLED
PAUSE 500
LOW RLED

HIGH GLED
PAUSE 500
LOW GLED

HIGH BLED
PAUSE 500
LOW BLED

SEROUT EMIC_TX, EmicBaud, ["V18", CR] 'Set volume to to maximum.
SERIN EMIC_RX, EmicBaud, [WAIT(":")]

DEBUG "Speaking some text..."
SEROUT EMIC_TX, EmicBaud, ["S", ":-)4Hello. I am Sentry bot. Please state your business", CR] ' Send the string to convert to speech
SERIN EMIC_RX, EmicBaud, [WAIT(":")] ' Wait here until the Emic 2 responds with a ":"
'indicating it's ready to accept the next command
DEBUG "Done!", CR

DO

MOTION:
INPUT PIR

DO
i = i - 10

DEBUG HOME, "WAIT 10 seconds FOR PIR Sensor warm up",CR,
DEC i, " seconds left ",CR
LOOP UNTIL i = 0

NAP 6 ' Nap for 1152 ms (1.152 Seconds).

MAIN:

IF (PIR = 1) THEN ' If PIR sensor detects motion, then speak and drive motors.

HIGH RLED
HIGH BLED
DEBUG CRSRXY, 0,4, "PIR Sensor State = ", BIN1 IN10
SEROUT EMIC_TX, EmicBaud, ["S", ":-)4 Please state the passcode", CR] ' Send the string to convert to speech
SERIN EMIC_RX, EmicBaud, [WAIT(":")] ' Wait here until the Emic 2 responds with a ":"
PAUSE 20 ' Wait 20 mS Before Ramping
FOR pulseCount = 0 TO 100 ' Ramp Up To Full Speed
PULSOUT HB25, 750 - pulseCount ' Motor 1 Reverse
PAUSE 1 ' 1 mS Delay For Motor 2 Pulse
PULSOUT HB25, 750 + pulseCount ' Motor 2 Forward
PAUSE 20 ' 20 mS Smoothing Delay
NEXT
PAUSE 3000 ' Wait 3 Seconds
FOR pulseCount = 100 TO 0 ' Ramp Back Down
PULSOUT HB25, 750 - pulseCount ' Motor 1 Reverse Slowing
PAUSE 1 ' 1 mS Delay For Motor 2
PULSOUT HB25, 750 + pulseCount ' Motor 2 Forward Slowing
PAUSE 20 ' 20 mS Smoothing Delay
NEXT

ELSE
DEBUG CRSRXY, 0,6, "PIR Sensor State = ", BIN1 IN10
LOW RLED
LOW BLED
HIGH GLED
PAUSE 3000 ' Wait 3 Seconds
PAUSE 20 ' Wait 20 mS Before Ramping
FOR pulseCount = 0 TO 100 ' Ramp Up To Full Speed
PULSOUT HB25, 750 + pulseCount ' Motor 1 Forward
PAUSE 1 ' 1 mS Delay For Motor 2 Pulse
PULSOUT HB25, 750 + pulseCount ' Motor 2 Forward
PAUSE 20 ' 20 mS Smoothing Delay
NEXT
PAUSE 3000 ' Wait 3 Seconds
FOR pulseCount = 100 TO 0 ' Ramp Back Down
PULSOUT HB25, 750 + pulseCount ' Motor 1 Forward Slowing
PAUSE 1 ' 1 mS Delay For Motor 2
PULSOUT HB25, 750 + pulseCount ' Motor 2 Forward Slowing
PAUSE 20 ' 20 mS Smoothing Delay
NEXT
ENDIF

LOOP

Thank you,
Paul

Comments

  • Mike GreenMike Green Posts: 23,101
    edited 2017-09-26 14:43
    The BS2px runs at a higher speed than the BS2 and most of the statements that involve timings are affected (except PAUSE). In your case the timings of the pulses with PULSOUT are different. For the BS2, each count is 2us. For the BS2px, each count is 0.8us. A PULSEOUT HB25,750 results in a 1500us pulse on the BS2. You need a PULSOUT HB25,1875 on the BS2px to get the same width pulse. That's 2.5 times larger (multiply by 5, then divide by 2)
  • Thank you Mike! I figured it was something that was different between the two; the motors are moving now, I just need to tweak it to have them move to my liking.

    Thank you and have a blessed day!
    Paul
  • GenetixGenetix Posts: 1,754
    edited 2017-09-27 20:32
    Paul,

    I've been looking over your program and I noticed a few things:
    Twice in your program you switch to Voice 4, using ":-)4", so why not just change to Voice 4 after you set the volume to maximum.
    SEROUT EMIC_TX, EmicBaud, ["N4", CR]
    SERIN EMIC_RX, EmicBaud, [WAIT(":")]
    

    The PIR documentation initializes with only this instead of the strange DO...LOOP you use and I/O pins starts as Inputs.
    PAUSE 40000   ' PIR warm-up time     [PIR_Simple.bs2]
    

    I am guessing you have your LEDs wired to be Active-High or on when the output is high. According to the BASIC Stamp Manual the NAP will momentarily turn off the current to all I/O pins as it wakes up.
    Use PAUSE instead and if you need more time then use a FOR...NEXT loop or several PAUSES in a row.

    You have 2 lines in each part your IF...THEN...ELSE that display the status of the PIR sensor using IN10. You are using PIR for pin 10 so change the IN10 to PIR.

    The only variable your program uses in pulseCount.

    You also need to change the 100 in your FOR...NEXT loops for pulseCount to 250 since the BS2px PULSOUT command uses a smaller time interval than the BS2.
    I don't know what motors you are using but the HB-25 documentation says that pulses of 1 and 2 milliseconds will more the motor at full speed in each direction.
    Remember that the pulse value starts at 1875, which results in a pulse of 1875 x 0.8 = 1.5 ms or motor neutral (off).
    To get the full speed values, remember that 1000 us are in 1 ms since PULSOUT is in us or micro-seconds.
    1 ms = 1000 us, 1000 us / 0.8 us = 1250
    2 ms = 2000 us, 2000 us / 0.8 us = 2500
    
    Those are the PULSOUT full speed values but you need to ramp up to them, so you need to know difference between stop and full.
    2500 - 1875 = 625
    1875 - 1250 = 625
    
    Changing the FOR...NEXT value from 100 to 625 should make your motors run at full speed but you might want to try 300 or 400 first and then increase it until your happy.














  • Thank you Genetix for looking so deeply into my program; that was nice of you. Thanks for all the very useful information, I have made necessary adjustments and my Robot is working much better now, still tweaking, but working as I designed. I had the NAP command in there for something I was testing and forgot to take it out. I now changed it to a PAUSE. I modified the PIR warmup from PAUSE 40000 to 10000 to speed up the testing process. All is well now and the timings and duration information is very useful...We both thank you again!

    Paul and Dylbot :smile:
  • GenetixGenetix Posts: 1,754
    edited 2017-09-28 18:09
    Hello Paul,

    Your program already has conditional compilation code for serial baud values so you could add PULSOUT values to the list also.
    Unlike the baud rate, the BS2px uses the same PULSOUT duration as the BS2sx and BS2p.
    #SELECT $STAMP ' Select Baud constants
      #CASE BS2, BS2E, BS2PE
        T1200 CON 813
        T2400 CON 396
        T4800 CON 188
        T9600 CON 84
        T19K2 CON 32
        MotorStop   CON   750   ' PULSOUT duration that stops motor
        RampRange   CON   250   ' PULSOUT duration for ramping range
      #CASE BS2SX, BS2P
        T1200 CON 2063
        T2400 CON 1021
        T4800 CON 500
        T9600 CON 240
        T19K2 CON 110
        MotorStop   CON   1875   ' PULSOUT duration that stops motor
        RampRange   CON   625   ' PULSOUT duration for ramping range
      #CASE BS2PX
        T1200 CON 3313
        T2400 CON 1646
        T4800 CON 813
        T9600 CON 396
        T19K2 CON 188
        MotorStop   CON   1875   ' PULSOUT duration that stops motor
        RampRange   CON   625   ' PULSOUT duration for ramping range
    #ENDSELECT
    
    Then just change the PULSOUT values in the program to these constants.

    Some of the code in your program repeats so you might want to consider using subroutines instead.
    For example, you first blink each of the colored LEDs.
    A variable now controls which LED will be blinked and the blink time can be easily changed.
    ' --- New Constants --
      BlinkTime   CON   500   ' Time the LED will blink in milliseconds
    ' -- New Variables ---
      ' Notice that the first letter of a variable is always lower-case
      blinkLED   VAR NIB   ' The pin number of the LED to be blinked
        ' Since there are only 16 I/O pins we can use a Nibble variable
        ' A Nibble variable will hold a value from 0 to 15
    
    ' --- Initialization ---
      ' Blink Red LED
      blinkLED = RLED   ' The Red LED will be blinked
      GOSUB Blink_LED   ' Call the blink subroutine
      ' The program will resume here
    
      ' Blink Green LED
      blinkLED = GLED
      GOSUB Blink_LED
    
      'Blink Blue LED
      blinkLED = BLED
      GOSUB Blink_LED
    
    ' --- Subroutines ---
      ' Subroutines are always placed at the bottom of the program
      ' Notice that subroutines use underscores between the words
    Blink_LED:   ' Blink an LED
      HIGH blinkLED   ' Turn LED on
      PAUSE BlinkTime   ' Keep LED on for blink time
      LOW blinkLED   ' Turn LED off
      RETURN   ' Go back to the program
    
Sign In or Register to comment.