Potentiometer Lab

Download Report

Transcript Potentiometer Lab

Last week’s project demos
• Servo loop with E-Stop and Reset
buttons
• Demo in class tonight – don’t start on
the next project until I’ve seen this one!
More circuit design
Potentiometers, capacitors, and
motion control
The Potentiometer
• Also known as a “pot”
– It’s a dial that can be turned
• Nothing more than a variable resistor
Schematic
• The schematic shows it as a resistor
with three leads
– One on each end of the internal resistor
– One that cuts into the middle of the internal
resistor (this is called the “wiper”)
What will this circuit do?
Capacitor
• A capacitor is essentially a rechargeable
battery
• The [typically] only hold their charge for a short
period of time
• When coupled with a resistor we create an “RC
circuit” of which we can measure the
capacitor’s discharge time
• With that time measurement, we can do
wondrous things
Capacitor
• A capacitor’s value (capacitance) is
measured in farads
– Our circuits will use values in microfarads (μF)
• Two types
– Polarized – these have a +/- side and MUST be
put in the circuit in the proper direction or bad,
really bad things can happen!
– Non-polarized – these are like resistors and can
be placed in the circuit either direction
Two types of capacitors
• Polarized
• Non-polarized
Capacitor usage – the RC circuit
Protective resistor
Timing resistor
I/O pin
How to use it
• Send 5V to the circuit via the I/O pin for a set period
of time
– This will charge the capacitor
• We then cut the 5V and monitor the I/O pin
– This monitoring removes the I/O pin from the circuit – it
becomes a passive device
– Thus the voltage stored in the capacitor will drain through
the resistor to Vss (ground)
• The time it takes the I/O pin to change from a 1
(capacitor charged) to a 0 (capacitor discharged) is
the RC time of the circuit
Measuring the discharge time
• There are 2 ways to do this
– Charge up the capacitor then loop on
reading the I/O pin until it drops to 0
(counting the time through the loop)
– Use the PBASIC RCTIME command
RCTIME 0, 1, time
• Read pin 0, waiting for it to change from a 1,
tell us the time (accuracy is dependent on the
model of BasicStamp you are using)
To do
• Perform the lab (Activity 2) on page 143
of the book
• CHECK THE DIRECTION OF YOUR
CAPACITOR BEFORE APPLYING
POWER TO THE CIRCUIT!!!
• AND AFTER YOU’VE CHECKED IT,
CHECK IT AGAIN!!!
Use of fractions in PBASIC
• There are no floating point data types
• Anything requiring fractional precision
must be done with scaled arithmetic
• PBASIC provides some operators to
assist
Scaled math
• We want to do floating point math!
value = value * 3.1415926
– The 3.1415926 must be scaled by 256 and
the result “unscaled” by 256
value = (int)(value * (3.1415926 * 256)) / 256
– The result is our desired value to a
precision of 1/256
Multiply Middle operator
• PBASIC provides an operator to do this
*/
• To use it in our previous example
– Pre-multiply
(int)(3.1415926 * 256.0) → 804
– Use the Multiply-Middle operator
value = value */ 804
You’ll need this…
• … as it is typical of low-cost microcontrollers to not support floating point
math but it is equally typically of
applications that use low-cost microcontrollers to require floating point math
• … for the homework assignment
Homework
• This week’s homework assignment will
be controlling the servo motor (from last
week) with the potentiometer as
described in the book on page 152,
Activity 4 with the following
modifications…
Homework
• Add two buttons (ON and OFF)
–
–
–
–
The ON button places the circuit in the ON state
The OFF button places the circuit in the OFF state
At power on reset the circuit is in the OFF state
The servo motor can only be moved [by the
potentiometer] when the circuit is in the ON state
• Add two LEDs (ON and OFF)
– A green LED indicates that the circuit is in the ON
state
– A red LED indicates that the circuit is in the OFF
state
Question
• What happens if I move the VSS
connection of the circuit from the A (B)
side of the potentiometer to the B (A)
side?
– That is, I move it from the pin to which it is
currently connected to the other
– Why does this behavior occur?
Deliverables
• A state-machine diagram depicting the
operation of the system
• Source code
• A schematic diagram of the circuit
• A working demonstration on the Basic
Stamp development board (in class)
• Answer to question on previous slide