Gas station without pumps

2016 January 19

Reading switches with ADC

Filed under: Uncategorized — gasstationwithoutpumps @ 22:49
Tags: , ,
Circuit for reading 4 switches.

Circuit for reading 4 switches.

It is often necessary to read the pattern of a large number of switches using few pins on a microcontroller—this problem came up for my son and me in planning to read 9 switches of a DIP switch for setting a DMX-512 address on theater lighting.  There are many ways to do this, but I’ll only talk about one today—using an analog input to read a voltage provided by a voltage divider.

In the circuit to the right, each switch can be open (1) or closed (0). The resistance of the pulldown is the sum of the resistances associated with each switch, and the voltage is Rsum/(Rup+Rsum) Vdd.

To make this work, all the pulldown resistors must be different, so that each combination of switches makes a different voltage. We want to make sure that the values are all easily distinguished by the analog-to-digital converter of the microcontroller, even with worst-case tolerances of the resistors and noise on the ADC input.

I wrote a little python program to optimize the values for different number of switches, selecting optimal thresholds and measuring how close the worst-case resistance values come to the thresholds. I used only standard resistor values from either the E48 series or the E24 series, all with 1% tolerance, and assumed that the ADC had either a 10-bit resolution (like Arduinos) or a 16-bit resolution (like Teensys).  The resolution matters, because the thresholds are integers, and so rounding may reduce the tolerance for noise when the ideal threshold is halfway between integers.

E48 resistor series, 1% tolerance. 10-bit DAC

pulldowns pullup minimum distance to threshold
 1,1.62  1.62 58.322
 1,1.87, 3.48  6.49 19.772
1,1.96, 3.83, 7.5  14.7 7.187
 1, 2.05, 4.02, 7.87, 16.2  30.1 2.016

E48 resistor series, 1% tolerance. 16-bit DAC

pulldowns pullup minimum distance to threshold
 1,1.62  1.62 3704.975
 1,1.87, 3.48  5.9 1239.316
 1,1.96, 3.83, 7.5  14 430.585
 1, 2.05, 4.02, 7.87, 16.2  31.6 103.930

E24 resistor series, 1% 10-bit ADC

pulldowns pullup minimum distance to threshold
 1, 1.6  1.5  56.952
 1, 2, 3.6  4.7 18.586
 1, 2, 3.9, 7.5  12 6.993
 1, 2, 3.9, 8.2, 16  33 1.804

E24 resistor series, 1% 16-bit ADC

pulldowns pullup minimum distance to threshold
 1, 1.6  1.5   3644.94
 1, 2, 3.6  6.2  1181.525
 1, 2, 3.9, 7.5  13  425.540
 1, 2, 3.9, 8.2, 16  27 103.065

Note that a 10-bit DAC with ±2LSB of noise can decode 5 switches only with the E48 series—the E24 series does not allow values to be tweaked sufficiently (and ±2LSB on a 10-bit ADC is unusually low noise—it probably isn’t safe to put more than 4 switches on a 10-bit ADC). A 16-bit ADC with <±100LSB of noise should be able to decode 5 switches with no trouble.

I was not able to find a 6-switch solution with 1% tolerance resistors, even assuming a high-precision ADC.

 

2016 January 18

Theatrical weekend

Filed under: Uncategorized — gasstationwithoutpumps @ 19:59
Tags: , , , ,

This weekend has been a busy one for me—I went to three different theatrical performances:

Saturday night: 8 tens @ 8
Each year, the Actors’ Theatre puts on a show consisting of 8 10-minute one-act plays, which they select from submitted manuscripts.  (I wrote a little of the history in 8 Tens @ 8 in 2016). My wife and I went to see the A show on Saturday night—we’ll go to the B show in a couple of weeks.  The plays were not all of equal quality—not in the writing, not in the directing, and not in the acting.
Our favorite of the A show was You Too, by Tim Woods, directed by Scott Kravitz.  The lines were good, the characters believable, and acting and directing spot-on.
Also excellent was A Shared View, by Mary Caroline Rogers, directed by Audrey Stanley.  The script was a little less strong, but the acting and directing were excellent (both MarNae Taylor and Marcus Cato were well cast).  Good Medicine by Rod McFadden was fun, but very predictable. Flirting with Age, by Jack Spagnola (the only author without a blurb in the program), was a pretty predictable farce, but we enjoyed seeing MarNae in a very different role than she had in A Shared View. It is always a good idea to end with a farce (or at least a comedy), so that people leave feeling good about the show. Flirting with Age was a good choice for this position (though Good Medicine might also have worked, it wasn’t quite as fun).  
Threatened Panda Fights Back was too silly for the somewhat serious theme of extinction—the costuming was fun, but I was not otherwise impressed with the play. The Italian Prisoner by Paul Lewis had directorial problems (the singer was much too loud relative to memory of the boy Joey Rosen), the acting was a bit wooden, and the script too obviously borrowing from Tosca. Following Ms. Sergeant was a good effort with a rather flawed script—the sudden confessional mood seemed out of character for both characters, and the resolution too forced. Janis Gives Comfort was trying to handle “death and sex” as a theme in a nostalgic vein, but it didn’t resonate at all with me—perhaps I just didn’t care enough about Janis Joplin, who the main character was obsessed with.
Sunday morning: Winter’s Tale
The Del Mar Theater had the broadcast of Shakespeare’s Winter’s Tale performed by the Kenneth Branagh Theatre Company from the Garrick Theatre.  The Winter’s Tale is not often performed, because it is a somewhat muddled combination of a number of themes (jealousy, young lovers in disguise, rustic merriment, …) better handled in other plays. Branagh assigned himself the choice role of Leontes, but then over-acted the part. OK, it isn’t the subtlest part Shakespeare ever wrote, but it doesn’t call for crumpling up on the stage with stomach cramps all the time.  Setting the initial scene at a Victorian Christmas party exchanging token presents also seemed rather forced. Judi Dench as Paulina was very good, though, and the dancing in the rustic scenes quite impressive (if a little more balletic than country).  It was worth going to see The Winter’s Tale, but there’s no reason be sad if you missed it.
The Del Mar had put the broadcast in one of their small upstairs theaters, which sold out—I think that there was a high-school class getting credit for attendance. It would have been better in the larger theater downstairs.  But the Del Mar was definitely the right theater to show the broadcast in, as it has the closest that Santa Cruz gets to the gilt plaster ornamentation of the Garrick Theatre.
Sunday evening: Neil Gaiman’s Graveyard
West Performing Arts did a theatrical performance of Neil Gaiman’s Graveyard, using only 6 actors (5 female, 1 male) and 3 musicians. The actors were fairly young (middle school or early high school, I think). One review on a homeschool mailing list said “Very different from everything else I’ve seen going on locally in this age group,” but it seemed to me to be pulling together many of the theatrical techniques I’ve seen WEST developing over the past few years with their teen actors. 
They did a lot of chorus work, like at the Shakespeare conservatory; they did a lot with solid colored lights and backlighting (using their LED floods); they had movement pieces like the ones S. Kate Anderson had done for Call of the Wild; there was a “seduction” scene done in single-word lines, inspired by a Carol Burnett sketch that my son and another teen actor had performed at AFE (under WEST direction); and the actors kept changing roles, with a hat or a shawl to mark the characters (also from a Shakespeare conservatory). They had a dance scene under blacklight with fluorescent makeup (WEST has learned something since the days they tried Star Wars with glow-in-the-dark paint—fluorescence is much more visible and controllable than luminescence).
They were pretty true to the plot of the book, while making a very theatrical production, and I was impressed by how well they pulled off a rather difficult bit of theater.  The next generation of WEST actors is going to do well. I was only sad that the light rain had kept people away, and the house was only about 80% full—the performance was good enough that they should have been selling out every night.  (Of course, with only 6 actors, the built-in audience of family and friends is smaller than when they have a larger cast.)

My weekend was busy (in addition to the theater, I did a bit of blogging and spent most of a day putting together a course fee request for two-quarter version of the Applied Electronics course), but my wife was even busier, as she went to a Metropolitan Opera broadcast on Saturday morning, at a different theater chain than the Shakespeare broadcast on Sunday morning.

Reading glasses

Filed under: Uncategorized — gasstationwithoutpumps @ 18:12
Tags: , , , ,

At my last eye examination, my ophthalmologist told me that my astigmatism had gone away—I now needed a simple –4 circular correction in my right eye (my left eye is difficult to measure correction for, as I have essentially no central vision in that eye).

I have almost no accommodation left in my eyes—my focus range without glasses is about 22cm–26.5cm (3.75–4.5 diopters—a diopter is the reciprocal of the focal distance in meters).  With –4 diopter glasses, my focus range should be 2m—∞, which seems about right for my distance glasses (I don’t remember their prescription).  I just bought a new set of computer glasses with –2 diopters, giving me a focus of 36–52cm, which would be 1.9–2.8 diopters after correction, or 3.9–4.8 diopters before correction, slightly further away than I measured directly).

For bicycling, my distance glasses are fine; for screen work, my computer glasses are fine; and for reading paperbacks I can go without glasses. For really close work like soldering, I want reading glasses—even weak ones would let me get close to the soldering iron without having an exposed eyeball that could easily be damaged. Reading glasses would also be a good substitute for a jeweler’s loupe when looking at the markings on tiny capacitors or integrated circuits

So today I went to the discount store about 1/4 mile from my house and bought 3 pairs of reading glasses at $2 each: +1.5, +2.5, and +3.5.

Three pairs of reading glasses at $2 each.

Three pairs of reading glasses at $2 each.

I tried measuring my focus distance (approximately) for each of the glasses:

glasses min focus max focus diopter range imputed eye range (diopters)
 distance (–4?)  1.5m?  ∞
 computer (–2)  35.5cm  51.5cm 1.94—2.82 3.94–4.82
 none (+0)  21.5cm  26cm 3.85–4.65 3.85–4.65
 +1.5  16cm  18.5cm 5.41–6.25 3.91–4.75
 +2.5  13.5cm  16.5cm 6.06–7.41 3.56–3.91
 +3.5  13cm  14.5cm 6.90—7.69 3.40–4.19

None of the focus measurements are very exact—I was using a ruler held against my face for all but the distance measurement, which was guesstimated—but they are consistent enough to be a useful guideline for me.  I expect that I’ll use the +1.5 reading glasses for soldering work for now, and the others I’ll keep in my toolbox for closer work

Note that even with changing glasses, I have a lot of distances that I can’t focus at—and I expect those gaps to get wider as I age and my eyes become more single-focus.

2016 January 16

Smoother I vs V plots for LED

Filed under: freshman design seminar — gasstationwithoutpumps @ 14:30
Tags: , ,

Yesterday I posted I vs V plots for the orange LED WP710A10ND and commented that “one can see the crude quantization of the bad DAC in the FG085 function generator, as banding in the line.”

 

Today I tried to improve the plots by using a 470µF capacitor across the function generator outputs.  Since the FG085 has an approximately 47Ω output impedance (nominally 50Ω, but see FG085 function generator output impedance), a 470µF capacitor would give a low-pass filter with a time constant of about 22ms, or a corner frequency of 7.3Hz.  I was doing a triangle wave sweep with a period of 9 s, so the 256-step DAC makes for about 57 steps/s or 17.6ms/step.  Having a time constant about the same duration means that the steps will be converted into ramps and we’ll avoid most of the quantization artifacts.

WP710A10ND_logI_V

The curves are indeed much smoother in this plot, and lack the obvious steps of previous plots. If I zoom way in on the plots with gnuplot, I can still see some clustering at the steps, but there is a lot of data between the steps.

Interestingly, I can see some hysteresis on the linear plot.

I had two conjectures about the source of the hysteresis:

  • The 32× averaging takes some time, so the voltage and current measurements are not precisely synchronized, and the current-before-voltage measurement would give different systematic errors depending whether the voltage and current were rising or falling.
  • The properties of the LED change because of heating and cooling effects.  The upward leg has a cooler LED than the downward leg.

Note that these two hypotheses are distinguishable by experiment.  If I slow down the ramps, then the time discrepancy results in smaller voltage and current discrepancies, and the effect should diminish.  But the LED gets hotter if it is run at maximum current for longer, so the thermal effect should be greater.

I tried using a 33s period instead of a 9s period, and the two curves moved further apart (from about 0.4mA to 0.6mA at near the max separation), consistent with the thermal theory, but not the time-bias theory.  (I leaned toward the thermal theory initially anyway, since the two curves are further apart than one step of the DAC in the FG085.)

The hysteresis makes it clear why manufacturers don’t try to specify the I-vs-V characteristics very precisely—not only can there be variation from component to component, but the parameters are temperature dependent.

Lawyers to avoid

Filed under: Uncategorized — gasstationwithoutpumps @ 10:40
Tags: , , ,

If I were ever stupid enough to run for public office, I know one group of lawyers to avoid at all costs: Seattle-based Garvey Schubert Barer.  Apparently the bright boys there decided to issue Wikimedia with a take-down order for putting up pictures of copyrighted campaign materials from the Bernie Sanders campaign. (source: https://boingboing.net/2016/01/15/facepalm-bernie-sanders-campa.html)

Never mind that the whole point of campaign stickers and buttons is to have them displayed as widely as possible.

Never mind that including pictures of campaign materials in an encyclopedia is clearly covered by fair-use doctrines.

Apparently Garvey Schubert Barer hires idiots.  I wonder whether they will make a public apology for doing something stupid, but they’re lawyers, so I doubt it—they probably still think that they can make a case for it being the “right” thing to do.   The takedown order has been withdrawn, but the media storm about it is just about to start.

If I were a conspiracy theorist, I would conjecture that this was not the act of an incompetent and idiotic lawyer (though, in the real world, that is the most likely explanation). Instead, I would conjecture that the lawyer who did this was paid under the table by some rich guy who feared that Sanders might win the election, after all the money he had spent to buy Clinton’s favor.  (The Republican candidates were all bought and paid for decades ago, and their handlers are unlikely to attack Sanders in this way, because in their bubble chamber Sanders can’t win—he has no billionaires backing him, and everyone in their world knows that anyone who isn’t a billionaire is a loser—just ask Trump.)

I understand that the Clinton campaign is starting to attack Sanders, which I think is a strategic error.  Part of what has been making the Democrats electable is that they have been behaving like adults, rather than petulant toddlers like the Republican candidates. In fact, I think that a lot of Democrats have been secretly hoping for Sanders/Clinton double-bill, with the primary mostly about who gets top billing. I know it goes against the grain of American politics to have a competent person as a vice presidential candidate—but it would be nice to have two competent people, either of whom would make a good president, working together as President and Vice President.  If the Clinton and Sanders campaigns start throwing mud or engaging in dirty tricks, then it will be nearly impossible to put together such a winning ticket.

Personally, I’m rooting for Bernie, as is most of the town I live in (Santa Cruz has been described as The Leftmost City), as I am tired of center-right politicians like Obama and Clinton being described as leftists or socialists.  Why does the media allow the wingnuts on the far right to redefine the “center” far to the right of where the center really is?

We need to get more progressive politicians at the state and national level, to undo the  damage that has been done by the concentration of wealth and privilege in the hands of a very small group of greedy men.  Bernie Sanders is one of the few progressives who has survived Washington with his honor mostly intact.  (Barbara Boxer is another, but she seems to be withdrawing from electoral politics and has rather tepidly endorsed Clinton, as a show of support for female politicians.)

 

« Previous PageNext Page »

%d bloggers like this: