border
topbkg
americanflag2_z
Orders
Email Us
Contact Info
Return Policy
mc ivsa

Diverse Electronic Services

Home

Motor Controllers

Battery Chargers

Interface Circuits

Radio Controlled Devices

My Robot Page

Sample Program To Control 2 Motors With 2
H-Bridge Motor Controllers and a Basic Stamp 2

'-----------------------------pwm2mtr.bs2-----------------------------
' written by Carl A. Kollar
'Purpose: To demonstrate the simultaneous and identical control by
' BS2 of two 12 volt motor controllers described on this
' web page.
'
'Motor action: Both motors initially remains in neutral for a few seconds.
' Then they: (1) Gradually increases in speed in the forward
' direction until they reach full speed. (2) Gradually
' reduce speed until they stop. (3) Wait in neutral for
' awhile. (4) Gradually increases speed in the reverse
' direction until they reach full reverse speed.
' (4) Gradually decreases speed until they come to a stop.
' (5) Does it all over again. This program controls both
' wheels identically.

'---------------------Define Constants & Variables-------------------------
pwmpin1 con 1
pwmpin2 con 2
duty var byte
cycles var byte: cycles = 100
neutral var byte: neutral = 163 'pwm value for 2.5V out
full_fwd var byte: full_fwd = 190 'pwm value for 3.0V out
full_rev var byte: full_rev = 136 'pwm value for 2.0V out
x var byte: x = 0 'counter variable
pause_time var word: pause_time = 250 'pause between counter increments

'----------------------------Preliminary stuff----------------------------
pwm pwmpin1,neutral,cycles 'bring left mtr voltage to 2.5V (neutral)
pwm pwmpin2,neutral,cycles 'bring right mtr voltage to 2.5V (neutral)
high 0 'turn on relay to apply 12V to SW leads

'----------------------------The Main Program-----------------------------
' (All sub-routine names are self-explanatory
main:
gosub neutral_stop
gosub neutral_to_forward
gosub forward_to_neutral
gosub neutral_stop
gosub neutral_to_reverse
gosub reverse_to_neutral
goto main

'***************************Sub-Routines**********************************

'Wait in neutral for awhile while keeping pwm going to maintain 2.5V
neutral_stop:
for x = 1 to 5
' debug ?x
pwm pwmpin1,neutral,cycles 'keep left mtr volts at 2.5V (neutral)
pwm pwmpin2,neutral,cycles 'keep right mtr volts at 2.5V (neutral)
next
return
'-------------------------------------------------------------------------

'Bring speed of both motors gradually to full forward
neutral_to_forward:
for x = neutral to full_fwd
' ?x
pwm pwmpin1,x,cycles
pwm pwmpin2,x,cycles
pause pause_time
next
return
'-------------------------------------------------------------------------

'Bring speed of both motors gradually to a stop from full forward
forward_to_neutral:
for x = full_fwd to neutral
' debug ?x
pwm pwmpin1,x,cycles
pwm pwmpin2,x,cycles
pause pause_time
next
return
'-------------------------------------------------------------------------

'Bring speed of both motors gradually to full reverse
neutral_to_reverse:
for x = neutral to full_rev
' debug ?x
pwm pwmpin1,x,cycles
pwm pwmpin2,x,cycles
pause pause_time
next
return
'-------------------------------------------------------------------------

'Bring speed of both motors gradually to a stop from full reverse
reverse_to_neutral:
for x = full_rev to neutral
' debug ?x
pwm pwmpin1,x,cycles
pwm pwmpin2,x,cycles
pause pause_time
next
return

Schematics

Model MCIPC-24 Motor Controller Connection Diagram

Schematic - Joystick/MCIPC-24 Controller

Schematic - Connecting A BS2
 to 1 Motor Controller

Schematic - Connecting A BS2
to 2 Motor Controllers

Sample Programs

Sample Program to Control 1 Motor with a BS2 and 1 MCIPC Controller

Sample Program to Control 2 Motors with a BS2 and 2 MCIPC Controllers

Sample Program To Control 2 Motors with a BS2, MCIPC-24 & Joystick

 

Notes & Views

MCIPC-24 Motor Control Notes

MCIPC-24 Motor Control Specs

Home

Motor Controllers

Battery Chargers

Interface Circuits

Radio Controlled Devices

My Robot Page