Lab Assignment |
|||
|
Intro to Physical Computing Syllabus code, circuits, & construction
|
Analog output: Servo Control |
||
|
Minimum parts needed: (new parts in bold. See parts list for details)
Step 1: Connect a servomotor to your PIC or BX-24 as shown:
PIC 18F452 with servo on pin RC3
BX-24 with servo on pin 12
Program the PIC or the BX-24 to control it using the code from the servo examples. Note that this code just moves the servo from one end to the other of its travel, then resets it and starts over. |
|||
| Step 2:
Connect an analog sensor (potentiometer, variable resistor) to any of pins the analog pins of your microcontroller as shown in the analog input lab assignment. Program the microcontroller to convert its range into a value that you can use to control the servo. A few changes are needed. First. we add a new variable, to keep the range of the servo's pulsewidth: PIC: pulseRange var word ... pulseRange = maxPulse - minPulse BX-24: dim pulseRange as single ' the range of possible pulses pulseRange = maxPulse - minPulse then we read the variable resistor (make sure to declare the variable sensorValue, and add the necessary DEFINEs for ADC on the PIC): PIC: main: adcin 0, sensorValue BX-24: ' the main do loop: do ' read a variable resistor sensor on pin 13: sensorValue = getADC(13) And finally, a little math to make the servo move according to the sensor's value (this replaces the if-then-else block that used to set the value of pulseWidth). In the following example, a sensor with the full range from 0 to 1023 was used. n.b. on the PIC, it's necessary to change the variables pulseWidth and pulseRange from a byte to a word for this: PIC: pulseWidth = minPulse + (pulseRange * (sensorValue/10)) / 100 In this formula, we have to divide sensorValue by 10 to keep everything fitting in one word. We lose a little resolution, but not enough to be noticeable in practice. BX-24: pulseWidth = minPulse + ((pulseRange * cSng(sensorValue)) / 1023.0) You will need to modify this somewhat so that your sensor's range maps to the pulsewidth range, so figure out the total range of the sensor first. |
|||
| Step 3:
Use a servo as part of a creative application; make a sundial that follows the light, for example, or some other application that translates sensor data from the world into motion. |
|||
| Step 4 (alternate to 3):
Build a creative application using other forms of analog output. Here are a few possibilities to think about: Stopwatches A stopwatch measures time in regular increments, and is usually used to give an indication as to how long a person takes to complete an activity. Stopwatches often give helpful updates as to when regular time increments have passed. They do this by changing some physical property of the watch's display. Stopwatches can be interrupted; in fact, it's part of the definition of a stopwatch that it can be interrupted. An alarm clock. Alarm clocks are similar to stopwatches in that they can be interrupted. They can also interrupt. Watches often have a pendulums, springs or some other form or periodic motion to count the ticks. Incorporate a pendulum, kinetic or otherwise. Look up the physical formulas for these systems and incorporate them in your project. Watches and clocks do not have to have digits, hands, or faces. But they have to be periodic in some way. Musical instruments are great for real time interaction. They have to respond immediately, and they have to allow for spontaneous performance. Ripple effects can make simple systems seem more rich in their response. Likewise decay effects. Both effects require you to handle multiple processes simultaneously; monitoring input, keeping track of the state of output, and balancing the two. |