rctime (review)...2 time constants •for c = 3300 µf = 3300 x 10-6 f= 3.3 x 10-3 f,r (ohm) rc...
TRANSCRIPT
-
1
ME456: Mechatronics Systems Design
Chapter 5:Measuring Motion
Prof. Clark J. RadcliffeMechanical Engineering
Michigan State University
http://www.egr.msu.edu/classes/me456/radcliff
RCTIME (review)
• RCTIME Pin, State, Variable– Measure time Variable that Pin remains in
State; usually to measure the charge/dischargetime of resistor/capacitor (RC) circuit
Initial State = 1
Final state = 0
1
0
RCTIME call State Change
Time
The RC Circuit
Resistor - Capacitor combination circuitUse in two steps:1. P7 as Output with
Low Impedancesets initial state(5 v in this case)
2. P7 as Input withHigh Impedanceto monitor changeto final state(0 in this case)
RC Circuit – Stage 1
Set Initial State to 5 volts (HIGH 7)– Steady-State,
e2/e1 = (R1/(220 + R1 ))
For R1>>220, e2/e1 ≅ 1 so
e2 ≅ e1
Allow 4 time constants, ΔT ≥ 4RC
e1= 5 volts i2e2
RC Circuit – Stage 2
Set P7 to INPUT = VERY high ImpedanceIn the transient,
So that
i2e2i = 0
( )[ ]CRteete 1)0()( 22 !=
( ) 0)()( 221 =+ teteCR !volte 5)0(2 =
The RC TransientState change (1-0) occurs after
approximately one time constant τ = R1C
1.2
-
2
Time Constants
• For C = 3300 µF = 3300 x 10-6 F= 3.3 x 10-3 F,
R (Ohm) RC (sec) (1.2)RC470 1.55 1.861,000 3.30 3.962,000 6.60 7.9210,000 33.00 39.60
RC Circuit for RCTIME
“Pull-up” circuit measures potentiometerresistance
Hint: Short “nc” to wiper on Potentiometer toprotect against pot wiper loosing contact.
Figure 5-11: BASIC StampRCTIME Circuit with
Potentiometer
“Short”
Expected RC time constants
• ParametersC = 0.1 uF = 0.1 x 10-6 FR = 0 to 10k Ohm = 0 to 104 Ohm
• Maximum Time constant
• Minimum time Constant( )( ) msec1101010 RC 374 ==== !!"
( )( ) sec0100 RC 7 === !"
RCTIME count
For RC = 10-3 sec, ΔT = 1.2x10-3 sec
RCTIME Pin, State, Variable
– Should yield (2x10-6 sec ea)count = (1.2x10-3 sec)( 1count/ 2x10-6 sec )
= 600 counts
RCTIME Test Software' What's a Microcontroller -
ReadPotWithRcTime.bs2' Read potentiometer using RCTIME command.' {$STAMP BS2}' {$PBASIC 2.5}time VAR WordDO HIGH 7 ‘Pull Capacitor High PAUSE 100 ‘Wait at least 4 tau RCTIME 7, 1, time ‘Measure tau DEBUG HOME, "time = ", DEC5 timeLOOP
The Hardware
Potentiometer:Third pin “shorted” to wiper Limited Max resistance
with lost wiper contact
Figure 5-11: BASIC Stamp RCTIMECircuit with Potentiometer
“Short”
-
3
Run Servo' ReadPotRunServo.bs2' Read potentiometer using RCTIME command then' Send proportional motion to servo' {$STAMP BS2}' {$PBASIC 2.5}time VAR WordDO HIGH 7 'Pull Capacitor High PAUSE 20 'Wait at least 4 tau RCTIME 7, 1, time 'Measure 1.2*tau DEBUG HOME, "time = ", DEC5 time PULSOUT 14, 500+time 'Send pulse to servo DEBUG " and pulse = ", DEC4 500+timeLOOP
Controlling a Servo
• Using the potentiometer, generate a pulsewidth between 1.0 and 2.0 msec
• For PULSEOUT(pin, state, variable) 500
-
4
Computing the Lower Byte
• We need 0.724• Trick: just compute 0.724*256 =185.344
– 18510 =1x128+0x64+1x32+1x16+1x8+0x4+0x2+1x1
= 101110012
• So that 0.72410 = 0.101110012
A Closer Look
• 0.101110012 = 1x2-1 = 0.510 1x2-3 = 0.12510 1x2-4 = 0.062510 1x2-5 = 0.0312510 1x2-8 = 0.00390625100.101110012 = 0.72265625 (approx 0.724)
A Simple Binary Multiply
• 1.510 = 1.12 and 810 = 1000.2• What is the binary result of 1.510 x 810 1000.2 x 1.12 100.02 1000.02 1100.02 = 810 + 410 = 1210
Our Scaling0.724 x 691 = 0.1011│10012 x 10│1011│0011.2 (two 16 bit values)
= 1│1111│0011.0101│10112 (one 32 bit value) = 1│1111│0011. 2 = 499.10 ≈ 500. 10 (w/roundoff)
I have used the “│” symbol to mark “nibbles”It is easier than counting “bits”
Use your Windows Calculator set to“Scientific” and “Binary”
You must track the “binary point” location yourself just likedecimal multiplication with paper and pencil
A BS2 Example• 'BS2 Floating (binary) point multiply• ' {$STAMP BS2}• ' {$PBASIC 2.5}• 'Code to compute 0.724*691
• 'Symbols• F CON 185 '0.724*256=185.344 (Storage for Fraction)• A VAR Word 'Storage for Integer• B VAR Word• A=691• 'Output Fraction and integer values as decimal• DEBUG ? F• DEBUG ? A• DEBUG "F (binary) = ", BIN16 F, CR• DEBUG "A (binary) = ", BIN16 A, CR
• 'Multiply and select Right Hand 2 bytes• B= F*A• DEBUG "RH two bytes of F*A = ",BIN16 B, " = ", DEC B, CR
• 'Multiply and select middle two bytes• B=F*/A• DEBUG "Middle two bytes of F*A = ",BIN16 B, " = ", DEC B, CR
• 'Multiply and select Left-hand two bytes• B=F**A• DEBUG "LH two bytes of F*A = ",BIN16 B, " = ", DEC B, CR
• END