Home / Lab 5

Lab 5

The questions below are due on Friday March 06, 2020; 05:15:00 PM.
You are not logged in.

If you are a current student, please Log In for full access to the web site.
Note that this link will take you to an external site (https://shimmer.csail.mit.edu) to authenticate, and then you will be redirected back to this page.

Music for this Lab

Goals: In this lab we'll use our knowledge of RC step response to create a proximity sensor.

Before starting this lab check that your function generator is in High-Z mode by pressing Shift, Enter, the right arrow three times, down arrow twice. If it shows 50 Ohm, use the left or right arrows and Enter to switch to High-Z.

1) RC circuit step response

Remember from the pre-lab that we will be sensing distance by using the subtle change in capacitance caused by your finger moving near the circuit. To start off, create an RC circuit on your breadboard with the values you calculated in the final section of the prelab, with schematic as shown below:

Use the function generator to create a 500 Hz square wave at 1 V_{pp} that is offset by 0.5 V, so that the signal goes between 0 V and 1 V.

Use the scope to view both the applied square wave V_s and the voltage across the capacitor v_c.

You'll notice that the voltage across the capacitor doesn't quite reach 1 V. That's troubling. We'll come back to that. But first, let's see if the time constant is what we expect.

There are several ways of measuring \tau on the oscilloscope. One is to use cursors, which are lines you can move back to measure differences in time or voltage. You could use that to estimate the time it takes for the voltage to reach 1-1/e = 0.63 of its final value. That's a bit tedious once we start making many measurements, though. So instead, we'll use the fact that the oscilloscope can do some measurements for us, in particular a measurement called rise time.

Rise time is the time for a signal to go between 10% and 90% of its final values, shown here with a picture from here:

For an exponential rise, which is what we're always dealing with in a first-order circuit, we can do the math to show that the rise time is related to the time constant via a simple relation:

\tau = \frac{t_{rise}}{\ln(9)}

Set up your scope to measure the rise time of the voltage across the capacitor and use that to determine the time constant of the system. You should get a measured time constant that is within 10-20% of calculations. If not, ask for help!

Now let's go back to the issue that the voltage doesn't reach the source voltage. We know from our analysis of the RC step response in lecture that v_c at t=\infty should equal V_s. so what's going on here?

Well, what's happening is that we are assuming that the oscilloscope is measuring the voltage perfectly without disturbing it at all. However, life is not so easy. Oscilloscope probes have an associated resistance and capacitance! A highly simplified circuit model for the probe + oscilloscope that we are using is:

Argh, that's much more complicated than a simple RC circuit. However, we can see if this more realistic circuit helps understand our measurement.

What is the final ratio v_c/V_s for this circuit, assuming that the capacitors have had enough time to fully charge so that they appear as open circuits?

That should help explain our maximal voltage issue. But shouldn't the probe capacitance affect our time constant measurement? How come it didn't seem to before? Let's figure it out.

What is the equivalent resistance of this circuit as seen by the capacitor (in \Omega)?

What is the equivalent capacitance of this circuit (in F)?

What is the time constant of the overall circuit, in microseconds?

So that's why. The extra resistance and capacitance balance just so! And this also means that, since we know the probe parameters and the resistance, we could still estimate C from the rise time.

Checkoff 1:
Explain your measurements to a staff member.

2) Moving onto the Teensy

Measuring rise times with the scope is fun, but it's going to be tricky to measure capacitive changes due to finger or hand movement, which will be very small (around 0.1-1 pF), and the inability to plot or average the rise time values can get frustrating. Let's use the Teensy instead, which is convenient since we ultimately want to make an interface for it.

We can use the Teensy digital outputs to create a square wave, and we can use the inputs to measure the response. There are two ways to go here: we could measure the analog signal using the Analog-to-Digital Converter (ADC), or we could send the analog signal into a digital input pin. We'll do that latter, since it's faster. (Also the input resistance on the ADC pins is much lower than on the digital pins and that could "load" the circuit more making it harder to get measurements).

The idea is that a digital input pin can take in any range of analog voltages (limited to 0 V and Vcc), and outputs a digital 0 or 1 depending on the value. It performs a threshold function on that input voltage, deciding what counts as a "High" or a "Low" voltage. This is the "digital abstraction" discussed in 6.004/6.111. If we know the voltage at which a signal transitions from digital 0 to digital 1, and we know the time at which this occurs, we should be able to estimate \tau.

Download today's zip. There will be a library folder in there (CapacitiveSensor-Teensy) that you need to put into your Arduino libraries folder (Usually under Documents>Arduino>libraries). Here's the circuit and what the code does:

  1. It first initializes the circuit by grounding both the Vs_pin (digital pin 3) and Vc_pin (digital pin 4) to quickly discharge the capacitor, since the resistance looking into the Vc_pin is small.

  2. Then it applies a digital high voltage (3.3 V) to the Vs_pin and repeatedly measure the digital value on the Vc_pin until that value goes to 1. The code records that time.

  3. It repeats steps 1 and 2 NUMBER_OF_MEASUREMENTS times and adds up the total charging time, in effect doing a bit of averaging. We have an additional first-order low-pass digital filter for added smoothing. If you don't know what this means that's great... Please ask and talk with the staff!!

What we need to do, then, is to convert the time needed to achieve digital HI voltage into \tau. According to page 11 of the Teensy datasheet, the threshold voltage needed to register a HI is 0.7 \times 3.3 V. This is not quite 63% of 3.3 V, and in fact, this v_{HI} is only the minimum voltage guaranteed to be HI. So to convert from this time to \tau, we'll do an empirical measurement.

Attach a 2.2 M\Omega resistor between the Vs_pin and Vc_pin and a 47 pF capacitor between Vc_pin and ground, as shown in the schematic above, where:

  • Vs_pin is digital pin 3
  • Vc_pin is digital pin 4

Then, compile and download the code. The screen will display four things:

  • The number of microcontroller cycles it takes to reach the input high voltage on the capacitor
  • the time to digital high in microseconds
  • the estimated time constant \tau
  • the estimated capacitance C (which at this point in the lab is not valid since we haven't calibrated yet!)

Right now the displayed time constant and the time to digital high are the same. But we'd really like to estimate \tau. Since we know R and C for our network, we can empirically determine a factor TAU_CALIBRATION:

\tau = \text{TAU_CALIBRATION} \cdot t_{digital-HI}

One caveat is that the C for our network is not only the 47 pF that we put in, but also includes the input capacitance of the Teensy digital input pin, capacitance due to the breadboard, etc. These capacitances are typically in parallel with each other and so add. So, for the purposes of the calculation, assume that the effective C is 57 pF. Using this C and the R from our circuit, we can calculate how much \tau is, so we can adjust TAU_CALIBRATION until the estimated \tau matches the expected value. Do this and enter the value for TAU_CALIBRATION in the code.

3) Make Your Own Prox Sensor Capacitor

A proximity sensor is nothing more than a pad (electrode) whose capacitance varies as a finger approaches.

Take a piece of copper foil tape and cut out 2 pieces:

  • a ~0.5" x ~0.5" square
  • a ~1" x ~1" square

Rough dimensions are fine here. Note that the strip is 1" wide, which may help in measurement!

Get a piece of quality high-end cardstock from the staff table. Peel off the backing from the copper foil and attach the tape pieces to the cardstock so that they are not too close to each other, kind of like so:

Cut and strip both ends off two pieces of wire, and use a piece of electrical tape to attach the wire to the electrode. Try to get good contact between the wire and electrode.

Feel free to solder the wire to the copper foil if you prefer, though it is not necessary.

3.1) Measure

The variable capacitance you will be measuring using the Teensy is in a circuit between the copper foil tape pad and your hand (represented as a blue capacitor in the diagram below), and eventually returning to the Teensy. However, there are other capacitances in the measurement system that you should be aware of. These are the capacitances between your laptop and ground and between you and ground (both represented as red capacitors in the diagram below). All three capacitors are in series with a 3.3V source (from the Teensy). For capacitors in series, the smallest capacitors tend to dominate the total equivalent capacitance. Since the capacitances in red are relatively large (~5 to 10 times) compared to the capacitance between your hand and the copper pad (the blue capacitor), we can neglect the effect of the stray capacitances in our measurement.

Another way to think of this is that one electrode of the capacitor is the copper foil pad, while the other is the ground signal of the Teensy. Your hand then changes the dielectric medium that makes up the center (insulating) portion of the capacitor, and thus changes the capacitance.

In either picture, an effective variable capacitance to ground results.

Remove the 47 pF cap from the breadboard and attach the 0.5" sensor to the Vc_pin. After the estimated capacitance settles, progressively bring your hand closer to the sensor (but don't touch!). Write down:

  • the maximum distance at which you see a reproducible change
  • C when your finger is about 0.5 cm from the electrode
  • C when you touch

Now repeat with the 1" pad. Make sure to use multiple fingers or your entire hand to maximize the signal.

Think about the performance of the different sensors. When positive charge is applied to these plates by the Teensy, field lines emanate from the plate and terminate somewhere. In a properly designed proximity sensor the field lines are designed to go up and away from the pad as far as possible rather than fringing over to a nearby conductor. A larger pad will have more field farther away and should be more sensitive farther away.

Think also about that sense resistor. Right now it is set so that a small change in capacitance \Delta C results in a change in time constant \Delta\tau = R\Delta C. So a large R permits small changes in C to be measured. What would happen to our sensor if we make R very small, i.e., decreased R to 1 k\Omega? On the other extreme, what happens if we make R too big?

3.2) Design

Create a sensor that:

  • can detect a finger/hand that is ~4-cm away
  • minimizes sensor size, which minimizes system size

Feel free to create a new sensor pad in whatever shape you desire. And feel free to alter the sense resistor if you wish, though that is probably not necessary. If you do alter the resistor, you'll want to change that variable value in the code.

Checkoff 2:
Choose your sensor pad size and sense resistor. Discuss your measurements and choices with a staff member.

4) Victory

Once you have your system designed, in the code set parameter PLAY equal to 1, and update the parameters CMIN and CMAX based on your measured values. Enjoy the show!

If you'd like, you can turn this into a Theremin by attaching a piezo buzzer (get one from the staff table) between digital pin 9 and ground.

5) Cleanup

Before you leave, it's time to clean up again! Steps for cleanup:

  • Keep your sensor(s), though you can disconnect them from the Teensy.
  • Please return the piezos so we have enough for other sections.
  • Carefully pick up your system and place into its plastic case.
  • Throw away loose wires on your desk.
  • Throw away paper, food, etc. on your desk.

Checkoff 3:
Show your cleaned-up lab space to a staff member.