Shop OBEX P1 Docs P2 Docs Learn Events
Controlling DC motor and Servo with PWMPal and Basic Stamp — Parallax Forums

Controlling DC motor and Servo with PWMPal and Basic Stamp

h3n7yh3n7y Posts: 11
edited 2009-11-17 16:18 in BASIC Stamp
Ok I committed an error for stating that I only want to control Servo. The problem is that I want to control the back motor of the car is DC Motor and the Front wheels of the car is a servo, I have an L298 H-Bridge and I want to control the pulse coming from the Pwmpal to control the Bridge, while the BS2 control the Find Range Sensor, I though the connection were a problem and is working, in hardware connection I can do it but I am not so much of programming this is the codes I want to tweak to include the h-bridge to be controlled, the Enable ping from the bridge is connected to PIN 1 on pal and the out put is connected to Pin 15, PIN 2,3, are the Front wheel from the servo, and 4,5 are the DC motor, down are the codes i want to try, at least to get the car moving after that i am can work on programming the sensor. please any help. Below is the code I want to tweak




' =========================================================================
'
' File....... PWMPAL_Servo.BS2
' Purpose....

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


'
[noparse][[/noparse] Program Description ]


'
[noparse][[/noparse] Revision History ]


'
[noparse][[/noparse] I/O Definitions ]

PpPin PIN 0 ' PWMPAL Serial I/O


'
[noparse][[/noparse] Constants ]

#SELECT $stamp
#CASE BS2, BS2E, BS2PE
T9600 CON 84
T19K2 CON 32
T38K4 CON 6
#CASE BS2SX, BS2P
T9600 CON 240
T19K2 CON 110
T38K4 CON 45
#ENDSELECT

Baud CON T38K4


'
[noparse][[/noparse] Variables ]

s1Pos VAR Word ' servo 1 position
temp VAR Word ' work variable


'
[noparse][[/noparse] EEPROM Data ]


'
[noparse][[/noparse] Initialization ]

Reset:
SEROUT PpPin, Baud, [noparse][[/noparse]"!PWMSS", %00010000] ' enable output (on P12)


'
[noparse][[/noparse] Program Code ]

Main:
FOR s1Pos = 1000 TO 2000 STEP 250 ' position is uS
temp = s1Pos / 25 ' convert to PWMPAL units
SEROUT PpPin, Baud, [noparse][[/noparse]"!PWMM1",
temp.BYTE0, temp.BYTE1,
$20, $03]
PAUSE 500
NEXT
GOTO Main

END

Comments

  • Mike GreenMike Green Posts: 23,101
    edited 2009-11-15 18:58
    What's your question?

    The usual way to do this sort of thing is to start with known good code that does something close to what you want and modify it step by step, adding one feature at a time until it does what you want.

    Do you know (and understand) how to do the individual pieces of what you want to accomplish? If not, that's where you need to start.

    You have a sample program for the PWMPal. Do you understand it? If not, break it down into pieces and sit there with the Stamp Manual and PWMPal documentation until you do. Ask questions of others if there are pieces you don't understand and the Manual and documentation don't have the answers.

    There's plenty of information on the control of servos in the "Robotics with the BoeBot" tutorial. If you don't have it, download it and work through the examples and exercises until you understand that.

    I don't know what kind of sensor you plan to use, but, if it's anything like the PING, you may be able to start with the PING documentation and examples.

    There's no magic to learning how to make a robot work. It's a lot of work and a lot of reading and working through simple cases. You're not going to find ready-made solutions for the whole of what you want to accomplish, partly because it's different from what other people have done. You will find pieces, but you're going to have to modify and integrate them to fit your situation.

    Post Edited (Mike Green) : 11/15/2009 7:05:11 PM GMT
  • h3n7yh3n7y Posts: 11
    edited 2009-11-17 16:18
    Yes I do understand how to do individual pieces of what I want to accomplish. The problem is that when I am trying to integrate the piece of codes and it does not work

    Like the program above is to enable the pin 12 to be the output for the PWM to position the servo on the center position. my question is how do I change from pin 12 to pin 15
    because if am not wrong i think the binary number he has is. and I been looking into the PWMPAL codes to control a modified car and the only example they use is pushing a buttong and I don't want to use a button on my codes is just connect the battery and the robot has to go forward and backward.


    The sensor I am using is a Parallax Find Range. but as I said before i am i can integrate the sensor later I just want to get the robot moving for now. can you at least can write a modified code from the copy i posted?

    Thank you for your reply
Sign In or Register to comment.