View Full Version : Controlling DC motor and Servo with PWMPal and Basic Stamp

11-15-2009, 01:59 AM
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}
' ================================================== =======================

' -----[ Program Description ]---------------------------------------------

' -----[ Revision History ]------------------------------------------------

' -----[ I/O Definitions ]-------------------------------------------------

PpPin PIN 0 ' PWMPAL Serial I/O

' -----[ Constants ]-------------------------------------------------------

#SELECT $stamp
T9600 CON 84
T19K2 CON 32
T38K4 CON 6
T9600 CON 240
T19K2 CON 110
T38K4 CON 45

Baud CON T38K4

' -----[ Variables ]-------------------------------------------------------

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

' -----[ EEPROM Data ]-----------------------------------------------------

' -----[ Initialization ]--------------------------------------------------

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

' -----[ Program Code ]----------------------------------------------------

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


Mike Green
11-16-2009, 01:58 AM
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

11-17-2009, 11:18 PM
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