# Gas station without pumps

## 2013 March 23

### Triangle-wave oscillator

Filed under: Circuits course — gasstationwithoutpumps @ 23:09
Tags: , , ,

One of the student suggestions from the “bar exam” was to design a protoboard for the class D amplifier, so that they could keep it as a permanent object (a more useful one than the pressure-sensor amplifier, since they don’t have any strain gauges).

I’ve been thinking about that and see a few problems:

• The block diagram the students came up with this fall (with my guidance) calls for 3 power supplies, which makes the amplifier a bit impractical to power from a battery or wall-wart power supply.
• The students used an external triangle-wave generator.
• The protoboard would have to be fairly large to accommodate the FETs and inductor and enough wiring space, which would probably result in a larger board than 5cm × 5cm, and so \$2/board rather than \$1/board.

I’ve not given much thought yet to the power-supply problem, but I did think a little about the triangle-wave generator.  Since they only need to generate triangle waves at a single frequency (in the 60kHZ–100kHz range), it should be possible to use a hysteresis oscillator with an integrator rather than a simple RC timing circuit.  Something like the following might work:

The slew rate of the MCP6004 op amps is only 0.6 V/µs, but the triangle wave only swings from VIL to VIH, or about 1V, so the minimum period is about 3.3µs, for a maximum frequency of 300kHz. If we use another op amp to amplify the signal to make it swing almost 5v, instead of 1V, the maximum frequency would be only 60kHz.

I might want to try this circuit out this week, to see if it is worth having the students play with next year.

## 2013 February 25

### Tinkering lab reports show problems

Filed under: Circuits course — gasstationwithoutpumps @ 11:53
Tags: , , , ,

I thought that the tinkering lab (lab handout)had gone ok, because students had done a lot of experimenting and had all ended up with functional circuits.  But the lab reports that I graded this weekend indicated some serious problems:

• A lot of the students made serious errors on their schematics.  Shorts, missing wires, and mislabeled parts were common. I’m making the students who had serious errors redo the report, and keep redoing it until they can produce correct schematics.  It wasn’t just the weakest students in the class making errors on the schematics—almost everyone was.
• A lot of the students did not check their predictions of the behavior of the board when components were added between pairs of terminals.  If their initial predictions had been accurate, this would not have been a problem, but students with predictions that were way off didn’t check them.
• There was no evidence that anyone improved their mental model of how the hysteresis oscillator worked as a result of either making the observations (which about half the class did) or thinking about the model more (which those who did not check their predictions could have done).
• Some of the students appear to have poor technique for recording observations, as they tabulated observations that were not really consistent with how the boards behave.  Either they mis-recorded the conditions under which they did the test or they shorted together some nodes without noticing.  No one checked for consistency of the observations to see whether things that should have been nearly the same were nearly the same.

I’ll probably rant in class about wrong schematics ruining otherwise fine reports, and hope the message gets through that they have to check their work much more carefully.  They’ll really suffer on the labs that they have to solder up on the protoboards if they continue to work with such sloppy, useless schematics. I may rant about lab notebook technique also, since that will be even more important in biomolecular labs.

Next year, I’ll want to split this lab into 2, with one lab dedicated to collecting data, a class in between to analyze the data, and the next lab dedicated to doing the design.

## 2013 February 14

### Tinkering lab

Filed under: Circuits course — gasstationwithoutpumps @ 22:33
Tags: , , , , ,

Today’s lab was a “tinkering lab”, using the oscillator board they made in the hysteresis lab as a component to make a light-controlled sound generator.  They did not have a specific goal, other than to use the oscillator board, to produce sound on the loud speaker, and to be able to control/change the sound by shadowing a phototransistor.

I had them try to predict the effect of adding resistors or capacitors between each pair of points on the oscillator board (+5v, GND, Cap, and OUT), and to test how many of their predictions were right.  A lot of students turned out to have such weak mental models of the oscillators that they couldn’t figure out what would happen in even the simple cases. Few of them were able to do the prelab exercise of predicting what would happen if the added components in various places. Most of them eventually remembered or figured out again how the oscillators worked, and so were able to modify them in reasonable ways, but a lot of lab time was wasted doing what was supposed to be prelab work.

A few of the students were trying to figure out what to do without even a schematic in front of them, and when they drew a schematic it did not correspond to what they told me they were trying to do.  They worry me a bit, as by this point of the quarter the students should be able to copy schematics accurately and wire from them, even if they are sometimes a bit hazy on how the circuits work.

I’m also finding that several of the students seem to be incapable of learning from written material—students with no understanding of FETs as switches seemed to understand it fairly well after I explained it—using almost the same words as I used in the lab handout.  I’m not sure I understand why the explanation given verbally seemed to work, while the same one given in writing seemed to fail.  I find it difficult to believe that they really can’t learn from written materials, so there must be a different explanation.  Too much in the handout, so that they shutdown while reading it?  Not having read the handout? (possible with some of the students, but unlikely with the ones I observed the problem in)

I rely heavily on written material to communicate both design goals and details about the parts they are using, so I really need to figure out what is going wrong with the written channel for information.  Is there a way I could write the lab handouts that would be more digestible for the students? If the difficulty absorbing information from written sources is a real one, I may have to do more lecturing, though that seems like the wrong thing to do, as engineers have to be able to read spec sheets and learn from written sources.

Only a few of the students did the systematic exploration of what components in different places and predicting/observing the effect.  I may need to reduce the emphasis on that next year, and focus their attention more on potentially useful interventions (one pair wasted a lot of time looking at the least interesting pair: connecting extra components between power and ground).

Everyone eventually managed to get loud sounds out of the loudspeaker, and to control the sounds by shadowing the phototransistor, but I think that some just copied what others had done, without completely understanding what they were doing.  I think that they all ended up with essentially the same design I had, with the phototransistor shorting out the capacitor in bright light.  Everyone did eventually get the right pFET driver for the loudspeaker, though one group worked through the other three circuits first, and found why they were less desirable. We’ll see in the lab reports whether all the groups can accurately draw their schematics and explain how their devices work.

Overall, I’m moderately pleased with how the lab went.  Students deepened their understanding of RC time constants and the hysteresis oscillator circuit, and they got a feel for “cut-and-try” engineering. But I think I need to rewrite this lab for next year, with a little more direction in which pairs of terminals are worth exploring and how to think about the effect on the oscillator.

## 2013 February 2

### Idea for phototransistor/FET lab

Filed under: Circuits course — gasstationwithoutpumps @ 21:12
Tags: , , , , , ,

Based on the conversation I had with the students at the beginning of class yesterday, I came up with an idea for a lab that uses both the phototransistor and an FET that should be fairly fun and easier than many of the labs we’ve done.  The students were saying they would enjoy a musical application—the student who mentioned it was thinking of a light harp, where the “strings” are light beams that you break with your hands to trigger synthesized notes.  It would be pretty easy for them to make a circuit that detects the presence or absence of light, but all the fun parts of such a lab are in the programming, which is not part of this class (and which most of the students have no training in).

I decided to try making a sound that the students could control in some way with a phototransistor, but not necessarily a particularly musical sound.  The obvious application of an FET is to put it in series with the loudspeaker and a power supply and turn the FET on and off.  The relaxation oscillator that they did for the hysteresis lab this week could be used to drive the FET (at least, if we lower the frequency down into a comfortable part of the audio range). The students don’t have another 74HC14N chip, but they don’t need one, since all four nodes of the hysteresis oscillator (+5v, out, in, GND) are available at the screw terminals of the board they soldered.

Since we are interested in increasing RC, we can do it by increasing C—adding another capacitor in parallel with the one on the board. All they need to do is connect wires from the board to a breadboard, add capacitance to lower the frequency, and connect the output to the gate of the FET.

So we’ve got sound (pretty loud sound if they use a high pitch) out, all we need is control.  The simplest thing I could think of was to put the phototransistor across the capacitor.  In bright light, it conducts a large current, discharging the capacitor and keeping the input low (thus keeping the output high).  In darkness, it conducts essentially no current and the oscillator oscillates as it did before we added the phototransistor.  At intermediate light levels, it conducts some current, which means that it takes the oscillator much longer to charge the capacitor up to the high threshold, so the output-high time is stretched.  If the current through the resistor is slightly larger than the current through the phototransistor, the oscillator oscillates at a low frequency.  If it is much higher, the oscillator output is stuck high, and if it is much lower, the oscillator oscillates at its maximum frequency.  So by shadowing the phototransistor, one can modulate the frequency of the output.

One problem with the design as a toy is that the resistor used determines the amount of ambient light needed to shut the thing off.  I had to add resistors in parallel with the one already in the oscillator to make the current large enough to oscillate even in dim light, and I needed to increase the current a lot more to have any control in sunlight.  When I had the current that high, though, the oscillator would not shut off with just room lights at night.

I suppose I can make a virtue out of this problem, though, by having the students measure the range of currents that they get from the phototransistor (with a bias voltage around the VIH threshold) for the lighting in the room and the shadowing they can do with their hand, then pick the resistance they would need to use in parallel with the existing resistor. After that, they could compute the capacitance they would need to add to get a reasonable high frequency in darkness.

This is a simple design exercise, gets another use out of the hysteresis oscillator board, and is sort of fun to play with (though the pulse-train buzzes do get annoying to listen to after a short while—I’m sure I’ll have a monster headache by the end of the lab session. I’ll try to write up this lab as soon as I get Monday’s quiz written.

I’m now thinking that next year I’ll rearrange the first 6 labs into several shorter labs:

1. buying parts kit and familiarization with it.  Marking bags of capacitors, learning to use multimeter to measure resistors.
2. thermistor lab using multimeter  (and make sure we have water hotter than 70°C and colder than 10°C)
3. thermistor lab using voltage divider and  Arduino
4. microphone lab getting DC characteristics with Arduino
5. microphone lab setting DC bias and learning to use the oscilloscope
7. soldering hysteresis oscillator design
8. phototransistor and FET lab
9. characteristics of stainless steel electrodes
10. characteristics of Ag/AgCl electrodes
11. audio amplifier with op amp, dual power supply
12. audio amplifier with op amp, single power supply

That order would give us more time to develop the notion of impedance before the electrode lab, as well as more time to learn to use gnuplot, but after 6 weeks will be in about the same place I hope to be at the end of next week after 6 weeks.  It might be necessary to spend two of the shorter labs on the dual-power-supply op amp, but we’ll see.

## 2013 January 31

### First soldering lab went fairly well

Filed under: Circuits course — gasstationwithoutpumps @ 22:31
Tags: , , , ,

Today’s lab, the hysteresis oscillator lab, went fairly well, though it needs a bit of tweaking for next year.  There were three parts to the lab: finding the upper and lower threshold voltages of the 74HC14N Schmitt-trigger chip, choosing a resistor and capacitor for the relaxation oscillator and testing it on the breadboard, then soldering the circuit and demonstrating it working as a capacitance touch sensor.

The first part, finding the threshold voltages, took longer than I expected.  Students needed more help than I thought they would in setting up a circuit to determine the thresholds—not unreasonably more, but I was a little over-optimistic about how independent they would be at this point.   I think I should provide a bit more support for the threshold measurements in the lab handout, and allow a bit more time for it. Using a bench power supply to provide the input voltage confused them and did not really save much time compared to setting up a pot from the 5V supply, as they did for the microphone characterization.

The hysteresis oscillator was the main design challenge, deepening their understanding of RC timing.  They had the circuit for the oscillator (though I should switch to using a CircuitLab circuit, since the Eagle one for the board was too confusing with the extra symbols for off-board connectors and extra holes).  All they needed to do was to pick appropriate resistor and capacitor values and wire it up.  There was one constraint and one design goal.

constraint
the low pulse width has to be between 20µsec and 1 msec
goal
the low pulse width has to increase by 40% or more when the capacitive touch sensor is touched

For the pre-lab students were supposed to have computed the approximate increase in capacitance of the touch sensor  they made (Al foil covered with a layer of packing tape) when touched by a finger, but many were scrambling to do it during lab, which increased the lab time. I did not tell students whether they had gotten the value right, nor whether their resistor and capacitor values were reasonable. Instead, I told them what my Dad always said, “Try it and see!” [I need to make a poster for that!] In fact, some students appeared to have calculated the capacitance close enough, while others messed up their units and were off by a factor of 100–1000.  I hope that in their design reports, they provide both the corrected estimates and what they did with the initial mis-calculation.

I did do a 5-minute mini-lecture when one of the students was stumped because he couldn’t find a formula to compute the resistance and capacitance, and several other seemed similarly stuck but were too nervous to say so.  I had a mini-tirade about how the course wasn’t about finding the right formula, but about thinking through problems with the tiny set of  formulas on the study sheet they’d gotten the day before.  Then I calmed down and stepped them through a series of questions to show them how to think about the problem:  the goal was to pick R and C to get the right low pulse width.  What was the capacitor doing when the output was low?  About what voltage did it have? About what current was there?  How much charge had to be removed from the capacitor to get it from one threshold to the other?  How long would that take with that current?  I did say that they could use the proper exponential decay formula if they wanted, but that we only needed crude approximations, so a constant-current approximation was good enough.

One of the beauties of the Schmitt trigger oscillator is that it will oscillate over a huge range of resistor and capacitor values, so even if the students were way off in their component values, the circuit would still oscillate, once they wired it up correctly.  A lot of them are still rather careless about converting schematics to wires on the board, and fixing wiring errors was a big part of their debugging time.  Several still had the wires in place from the hysteresis voltage measurement, which really interfered with the oscillator.  When the oscillations were visible on the scope, I  had them touch their capacitive sensors to see how much the pulse width changed.  Most of the students who had mis-computed the capacitance of the touch found almost no change when the sensor was touched, but (with only a little hinting) could figure out that this meant they had used too large a capacitor and tried again with a much smaller one.  (I’m so glad I had them buy a large assortment of capacitors, so that they didn’t get strong hints about the “right” values from what was in the parts kit.)

Once they had an oscillator that responded to touch with a large change in period, I had the students estimate the low pulse widths from the scope display.  Many found that they were not in spec for the pulse width, so had to change their resistor values.  I think that this exploration of the design space is a valuable aspect of this lab, so I actually am pleased that students did not immediately get the “right” answers.  I hope that some students recorded the low pulse widths with and without the sensor touched, and use it to compute a better estimate of the capacitance of the touch.  (If they didn’t, that is a quick addition to the lab that they could do Monday after class, since it only requires the oscillator board, an oscilloscope, and a 5V power supply—they don’t even need the Arduino.)

```// Capacitive sensor switch
// Sun 2013 Jan 27 15:23 Kevin Karplus

// To use, connect the output of the hysteresis oscillator to
// pin CAP_PIN (default is digital pin 2) on the Arduino.
// The code turns on the LED on pin 13 when a touch is sensed.

// The Arduino measures the width of one LOW pulse on pin CAP_PIN.
// The LED is turned on if the pulse width is more than high_pulse_usec
// The LED is turned off if the pulse width is less than low_pulse_usec
// The LED state is unchanged if the pulse width is between these

// pin that oscillator output connected to
#define CAP_PIN (2)

// Two thresholds for detecting touch by change in period of oscillator
// The initial values here are not used---the values are automatically
// set when the Arduino is reset.
// The sensor should not be touched until the LED is flashed 3 times,
// to indicate that the automatic sensing is done.
static uint16_t low_pulse_usec=40;
static uint16_t high_pulse_usec=50;

void setup(void)
{
pinMode(CAP_PIN,INPUT);
pinMode(13, OUTPUT);
digitalWrite(13, 0);

// Assuming that the touch sensor is not touched when resetting,
// find the maximum typical value for untouched sensor,
// and use this for the lower threshold.
low_pulse_usec=1;
uint32_t start_time=millis();
while (millis()-start_time < 300)
{   uint32_t pulse=pulseIn(CAP_PIN,LOW);
if (pulse>low_pulse_usec)
{    low_pulse_usec =pulse;
}
}
low_pulse_usec += 1;	// add some room for noise

// Set the high threshold for detecting the pulse at 20% longer low time
high_pulse_usec = 12*low_pulse_usec/10;

// flash the LED three times to indicate that the board is ready
digitalWrite(13, 0);
delay(100);
digitalWrite(13, 1);
delay(100);
digitalWrite(13, 0);
delay(100);
digitalWrite(13, 1);
delay(100);
digitalWrite(13, 0);
delay(100);
digitalWrite(13, 1);
delay(100);
digitalWrite(13, 0);
delay(100);
}

void loop(void)
{
// Measure the pulse width from the hysteresis oscillator
uint32_t pulse_width= pulseIn(CAP_PIN,LOW);

if (pulse_width>= high_pulse_usec)
{   // pulse is long enough to turn LED on
digitalWrite(13, 1);
// wait, to make sure LED stays on for 1/5 second
delay(200);
}
else if (pulse_width<= low_pulse_usec)
{   // pulse is short enough to turn LED off
digitalWrite(13,0);
// wait, to make sure LED stays off for 1/5 second
delay(200);
}
}
```

Most students had no trouble getting this code to turn an LED on and off from their capacitance touch sensor. A few students had trouble with poor wire connections to the Arduino headers. The 24-gauge wire that is provided in the lab is really too fine a gauge—a 22-gauge wire would work better. I think I may want to mention the flexible wire jumpers that I use for connecting off a breadboard (I prefer short solid wires on the breadboard, but flexible wires for off-breadboard connections). There are lots of hobbyist electronics places that sell the jumper wires (for as low as \$4.32 for 65 jumpers ordered from China or \$5.50 for 75 shipped from California by wosang). They aren’t really needed for the course, so I didn’t include them in the parts kit, but they do make connection to the Arduino a bit easier.

My co-instructor gave a brief tutorial on soldering, which included having students melt solder on scraps of copper-covered PC boards (blanks, not etched) to see the flow when the solder is hot enough.

The students were all showing me their solder joints after soldering up the boards, and most were ok, though I had to send a few back for reheating the cold solder joints. One student who was in a hurry had to reheat his solder joints twice, because they were cold both times, and the oscillator did not work. After the second time, he heated the joints enough and the board worked beautifully. (He was late for his next class, though.) A couple of student had gotten solder blobs into vias that they needed to put components through. In one case, we were able to clear it fairly easily with a solder sucker, but in the other case, the via and attached trace delaminated from the board by the time the hole was cleared. It is probably easier for the student to start over with a new board (I ordered lots of extras of this board), rather than try a complicated repair. Only one student soldered the 14-pin DIP in backwards. While it is possible to unsolder the chip and turn it around, that’s a real pain and it will be faster to start over with a new board and a new chip—the 50¢ board and 30¢ chip are not worth trying to salvage. The 60¢ screw terminal probably is worth removing—not for the part value but for the desoldering practice, since it is pretty easy to remove and reuse.

Overall, the soldering went fairly well for a group of students who had never held a soldering iron in their lives. A few students did not get the soldering finished, but will come in over the weekend (supervised by the undergrad group tutor) or after class on Monday (supervised by me). There will be two more soldering projects later this quarter, after which the students will be as good as most hobbyists at through-hole soldering (I’m not going to try surface-mount soldering with them!)

I’m not sure where best to break this lab in two next year. There are really three distinct parts: determining the hysteresis voltages, designing the relaxation oscillator, and soldering the oscillator (perhaps plotting out the full Vout vs. Vin transfer characteristic). I think it could profitably be broken into three shorter labs, spending a bit more time on characterizing the 74HC14N, then having a day to think about the RC values before coming back to the lab, then having a separate day just doing the soldering.

Overall, I think that the students are beginning to get the idea of the course, and starting to have some fun with the labs. I definitely need more time for the labs next year—I was in the lab from 2 to 7 today, and that is too long a stretch at once. I’m beginning to think that I’ll need to have three days a week of lab and only two of lecture.

Next Page »