Gas station without pumps

2016 February 21

Optical pulse monitor software

Filed under: Circuits course,freshman design seminar — gasstationwithoutpumps @ 18:43
Tags: , , ,

I have previously written several posts about doing an optical pulse monitor as a lab exercise in the applied electronics course or as a project in the freshman design seminar. Most of what I’ve written up as has been the electronics design, with recording using PteroDAQ and post-processing using filters written in Python for display using matplotlib or gnuplot.

I decided today to try writing the software to do the pulse monitor on the Teensy and report the pulse rate out the serial port.  This meant sampling at a fixed rate, doing digital bandpass filtering to remove drift and noise that is not eliminated by the electronics, detecting rising edges in the filtered output (with hysteresis to increase noise immunity), and converting the measured period to beats per minute.  I used the LED on the board to report the pulses detected (flashing the light synchronized with the pulse).

I also added some tests to see if the pulse has been lost, and only report the pulse rate if there have been enough pulses properly detected since the last loss so that a smoothed pulse rate can be reported.

I output the time, the unsmoothed pulse rate, and the smoothed pulse rate to the serial monitor, and I can save that output to a file for plotting:

The movement artifacts around 20s and 40s are greatly reduced by either averaging or median filtering, but median filtering provides a more stable output. At 70s, I removed my finger from the sensor for about 2s, so that the pulse was lost and had to be reacquired.

The movement artifacts around 20s and 40s are greatly reduced by either averaging or median filtering, but median filtering provides a more stable output.
At 70s, I removed my finger from the sensor for about 2s, so that the pulse was lost and had to be reacquired.

 

 

 

Before anyone asks, the pulse rate of 44 bpm is normal for me when resting—this is not likely to be a timing bug.

I’ll also want to try the 240×320 RGB ILI9341 TFT display that I bought, so that I can display the pulse (and maybe the pulse waveform) without needing a USB connection for anything but power.

2016 February 20

LED multiplexing

Filed under: freshman design seminar — gasstationwithoutpumps @ 12:04
Tags: , ,

In the freshman design class on Friday (2016 Feb 19), I did not cover any of the material I had queued up as things students might need.  Instead, I responded to a question from one of the students working on the LED cube project about how pin multiplexing worked.  I had covered this once before in the class, but in a rather hurried way, and the students did not appear to have investigated the designs on their own to figure it out. So I decided to take the time to go through the development of the idea from the initial problem to one of the many possible solutions.

The problem is fairly simple to state: in a 4×4×4 RGB LED cube, there are 192 LEDs that need to be separately controlled—we want to be able to have any combination of them be on or off (I’m not getting into PWM control for adjusting the brightness in this class, though the hardware is not really different).  The problem is that there are not 192 output pins on the Teensy boards, so they have to pack more functionality into fewer pins.

I started out with the idea of time-multiplexing.  We don’t really need every LED that is on to be on all the time—if we are willing to have the whole cube be dimmer, we can have each LED on only a fraction of the time.  For example, if we are willing to have each LED on for only 1/16th of the time, we can make 16 time slots, assign each LED to one time slot, and only need to control 12 LEDs in each time slot.  If we specify which time slot we are currently in with 4 pins (binary encoding of the 16 possible values), then we only need 12+4=16 pins to control the 192 LEDs.

I then drew a grid of 12 rows and 16 columns (actually, I only showed a couple of each, and used …) and put an LED in each grid position, connecting the row to the anode and the column to the cathode.  I then showed that if we had exactly one of the columns low, we could control all the LEDs in the column with a high voltages on the rows for the LEDs in the column that should be lit.

We then looked at current-limiting resistors, deciding that it made more sense to put them on the rows than on the columns, because the number of LEDs lit on each row is either 0 or 1 at a time, but anywhere from 0 to 12 may be lit on a column.  We can compute a resistor that provides the desired current for the row, but the column has very different current needs depending on the number of LEDs lit.  We also discussed that all the LEDs on a row should be the same color, since the forward voltage for the LEDs is different for different colors, and the needed resistor size depends on the forward voltage at the desired current. (I reviewed how to do the calculation of the current-limiting resistor.)  Note: choosing columns to have the cathodes and rows to have the anodes, combined with needing a single color on each row, puts a constraint on whether we use common-anode or common-cathode RGB LEDs.  If the wrong type of RGB LED is bought, then the columns would have to have the anodes and the rows the cathodes.

I suggested the use of a decoder or demultiplexer chip to decode 4 output lines into 16 column lines, with exactly one column being active. There is a 4-to-16 decoder chip available as a through-hole part (CD74HC4515EN), but it is a bit pricey, and students would be better off with a pair of 3-to-8 decoders (SN74HC138N), using the enable inputs to decode the remaining bit. Note: theSN74HC138N has an active-low output, with only one output low at a time (or 0, if the chip is not enabled).  The CD74HC238E has an active-high output, with only one output high at a time.  I did not talk about the different logic families and the logic levels needed for them. The HCT family, which needs a 5V power supply and uses traditional TTL signal levels is not a good choice for being driven from the Teensy outputs—the HC family is a better choice.

We then looked at another problem.  If we want 20mA in each LED, then we need up to 240mA for a column and 240mA combined from all the outputs.  The Teensy boards can’t deliver that much power from the output pins! Even the decoder chip is only designed for about 6mA on the output. So we can’t drive the rows and columns from the Teensy or decoder outputs.

For that matter, we can’t get 240mA from the 3.3V regulator for a Teensy LC or Teensy 3.1 (though the Teensy 3.2 is specified fairly conservatively to allow up to 250mA, which is barely enough).  I suggested that we might want to power the LEDs off of the USB 5V power, which can deliver 500mA—more than enough.

I then introduced field-effect transistors (specifically MOSFETs) as voltage-controlled switches. For the columns, we just need an nFET for each column, with a threshold voltage between 0V and 3.3V, so that it is off when the decoder output is low and on when the decoder output is high.  The gate of a MOSFET takes essentially no current, and even the cheapest nFETs can work in this application.  I showed the students how to use the DigiKey search page to find a through-hole nFET with a threshold voltage in a reasonable range and sort by price for buying 20.

We talked about including the on-resistance of the MOSFET as part of the current-limiting resistance. The 5LN01SP-AC had an on-resistance of 7.8Ω, which is a little high—it might be better to use a slightly better nFET with a lower on resistance, as the column current varies with the number of LEDs lit, and we don’t want the brightness to change much. For about 13¢ more per transistor,we can get NTD3055L104-1G, which have a 100mΩ resistance—though that is for a 5V Vgs, and we are planning a 3.3V Vgs, which appears to increase the on-resistance by about a factor of 5, based on the current-vs-Vgs curves on the data sheet.

We then looked at using a pFET to control the rows.  The gate voltage would be 0V for an on pFET, and 3.3V for an off pFET, so with the source at 5V, Vgs is -5V for off, and -1.7V for on.  We had a hard time finding many pFETs with a threshold guaranteed to be between -1.7V and -5V, so I added the idea of adding an inverter powered from the 5V supply, so that the gate voltage is 0V or 5V, and the threshold merely needs to between 0V and -5V, which is easy to meet (VP2106N3-G, for example, which has a 7Ω on-resistance for a 5V drive).  We discussed the need to include this on-resistance in the current-limiting resistance calculation, but there is no need to seek a very low resistance, as only one LED is drawing current through the pFET at any time.

So the final design that we came up with by the end of class looked something like this:

LED-multiplexer

We didn’t discuss it, but the decoder should probably also be powered from the 5V USB power, so that it can turn the nFETs on more completely, giving a lower on-resistance for the columns.

On not using kits for a design class

Filed under: freshman design seminar — gasstationwithoutpumps @ 10:07
Tags: , ,

A question came up in e-mail from a student in my freshman design seminar that I had planned to discuss in class, but I ran out of time before getting to it:

Upon determining the actual parts and part numbers for our design, its become increasingly apparent that the DIY kits neatly contain all of the parts we require. Considering this, we wanted to recap with you regarding the DIY kits from our projects. Are we allowed to purchase a kit and build our pulse monitor from it, or are we only allowed to use some parts but not the entire kit?

I answered the student after class, but I wanted to share my thinking more widely.

I like kits in many ways—I learned a lot from building Heathkits as a kid (see Thanks, Dad), but there are limits to what a kit can do for learning, particularly if people just assemble the kit with little or no attempt to understand what each part is for and how the whole thing works.

In a freshman design course, where students know very little or no electronics or programming when they start, the projects that they can reasonably tackle have to be quite simple. Most of the problems that they can solve have been solved before, and solutions by experienced engineers are easily found. Furthermore, commercial solutions are often available for less money than the parts needed to build them, due to the high cost of stocking, distributing, and shipping low-volume parts.

So students who see their role as answer getting are easily convinced to grab one of the good designs so readily available on the Internet and present it as the solution—very little work on their part and a good design, so what could be better?

The problem, of course, is that it is not the goal of the course to have a pulse monitor, an LED cube, or an ultrasonic rangefinder—none of those were part of the syllabus.  I can buy a pulse monitor for a few bucks, and for under $2 an ultrasonic rangefinder module that works better than anything the students are likely to come up. A finished RGB cube is a bit more expensive, but kits are still pretty cheap. One can buy the products the students could produce for far less time and effort than designing and making them. So the product is not the goal of the course.

The goal of the course is for students to (begin to) learn to design things.  This means doing things like writing specifications, drawing schematics, building prototypes, debugging prototypes, writing design reports, and doing iterative prototyping. It means learning a lot about how things work—not everything, but the specific details they need for the projects they have selected. The process of design is the core of the course, not the product of the design.

Buying a kit and assembling it short circuits a lot of that design learning.  You can build a kit and get it working with little or no understanding of how it works, and with no ability to modify the design. Of course, it is not the bundling of parts into a a kit that is the problem—copying a design off the Internet and buying the parts separately also does little to help students learn design. If you just copy other people’s work, then little learning takes place, and there is not much point to doing the class. Perhaps there is a little skill learning—how to use a soldering iron or an oscilloscope and how to order parts from a distributor, but not much how-to-design learning, which is the main point of the course.

That is not to say that students shouldn’t be looking at designs on the web!  Indeed, the freshmen do not have enough of the basic building blocks of electronics and programming to come up with their own designs de novo (though by their senior year they should be able to, if they continue into the bioelectronics or assistive technology: motor concentrations). So they need to look at solutions others have come up with, in order to know where to start on the design. But they should not just pick one design and implement it—they should be looking at several designs and trying to find common elements, figuring out what tradeoffs the different designers have made. Some of the designs come with good explanations of how they work—they should be reading those very carefully, so that they can follow the design decisions and reproduce the design from understanding.

Understanding designs well enough to explain each part, how it functions, and what the effects would be of changing the part may be enough at this stage of their design learning. Part of the point of the freshman design course is to inspire them to want to learn the foundations in other courses, many of which seem to students to be irrelevant gatekeeper classes to survive by cram-and-forget techniques. If they have some idea why complex numbers are important for filter design, or why capacitors are useful, they are more likely to pay attention in those parts of math and physics classes and to retain the knowledge later on.  Of course, it would be best if the math and physics classes included more of the inspiration themselves, but there are many different applications for the material, and it is difficult to find universally inspiring applications—what excites a math major, a computer science major, a physics student, or a bioelectronics student may be quite different, but the same course has to serve all of them.

My role in the classroom is to provide explanations for those things that the students have trouble figuring out on their own, give them generic guidance in the design process, anticipate things they will need to know, and try to hurry them up (in the past most waited far too long before starting their projects, with the result that they get very little done). Having three different projects going on at once means that there is not enough class time for students to get everything they need from me—they must be reading on their own and trying to understand their project thoroughly, but based on the time logs they have been submitting, few in the class have been doing that—they mostly seem to be waiting for me to tell them what to do, which is not going to work for them. I had hoped that having students pick their own projects would inspire them to investigate the projects more deeply without my having to keep kicking them with assignments, but that only seems to be working for a few of the students.

Some aspects of the design they can do—for example, everyone in the class should now be able to size a current-limiting resistor for an LED, and those who need amplifiers should be able to make a simple non-inverting amplifier out of an op amp.  (Hmm, I should probably give a quiz on those ideas next week—maybe the students have absorbed less than I expect.) By this point, the students should be asking about those parts of the design that they don’t understand, but I’m not getting very many questions, despite starting each class asking for questions and covering student-requested material before anything that I have queued up as things students might need.

A big chunk of what the class is trying to do is to nudge students away from regurgitating factoids that have been spoonfed into learning for the sake of understanding deeply enough to do things themselves—that means generating a lot of the questions themselves and seeking solutions by trying things out, and not just by looking up “the answer” or waiting for a teacher to tell them what to do and what to think.  That is a hard transition for many students to make, as they have been steeped in “answer-getting” culture for the past 13 years.

 

2016 February 17

Ultrasonic rangefinder with loudspeaker

Filed under: Data acquisition,freshman design seminar — gasstationwithoutpumps @ 23:29
Tags: , ,

Continuing the series Ultrasonic rangefinder project , More testing for ultrasonic rangefinderUltrasonic rangefinders arrived, and Ultrasonic rangefinder without amplifier, I tried today to look at creating pings with a non-resonant transmitter: a cheap, mid-range 8Ω loudspeaker that I’d used for the applied electronics class.  It was a buyout special from Parts Express, and so is no longer available.  There is an analysis of this speaker (or another one like it) in Better model for loudspeaker.

I was curious whether I’d be able to get it to produce sound at 40kHz, so I hooked it up to a pair of output pins of the Teensy 3.1 and used the microphone and preamplifier to listen to it with the Teensy, as in Ultrasonic rangefinders arrived.  The results were disappointing (as I expected).  The loudspeaker made an audible click, but the waveform showed no evidence of 40kHz signal, even with 10 cycles of excitation. I got echos, but they were of the click rather than of a ping, and were essentially independent of how many cycles of excitation I provided.

I then tested the loudspeaker and microphone combination with my FG085 function generator, and saw that the amplitude of the response varied enormously with frequency (and that some of the largest responses were ones I couldn’t hear—my deafness does not seem to be uniform in the higher frequencies).  There are zeroes around 21750Hz and 28500Hz, and no signal above 31750Hz.  The microphone and preamp were still working at 40kHz, so the problem is with the loudspeaker, not the mic or preamp.

I should probably get a cheap little speaker that is rated to 20kHz, and see whether it can actually go to 40kHz.  Digikey has some $1 and $2 speakers that look suitable, except that they seem to be designed to be pressed against a PC board with a spring, which might make them hard to connect to a breadboard.  For about $3, I could get one with pins, but the high-frequency response seems not as good.

I could also try making a pinger at 20kHz, instead of 40kHz, and see whether I can get decent pulse shapes with the existing speaker.

I managed to get a 20kHz ping recorded from the loudspeaker, but I had trouble getting a clean ping, as there was always echo off the floor, my hand, or the tabletop (whatever was supporting the loudspeaker) producing another burst very soon after the first one, interfering with it. I tried separating the mic and loudspeaker to record the direct wave (without much echo), but that was still unclean. I think I need to have a good baffle to make a clean pulse, and a directional mike would be better than the omnidirectional one I currently have.

Here is a sample recording with the loudspeaker putting out 5 cycles (10 half cycles) at 20kHz and a bounce off the bottom of my table.  The messiness of the return echo is partly interference from bounces off the floor behind the mic and speaker, and partly the unevenness of the bottom surface of the table (which is made of aluminum slats).

The burst begins almost exactly when I would expect it to, but it is not as clean as I would like to see.

The burst begins almost exactly when I would expect it to, but it is not as clean as I would like to see.

I think that with non-resonant transducers I could get cleaner deconvolution of the echoes, but first I have to find a way to reduce the multi-path problem (perhaps with a directional mike and a baffled speaker?).

2016 February 15

Applying for Mini Maker Faire

Filed under: Uncategorized — gasstationwithoutpumps @ 21:02
Tags: , ,

In Santa Cruz Mini Maker Faire 2016, I posted about the upcoming Mini Maker Faire on 2016 April 16 in Santa Cruz.  At that time (the beginning of January), I was undecided about whether I should just go as an attendee (for $8) or register as a maker and have a table.  I’ve decided that I will take the extra time to apply as a maker, though that means about 9–10 hours on April 16, plus work getting ready for it.

I’ll want to transport everything for the display in one bike-trailer load, and it will all have to fit on top of whatever table they provide.  Luckily most of my relevant stuff is fairly small, so that should not be too serious a constraint.

When I posted about the Mini Maker Faire in January, I asked my readers for advice on whether I should register as a maker and what I should show. I got one reader suggesting I not bother and urging me to have something flashy to attract kids’ attention.

Here are some things I could do:

  • Display the PC boards I’ve designed.
  • Display the desk lamp and the strobe light (which use the same electronics hardware: only the firmware is changed to turn the dimmer into a strobe controller).  I can show both at once, and have a few of the LED boards on display also.
  • Display some of the tools a hobbyist needs (soldering iron, bread boards, wire strippers, …).
  • Display some of the projects from the book.  The problem is that the components and boards are not very exciting unless they are in use, and I’ve only got one computer to run PteroDAQ on, unless I haul the huge iMAC on the bike.  I might be able to set up some quick reconnection on a bread board, so that I could demo different projects.
  • Have a poster or banner with the book cover on it.  It may be cheaper to print a cloth poster to hang from the edge of the table than to print a paper poster, but I’d need a lot of lead time. I’d have to design the banner.
  • Hand out business cards that point people to this blog, PteroDAQ, and my book. I’d have to design the cards, but printing them should be cheap.  Should I get separate cards for PteroDAQ and the book/blog?
  • Set up an optical pulse monitor with PteroDAQ to record the waveforms.  (Problem: the waveforms look much better after band-pass filtering, and PteroDAQ doesn’t do filtering.)  The optical pulse monitor takes less setup per person than an EKG or blood pressure cuff, but I’d probably need to make a new finger block with shallower holes, for shorter fingers than the college students I’ve been working with.
  • Display the nerf-gun prototype (not pressurized) and the soda-bottle rocket launcher (again not pressurized).  These are a bit off the main theme of electronics, though, and take up a fair amount of space.
  • Hook up the analog oscilloscope to a couple of function generators to display Lissajous figures.  Kids could play with the frequency and amplitude of the sine waves to get different patterns.
  • Set up the oscilloscope with the microphone preamp, so that kids could see their speech waveforms.
  • Have kids make LED “throwies” out of CR2032 batteries, LEDs, magnets, and electrical tape, but I’d have to find cheap sources for all those parts, and I’d need to spend a lot of the time managing the activity.

Any other ideas?

pterodactyl-512I’d like to get my application submitted this week, and I need to write a one-paragraph description for my “Maker sign”, so I’ll need to finalize at least a generic description.  I also need a “Project Name”.  I’ve considered three names so far:

  • PteroDAQ (and use the PteroDAQ logo on a banner)
  • Applied Electronics (and use the draft book cover on a banner)
  • Kevin Karplus, Maker (I could use the PteroDAQ logo and the book cover side-by-side on the banner)

Does anyone have any better ideas for a name to register?

I’m rather partial to PteroDAQ as a catchy name, but only part of what I’ll be showing is the PteroDAQ project, so that may not be such a good fit.

That reminds me—I still haven’t mentioned the mini Maker Faire to the freshman design seminar.  They will have finished their projects by the March 15 deadline to register as makers, so they will be able to decide whether or not they want to show them off.

« Previous PageNext Page »

%d bloggers like this: