Let's Make Robots!

DC motor control - BS2

Alright. This is the last element for my robot to final come together. I need some help with DC motor control for my robot which will interface with the basic stamp 2. 

Here are some requirements:

- Able to go in 2 directions (DUH!)

- speed variations

- simple and easy to make

- easilt programmable with basic stamp 2.

 

thanks in advance  

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
how to "high" the  motor for a period of time

The HIGH command makes a pin high. So HIGH 8 and HIGH 9 would make those PWM pins high. To make it run for a period of time, have it in a loop combined with PAUSE to get however long wanted. Below will have pins 8 and 9 high for 1 second (200 x 5 ms) before setting them low again.


count     VAR   Byte

Setup:
  LOW 8
  LOW 9

Main:
  FOR count = 1 TO 200
    HIGH 8
    HIGH 9
    PAUSE 5
  NEXT
  LOW 8
  LOW 9
   
  END
can i pulsout more than 1000? i cant seem to get max speed.

What does the Basic Stamp manual say on page 351?

Making pulsout longer does tie up the Basic Stamp for a longer period of time, til eventually it can do nothing else.

At any rate, if you want max speed, simply make the PWM pins high.

if im right i also need to use  this 

  • PWMA to +5 volts
  • AIN2 to  P4
  • AIN1 to P5
  • STBY to +5 volts (can be wired to Stamp pin to disable/enable driver)
  • BIN1 to P6
  • BIN2 to P7 
  • PWMB to +5 volts
  • GND to ground
  • GND to ground
  • VMOT to motor positive supply (+6 volts for above motor)
  • BO1 to left motor terminal
  • BO2 to other left motor terminal
  • AO2 to right motor terminal
  • AO1 to other right motor terminal
  • VCC to +5 volts
  • GND to ground

To make the right motor turn one direction, make the BS2 pin P4 high and pin P5 low. To have it reverse direction, make P4 low, and P5 high. To make the right motor stop, make both P4 and P5 low.

To make the left motor turn one direction, make the BS2 pin P6 high and pin P7 low. To have it reverse direction, make P6 low, and P7 high. To make the left motor stop, make both P6 and P7 low.

 

but just to control the speed  

 

i use this


' pin8 to pwmA
' pin9 to pwmB 

reps VAR BYTE  ' up to 255 for BYTE
tmr  VAR NIB   ' for adding off time for sim PWM, PAUSE in milliseconds

INIT:
LOW 8          ' make sure pin 8 and 9 are low so pulsout is high
LOW 9
tmr = 0        ' change this value to try different PWM "speeds" to 0, 1, 2, or 3
               ' 0 => 100% duty, 1 => 66% duty, 2 => 50% duty, 3=> 33% duty cycle

MAIN:
FOR reps = 1 to 100  ' pulses lasts 0.2 seconds, pause adds 0, 0.1, 0.2, 0.3 seconds
   pulsout 8,1000    ' produces 2 ms pulse
   pulsout 9,1000    ' produces 2 ms pulse
   pause tmr         ' gives the off time for each cycle 

NEXT 

Yes, the wiring is the same, jsut with the added part for a pseudo-PWM speed control added. That code will give anywhere from 0.2 to 0.5 second of running the motor every time it is called, and so must be called constantly to keep the motor turning. Your actual program might have a few other things going on, and call the MAIN part periodically (probably best to call it another name, for good programming technique).
also, is this motor feasible? http://www.pololu.com/catalog/product/1091
Very similar to the other motor, so should work electrically, and torque. May be a little bit too long dimensionally to fit in a minisumo footprint with wide wheels.

sighs, u got a sample of how to do the PWM? 

can i use this? :

' pin8 = pwmA

'pin9 = pwnB 

counter VAR WORD

for counter = 1 to 150

pulsout 8, 750

pulsout 9,750 


' pin8 to pwmA
' pin9 to pwmB

reps VAR BYTE  ' up to 255 for BYTE
tmr  VAR NIB   ' for adding off time for sim PWM, PAUSE in milliseconds

INIT:
LOW 8          ' make sure pin 8 and 9 are low so pulsout is high
LOW 9
tmr = 0        ' change this value to try different PWM "speeds" to 0, 1, 2, or 3
               ' 0 => 100% duty, 1 => 66% duty, 2 => 50% duty, 3=> 33% duty cycle

MAIN:
FOR reps = 1 to 100  ' pulses lasts 0.2 seconds, pause adds 0, 0.1, 0.2, 0.3 seconds
   pulsout 8,1000    ' produces 2 ms pulse
   pulsout 9,1000    ' produces 2 ms pulse
   pause tmr         ' gives the off time for each cycle
NEXT