Gas station without pumps

2017 December 18

EKG without amplifier

Filed under: Circuits course,Data acquisition — gasstationwithoutpumps @ 18:24
Tags: , , , ,

I have done a lot of EKG projects on this blog, mostly for the Applied Electronics course, where an EKG amplifier is Lab 12, but some just for fun. Today I decided to see whether one could do an EKG with just the Teensy LC board or just an Analog Discovery 2 USB oscilloscope.

The project was partly inspired by the Digilent post DIY ECG using a Analog Discovery 2 and LabVIEW, which I saw the title for and assumed that they were using just the USB oscilloscope.  It turns out that wasn’t what they meant—it is just a simple 6-op-amp EKG amplifier looked at with the USB oscilloscope.

The setup I tried was about as simple as you can get—I put on three electrodes wired up as Lead I (see earlier post for this configuration), connected the body electrode to ground, and the other two electrodes to the plus and minus leads of channel 1 of the Analog Discovery 2.

The signal I got was quite small (about 1mV) and buried in 60Hz noise:

The raw signal from the oscilloscope, sampling at 1200 Hz, shows some spiking from the pulse, but a lot of noise. The big R spike is only about 3 LSB, so quantization noise is a problem.

I ran the recording through a digital filter to bandpass filter it to 0.1Hz–100Hz and put in a notch from 58Hz to 62Hz. The 100Hz low-pass had the effect of averaging out the noise, producing a signal with much finer resolution than the raw ADC values:

After filtering, the EKG signal is fairly clear. I don’t recommend trying to use only a couple of the lower-order bits of an ADC, but it is surprising how much information can be recovered by the filter.

I also tried using a Teensy LC board running PteroDAQ, using the A10–A11 differential channel. I had to bias my body between 0V and 3.3V, so I used a pair of 120kΩ resistors (one to GND, one to 3.3V) to connect to the body electrode.

Once again the raw signal was not great:

The signal had less noise than the signal to the Analog Discovery 2, but the signal was smaller also, negating the value of the finer steps of the ADC on the Teensy LC.

Once again, digital filtering restored the signal:

The signal-to-noise ratio here looks a little worse than for the Analog Discovery 2, despite the raw signal looking cleaner.

I managed to get a cleaner signal for the Analog Discovery 2 by turning off the surge protector, so that there was no 60Hz current anywhere nearby. The results after filtering were no better (and possibly worse) than from the signal with the 60Hz interference, so I did not bother plotting them for this post.

My conclusion is that it is possible to get EKG signals without adding an amplifier, but you can only see the signal clearly if you do some filtering.  I’ll have to decide whether to recommend to students that they record signals directly from the EKG electrodes to get an idea what their amplifiers have to work with.

Advertisements

2017 December 17

Book released for Winter 2018 course

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

I’ve released a new version of the textbook Applied Electronics for Bioengineers, on the LeanPub website: https://leanpub.com/applied_electronics_for_bioengineers and sent the students registered for the course a coupon to get their free copy.  People who have previously bought the book (even if for $0 with a coupon) were also informed of the release, so that they could pick up a new copy.

This version is 481 pages including 38 chapters, preface, appendices, and index.  There are 10 tables and 199 figures (239 distinct images, since some figures have multiple subfigures).  I added a lot of new tutorial material, fixed some errors (including some serious ones), added more exercises, and modified the labs to use the Analog Discovery 2 USB oscilloscopes rather than the expensive bench equipment we used to use.  The book is not “done”—I still have over 50 to-do notes in the margins, but I believe it is significantly improved over last year.  Improvements would be faster if students would tell me when they find errors or confusing writing, but they rarely do, and I have to guess what needs fixing from mistakes they make weeks later.

The use of the Analog Discovery 2 enabled me to offer a larger course this year—I managed to equip a 25-station lab for 50 students for under $10,000—less than the cost of a single station in the old lab. Because the space I’m using for the two 50-student sections is used as a classroom by other courses, I need to wheel everything in on a cart 20 minutes before labs start and clean it up and pack it away after the labs.

I still have a little work to do before next quarter starts:

  • recording the serial numbers and setting the names of the 25 Analog Discovery 2 units.
  • checking the 25 soldering stations and tinning the tips.
  • soldering 25 pressure sensors onto breakout boards.
  • packing everything into tubs that I can wheel to the other building on the cart.
  • cleaning up the electrode holders that did not get cut cleanly by the laser cutter.
  • getting reimbursed for over $3000 worth of parts and tools that I ordered for the students (UCSC can’t buy from AliExpress, and US vendors were over 3 times the price).

But I think that tomorrow I’ll take a break—maybe even see if I can get anything working on the robot I didn’t finish for the mechatronics course.

2017 November 16

Another day fighting SolidWorks

Filed under: Robotics — gasstationwithoutpumps @ 22:14
Tags: , ,

I spent another day working on the SolidWorks model for my robot.  I’m getting better at it, but the user interface is still a struggle to deal with.  Here is my model so far:

I’ve got the first layer mostly done, but the second layer is barely started.

On the first layer, I still have to put in small starter holes for screwing down the optical reflection sensors, which I plan to mount on pieces of perfboard. Having the sensors on perfboard will make wiring them easier (I hope), and make them easier to replace if one fails. Also, recessing them into the perfboard should improve their directionality.

I’m planning to clamp the layers of the robot together with ¼” threaded rod—the acorn nuts I’ve put on the ends are just decorative, and there isn’t room underneath for an acorn nut.  My clearance to the ground is just 8mm, which is less that the ⅜” minimum height for an acorn nut.  There is room for one 7/32″-high hex nut or two 5/32″-high thin hex nuts, but that’s it.

[Update 17 Nov 2017: I’m now going to use 8-32 threaded rod, not ¼”, so there will be room on the bottom for the acorn nuts. See Hardware obtained today.]

The view here is mostly from the back, showing the power panel (with a voltmeter/ammeter and a hole for a barrel jack) behind the LiFe battery.  I should remodel the battery to curve the wires up to the jack and to tuck the charging wires back along the battery.

I have to decide on how the AT-M6 ball launcher interacts with the rest of the components—if I use an accelerator wheel  underneath (which I was planning), then there needs to be clearance for the wheel between the first and second layers.  But the tops of the drive wheels look like they’ll interfere with such an accelerator wheel.  I could mount the accelerator wheel in front of the drive wheels, but then I’ll have the track-wire sensor further from the edge—will it be sensitive enough? I guess I’ll to make the sensor and test it. I should also prototype the accelerator-wheel design, to make sure that it will throw ping-pong balls.  I still have a few inches of uncollapsed 1-½” PVC pipe that I could use for making (or at least prototyping a launcher.

The track wires will be running a current of 180mA—the design used in the targets is a 12V power-supply with a 1.2V drop from using a darlington transistor (why not an nFET?), and two 120Ω 1W current-limiting resistors in parallel.  The typical VCE for the TIP122 darlington at 180mA is more like 0.75V, so the current is going to be more like 188mA.

To imitate that with my track-wire that has 2 47-ohm resistors in parallel, I’d need a voltage of 4.4V.  The power dissipation would be (4.4V)^2/(23.5Ω) (0.5) = 412mW, which is just below the ½W limit from using two ¼W resistors. Rather than wire up a special circuit (using an LM555, as they did), I’ll just use the Analog Discovery 2 power supply for the 4.4V and the function generator for the pulse train to the gate of an nFET.  It’ll be a little inconvenient, since the function generator, power supply, and oscilloscope leads are so short, but I can make it work with some “extension cables”.

I think that tomorrow I’ll work on sensors, both electronics and programming, and leave the mechanical design for later—I think I’ll make more progress on the more familiar tasks, and I’m so far behind most of the groups that I’m not sure I’ll ever catch up.  I don’t even have a name for my robot!

 

2017 September 7

Ultrasonic transmitter and receiver impedance measurement

Filed under: Data acquisition — gasstationwithoutpumps @ 18:53
Tags: , , ,

In Ultrasonic rangefinder with Analog Discovery 2, I looked at the impedance of  an ultrasonic transmitter with the Analog Discovery 2, but I only modeled the transmitter as a capacitor, not modeling the resonances.

So today I collected new data, both for a transmitter and a receiver, using a 1nF C0G (1%) capacitor as the reference impedance, so that I could have clean data from a known pair.  I also looked at the transmitter+receiver as a network, and located the peaks of the signal transmission.  I was curious whether they corresponded more to transmitter or receiver resonances.

I could model the transmitter quite effectively as a capacitor with 4 LCR resonators in parallel.

I could model the receiver quite effectively as a capacitor with three LCR resonators in parallel.

The fitting was done with gnuplot, fitting one resonance at a time starting with the lowest frequency one, then refitting the previously fit parameters to tweak the fit. The radius of convergence for the fitting is pretty small—I needed to get the LC resonant frequency pretty close to correct before the fitting would converge. Increasing L makes the down-spike and up-spike closer together, and R controls how low the minimum gets, so I could get reasonable initial values (good enough to get convergence) without too much guessing, by plotting using the initial values, adjusting L to get the spacing between the spikes about right, adjusting C to get the resonant frequency right, and doing a rough guess that R is about the minimum value.

The peaks of the transmitter+receiver characteristic seem to correspond most closely to the minimum impedance points of the transmitter, which is reasonable when you consider that I’m driving the transmitter from a fixed voltage—the power is going to be V2/R, so power out is maximized when the impedance is lowest.  The one exception is the 331kHz peak, which seems to fall on the higher frequency of the two closely spaced transmitter resonances, and near the peak of receiver impedance. (Of course, only the 40kHz resonance of the transmitter or receiver actually gets used—the other resonances don’t provide nearly as much response in the transmitter+receiver pairing.)

Zooming in on the transmitter impedance for the high-frequency resonances, we can see that there are minor resonances that have not been modeled, but that the model does a good job of capturing the shape of the peaks. The peak of the transmitter+receiver response here falls on the higher-frequency resonance.

I did all my modeling with just the magnitudes of the signals, so it is interesting to see how well the model fits the phase response.

I got excellent matches to the phase response (even when I zoomed in on each peak), except for the low-frequency region, where the impedance seems to have a negative real part (phase < -90°).

I do have models for no resonance, single resonance, two resonances, and three resonances for the transmitter, as well as the four-resonance model. If a simplified model is needed, then it is better to take one of those fits, rather than omitting parts of the more complicated model, as each resonance affects the other parameters somewhat.
As a simple example, the receiver can be modeled as just a 739pF capacitor, but the LCR circuits contribute some of the capacitance, so 708pF gets used for the base capacitor of the model with the 3 resonances.

2017 August 23

Motor testing

Filed under: Data acquisition,Robotics — gasstationwithoutpumps @ 02:20
Tags: , ,

I bought some 6V motors with mounting brackets, wheels, and Hall-effect rotary encoders from Ali Express (https://www.aliexpress.com/item/1-set-2-set-High-torque-Electric-Encoder-Gear-Motor-DC-6V-210RPM-0-13A-Mayitr/32820157282.html), which arrived today, so I spent most of the day playing with them and trying to characterize them.

The first thing to do was to try to relate voltage, current, and speed.  I used the power supply in the Analog Discovery 2 to drive the motor through a resistor, monitoring both the voltage across the motor and the current through the resistor.  I used a Teensy LC board running PteroDAQ to monitor the frequency of the pulses from one of the Hall-effect sensor.  Initially I had tried looking at the pulses with the logic analyzer of the Analog Discovery 2, which gave me a fine short trace from which I could look at individual pulse widths and periods, but not get a long-term average frequency.

Varying the voltage on the motor gave different speeds, and the speed was linear with the voltage.  The current also went up with the voltage, but not linearly (it remained around 40mA even for very low voltages, and only went up to about 67mA at the highest voltages).

The standard simplified model for a motor is an “RLV” model: a resistor, an inductor, and a speed-dependent voltage source (referred to as the back-EMF).  V(s) = R I + L dI/dt + V_s s, where the speed is s, and the current is I. With a constant input voltage, the inductor is not really modelable, so I came up with an RV model:

The speed here is represented by the Hall-effect sensor, which gives 11 ticks per turn of the motor shaft. The back-emf is about 7.64 mV/Hz and the resistance is about 4.8Ω.

I needed about 2.5–3V to start the motor, but once it was running I could reduce the voltage to around 0.667V before the motor stopped (the lower speeds in the plot above were done by reducing the voltage with the motor running).

I tried measuring the impedance of the motor with the new impedance tool of Waveforms 2015. I got somewhat different results depending on the frequency used and the test voltage. For ±1V and low frequencies (under 300Hz), I got around 3.5–3.6mH+4.25Ω, but at higher frequencies the inductance dropped and the resistance increased: at 40kHz I had 1.946mH+438.5Ω. With a 5V signal I got 5.1mH+4.88Ω around 20Hz and down to 1.62mH+484Ω at 40kHz. The resistances at low frequencies are fairly consistent with the resistance I inferred from the back-EMF+IR model. So I’m reasonably comfortable in modeling the motor as having
V(s) = (7.64 mV/Hz) s + 4.8\Omega \,I + 4mH \,dI/dt.

I may have to tweak that inductance, though, as I’m not sure which frequency’s inductance is relevant.

I also recorded the turn-on transients of the motor. I tried first doing this by turning on the power supplies while the oscilloscope was waiting for a trigger, but the power supplies turn on quite slowly, so I added an nFET to the negative rail and controlled the gate with a pushbutton. The pushbutton connected the gate to a positive voltage and the gate had a large pulldown resistor to ground. The large pulldown resistor eventually turns the FET off when the button is released, but slowly enough that contact bounce does not result in turning the nFET on and off.

The voltage initially spikes up to the supply voltage, then the current increases through the inductor, until the resistive voltage divider controls the voltage. Then the motor starts moving and the back emf increases. The initial spike is very short (about 2ms), but spinning up the motor takes over 200ms.

You can see the enormous commutator signal in the voltage and the current. The current is directly controlled by the commutation—the voltage signal is only affected because of the IR drop across the 10Ω sense resistor I used for sensing the current.

We can use the initial turn-on spike to estimate the inductance, by looking at the exponential curve for the growth of the current:

The current is growing towards 412.5mA with a time constant of 311.76µs.

The inductance is just R times the time constant, where R is the series resistance (the 10Ω sense resistor and the 4.8Ω internal resistance—I’ll ignore the on-resistance of the MOSFET). L = 311.76 \mu s 14.8\Omega = 4.61 mH.

All the speed measurements here were in terms of how fast the Hall-effect sensor on the motor shaft was pulsing, but how fast is the output shaft of the gearbox turning? There are two questions: what is the ratio of sensor pulses to motor rotations, and what is the ratio of motor rotations to output shaft rotations?

The website for the motor claimed “Encoder motor end: 11 signals”, which I took to mean that there were 11 pulses per rotation.  I confirmed this by doing a Fourier transform of the commutation signal (the current) and of the pulse signal.  The fundamental of the pulse corresponded to the 11th harmonic of the current, so there were 11 pulses per turn of the motor shaft.

Determining the gear ratio (ratio of motor speed to output shaft speed) was more difficult.  I set up an optical interrupter to be blocked by a bit of electrical tape on the end of the output shaft once per revolution, and recorded the optical signal on every rising edge of the Hall-effect pulse using PteroDAQ.  By recording for a while, I could count the number of Hall-effect pulses for some integer number of shaft rotations.  Taking the pulses/output rotation and dividing by 11 gave me the motor-shaft rotations per output shaft rotation (the gear ratio I was seeking).  Getting a real number for this was fairly straightforward, but I wanted a rational number using products of small integers, corresponding to the gear teeth on the gears!

For one run, I had 856 shaft rotations with 200523 or 200524 pulses (depending whether I counted between rising edges or falling edges of the optical signal), giving me 234.255841121 to 234.257009346 pulses per rotation, or a gear ratio of 21.2959855565 to 21.2960917587.

I did a longer run with 4811 shaft rotations with 1126978 pulses or 1127000 pulses , giving me 234.250259821 to 234.254832675 pulses per rotation or a gear ratio of 21.2954781655 to 21.2958938795.

I converted the gear ratio to a continued fraction using my pocket calculator, getting

21+\frac{1}{3+\frac{1}{3+\frac{1}{-3+\frac{1}{2+\cdots}}}},

which expands to

21 + 1/3 = 21.3333333…

21 + 3/10 =21.3

21 + 8/27 = 21.29630…

21 + 37/125 = 21.296  = 2662/125 = 2 * 11^3 / 5^3   

The last ratio factors nicely, and looks feasible for a gear ratio.  To confirm my estimate, I carefully took apart one of the gearboxes and counted the teeth on the gears.  I got

  • motor shaft 12T
  • engages 22T linked to 10T
  • engages 22T linked to 10T
  • engages 22T linked to 10T
  • engages 24T on output shaft

This gearing does indeed give me the 2 (11/5)^3 gearing I calculated!

So my gear ratio is exactly 21.296 and I have exactly 234.256 pulses per rotation of the output shaft (with the quadrature coding from two Hall effect sensors, I get exactly 937.024 transitions per rotation).

With 6.0364V across the motor, I got 752.37Hz from the sensor, so the output shaft was rotating at 3.212Hz, or 192.7 rpm (somewhat slower than the claimed 210 rpm for 6V no load). The wheels that came with the motors have a circumference of 215mm, so the maximum speed would be 69cm/s, which is about 1.54 mph—not a real zippy machine, but more than fast enough for a small robot.

The tires are pretty squishy, though, and if I want to use the wheel turns to keep track of location, I’ll probably want wheels whose diameter doesn’t vary with the load—perhaps I could wrap the hubs with friction tape. The hub circumference is only 161mm. I could also laser-cut some wheels to get whatever diameter I want.

Next Page »

Blog at WordPress.com.

%d bloggers like this: