Total Pageviews

Tuesday, February 20, 2018

Toshiba Ultrasound Machine Teardown, Part 1

     I've wanted some medical equipment to tear down for some while now so when I saw this for 90 Euros, I couldn't pass up the opportunity.

     Before we start, I'd like to tell you what to expect from this article... This is too nice of a machine to just do a teardown on it, so I figured  I'd also do a bit of reverse engineering. Going down this rabbit hole, I thought I'd also lay down some facts about the theory of operation of such a device and before I knew it, it got to be several pages long. Because there isn't much info out there covering these aspects, I think it might be of some use to people.
    However, if it's getting a bit too long winded for you, you can always jump straight to Part 2 where I actually do the teardown and reverse engineering.

      Ladies and gentlemen, let me introduce you to the Toshiba Sonolayer SAL-32B ultrasound machine.
OK, admittedly, it's old, but it still works. And quite well actually. I've tried it on myself even, and since, I discovered I have at least 3 types of cancer,  a few extra kidneys and something that looks like one of those face-huggers from "Alien".

Now, before I take one of these things appart, I should probably get an idea of how exactly is an ultrsound produced. And for that, I'll have to go full geek and explain what this ultrasound thing is all about. Also, seeing how I'm going to need some pictorial help to get some points across, I'm going to try something new here, so any input about this (love it, hate it, you couldn't care less) is greatly appreciated.

School's in
Sound, like most things around us, is a wave. And in order for it to travel between point A to point B, it displaces molecules in the medium it's travelling through. And it's because of this that sound is considered to be a mechanical disturbance happening in the propagation media.

But "displacement" doesn't mean that molecules are actually swept up by the wave and carried to the receiver. No. They just stand there, moving up and down or side to side. Let's put this on paper, to clear the air a bit.... get it? Ok, ok, not that funny...

                                         Figure 1. A particle moving perpendicularly to the incoming wave. 
                                                        The movement corresponds to the actual shape of the wave

  So, sound consists of local vibrations that disrupt the medium it's travelling through. These disturbances make up the wave. And after the wave passes, the particles go back to their original position.
Sounds easy enough, right ? Ahem.... anyway...

So bearing in mind what was said this far, it's not particles that carry the wave from sender to receiver; the wave is propagated by mechanical energy.

    Now, whenever sound travels through a media, it does so at constant speed (given that the medium is homogeneous all the way through).   And if you want to calculate what that would be, turns out, all you need to know it the medium's density (ρ) and its compresability (k). Just drop these into this:


and you've got your speed.
    So, because a medium is compressible, sound travelling through it can generate local spots of high or low pressure. Peaks in the wave create high pressure, troughs create low pressure. This also implies that the particles in the medium  have had imparted on them a certain velocity, for them to move the way they do.

"It's all fine and dandy, but what does this have to do with anything?"
      Well, think about it for a second.... the medium is compressible,  therefore it also resists the wave travelling through it. 
     That means the wave can be attenuated by the medium...kinda like an electrical signal travelling down a conductor (the conductor having resistance of course) That also gets attenuated and the thing responsible for that is the IMPEDANCE

Any medium through which sound travels also has impedance.
And that impedance is equal to

                                                         $Z=\rho \times C$

where C is the propagation speed and $\rho$ is the density

In a human body, there are all kinds of tissues, some with different densities. What happens when sound passes through  them?
Well, like I said, sound is a wave. And so is light. So, as an analogy, what happens when light hits a  piece of glass? Well, it goes right through, right ? 
Yes.... mostly. Some of it is also reflected back. The same holds true for sound waves.

                               Figure 2. Sound waves passing through a boundary formed by media with                                                             different densities. Incident wave is perpendicular to the boundary.

In Figure 2, there's a typical (but only theoretical) case where sound propagates through media M1 and M2. Where the media meet, a boundary layer is formed; kind of like the piece of glass in in the above example.

Notice that the media also have a characteristic impedance Z1 and Z2, through which an incident wave is propagating -  I0. When it hits the boundary layer, most of it passes unimpeded as incident wave It. A small part of it is also reflected back, along its original path as IR.

But as luck would have it, it's very rare that a wave would hit tissue at exactly 90 degrees. So putting the old thinking cap on, let's take the previous example with the light and the glass and imagine what happens if the incident wave is off center by some angle? 
"Why, the wave will be refracted of course."

And again, that'd also be the case with the sound wave.

                               Figure 3. An incident sound wave propagating through two different media at an                                                   angle with respect to the boundary layer

In Figure 3 the exact situation is depicted. The incident wave I0 comes in at  an angle αi and when it passes through the boundary layer, it travels onward, but at a different angle αt.
And just like the previous example, some of the wave is reflected back (IR), but this time, the angle will be the same but opposite to αiR)

                                     Figure 4. Curved boundary layers can act just like optical lenses,                                                                             in the way that these can disperse of focus sound.

And if you're wondering how exactly is the proportioning of the wave is determined, i.e. how much is reflected and how much is refracted, the answer depends on the impedance of the media.       

     Also, bear in mind that tissues don't have a perfectly flat surface to them. The boundary layer can have curves and irregularities to it and these can also influence how sound travels through them.
In Figure 4 the sound-light analogy is again called to action. Here, one can see how sound waves  can be focused of dispersed whenever travelling through a boundary layer that is concave or convex in shape.

Let's make some noise

    You can't really have an ultrasound machine without the sound, right ?
The probe of such a machine might often get overlooked, but it's just as important if not more so because it is the sole element that dictates the overall resolution and performance.

    It works by applying an electric pulse or a time-variable voltage to a piece of piezoelectric crystal or ceramic material.
The piezoelectric property of the material will convert that electric signal into a mechanical movement which in turn is propagated through the media.

Perhaps one of the best known piezoelectric materials is quartz. If it's good enough for oscillators, it's good enough for ultrasound, right?
Well...not really. Quartz, though it is used for this exact purpose, has losses when it comes to converting electrical to mechanical energy.
But fear not, there's a ton of other materials out there, "more better" than plain quartz.

 - Rochelle salt or Sodium Potassium Tartrate Tetrahydrate
 - Tourmaline
 - Barium Titanate
 - PZT or Lead Zirconate Titanate
 - Lead Titanate
 - Lead Metaniobate
 - Litihum Sulphate

                                          Figure 5. Piezoelectric crystal with silver deposition on its face, being                                                                    subjected to a time-varying voltage to produce sound waves

      The slivers of quartz used in a probe can vary in shape, size and thickness and each will have a certain distribution of waves.
Because thicknesses of 0.5 mm and lower are used,  one could ask how exactly are the wires connected to the crystal itself?

      Well, Figure 5 is going to help here. The crystal (yes, the drawing is curved like that on purpose) has silver vapor deposited on its front and back surfaces, creating a uniform conductive layer. And to these, electrical connections are attached.

                            Figure 6. An ultrasound probe consisting of a single piezoelectric crystal

    If you were to take the crystal and build a probe with it, it'd most likely look something like Figure 6. 

   Now, because the crystal actually moves in order to create mechanical waves,  it makes sense that it's going to generate sound from both its faces, not only the front one.
But that would be wasted energy. So in order to keep the back from moving, you shove some  backing material up against the face you want to quiet down.
    Specialty literature states that the backing material is mostly some kind of epoxy resin or hard plastic, to which  tungsten carbide powder is added, in order to dampen the oscillations. Some recipes even have some bits of rubber added.
Then the  whole thing is put inside a metal  case, so that stray noise pick-up is limited and also to better support the crystal wafer.
But because this is a mechanical as well as an electrical system, any material in contact to the crystal itself will affect its resonance frequency. That's to say, inside the probe, a crystal's resonance frequency will be lower than what it would be in free air.

    The business end of the probe is its front, obviously. Here is where all the magic happens. Skin is a soft stretchy material, unlike the hard brittle face of the crystal. Such two media would most likely have a horrible acoustic coupling, so to get around this, we need to do some impedance matching.
This is why a special layer of plastic or epoxy resin is placed in front of the wafer and this is what actually comes in contact with the human body.
And because it's been a while since I've added something geeky,  the impedance of this plastic is the geometrical mean of the two  impedances, that of the crystal and that of the human body.

                                                  $Z_p=\sqrt{Z_c \times Z_b}$

Oh, and it seems that this plastic or resin has aluminium powder added to it. Or so the books say.

Get in shape, man!

    Like I said earlier, piezoelectric elements come in all shapes and sizes and the application where they're used  determine what material and shape they are.
The single crystal probe, as per Figure 6, would mainly be used  for pulsed echo ultrasounds and some therapeutic applications. But for imaging, you can imagine that having just one crystal isn't really going to cut the mustard.

    Dual crystal  probes are used for when doing Doppler ultrasounds. This is because one of the crystals will transmit the signal while the second will only "listen" for echoes.

    As you might imagine, the crystals are very thin and can have a relatively high surface area. 
Now,   at some point, if you sweep the frequency applied to the crystal, it will start resonating. And whenever you have some oscillations, you also have harmonics of the main oscillation frequency (or the crystal's fundamental frequency).

This resonance, happening at the fundamental frequency, is also called the half-wavelength resonance. That's because the resonance frequency is actually determined by the crystal's thickness. And when the thickness is half the wavelength of the applied frequency, then it oscillates the strongest.

         Now, because of those harmonics that are generated, you can also talk about a crystal's bandwidth.
Some will have a broader bandwidth and some a narrower one. And what this implies is that narrower bandwidth ones will deliver more of their energy focused in a narrower spectrum. That means that the crystal's Q (quality factor) will be  high. Makes sense, right ?
And, of course,  the opposite is true: a crystal with a broader bandwidth will have a smaller Q.

These are properties quite useful for different applications. For example, for therapeutic purposes (eliminating clogged veins and arteries) a crystal with a large Q factor is used.

                                Figure 7. Characterization of a crystal's emitted field

    And because we're on the subject of shapes. let's tackle a crystal's emitted field shape.

As you can imagine, the mechanical wave of the crystal can not be uniform in every direction. For that to happen, the crystal's face would have to span...infinity. But it doesn't.

    In the lower part of Figure 7 you can see that there's a central beam, coming from the crystal's point of origin. Then a few side lobes left and right, which don't do anything except waste  power.
The central beam tapers out, as you might expect, because there's nothing to focus it. That means that as it gets further from the crystal's face, it has less and less energy (that's to say, the energy is spread out over a larger area) 

Now, at some point, there will be little energy left in the mechanical wave and you can see that depicted in the upper part of Figure 7.

    Most of the energy is concentrated in the near field. In this area, it can be considered that the average intensity of the wave is constant. 

     In the far field, however, the pressure variation is not as uniform and here waves become spherical and average intensity drops inversely as the square of the distance from the center of the crystal increases.

So, if you're going to make yourself a probe, you'd most likely use  it to see stuff in its near field because here you get the most bang for your buck.

Never assume... unless there's physics involved

    We live in an imperfect world. That is a fact. Piezoelectric crystals are...yes, you guessed it.... imperfect.

Why am I telling you this? Well, in order to actually get the math going with ultrasound imaging, one has to make some assuptions.

     Let's assume that a crystal's face is perfect. And it generates a wave that is also perfect and uniform. And to make this somewhat possible, you can consider the surface of the crystal divided into  "sound pixels" each generating a uniform wave.

    When sound travels through tissue, it sends back echoes, who's amplitude depend on how deep the initial wave traveled into the tissue  and on the type of tissue it traveled through.
So, one can determine the type and shape of a tissue if the wave intensity and phase are known at an exact point.
And to know all this, you'd have to make the above assumption.

This is called Huygen's principle and it lies at the foundation of  ultrasound imaging.
So let me geek-ify what I just said:
Any source of sound can be considered to be made up of a series of sources, small in respect to the emitted wavelength, all of which radiate uniformly, in all directions.
The field, at a certain point can be determined by taking into consideration the wave's phase and intensity of each of the sources, at that point. The wave thus produced will be spherical and will have an intensity related to the source's power and distance.

                                          $I=\frac{P}{4 \times \pi \times r^2}$

Also, there needs to be assumed that in the near field, both plane and spherical waves, at the edges of the crystal, exist so that an approximation of the field at a certain point can be determined.

The Doppler effect

    You'd expect this to be the main principle behind ultrasound, but it's really not. This is only used when movement is involved i.e. calculating distance between two points on the display.

In Doppler mode, two tranducers are used. One for transmit, the other for receive. The beauty of this is, the probe can tolerate a lot more imperfections in the crystal and a lot less damping for its back face.

    Now, what this effect is all about is how the wave is scattered by tissue. The wave hits tissue, some of it being returned to the probe. The returned wave will now have a phase difference from the initial TX wave. The phase difference, together with knowing the propagation speed of the medium and the phase of the TX wave correlate to a calculable distance between the crystal's face and a point inside the body or the tissue.

Theory meets real life

     It's time to put to good use all the math and physics from above.
Like I said earlier, Huygen's principle is what really makes everything work. And because a single element probe isn't really going to cut it (for imaging utrasound) let me introduce you to the multi-element probe.

                                          Figure 8. Multi element ultrasound probe

    This is necessary because it really makes the math more easy and because one doesn't need to make so many assumptions. Also, with multiple elements, you can do a bit of wave-shaping, which definitely can improve results.

    As you can see in Figure 8, the crystals are actually rectangular in shape. This means that the near-field will be kind of short. And this is where "more is better" comes into play. If you fire a whole group of crystals at once, the emitted near-field will be longer. Also, the central axis of this beam will actually coincide with the central axis of the crystal in the middle of the group. And also, as an added bonus, the focusing of the beam can be adjusted by the way each individual crystal is fired.

     A typical probe such as this is usually run in pulsed mode, powered by a voltage that can be anything from 500 to 1500 Volts.
Also, you'd want to make sure that each measurement cycle actually runs for several periods of the waveform, just to make sure the crystal is moving as it should  and operating at the actual desired frequency.
     Running the probe with pulses that are too short, would of course mean that the generated spectrum is spread out over a higher bandwidth. Also, the crystal wouldn't have time to mechanically move in tune with the applied frequency.

    The repetition period between 2 pulses can be between 8-120 Hz, depending on the manufacturer, the probe type, the desired application, etc.
The pulse width , from what I've come across in books, seems to be somewhere around 12 ms.

Now, power wise, I've found figures from 20 W and 3W / $cm^2$ all the way up to 80W and 8W / $cm^2$ . Again, probably depends on the manufacturer and application.

And before you ask, yes, there are strict guidelines for this type of gear and there are stipulated powers for the  probe that have to be met. You can't just go around, dumping hundreds of Watts of ultrasound into humans.

     And, a few words about real life probes.... The first piezoelectric material to be used was Barium Titanate. But from a modern material point of view, it's kind of lossy so nowadays, probes are built with PZT crystal. The rest of the materials in the probe remain just like I said at the beginning: epoxy or plastic with added tungsten carbide powder for the backing and aluminium-infused  epoxy for the impedance matching layer in the front.
    Oh, just a quick note: PZT does not posses piezoelectric properties, per-say, but if you heat it up to somewhere around 350 degrees C (C for Science, of course) and apply a voltage to it, the domains inside the crystal will align themselves in such a way as to make the material piezoelectric.

    Linear and Phased array probes:

    If you plan to do anything with modern ultrasound machines, it would be nice to get a feel for what's out there in terms of probes.
    Linear array probes contain 256 or 512 individual crystals which are triggered in small groups (about 20) at a time. As mentioned before, this is done in order to perform beam forming.
    The Phased arrays have much less crystals, about 64 or 128 and are fired at about the same time, producing a single beam. That "at about the same time" means that there is some deliberate delay in firing the elements, thus achieving beam forming and/or beam steering

"Well my little friend, you've got something jammed in here real good"

"But how do you actyually take sound and turn it into images on a screen?"
    Well, you take your probe, emit a pulse out of it then wait for the echo. It's of course, oversimplifying it, but there isn't more to it. 

     If you measure the time between these two waves and you know the propagation speed through the media, you can get an idea of the distance the wave actually travelled. All you have to do to see this, is hook up a scope probe on the crystal.
    This would be called an A-mode display or echo-ranging and is the simplest possible way to use ultrasounds to  "see" something.
Wondering if you can also use this to check for a duck's echo....
Anyway, I digress...
Of course, there's never going to be just echo arriving back. You're going to get a bunch of pulses, that get smaller and smaller because they are coming from tissue that is further and further from the source.
   In ultrasound imaging, of course, if you want to see inside the body, you'll need to record as many of the echoes as possible. And at some point, the arriving pulses will be so small tht you need some sort of amplification to see them.
   Reason dictates that the amplification would be time dependent. I.e. as time passes and more and more pulses arrive, the amplification factor would increase....

                                             Figure 9. Block diagram of an A-mode display

...Something like Figure 9.
    In an actual machine, this would be implemented as maybe a logarithmic amplifier, with gain control (gains up to 120 dB are possible). Of course, the amp has to have a wide enough  bandwidth, in some cases up to 10 MHz.
   Also, in the cases where there is no switching going on, from the RX to the TX path, the front of the amp usually has some sort of attenuator, to minimize the risk of damage from the TX pulse.

   In Figure 9, you can see that the crystal is  powered by the Pulse Generator. That would be Transmit path. The Receive path includes the crystal, the Receive Amplifier (RX Amp) and some way to control its gain. The latter is accomplished by the Time/Gain Compensation block.
   And of course, there's a main controller that oversees everything and controls the timings of both the RX and TX paths (C&C).
Finally, the Demodulator block handles the display part.

                                       Figure 10. Time/Gain Compensation scheme

    Now, let's take a closer look at the most important modules.
 Figure 10 shows how the time/gain compensation is done. There is an initial gain of the receive block which is kept for a certain amount of time. Then, as echoes from further away start coming in, the amplification is ramped up, to a final gain value.
   Like already mentioned, this is so that echoes from further away are amplified enough as to provide in-depth views of whatever tissue is being visualized.
The Demodulator is responsible for taking the incoming amplified echoes and displaying them. It does this by first rectifying them, then generating an envelope of this rectified pulse. For those that like to get really down and nerdy, this is sometimes done by applying the Hilbert transform to the echoes which generates the wanted envelope (probably in digital sound machines)
  The boss, a.k.a the Command and Control module keeps things synched. It generates the TX pulses, with repetition rates from 50 to 2500 Hz and then waits enough time, for the echoes to arrive from the deepest tissues.  Then it's rinse and repeat.

   Another way to view things is by having something like a rolling view and just plotting the amplitude of the echoes on it as they arrive.

                                           Figure 11. M-Mode display. Cross-sectional view of different tissues                                                                       (waves travelling from left to right) Time axis here is on the                                                                     vertical
   If you imagine a time axis going from the bottom to the top and plotting the amplitudes of the echoes as they arrive on that time scale, you can get not only  a cross-sectional view of the tissues the wave has traveled through but also a view of the shape of the tissue and also how it moves over time. Clear as mud, right?

                                          Figure 12. M-Mode cross sectional view

    There... That's much better. Like I said, what you're getting is a cross-sectional view of the tissues, along a time axis. It's basically the same as Figure 11, except rotated by 90 degrees....and with a bit more detail.

    But really, we've all seen ultrasounds or even had one...and they don't really look like some bleeps on a radar screen....they look like actual, internal images of what's inside the human body. And if you're wondering how they achieve this, well....

It's called B-Mode or Brightness modulation:

                                                  Figure 13 - B-Mode  block diagram

   The schematic looks a lot like the one before and that's because  the main difference is mostly in the software. 
  In B-Mode, individual echoes are taken, analyzed, and each one is actually given a grey-scale value, corresponding to their amplitude, which in turn is proportional to the density of the tissue they came from. So denser tissue will have something like light grey or white and fat or air pockets will show up as black of dark-gray.           

    Now, we're getting closer to how an actual ultrasound machine operates. Of course, it needs a few add-ons, so let me just throw in this block schematic:

                                   Figure 14 - Ultrasound machine conceptual block diagram

 This should be much closer to the actual inner workings of the Toshiba Sonolayer.

     The one that runs the show is the Digital Control Logic block.  It's like the C&C block from the previous diagrams, except this has some extra features added, like RX and TX switching and is also responsible for taking in the digital data and turning that to comprehensible images.
It's also responsible for generating the electronic delays for individual transducer elements in an array, be it linear or phased. 
    Equipment manufactured after the year 2000 would include a digital beam former and digital electronics for both transmit and receive functions. However, this is not the case of the Sonolayer.         This baby is all analog. However, there is some magic happening in the digital domain, but without a  manual for the machine, I can only speculate.
    It most likely also adds controlled delays to the received echoes, to adjust for beam direction.
Dynamic receive focusing might also be a thing, in order to align the phases of detected echoes from the individual elements in the array as a function of echo depth.
   After the phases of the echoes have all been aligned, the pre-processed signals from all of the active transducer elements are summed. The output signal represents the acoustic information gathered during the pulse repetition period along a single beam direction. It's this information that is sent to the RX block for further processing.

    On the RX path, there's an Amplifier, which again has the obligatory Time/Gain Compensation added to it. 
 In multi-element array transducers, processing the data from each individual crystal is done in parallel (though I do not know if this is also the case with the Sonolayer)
Each transducer element produces a small voltage proportional to the pressure amplitude of the returning echoes. As mentioned earlier, during the listening phase, as each echo returns from deeper and deeper tissue, the amplification factor is increased. A typical end value would be a factor of about 120 dB.
  Now, because I only have specialty literature to go by, I can only speculate that some of the processing done here might include:

1. Time/Gain Compensation: All returning echoes are amplified so as to have almost the same amplitude. I.e., the echoes from closest to the probe will have the same amplitude as those from deep inside the body. For multi-element probes, the TGC amplification is applied to each signal simultaneously. Some newer machines might utilize dynamic frequency tuning in conjunction with broadband crystal elements. What this allows is echoes returning from shallow tissue will be received at a higher frequency that those coming from deeper tissue. This is done in order to combat high frequency attenuation from the deeper tissues.

2. Dynamic range compression: ADCs can only take so much dynamic range. For this purpose, the signals are all passed through a logarithmic amplifier before being fed to the actual ADC. Thus, higher amplitude signals will be reduced and lower amplitude signals will be amplified, the end result being all of them having more or less the same amplitude.

3. Rectification, demodulation, envelope detection, rejection: Rectification takes the negative-going signals and inverts them, demodulation and envelope detection turns the amplitudes of an echo into a nice smooth single pulse. Now, there will be some signals that make it through but have very small amplitude. If left alone, these signals would create unwanted speckles in the final image, so these need to be filtered out. This is done with a simple comparator with selectable threshold.

    The output from the RX Amp is digitized then fed to the Digital Logic Control unit.
The actual magic happens in a separate module where the data is processed and assigned greyscale values, then fed to the Scan Converter. Here it is stored in RAM memory and it also gets some post-processing done to it before being sent to its final destination, the display.

RX amp and A/D Converter:
The Scan Converter takes the digitized data and creates a 2D image from them. Most modern machines have a memory matrix storing a 500 x 500  pixel image. Each pixel is stored into RAM, with a certain greyscale value (usually 8-bit)
During acquisition, the digital signals are stored, depending on the beam orientation and echo ddelay times.

I've talked about this beam steering stuff a few times, but what is it and what does it do?
Well, as mentioned, it fires groups of transducer elements on the probe head, with delays between each group. Because of destructive and constructive  interference of the waves, the beam actually comes out at an angle. Something like this:

                                        Figure 15 - Beam Steering in multi-element probes

   This allows for an increased Field of View from a probe. Now one can "see" stuff not only directly in front of the probe, but to a much widened angle. This is where those delays come in real handy. By firing the elements with a knows phase offset, you can shape the beam like in Figure 15

    The final element would be the TX/RX Switch. This is synchronized with the pulser and isolates the high voltage
used for pulsing (~150 V) from the sensitive amplification stages during receive mode. After the ring-down time, when vibration of the piezoelectric material has stopped, the transducer electronics are switched to sensing small voltages of the returning echoes, over a period up to about 1 ms.

Creating an actual image

     Though the earliest form was the A-mode, that is pretty much still used today, to some extent. A normal 2-D ultrasound image is composed of a number of A-mode lines ( maybe 100 or more), all of which are acquired across the whole field of view of the probe (using the beam steering method). It would make sense that if the number of A-mode lines is increased, you'd get more resolution. However, because you have to wait a finite time for the echoes, that limits how many lines you can acquire.
   Now, doing a little math, a line is acquired in ~ 13μs/cm x D [cm], where D is the desired depth of acquisition. So if you want the acquisition to last less time, you'll get less depth information. i.e. the less you wait, the more echoes from deep tissue you loose.

   Therefore, if you're limited by a finite ammount of time, that means that you can also show only so many frames per second.

                                     $Frame rate = \frac{1}{N \times 13\mu s \times D}$

    The A-mode signals are converted to B-mode signals.
Then, once converted, they have to be stored somehow. Most machines have a 512 x 512 or 640 x 480 screen, each pixel having 8 bits of grayscale levels. That's not much memory, even for the late 80's standards.
    In the second part, I'll try and go over the boards and identify the blocks mentioned in this part with actual physical components and boards. I've only scratched the surface of what is ultrasound imaging in this post. If you want some more in-depth knowledge, maybe these can be of help:


 - Alan J. Mortimer, Michael H. Repacholi, Deirdre A. Benwell: Essentials of Medical Ultrasound A Practical Introduction to the Principles, Techniques, and Biomedical Applications

 - Matthew Hussey: Basic Physics and Technology of Medical Diagnostic Ultrasound

 - Haim Azhari: Basics of Biomedical Ultrasound for Engineers

 -  J. Bushberg, Anthony Seibert, E. Leidholdt, J. Boone: The Essential Physics of Medical Imaging, Second Ed.

There's also an open-source Ultrasound Imaging project out there called Murgen. You might want to check it out. Trust, me, it's cool a frig (nope, not affiliated with it in any shape, way or form)

    Oh, by the way, if you are curious to know what software I used to make those drawings, it's called CatCAD. It's in Beta right now, but I hope I'll have it out soon

Thursday, July 20, 2017

My Hi-Fi Raspberry Pi DAC project. The Build Phase

    This is part two of my Raspberry Pi DAC project. If you  want to know how this came about, you might want to read part one

So, the fun begins.

The PCB are here!

     Oh, happy day!.

  I ordered my PCBs from PCBWay, and they're not half bad. Pads look OK, the footprints for the TPA op-amp, which had me worried a bit,  turned out nice and so did the solder mask.

Of course, the first thing was to check and see if the PCBs actually fit the Pi....and they do. Phew!

Next up for inspection, the PSU boards:

Lovely. Except, this is the last time I order black solder mask. Every speck of dust is visible, the flux residue looks horrible on it and you can't see anything if the light is not at the right angle.

That being said, let's start assembling these things.

I don't own a hot air station, but I do have a digital controllable hot air gun. Soldering the PCM5242 was easier that expected and that kinda built up my confidence. But, like always, Murphy stuck out his head and had a say in the soldering of the TPA op-amp.

Because it only has 2 pads on 2 of its sides, it made it especially difficult to keep it on the pads. Every time I came closer that 10 cm with my hot air gun, it just blew it off my board.
It took me about 40 minutes of frustrating work to finally get the TPA to stick and reflow properly.

    My method consisted of applying some solder to the QFN package and a little to the pads on the PCB. Garnish everything with tons of rosin flux and voila!
 Just be careful, because if there's too much solder on a pin, the surface tension when the it reflows will keep the package from leveling out on the board or leak out and short to adjacent pads, if the part is slighly moved or pressed.
    After checking for shorts on the DAC and op-amp I went on to solder the rest of the components on the Pi hat

Next up, the PSU boards. These have fairly large components, so they were no trouble at all.


    No, this one isn't about an uninterruptible power supply... I just messed up. Some keen-eyed readers (you the few, the proud, the EEs) might have spotted in the schematic (or, if you haven't, you will now) that the DIN pin of the DAC is atually tied to the DIN of the Raspberry Pi. Yeah, that should have been the DOUT pin on the Pi.

    The Pi has DIN on pin 38 and DOUT on pin 40. My DAC is tied to pin 38....I can personally guarantee you that this set-up won't work.
Why did I mess up? inconsistent data on some Pi pinouts on the web. That and I was too much of an eager beaver to get the board done so I didn't bother  to check more than 2 photos online

    But, like always, I found a nice easy fix for it. I wasn't really  in the mood to cut the trace to pin 38, so I lifted and isolated the pad to R14 going to the Pi's DIN, then soldered a wire from the resistor, to pin 40. There. Problem solved.


     I've seen enough fancy DACs on Google's searches to instill in me the conviction that I needed to put everything in a nice anodized aluminium case.... minus the blue LEDs. I hate those, but they seem to be on everything these days.

    Ok, micro-rant over. So, I had to fit a Rasberry, its own PSU and two oversized linear PSUs.
Loca suppliers didn't have  the size or look of what I wanted, so I went shopping elsewhere. In France, actually. I mean, they make fancy everything there. Fancy cheese, fancy wine, horrible cider (interesting story here), fancy aluminium cases. Perfect!

    The case I got was from Audiophonics. I'm in no way affiliated with them, these guys seem to  have everything  audio and audio related.  My case was about 35 Euros and is 280 x 158 x 48 mm (L x W x H) which is just about the right size to get everything squeezed and allow for some cable management. Some might call this luck. I call it engineering.

Oh, the feet I also got from Audiophonics. They're just plastic, but they certainly look the part.

Testing, testing... Is this thing on?

    If a picture is worth a thousand words, then here's..... well, a few thousand words for you.

The cobbled stuff you see on that perf board is a single-ended to differential signal converter. It sounds fancy, but it's just 2 amps in an inverting and non-inverting configuration. This is to test the TPA6120 op-amp to see if everything got soldered on properly.

    In the scope pics, the yellow trace is the input signal (before the differential converter) and the blue and pink (or magenta? hell if I know) are the outputs of the TPA. The dark blue trace (the lowest trace) is the output of the op-amp. One channel only.

You might recognize the beast that is the  Interstate Electronics generator in the pics. I'm happy to say that it's running quite nice for its age. It has the occasional hiccup at power-on, but nothing a little hard rest can't cure.

Tying up loose ends

    I stuck a heatsink onto the TPA6120 op-amp because during my tests with an open case showed that the op-amp will heat up to 55 degrees C and stabilize at this point. I figured that once it'll be put in its enclosure, together with all the other heat sources, it might get a little too toasty for long term reliability, therefore, I give you the pic above.
  The grey square is a silicone pad. Even though the heatsink is anodized aluminiun, I just wanted to make sure it'll never touch the resistors next to the amp. I've laso added heatsinks to the Pi's chips as well. Those are underneath the DAC hat.

    Being  the paranoid guy that I am, even though the PSUs are mounted on 3.5mm nylon standoffs, I thought I'd play it extra safe and add some isolation between the case and the through-hole pins carrying live mains.

    Another important thing would be the DAC output filter.  The data sheet for the PCM mentioned using 1nF NP0/C0G caps.  Now, I'm no audio guru, but  an electric guitar mostly sounded as if it wanted to come at you and cut off you ears with a bread knife. The 3dB point of the filter with the original 1nF caps was 422 KHz, so I changed these to 2.2nF caps, decreasing the bandwidth to ~300 kHz.
  This is what LTSpice told me, so that's what I'm tellng you now.
    It made for a much cleaner sounding audio experience, especially on the highs. The issue was most likely caused by intermodullation products making thair way into the audio range. By reducing the filter's bandwidth, some of the haronics were attenuated, rendering a nicer, cleaner sound.
    I might consider going all the way up to 3.3nF caps just to see what happens....
 Oscillators, anyone? get your free oscillators here!!


    Well, if youre wondering about geeky stuff like THD and noise performance, you're not the only one. I lack the proper equipment, but I do plan to build me some  nice THD measurement unit.
  Quoting the THD figures from the DAC's datasheet isn't that relevant, but might I remind you that the supplies for the DAC and op-amp are linear ones and the DAC's channel outputs are differential, so the only significant part, susceptible to noise pick-up is the op-amp itself. But because it has a high PSRR and the ground loops are (I think) on the  small side, there is a fair chance that the distiortions on the audio output of the hat might be quite low.
    Untill I find the equipment to make real world measurements, I can only say that to my ears, the DAC hat is a success. A 196 KHz, 24 bit  song sounds prety impressive, so for now, this is where things stand

Volumio Set-up

    Well, there are lots of places online detailing how to get your Volumio up and running. So why not add another one the list?
    OK, so it's pretty easy. Just go to the Volumio download page and get the latest build. That will be in a .zip format and inside that there will be a .iso file.
After you've formatted you SD card  (I formatted mine as a FAT32) you plug it in and write the image to the card.
Hold on, it's coming.... For writing the image file, I used Win32 Disk Imager. It's basically "point and shoot", so there's no reason to go into further details.

....and here comes the fun part. Once you write your .iso file  (not the .zip, like I did...doh!) just plug the card into your Raspberry and you're on your way.
  Of course, once it boots up, you have to access it. I only access mine over LAN, so I don't know much about the wireless set-up, but I can assure you that once it's all booted up, you can go and write in your browser http://volumio.local/playback and you should be in like Flynn...
  On the off chance this doesn't work, you'll have to go into your router and see what devices are connected to it. The DAC should come up as "Volumio". Then just access it via its IP address.


    Let's say you want to share the folder "Music".
  If you have a NAS, just type in its IP address and the name of the file you want Volumio to play from. Do not leave the "Alias" field blank. You have to write something there or the sharing won't work. And, whaterver you do, please DO NOT share files with spaces in its name (e.g. My Music). It screws up the sharing somehow. I wasted an entire day with this crap. Just use underscores (e.g. My_Music) It'll save a lot of freakin' time.
    If you are just running a version of Linux on your NAS, select "nfs" from "File Share Type". However, if you're running Samba, then just leave the default "cifs"

    Ok, so you're no that fancy and  just have a PC. No problem.... just do the same procedure as mentioned and leave the default "cifs" in the "File Share Type". If by any chance you have a user and password for you PC, then just write these in the appropriate fields. But really, who does that? Who has a passworded PC at home? That's no security, that's just a waste of time. You want security?  Then run Linux on your PC. Everyone in the house will hate you.

Final thoughts

    I ended up building two almost identical DACs, one for me and one for a friend of mine. The only difference is that while I used a Raspbeery Pi 2 B+, his was a Raspberry Pi 3.
Our choice of web players was Volumio, which worked on both versions without a hitch.
Also, because the Pi 3 has built-in Wi-Fi, I added an antenna for it in the back of the case. If you need some more info about how to do this, you can check out this article. It has a lot of nice pictures regarding this mod. Also, if you're going to do this, u.FL connectors are a pain to solder, so if I were to do it all again, I'd go with just soldering a coax cable to the Pi's PCB and tack it in place.

    Like always, you can see the whole album of this build here. Hope you like what you see and if you want to comment, leave one below.

    Later edit:  The DAC has been so far running non-stop for about a week and everything looks OK. The op-amp did start heating up as soon as I gave it power, so that heatsink really helps. I want to do a thermal profile of the DAC to see how it behaves in the long term, therefore I'm searching for a way to do some temperature data logging. I'll  probably do a post on this as well, in the future,

Disclaimer: The stuff from TI I bought myself. I'm in no way affiliated with them. It just happened that they have the kind of parts I  needed

google-site-verification: googlee8a41f51abde7545.html