h3n7y
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
#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
' -----[ Variables ]-------------------------------------------------------
s1Pos VAR Word ' servo 1 position
temp VAR Word ' work variable
' -----[ EEPROM Data ]-----------------------------------------------------
' -----[ Initialization ]--------------------------------------------------
Reset:
SEROUT PpPin, Baud, ["!PWMSS", %00010000] ' enable output (on P12)
' -----[ Program Code ]----------------------------------------------------
Main:
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]
PAUSE 500
NEXT
GOTO Main
END
' ================================================== =======================
'
' 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
#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
' -----[ Variables ]-------------------------------------------------------
s1Pos VAR Word ' servo 1 position
temp VAR Word ' work variable
' -----[ EEPROM Data ]-----------------------------------------------------
' -----[ Initialization ]--------------------------------------------------
Reset:
SEROUT PpPin, Baud, ["!PWMSS", %00010000] ' enable output (on P12)
' -----[ Program Code ]----------------------------------------------------
Main:
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]
PAUSE 500
NEXT
GOTO Main
END