All posts by

TDCS Controller Step 4 – Redesign

An unfortunate outcome of many first attempts is the learning that goes along with failure. My initial design for a TDCS controller had some weaknesses (okay… outright failures). At first, I attempted to fix them on-board by cutting traces and soldering wires to re-route power, or by dead-bugging extra components onto it. However, you can only do so much without having to shift gears and start over. This post is all about the redesign.

The driving force behind the re-design was my inability to make the TSC888 current sensing amplifier work like I wanted. However, I can accomplish the same thing with a simple op-amp. In fact, the LM358 that I used as a voltage comparator can work pretty well, and I have a few extras of those around. The trick with using this kind of set-up is to either reference the current sense voltage to ground, or to build up a differential amplifier. The simplest method I could think of was to put the current sense resistor in the circuit after the load and make it the last component the current flows through on its way towards ground.

The basic current regulator is unchanged. It worked so well, I can’t come up with a reason to change it. With R2 at 68ohms, the regulator (U1) is hard-wired to produce 1mA. When S2 connects iwth R1, the effective feedback resistance generated by connecting R1 and R2 in parallel is 34ohms and results in a 2mA current.

The LM334MX is set for either 1mA or 2mA depending on the position of switch S2

The nature of the LM358 calls for another change. It can have an offset voltage between inputs of several milivolts. With a 10ohm sense resistor like I had in the previous design, each milivolt of offset represents a 10% error at 1mA of current. However, increasing the sense resistor to 100ohms increases the sense voltage by a factor of 10, so a 1mV offset would only represent a 1% error. That’s good enough for me. Adding an extra 100ohms of resistance into the circuit shouldn’t really be an issue for my application.

With a 100ohm sense resistor (R3), I need a gain of 10 to produce 1V output per miliamp. Configuring an LM358 (U3A) for a gain very near 10 with a 91K (R10) and 10K (R9) resistors will replace the TSC888, and do so in a package that is easier to solder. I also added a 1uf capacitor (C1) to the output lead to absorb any transients that might inadvertently trigger the crowbar. I also added a 2.2K output resistor (R14) feeding another 1uf capacitor (C2). The resistor capacitor combination gives a 2.2ms time constant, so it will take about 10ms (5 RC time-constants) to react to changes in the output. This will help to further damp out any transients, but do so quick enough that a failure that result in a relatively high current won’t injure anyone.

R3 is in series with the load resistance (i.e. my head ultimately). The current flows out of the regulator (U1), out through the load resistance, and through R3 to ground. C1 is there to dampen transients at power-up. The LM358 amplifies the voltage by a factor of 10.1 thanks to the feedback resistors (R9 and R10) to produce an output of 1.01V/ma on pin1. R14 and C2 form an additional dampener against transients.

In order to determine if the output current is above 5mA, I can use an op-amp to compare the output of U3A with a 5V reference. However, that means I need a stable reference voltage. Since the supply voltage can vary from about 9V to 24V, I can’t use it directly. I could use a regulator like an LM7805, but there will be very little current drawn from that source so that would be overkill. Instead, I used a simple 2.2K resistor (R8) and 4.8V zener diode (D3) to derive the reference. The 4.8V zener blocks current until the voltage across it reaches the zener voltage (4.8V), at which point it lets current flow. R8 limits the current that can flow through the diode so it doesn’t melt once it starts conducting. I originally wanted a 5V reference, but the 4.8V zener was substantially cheaper than the 5V option and was close enough to meet my needs.

The 5V reference source is derived from a 4.8V zener diode (D3) and a 2.2K resistor (R8)

As before, I used an LM358MX op-amp for the voltage comparator. Each device comes with two op-amps in the package, including the one I used for the current sense amplifier. Ultimately, I need just one more amplifier to sense an over-current condition and trigger the crowbar, but I would also like some status indicators. Since the LM358MX is relatively inexpensive (and I have several extra available) I decided to add another one to the circuit.

The crowbar driver (U4B) is very simple. The inverting input (pin 6) is tied to the 5V reference and the current sense output is tied to the non-inverting input (pin 5). When pin 5 is less than pin six, the output on pin 7 stays low (ground). However, if the output from the current sense circuit exceeds the reference voltage (approximately 4.8mA), the output on pin 7 rises to the supply voltage and triggers the SCR (U2). U2 then latches on and shunts the supply to ground. Once that happens, the fuse (F1) opens up and cuts off power to the whole circuit.

Pin 5 of U4B is tied to the current sense amplifier. A 1V signal on pin five corresponds to a 1mA current through the load. If the current exceeds 5mA, the output of U4B goes high and triggers the SCR (U2), blowing the fuse and cutting power.

For convenience, I want two indicators: one to show when the 2mA setting has been selected, and one to show when the circuit can’t supply at least 1mA. The circuit for status indicators (LEDs) is similar to the crowbar driver, but I use a voltage divider (two resistors) off of the 5V reference to set the threshold voltage. I could have gotten rid of the indicator LEDs, and used one amplifier to run both the crow-bar and for current sensing, but they are cheap and easy to work with, so I opted to add another chip. The voltage divider on U3B set by R11 and R12 set a 1.4V reference on pin 6. If the output of the current sense circuit is above 1.4V (1.4mA output), pin 7 goes high and LED1 turns on. The divider on pin3 of U4A sets a 0.84V refrence. If the current sense voltage drops below 0.84V because the load resistance is too high (like when it’s disconnected) or because the battery has dropped too low, pin 1 goes high and turns on the red LED in LED2 (not shown). R5 and R13 limit the current through the LEDs to keep them from burning out.

U4A lights up the red half of LED2 when the current sense voltage drops below 0.84V to indicate a continuity problem or a low battery. U3B lights up LED1 when the current sense voltage is above 1.4V to indicate the 2mA output is active.

The final change I made from the previous attempt was to add diodes in line with the battery and power jack. If you’re only going to ever run this thing off of one or the other power source, there isn’t a need for the diodes, but if you happen to have a 9V battery plugged in and you connect a 12V power supply, you’ll end up with current flowing from the power supply into the battery. That can result in some nasty stuff. The opposite condition can occur if the battery voltage is higher than the power supply voltage. Two cheap diodes (D1 and D2) are all it takes to prevent that possible outcome.

D1 and D2 prevent current from backflowing if both a battery and power supply happen to be connected. F1 is a 100mA resetable fuse.

So, putting it all together, here’s the end result:

Copyright by Peter Johnson, February 2019 and released under the terms of the Gnu General Public License (GPL). This design comes with no warranty whatsoever, express or implied, for any purpose. It is provided for educational purposes only. Send recommended improvements or polite inquiries to

With the new design comes a new board layout (slightly larger, but easier to fabricate at home). The mask sheet containing the photomasks for both the photoresist and the solder mask can be downloaded here. The capacitors are Panasonic outline B, diodes are SOD-123 packaged, resistors are 0804 size, LED1 is 0804 and LED2 is a custom two-color LED footprint. The ICs are all SO8 packaged. The process I use for fabricating boards is described here if you want to try making one for yourself. The .brd and .sch files for Eagle Cad can be downloaded here.

I had to order a few extra parts with the redesign, and am waiting for them to arrive. Once they do, I’ll test the resulting circuit and post the results. Until then, if you make improvements or just decide to build your own, I’d love to hear about it. Leave me a comment below.

The almost completed board. There are a few resistors, capacitors, and diodes that are still on order, and I need to connect the switches. The two vias in the center of the board are reserved for connecting an optional panel-mount voltmeter to display the current.

TDCS Controller Step 3 – Testing the Design

In previous posts, I described the process I went through to design and fabricate a circuit designed to safely apply 1mA of current to any load (including potentially a human). Up to this point, things had gone well. The TSC888 amplifier intended to measure the actual current flowing turned out to be a little small for hand-soldering, but my practiced and patient hands managed it okay. I wouldn’t recommend it to someone who is just starting out with surface mount components though.

With the board built, I plugged in a 9V wall-wart transformer, connected a 1K resistor to substitute as a human, and switched it on. The LED blinked, then turned off. A little probing revealed that the fuse had been tripped. connecting my oscilloscope to a few test points and cycling the power switch revealed that the crowbar was working beautifully except for the fact that it was tripping due to power on transients. In an effort to continue evaluating the rest of the circuit, I added 1uf capacitors to the output of the TSC888 and to the input pin on the SCR. They are the blue cans visible in the picture below.

After the boards are cut out, I solder on the components. Surface mounts can be hard to deal with if you haven’t done them before. First, solder flux is your friend. It can help stick the components in place, and makes the solder flow well. Second, a dental pick in your non-dominant hand can help pin the part against the board while you tack it down with the soldering iron. Get some solder on the tip of the iron and use that. Drag the solder across the fluxed pins and the solder should flow pretty evenly. If you get too much and short out pins, solder wick is an easy way to clean it up. I’d also keep some chip-quick around for removing components that didn’t go on like you thought they would or that let the smoke genie out.

With the capacitors in place, the low setting seemed to work well. I measured 10mV across the 10ohm sense resistor, so the current source was working as designed. I switched the board to the 2mA setting, and so far so good. To test the ability of the regulator to handle extreme cases, I shorted the output leads together, and the low-current error light turned on. Weird… With the leads shorted, the current should be the same or higher than if the leads were disconnected. After a little fumbling and scratching my head, I realized what I had done wrong.

Consistent with most of the application notes and examples in the datasheet, I tied the power supply pin of the TSC888 to the output of the current regulator. This works fine when the load resistance (your body resistance) is relatively high, but when the resistance is low, the output voltage from the regulator drops very low to keep the current constant, and the TSC888 starts to behave erratically. It quits working all together if the connection is shorted because there is no power to drive its amplifiers, and that’s exactly when I want it to work the most. I had to pull off the chip, cut a trace, and tie the power supply pin (pin 5) to the input supply voltage (Vcc). A perfect example of why chip-quick is helpful… I know of no other way to reliably remove a surface mount component without destroying it (and often the board traces) in the process.

The output regulator worked perfectly everywhere from short-circuit to 10K ohms. If I didn’t care about monitoring or safety features, I’d be good to go. However, as I turned up the resistance, there came a point where the output of the TSC888 would drop out. Current would still be flowing, but the indication output would be 0V. I again connected my scope and dug in. Apparently the TSC888 is cutting of after a brief period. It’s unexplainable behavior. It could be because I damaged the IC by getting it too hot while soldering-removing-resoldering it, but if that’s the case, I should probably find something less sensitive. Otherwise, there is some “feature” I didn’t account for, and that part isn’t suited for my application in the first place.

The yellow trace is the indicated current flow. It turns on like it should, but then shuts off a very short while later. The actual current flow continues. The power supply line and sensing lines are clean and within specs, so I’m at a loss as to what causes this.

So. To summarize… After all that work, I have to go back and redesign. The core building blocks all work, but there are definitely things to change:

  1. Add a diode in line with the battery terminal and power jack to prevent current backflow if someone connects external power while a battery is installed.
  2. Add filter capacitors to the crowbar signal to suppress transients that erroneously trigger a shutdown.
  3. Move the 10ohm current sense resistor to the load low-side and build my own op-amp detector to sense current flow instead of the TSC888. If I use another LM358, I can use the remaining op-amp to drive an indicator for whether 1mA or 2mA is flowing.

More to follow. I’ll redesign the circuit, build another board, and come back when I have something to report.

TDCS Controller Step 2 – Building The Circuit Board

In the previous post, I described a circuit design for a TDCS controller I’m developing. Because I’m working almost exclusively with surface mount components, I can’t really breadboard the circuit. The best option I have is to build a circuit board and use that for testing. Conceptually, I could send the board out to a fab shop and have them produce one. However, doing a 1-off build, especially when the design hasn’t been proven, is expensive, risky, and takes a while. Because I’m impatient and like to do things myself, I make my own. In this post, I’ll describe the process I use for making my own boards.

If you happen to be interested in trying this yourself, you’ll need a few things:

  1. A circuit board layout
  2. Dry-film photo resist
  3. Double-sided copper-clad circuit board(s)
  4. 300-400 grit sandpaper
  5. Printable transparencies (ink-jet printable in my case)
  6. A good quality printer
  7. A laminator
  8. A laminator pouch that has been through the laminator
  9. Latex gloves
  10. Washing soda (sodium carbonate)
  11. Copper Etchant (I use ferric chloride)
  12. UV curable solder mask
  13. A UV light source (a black-light works well)
  14. A rotary tool (Dremel) and carbide bits
  15. A hacksaw to cut out the finished board
  16. Soldering Iron and solder

I make my boards by laminating bare copper clad board with dry film photoresist. I then print the pattern negative onto an inkjet printable transparency to use as a photomask while exposing the photoresist. To make the mask, I use Eagle CAD to build the board layout as part of the circuit design. However, I don’t like the way Eagle exports the graphics. I turn off all the layers but pads, vias, and either top or bottom layers and export the result as a PNG at 1200 dpi. However, the exported graphic isn’t quite ready for exposing a board. First, it isn’t black and white. In order for the photomask to work right, it needs to be either transparent (white) or black. Second, with the latest version of Eagle the signal names are printed on the traces and need to go away. Finally, the drill-holes are almost filled, and it’s much easier to hand-drill if the etched copper acts as a sort of pilot hole to guide the drill.

Using Gimp and a round brush I erase (paint over in black) anything that blocks the drill holes. Then I use the threshold tool to turn it to black and white. Once that is done, I mirror-image the bottom layer and add any graphics (like my logo) and text I want or have room for. In the end, anything black in the image will be areas where the copper is etched away.

To build the mask for curing the solder mask, I turn off all the layers in eagle except either the tStop or bStop layers, change the fill pattern to a solid color, and export it using the same settings as the board layout. Using Gimp, I use the threshold tool to make it black and white, then invert it so that the pad areas are black (black areas won’t cure and can be wiped off when the mask is applied).

Printable transparencies are kind of expensive, so I try to cram as much onto each one as I can. To do this, I use Scribus to lay out a full page that includes all the masks I need. A calculator and the properties dialog box are handy to make sure the relative geometries of tiled masks are the same. Finally, I use Scribus to export the result as a PDF for printing. Generally, I’ll print out a sheet on copy paper and make sure things line up, and that device footprints match the components I have on-hand. Make sure you don’t have “shrink to fit” selected on the printing options, and when you print the actual mask, set the print quality to maximum and resolution to at least 600dpi.

Printed mask sheet. The top right is the top of the board, bottom left the bottom, and the right side are the respective solder mask patterns for the top and bottom.

To laminate the dry-film photoresist onto the copper-clad board, I start by using 320-grit sandpaper to sand off oxidation and contamination from the board. I’ve tried using brillo pads and cleanser, but have had issues with the film not adhering strong enough and pulling loose at inopportune times. Once the copper has been sanded bright, I clean it off with acetone to make sure I didn’t leave any oils on it. I also wear cheap latex gloves from Harbor Freight any time I handle the board to make sure I don’t get skin oils on it.

Once the board is clean, I cut a piece of film about 1″ wider and longer than the board I want to laminate. I also cut a piece of card stock about 2″ longer and wider than the board. The dry-film photoresist is protected by a thin sheet of plastic on both the top and bottom, and one of these protective sheets needs to be removed in order for the film to work. To separate it, I sandwich the corner edge of the film between two pieces of scotch tape (sticky-side to sticky-side) and peel the tape apart. One side of the protective film will peel away (usually the inner side based on the way it wants to curve). If it doesn’t, try again, maybe on a different corner.

Stick tape to each side of the film and pull it apart to start separating the protective plastic from the film. Usually the film on the inside of the curl will pull away. Only pull the plastic off one side of the film at this point.

I then tape the top-edge of the film face-down (protective layer up) on the card stock. I align the board underneath the film and feed the film into a hot laminator taped-end first. The laminator will grab the paper and begin pulling it through. Gently lift up on the film to keep gentle tension on it and avoid bubbles or wrinkles as it feeds into the laminator. Once it’s been through, I usually run it through two or three more times just to make sure it’s good and stuck. At this point, the film around the edge of the board is laminated to the cardstock, so I cut around the board with a utility knife to get the board free. Then, I turn the board over and repeat the process for the bottom.

Tape one edge of the film (film side down) to a piece of card-stock. The card-stock helps pull the board through the laminator, taping the film to the paper makes it easy to put a little tension on the film to avoid bubbles and creases.
Run the cardstock-board-film combo through a laminator set for it’s hottest setting. Put gentle tension on the film as the board is fed through the laminator to prevent bubbles and creases in the film. I usually run it through the laminator 3-4 times in a row. To laminate film on the bottom of the board, flip the board over and repeat.
When the board comes out of the laminator, it’ll be stuck to the paper. Use a utility knife to cut around the edges of the board to release it.

To align the top and bottom masks I cut them out, leaving about a 1/2″ margin around the pattern, and use a piece of left-over circuit board to act as a spacer between them. I tape one of the masks to the piece of board, then flip it over and tape the other mask down so that it’s aligned. It isn’t exact, but it’s about as good a way as I’ve found for consistency. When I’m ready to expose the board being etched, I slide it between the masks, and sandwich it between two pieces of glass that I took out of a thrift-store picture frame. Rubber bands, binder clips, or clothespins work pretty well to keep it all together (you have to flip it over without messing with the alignment, so it’s important to get at least some tension on it).

I’ve seen lots of folks on the web double-layering their masks to get stronger contrast, but in my experience this is totally unnecessary, and can make it really hard to work with small features. It’s almost impossible to get them exactly aligned, and variances in the printer can make it absolutely impossible. Using a single layer mask I’ve reliably made boards with traces down to about 10mils (1/100th of an inch) that turned out crisp. However, I do prefer to keep all the clearances and trace widths 15 mils or larger just to make it easier on myself.

I tape the mask to a section of scrap PCB to keep the separation right and hold them aligned with each other. The photoresist under the black areas will wash away when developed, leaving exposed copper which will be etched away by the etchant solution.
I sandwich the mask and board between two thin sheets of glass I took out of a thrift-store picture frame to keep the mask tight against the board. The rubber bands keep the whole thing together so I can flip it over and expose the back side without changing the alignment.

The photoresist is sensitive to UV light (and to a lesser degree it’s sensitive to the blue-end of visible). Some people have had success using fluorescent lights a few inches above the board, but that didn’t work particularly well for me. Others use sunlight, but I like to be able to work when it’s dark or cloudy outside, and the UV from the sun can vary widely based on time of day and cloud conditions. My solution was a 13W black-light LED bulb I bought at Lowes or Home Depot. I rigged up a fixture that holds it about 4 inches above the board. In this configuration, a 5 minute exposure is about right. Your mileage may vary, and you’ll likely have to experiment with different exposure times to get consistent results. Take good notes and it won’t take long to make beautiful boards.

To expose the board, I put it about 4-5 inches below a 13W LED black light I bought at Lowes. 5 minutes exposure seems to be just about right with this geometry. After five minutes, I flip the board over and do it again on the back side.
After the exposure is done, you should be able to see the pattern in the photo resist. It may seem a little blurry, but seems to sharpen up when developed.

To develop the photoresist, carefully peel off the protective plastic. Use tape on the corner and lift up if you can’t get it with your fingers. Be very careful and gentle, pulling the plastic outward and upward to avoid tearing the film. This is one point where you find out if your board was totally clean and if the laminator was hot enough. If the photoresist starts to peel off, clean it off with acetone or a long bath in hot water and washing soda and start over. Assuming the plastic comes off cleanly, drop the board in some luke-warm water with washing soda* dissolved in it. It isn’t critical how much. I usually use about a teaspoon or two per cup of water. If the water is too hot, you may end up washing away both the developed and undeveloped portions and have to start over

*you can find washing soda in the laundry isle of most grocery stores, or you can make your own by heating baking soda in the oven at 350F for half an hour or so.

To develop the photoresist, drop the board into a solution of washing soda and luke-warm water. Agitate it gently, and gently rub it with a soft-bristled toothbrush to work the softened mask loose. Be very gentle or you may damage the finer features.

Gently agitate the board, and lightly rub it with a paintbrush or soft toothbrush (I used cheap acid brushes from the plubming section at Harbor Freight). The unexposed areas will soften and gradually wash away. Keep going until all the copper you want to etch away is completely exposed. You can patch up areas that are accidentally exposed by drawing over them with a sharpie after the board has dried off and before etching, but I prefer to just re-do the exposure since it turns out much neater that way. When all the copper you want etched away is exposed, rinse the board in cold water to stop the developer from eating away the film you want to keep. Let the board dry before you try to re-touch any copper that got accidentally exposed.

The developed board should have sharp lines and good contrast. If anything isn’t right, start over. Once you start etching, it’s really hard to fix things that aren’t right.

At this point, the board is ready to etch. At the moment, I’m using Ferric Chloride etchant, but you can find tutorials on the web for making your own etchant from hydrogen peroxide and hydrochloric acid (muriatic acid for cleaning swimming pools) you can buy at WalMart. Pour some etchant into a non-reactive container and swish the board around. The board will etch faster if the etchant is warm. Also be careful with FeCl… it indelibly stains almost everything it touches, especially clothes, skin and counter tops. Definitely use gloves, and lay down some paper towels or cardboard to protect your work surface. Check the board every few seconds. Quit when all the exposed copper has been eaten away and rinse the board with plenty of warm water. Don’t dispose of this stuff down the drain, the copper in it will kill aquatic life. I’m currently looking for a good chemist to show me how to precipitate the copper out of the solution so I can neutralize the remainder and flush it down the drain. Until then, I pour the etchant back in its original container and keep it.

The exposed copper with start to turn pink, and the etchant will begin darkening as copper is dissolved into it. Swish it back and forth gently. How long it takes to etch will depend on the strength and temperature of the etchant. When you think it’s done, rinse the board with water and look closely to be certain. If there is any copper that still needs to be etched away, put it back in the solution for a while longer.
At this point the etching is done, and the board has been rinsed off. There are two real options for removing the film. The quickest is a brief soak in acetone. The other is to throw it back in the washing soda solution overnight.

Depending on how impatient you are, and what you have available to you, a short soak in acetone will quickly loosen up the photoresist. I don’t really like working with harsh organic solvents like acetone, so I usually just drop the board into a solution of hot water and washing soda and leave it overnight.

The same solution used to develop the photoresist can be sued to take it off if you are patient. If not, hot water speeds up the process, or a quick dip in acetone will do the job.

If you are working only with through-hole components, you can stop after the film has come off, drill the holes with a dremmel or drill press, and start building the board. However, I prefer surface mount components, and those are much easier to work with if you apply solder mask. Besides, solder mask makes the board look better (even if you screw it up a little like I tend to). The soldermask I use is a UV curable epoxy paint that is heat resistant enough that it won’t blister when you solder components to the board. It’s available online from places like ebay and Amazon. To make it work, you need a thin layer, so I squeeze a small amount of the paint onto the board, then squeegee it under a sheet of transparent plastic (I use a laminator pouch that has been through the laninator). The biggest problem I’ve had is getting the paint too thick so the UV light doesn’t penetrate far enough to cure the deeper layers. Spread it out THIN. I’ve also found that taping one edge of the transparency to a piece of cardstock will help minimize the sheet or board slipping with respect to each other (not shown in the pictures).

Make sure the board is really clean and dry, set the board on a piece of card-stock or other disposable surface, then put a small blob of the solder-mask compound on the board. Put a piece of plastic trimmed to a little larger than the board over the paint (I use a laminator pouch that has been through the laminator because old-fashioned transparencies are hard to come by these days).
Use a flat surface (in this case a nylon kitchen scraper) to spread the compound out thinly and evenly. My biggest problems with producing good looking boards come from the paint being too thick and the UV light not making it all the way to the bottom and curing that portion of it. Make sure there aren’t any bubbles, and scrape extra paint out the edges and onto the paper.

Once you have a thin layer of paint, expose it using the same setup as was used to expose the photoresist. Five minutes seems about right with my setup, but you’ll likely need to experiment on some scrap boards to get it right. Don’t experiment on large areas. There is no way to peel off the stuff once it’s cured. It’s tough as nails. After exposing it, lift the clear plastic and wipe the board with a clean paper towel to expose the component pads and vias. Wipe it thoroughly. I’ve used an acetone dampened paper towel before, but you run the risk of blistering incompletely cured paint. Once the pads are clean and bright copper, put the board back under the light for another ten or so minutes to make sure it’s fully cured.

Place the board under the black light (with it turned off), align the mask on the board, and place one of the pieces of glass on it to hold it in place. About 5 minutes seems to be about right using the same setup as I did for exposing the dry film photoresist.

After wiping off the uncured paint, I put it back under the light for 10 or so minutes to make sure it’s good and cured. Once the paint is dry, I use a dremmel with bits I got on amazon to drill out the vias and through-hole components. Finally, I cut the board out. A hack-saw works okay, and band-saw works better (I don’t have one of those yet). A dremmel with a cut-off wheel will work in a pinch (what I used here).

You can see the blistered solder mask on the corner of the board on the left. I’m pretty sure it’s a matter of the paint being too thick, or the curing time being too short combined with the fact I used acetone to help wipe off the pads..

At this point, the board is ready to build up. Solder on the components according to the schematic and fire it up to test. Soldering surface mount components is an art form of its own, but the short version involves using plenty of flux paste, dental picks to hold things in place, and solder wick to suck up extra solder when you get too much. Be careful not to overheat the components. If things aren’t going as planed, stop and let things cool off.

After the boards are cut out, I solder on the components. Surface mounts can be hard to deal with if you haven’t done them before. First, solder flux is your friend. It can help stick the components in place, and makes the solder flow well. Second, a dental pick in your non-dominant hand can help pin the part against the board while you tack it down with the soldering iron. Get some solder on the tip of the iron and use that. Drag the solder across the fluxed pins and the solder should flow pretty evenly. If you get too much and short out pins, solder wick is an easy way to clean it up. I’d also keep some chip-quick around for removing components that didn’t go on like you thought they would or that let the smoke genie out.

There you have it. That’s how I build prototype circuit boards. Now it’s time to test it.

TDCS Controller Step 1 – Design

NOTE: This was an initial design, that evolved as I built and tested it. For the final design, complete with a description of each major component, see this post.

The fundamental building block for any TDCS controller is a current source capable of supplying between one and two milliamps of current through the human body. This can be a bit of a challenge because the resistance of the body varies with electrode placement, skin resistance (which can vary from one second to the next), body composition, and a bunch of other factors. The trick is to build a regulated current source capable of automatically adjusting the output voltage to get the desired current even with this rapid and unpredictable change in the person being exposed.

Digging through a pile of data sheets, I found a perfect solution already packaged and ready for integration. The LM334 current regulated source can be programmed to provide a constant current ranging from microamps to ten milliamps. All it takes it is a simple resistor to set the current. Two small and cheap parts are all that’s required for the basic circuit.

We’re I comfortable that nothing would ever go wrong, and didn’t want any feedback about what the thing is doing, that would be it. I could build one on a dime, and do it for just a few dollars. However, I’ve spent way too much time fixing electronics and have seen too many cases where the primary failure was a shorted out semiconductor to trust a piece of silicon to not short out. In fact, I made a good living in college taking advantage of that particular failure mode. If the regulator failed, there would be nothing to prevent a comparatively high current from flowing through my brain and doing significant damage. Clearly this thing needs a few more features.

First, I like the idea of being able to select a lower current setting. Most of the research I’ve seen uses either one or two milliamps, and I’d like to be able to use those two settings at least. I could pretty easily build in an adjustable resistor, but they are much more expensive than simple resistors, and I’ve not seen anything showing an advantage to being able to finely tune the output. Instead, I built in a switch and an extra resistor.

Pin 4 on the LM334 is the input power, and can be from 1 to 40V. The feedback resistance between the four output pins (R1 and R2) sets the output current.

Rather than switch R1 and R2 in and out of the circuit completely and deal with the undefined state that happens during the switch transition, I hard wired R2 into the circuit and selected it to produce a 1mA output. When the switch is closed, R1 is added in parallel with R2, cutting the effective resistance in half, and subsequently doubling the output current to 2mA. If the regulator doesn’t fail, the current won’t ever be anything other than 1mA or 2mA. A simple flip of a switch will seamlessly change the output between only these two values.

With that aspect of the design complete, the next step is to provide an indicator that the thing is on. It’s a simple matter of adding a resistor and an LED on the power line. The maximum voltage the regulator can handle is 40V, so I selected a resistor value that would limit the current to about 15mA or less through the LED at that input voltage. Lower voltages will still light the indicator, but it just won’t be as bright. For my purposes, that’s okay.

The LED is actually half of a two-color (red/green) led. When power is applied, the green LED will light up.

The last three things I want in the design can be incorporated with a single basic feature. I’d like some indication when current isn’t flowing, be able to monitor exactly how much current is actually flowing, and a safety feature to shut the thing down if the regulator fails for any reason. To do any and all of these things, I need to be able to monitor exactly how much current is actually flowing through the body.

It can be a little difficult to measure low currents without disturbing the system. Initially, I believed the pile of data sheets had a ready made answer. The TSC888CILT is designed to measure the voltage across a shunt resistor and provide a gain factor to make measurements easy. Combined with a 10 ohm precision resistor, the chip puts out a 1V/mA signal.

With a 0.1% Resistor on R3, and a gain of 100 built into the TSC888, the output on pin 1 comes out to a round 1V/mA so a simple panel-mount voltmeter can be used to monitor the current.

With a signal to monitor the output current I can do several things. First, and most importantly, I want the device to shut off completely if something goes wrong and current rises above a safety threshold. If the output current exceeds 5mA something has gone wrong, and 5mA is well below the damage threshold for tissue. The simple answer for circuit protection would be to put a fuse in the line. However, mA-range fuses are hard to find, are bulky, and may not react fast enough to satisfy me. On top of that, I’m not particularly keen on replacing fuses if I happen to accidentally short something out while testing. This is where the current sense signal comes in handy.

It’s pretty easy to set up an op-amp as a voltage comparator and use it to trigger a “crowbar” if the output current exceeds a set value. The idea of a crowbar is that it’s like dropping a metal crowbar across two electrical terminals to blow a fuse or trip a circuit breaker. With the 1V/mA sensing gain and a 5mA threshold current, all that is required is a 5V reference voltage on the inverting input and the current sense signal on the non-inverting input. For the reference voltage I used a simple zener diode and resistor. I also used a 4.8V zener because it was cheaper than the 5V ones available at the time, and because 4.8 mA is still high enough that I want to shut things down if the current goes that high.

U5 and R8 combine to form a constant 5V reference. If the voltage on pin 5 of IC1 exceeds this reference, the output of pin 7 goes to the positive supply rail. The other op-amp in IC1 is used as a threshold detector to turn on the red LED of U3 if the output current is below approximately 0.8mA. The voltage divider of R7 and R6 set the threshold voltage based on the 5V reference.

The output of the comparator then needs to drive the crowbar. I added a resetable fuse just after the power switch. This fuse is guaranteed to hold 100mA (plenty to run everything) and trigger before something like 250mA. The MCR08B Thyristor can handle 800mA, so it will happily load the fuse when triggered. The output of the voltage comparator will trigger U4, which will turn on and stay conducting until power is removed. When the SCR turns on, the resetable fuse opens up and cuts power until power is totally disconnected and the fuse cools. Theoretically, none of this part of the circuit should ever actually function, but I’m happier knowing it’s there. If the current regulator fails, the crowbar will shut things down without putting anyone in danger.

U2 is a 100mA resetable fuse which is tripped by U4 if the output current of the device goes above the safety threshold. This is a redundant safety feature to ensure that a short in IC2 (the current regulator) won’t expose anyone to dangerous currents.

Because the chip I used for the crowbar trigger has two op-amps, I have one to spare that I can use as a fault detector. If the output current falls bellow 1mA, either the electrodes are disconnected, the connections are poor (i.e. they are too dry), the battery is low, or something else is wrong. R6 and R7 form a voltage divider off of the 4.8v reference used for the crowbar, and sets an 840mV reference for the voltage comparator. Any time the output current falls below 0.84mA, the output of the op-amp goes high and turns the red LED on.

The last parts to add are jacks for power and to connect the output leads. I used a simple mono-headphone jack for the output, and a 2.1mm barrel jack for the input power. I also added a connector and a diode to make it so I can plug in a 9V battery instead of a wall-wart transformer. When connected to a human, you should run this thing on a battery all the time to make sure you don’t encounter any ground-loop issues. At a minimum, make sure that the output of your power supply is floating with respect to earth ground (if you don’t know what that means, use a battery). There are good reasons hospitals have outlets with the neutral floating with respect to the ground pin. Finally, I added some mounting holes to the diagram so they show up on the board.

All combined, the circuit looks like this:

The completed TDCS controller circuit with a 1mA/2mA current regulated source, a 1V/mA monitoring circuit, power and fault-indicator LEDs, and a safety crowbar to shut things down if something goes wrong. VDD is for powering a panel-mount digital volt meter hooked to TP1 to display the output current (optional), but I didn’t include that in the schematic.

I laid the board out in such a way that I can reliably make my own by using 15mil clearances between traces, and 20mil minimum traces. I could have made it much smaller if I were going to farm this board out to a fab house by putting components on both sides of the board, using small vias, and finer traces. However, I like rolling my own boards, so traces are pretty thick, all the components are on the top-side, and vias are large enough I can drill them, stick a wire through it, and solder it to both sides. The final board is just under 2″ on the long side.

Top board layout. The bottom board is almost all ground-plane with a few jumpers and pads for vias and through-hole components.

Now, on to making the board.

Another Project – TDCS Controller

CAVEAT: The design described here has fatal flaws. I’ve since re-designed it, and have left this here as a way to document the process and share the realities associated with designing even relatively simple things with whoever might read it. The current design is available here.

I don’t seem to be able to function well without some kind of project. Usually I have several waiting patiently for my attention. However, at the moment all my current ones require either time, money, or energy I just can’t afford to give. I have a coding project to finish the user interface for the antenna analyzer I designed and built. But that’s at a point where the interesting work is done, I’m stuck on something that should be easy, but there’s something I’m missing. I’ve been using the project to get better at C++, and have run into issues that probably stem from my poor understanding of class objects and their use in my implementation. I’m out of ideas, frustrated at my inability to figure it out, and just can’t convince myself to re-attack it. I’ll tackle it again, but not until I’ve quit being frustrated with it.

Many of the other projects require large enough chunks of money to move to the next step that they have to sit and wait for that arbitrary future when I’ll have enough cash to make more progress. Sometimes incremental progress isn’t really viable, so things just sit and collect dust. The rest (like my writing projects) require motivation and energy I just don’t have at the moment. I don’t have a good excuse other than I’m burned out on them. They’ll sit until I change how I feel about them.

I needed a project I could work on that didn’t take much creative energy, would keep my mind active, and that I could reasonably finish with the small budget I get to spend without having to impact the household finances. Thinking about it, I decided I’d try designing and building a Transcranial Direct Current Stimulator (TDCS). I’ve been seeing reports on the technology for years, and have watched agencies from DARPA to the Air Force research lab study it and demonstrate measurable effects. I’ve been curious to try it, but the controllers are either expensive, or I question the safety features in the slip-shod designs of products coming from places like China or fly-by-night hobby shops just trying to make a quick buck.

The basic concept behind the devices is really simple. The circuit applies a voltage just large enough to induce a small current through the head. Done right, the current is way below the threshold for causing any physiological damage. It can tingle or sting some, will probably leave a metallic taste in your mouth, and might cause a perception of a brief flash of light, but that’s about it. The theory behind its effect is that the small current creates a marginal potential in the brain that modulates the much stronger natural electrical signals already there. That modulation is thought to help selectively dampen or enhance those natural signals.

TDCS has shown clinical significance treating some forms of depression, anxiety, and chronic pain. It had been shown to increase user focus and accelerate learning. There are claims all over the place that it does everything sort of washing the dinner dishes for you. Some claims are backed up by robust research, others are anecdotal or even outright crap. I’m mostly interested in trying the more researched claims associated with depression and focus.

In particular, I’m interested in seeing how effective it would be against my particular variety of mood disorder. However, I’m not interested enough to buy a good device and not willing to risk attaching electrodes to my head driven by a device built and sold by Fast Eddy in his garage. I trust myself and the things I build in my garage. Not so much things built in other people’s garages.

So, with that in mind, I’m going to design my own. Over the next few posts, I’ll share the process and details. So without further adieu, on to Part 1 – Design.

Don’t Ask

How often do we casually ask someone we encounter how they are? Passing a casual acquaintance in the grocery store isle, the nearly universal greeting is to ask how they’re doing. Run into an old classmate you haven’t seen in a few decades who has their arms full of kids and is clearly on their way somewhere, and we ask how they’ve been. I know I’m guilty of it, and I’m pretty sure almost everyone else is too. This kind of callous or ignorant questioning needs to stop. We don’t really want to hear about our former classmate’s recent divorce and the ensuing financial difficulty. We don’t really want to know about how our co-worker is beside himself trying to figure out how to help a suicidal teenage daughter. They don’t want to hear our side of the story either.

Nobody’s life is boring enough to answer that question in a few syllables; and in reality, nobody really wants to answer it regardless of how much time you have to talk. The truth is, nobody can honestly say “fine” or “good” without perjuring themselves. Life is complicated. Those answers are not. However, those answers are the only socially acceptable variety.

When someone asks me that question, they aren’t really interested in hearing about how much I hate my job. They don’t have time to hear about the struggles I’m having raising my kids. They aren’t really interested in the difficulty I’m having with various medical issues. They don’t want to be faced with the reality of a midlife crisis in the makings. In short, they don’t really want to know how I’m doing. It would take too much time and emotional capital to listen, and then they would feel bad about being powerless to help. All people really want is to hear that you’re “fine” and then move along in their bubble of blissful ignorance.

Occasionally, someone actually does care, but then there is a different problem. Almost no one actually wants to talk about how they are doing. It’s depressing to think about it honestly. Even more than the people asking, I don’t want to think about how I’m doing. Life is easier when I can plug along mechanically without spending time thinking about things I can’t change. I’m happier when I don’t think about the things that make me unhappy. If you ask me how I’m doing, I have to ask myself; and the answer that returns isn’t often reassuring or comforting.

I suppose I could do the routine thing and mechanically answer “I’m fine,” but doing so makes me miserable because I know it’s at best a mischaracterisation, and more frequently an outright lie. Lying makes me even more miserable. I’d rather not do that.

I could tell the truth, but when you answer with any variant of “not good,” people instinctively ask why. Nobody (including myself) has the time or even the capacity to talk through complex and intractable problems then come out on the other end feeling better. In fact, it generally just makes everyone involved feel worse. Besides, the people asking are dealing with their own challenges, and life struggles shouldn’t be a competitive sport. They Don’t need to be weighed down with what I’m facing, and I don’t need to feel like you are trivializing my difficulty by sharing how much harder yours have been. You can’t compare pain and suffering, but that’s exactly what we tend to do when people start honestly talking about how they are doing.

So… After that rant… Can we please stop asking each other about how we are doing. It’s none of your damn business, and you don’t really want to know anyway.

First Rejection

I just received my first rejection letter from a queried literary agent.  Milestone achieved.  Now, the wait to see if there are any who think my attempt at a novel could possibly be profitable.

Update:  make that three, and the time has elapsed where I’m extremely unlikely to hear back from any of the others. Looks like a failed attempt all around. I guess I just overestimated my ability. 

Grandpa’s House

When I was young my parents would take us over to my maternal grandfather’s house almost every Sunday evening. I have a great many memories of that house and the people in it.

My Grandfather’s house was a small pale-green concrete-block structure built shortly after World War II in Kearns, UT. As originally constructed, it had three bedrooms, two bathrooms, a small kitchen, a living room, a small family room, and not much else. I doubt it was much more than about 1200 square feet. Grandma and Grandpa occupied the master bedroom with its rather small attached bathroom. As you came through the door to their bedroom, the wall on the left was covered with a number of cabinets enclosed with sliding doors. On the right wall was a small walk-in closet and the bathroom. The far wall and almost all of the floor was full with the bed. A desk and some shelving took the remainder of the space on the wall with the door.

The front door of the house opened into the living room, but we never used that door — friends and family came in the back door without knocking. If you did walk through it, you came past a small closet and entered the room with a black wood/coal burning stove immediately to your right and backed up against the wall to the closet. Beyond the stove on the right was the hallway to the kids’ bedrooms and the small shared bathroom. Grandpa’s room was across the living room to the left. A pocket door (that I never saw closed) opened into the kitchen from the back left corner of the living room adjacent to Grandpa’s bedroom door. I remember a piano on the wall between the kitchen and living room, a couch and a chair or two, but mostly I remember the stove.

By the time my memories become more than shadows, all of Grandma’s nine kids had grown up and moved away, so nobody slept in the kids’ rooms. However, there were only a few months between the oldest of my cousins and my youngest aunt. There was never a time when there weren’t a gaggle of kids around Grandma’s house, so the toys never got put away. Whenever we visited, we would eventually gravitate to the girls’ room (the one on the right), open the closet, and start pulling out the toys. In particular, I remember an old Fisher Price parking garage, Lincoln Logs, and Tinker Toys. All well worn and polished smooth with use, and all considered far too dangerous for young children these days.

I have fewer memories of the boys’ room. However, I do remember an electric exercise bike that was in there. The thing was built like a tank, and had an electric motor on it that could have driven a car. When you turned it on, the pedals would turn and the seat and handle bars would oscillate up and down. I never understood how it was exercise to let the motor push you around, but it was fun (if dangerous) to get on it in any number of unintended ways and turn it on — especially when we turned the speed all the way up.

In the hallway before you reached the kids’ rooms there was a cabinet built into the wall where Grandma and Grandpa kept games. Board games and card games like Uno were a staple at their house, but never face-cards. I have many memories of playing the game “Memory” with Grandpa. We would lay the tiles out on the floor in the living room, and Grandpa would play with us. As we took turns flipping over tiles looking for a match, Grandpa would invariably take the lead. He would always apologize with a giggle when he made a match at our expense, and we could tell he wasn’t even remotely sorry. Grandpa liked to win.

Behind the master bedroom and just off of the kitchen was the family room. This, along with the kitchen, was the center of the home. They had a television and two comfortable recliners where they would sit and enjoy shows like The Laurence Welk Show. I don’t remember if there was any other furniture, but there was another wood/coal burning stove set in a corner with brick behind and under it. There were nooks in the brick where there were small trinkets, and Grandpa hid his matches there under the bad assumption that we wouldn’t notice them. This room would house the Christmas tree (set in the corner and blocking the back-door to the master bathroom), and was where we did all the Christmas rituals.

When I was about eight or so, Grandpa and Grandma decided they wanted a little more space in the kitchen and somewhere to put a regular washer and dryer instead of the small stacking unit they had in the already crowded kitchen. I remember standing in the family room looking out the sliding glass door watching while Grandpa, Dad, and several of my uncles poured the concrete foundation for a small addition. I had been under the impression that I would get to help, but that wasn’t the case.

Grandpa’s yard was among my favorite places. Grandpa had grown up poor during the depression, and as such he worked hard to be self-sufficient. As a result, he always had series of gardens around the yard that grew all manner of vegetables that Grandma would can. There were also many fruit trees including at least two apple trees, an enormous cherry tree, a few peach trees, an apricot tree, and a plum tree. In case that weren’t enough, all the fences and a several trellises were covered in grapes. Anywhere you looked in Grandpa’s back yard, he was working to make it both beautiful and practical.

Towards the back of the triangular shaped corner lot he had built a play house and heavy-duty swing set with a teeter-totter. Behind the play house, he had built a sort of merry-go-round out of the hub and break drum of an old car axle. The swing set had to have been almost 12 feet tall, and you knew you were swinging high enough when your feet started to hit the branches of the nearby cherry tree. On more than one occasion, the teeter-totter functioned more like a human catapult than anything else.

There was a front porch across the house that had a few steel chairs that were painted white and designed so that the legs of the chair were more like leaf springs so you could rock/bounce in them. The driveway was on the left-side of the property, and was really quite long. It was wide enough for two cars parked next to each other, and long enough for probably four cars before it made it’s way back to the one-car garage. This large expanse of concrete was frequently full of cars from my aunts and uncles. However, one space was always occupied by the pop-up camper that Grandma and Grandpa used when we had our annual family reunion camp-outs in the Uintah Mountains or at Payson Lake.

The garage only fit one car, but it was rather wide given that limitation. Grandpa had built the garage with room for a workbench all along the right side of it. Under that workbench was a collection of tools and equipment, a bin for scrap wood, and the trap-door to a root-cellar he had conned my uncles into digging as a fort before building the garage over the top of it. I remember going out to the scrap wood box and getting out random scraps to play with and Grandpa telling us about how he used to do things like that during the Depression when money was so tight there weren’t any real toys to play with. I also remember going down into the root cellar and bringing up slightly withered apples to snack on.

Another feature Grandpa had built into the garage were coal bins on the right side. He would periodically buy a load of coal and fill the bins so he could heat the house with the two stoves. I remember going out with him to get a few shovels of coal on a few cold visits. Finally, the back three or so feet of the garage was a storage room that was only accessible from outside the garage.

Now… For some of the memories. There was always a small bowl of dried prunes, apricots, and apples sitting on the kitchen table. We would pick out the apricots and prunes because there were fewer of them, and they were sweeter. It usually only took a minute for us to clean it out, so grandpa would go to wherever he had more stashed (often the cupboards on the wall in his bedroom) and come doll out small handfuls with a warning that eating too many would give us belly aches. He seemed to have an almost endless supply thanks to the hard work he put into raising the fruit and harvesting it.

I also remember frequently coming into the kitchen through the back sliding glass door to smell fresh bread cooking and find my grandma there working on something delicious. Often we would ask for a snack, and she would offer up crackers. Almost always she would pull out salteens and graham crackers, then act surprised when we only really wanted the graham crackers. She knew before she offered that salteens were only acceptable if there were no other options.

I was always fascinated by the wood burning stoves. Fire has always had an indescribable draw, and I remember sitting on the fender of the stove in the living room feeling the warmth while I watched the glowing embers. One day, while I was quite young, my brother and I watched Grandpa build a fire in one of the two stoves. We realized that there was a place like that in our house. A metal box with flame inside.

Not long after, my brother decided to test that theory by loading the gas furnace with wood, starting with a broom sick. The end caught fire on the pilot light, and he pulled the stick out in a panic. It was very dry wood, and so it burned quite well and was sporting a two to three inch flame. My brother immediately snuffed the flame in the piece of carpet my parents had laid over the concrete under the furnace. It burned a perfect round hole in that carpet that stayed there for years.


You say I block you from success,
That my needs cannot be met,
Without sacrificing what you need.

You have not listened to understand,
Nor given me time to teach,
What and why or discuss alternatives.

There is space in the ground between,
What you need and want aren't one,
Step back and then meet me in there.

We can do what needs doing together,
We can both find some room to withdraw,
And then forward together much stronger.