Title: WAM
1WAM
- Chapter 4
- Controlling Motion
2 Controlling Motion with a Microcontroller
- Microcontrollers control the motion of many
things in our daily lives - Printer head movement.
- DVD and VCR mechanisms.
- Grocery store automatic doors.
- Robotic movement.
3(No Transcript)
4- Instead of being simply ON or OFF, many of these
motion devices require a variety very fast pulses
of signals for position control or movement.
These pulses must occur much faster than the
rates at which we turned LEDs on and off
5- The PULSOUT duration is a command that sends
pulses to the servo in 2 uS (microsecond)
increments. - 1 ?S .000001 seconds.1 mS 1000?S
- For a command of PULSOUT 14,750
- This would be sending a pulse that lasts750 x 2
?S 1500 ?S or 1.5mS out to the servo on pin 14.
6TIMING DIAGRAMS
PULSOUT 14,1000
1000 x .000002sec 0.002 sec 2ms pulse
PULSOUT 14,500
500 x .000002sec 0.001sec 1 ms pulse
PULSOUT 14,750
750 x .000002sec 0.0015 sec 1.5 ms pulse
7THIS IS CALLED PWM
- Analyze each signal on Data Studio Scope
8- Example Code
- If ran, the pulse of 750 is sent 150 times with
20mS pauses. - TOTAL TIME SPENT ON THIS POSITION 2 us x 750
1500 us 1.5ms20 ms 21.5 ms - 21.5 ms X 150 loops 3225 ms 3.2 seconds
9Activity 1 Connecting and Testing the Servo
Servo Connector Black Vss Red Vdd
or Vin White Signal
10- Circuit to be built
- Connecting to the servo to the board depends on
which board you have.
The servo can be damaged with voltages above 9V.
A wall-transformer may be stated to be 9V, but
output 12V. If using anything but batteries,
verify the supply is no more than 9V. See your
text.
11Servo on Board of Education Rev. C
1
2
3
4
12Centering the servo
- Enter and run this code
- Put a straw or a piece of tape on the horn
- Unscrew and reset horn so straw is in the middle
- RIGHT TIGHT
- LEFT LOOSE
DO NOT OVERTIGHTEN
13Enter, run, and save this code as servotest.bs2
14Adjusting position and hold timeREMEMBER
- PULSOUT and PAUSE controls where
- Loop controls how long servo is working on
achieving a given position.
15Save ServoTest.bs2 as ServoTestYourTurn.bs2
- Modify all for next loops so they execute half as
many times - FOR counter 1 to 75
- See if this works
- Modify all for next loops so they execute twice
as many times as the original - FOR counter 1 to 300
- See if this works
16Now lets change position
- Modify PULSOUT in the second loop to
- Pulsout 14,650
- What change occurs
- The servo goes to about 1 Oclock instead of
about 2 Oclock - Modify PULSOUT in the second loop to
- Pulsout 14,850
- What change occurs
- The servo goes to about 11 Oclock instead of
about 10 Oclock
17ACTIVITY 2 Controlling Position With Your
Computer
- Automation of a factory involves
- Microcontrollers reading sensors
- Sending data about the sensors to a computer
- Computer operator interprets sensor data
- Computer operator sends information back to the
microcontroller using the computer - Update conveyer belt speed
- Change position of factory welder
- IN THE NEXT EXERCISEYOU ARE THE COMPUTER OPERATOR
18- The DEBUG window allows the user
- to enter the number of pulses and the
- duration.
- Once prompted, the user enters the data
- The BS2 waits for your reply and then stores your
input for later usage.
19- The DEBUGIN command is used to send
- data from the computer to the
- BASIC Stamp when it is entered in the text
- box.Here is the syntaxDEBUGIN DEC Pulses
- We will be sending two values
- Pulse width or duration
- Number of pulses
20Enter, run, and save the code found on the next
slide (pg 122 in text), but stay withing 500
1000 pulse widths!!
If you make a mistake entering a number, press
the reset button on the board. The backspace key
sends data which the BASIC Stamp uses the same as
the Enter key.
21Stay within 500 and 1000...You can damage the
servo!!
22TRY THE FOLLOWING
- Try an experiment
- Put in a 2 for the number of pulses
- Put in a 1000 for the duration
- RUN THE PROGRAM AGAIN
- THIS TIME
- Put in a 150 for the number of pulses
- Put in a 500 for the duration
- RUN THE PROGRAM ONE LAST TIME
- Use the same numbers as your first trial, but use
150 instead of 2what is your conclusion about
the purpose of the loop
23Limiting the Software
- THE PROBLEM
- REMEMBER
- stay within 500 1000 pulse widths!!
- What if the user ignores this warning?
- THE FIX
- Resave your code as
- servocontrolwithdebugyourturn.bs2
- As the next slide states
- Replace 2 lines of code with a special
replacement -
24THE FIX
WITH
25Save and Run this program and verify that it is
working properlyyour new code should look like
that on the next slide
26(No Transcript)
27Activity 3 Converting Position to
Motioncontrolling servo velocity
- By changing the horn's position each pass through
a loop, you can get motion. The STEP part of the
FORNEXT defines how much to add to each
repetition. - By modifying the STEP value, the velocity of the
servo can be controlled.
28Why the DEC5 instead of DEC
- Look at the debug terminal while this code is
running (crsrup.bs2) - Monitor the terminal again with the DEC 5
replacing the DEC - Now see what happens when the CR before CRSRUP is
taken out
29Turning the opposite direction at various speeds
- A loop can also count down such as
- FOR counter 1000 to 500
- This would make the servo turn in the opposite
direction
- A step could be added to this to make the servo
turn this way faster - FOR counter 1000 to 500 STEP 20
301-Enter, run, and save ServoVelocities.bs2
on the next slide (page 126 in text)
31(No Transcript)
32How ServoVelocities.bs2 works
- Rotate clockwise
- DEC5 means the number to be displayed will be
five digits longwithout this the number
displayed will appear to exceed 1000 TRY IT BY
LEAVING OUT THE 5 IN DEC5 - CRSRUP must follow CRstands for cursor
up..allows the pulse width display to be
constantly updated in the same spot
33How it works contd
- Rotate counter clockwise
- BUT AT A FASTER RATE
- Repeat program
34THIS IS CALLED CODE OVERHEAD
35Make some adjustments
- Try different STEP values and observe the new
turning rates - Experiment with different PAUSE command Durations
(between 3 and 12)find the value that gives the
servo the smoothest motion
36Activity 4 Servo Control with Pushbuttons
- The servo can also be controlled by receiving
inputs from a button instead of a the debug
terminal - Add two pushbuttons to the circuit to control the
Servo's position.
37The goal will be to make each button activate a
different direction of rotation
38Write a program to do the following
- When the button on pin 3 is pressed, a 1 should
be reported, otherwise a 0 should be reporteddo
this using IF THEN and ENDIF - Revise the program, so it is receiving input from
the button on pin 4 instead. - Again, test to see that the program is operating
correctly
39In the next sample program
- IFTHEN code blocks are used to check the
pusbutton states and either add or subract from
the DURATION variable - DURATION will be used in the pulsout command
- This will have the effect of making the servo
turn one way or the other - A nested IFTHEN statement will decide whether or
not the DURATION value is too large or too small
40ENTER, RUN, and SAVE servocontrolwithpushbuttons.b
s2 on the next slide (page 132)
- Verifty that the servo turns counterclockwise
with pin4 button held - Verify that if duration exceeds 1000 the servo
stops - Do the same test for the pin3 button with a
clockwise rotation
41(No Transcript)
42Mechanical stoppers and software stoppers
- The servo has a mechanical stopper, that will not
allow the servo to rotate past a certain position.
- Your program can be modified to narrow this range
of motion even further. - Change the limits, so they are between 650 and
850 instead of 500 and 1000 - Run the program and note the differences
43Rotation rates
- Adjust the software imposed rate so that the
duration variable is incremented or decremented
by 10 instead of 25 - Run the program and notice the differences
- Now try 50 istead of 10
- Run the program and notice the differences