Friday, 24 August 2012

Circuit boards have arrived

I ordered some boards from SeeedStudio for the prototypes. Ten boards no more than 5cm by 5cm for less than $14 delivered to Australia was an offer I had to test out. From ordering to delivery took 18 days. I actually got 11 boards. Below are pics of the Eagle screenshot and the pile of boards with the first one I populated with components. I recovered the RN42 and MS5611 from an earlier prototype so they look  a little heat stressed.

Putting together the prototype with my soda can solder paste stencil and the skillet method took about an hour. Rather than put in the right angle headers for the programmer I just filled in the holes with solder and programmed using some pogo pins in the end of the PICKit2.

Based on the success with the first of these boards prototype I have ordered components to populate the rest of the boards. While I am waiting for these to arrive it will give me time to get back to improving the Android app.

Battery Rundown Test

The bottom line is that the BlueFlyVario prototype has a battery life of 17 hours. This is about three or four times the life of most Android devices that will run the app. It think it is enough.

Battery life in real world situations is important. Indications of charge level is something that routinely frustrates me with many devices. I get really annoyed when a device tells me that it goes from 90% charge to 50% charge in a few minutes, then stays there for a while, then all of a sudden goes down to 10% or completely flat. In most cases I think that the algorithm programmers use is screwed up. My aim for the BlueFlyVario is to be able to indicate charge level of the device to the user in a way that makes a lot of sense. Percent charge should mean percent of time remaining from a fully charged device.

Measuring charge level

Battery voltage can be used to give an indication of charge. The BlyFlyVario measures the battery voltage using an AD pin by measuring the voltage across the resistor divider (R6 -- R3). The resistor divider together is about 200k, and at about 4V 'consumes' only about 0.02 mA. It is only on when the switch is on so does not drain the battery when the device is off.

Calibration constants for battery charge level

My approach to battery charge level indication is to have the device spit out the voltage once every ten seconds. To calibrate the voltage requires two constants, one for the voltage from the TC1015 regulator (Vdd), and one for the ratio of the resistor divider network RDratio = R6/(R6+ R3). As each regulator and resistor is slightly different (manufacturing tolerances!) these constants are measured on each device after it is built using a multimeter, and the constants are programmed into the EEPROM of the pic. In practice Vdd is about 3.01 to 3.04, and RDratio is between 0.95 and 1.05. The battery voltage can then be calculated from the voltage measured at the AD pin (Vpin[16]). The formula used for the battery voltage is then:

Vbat = RDradio * Vdd * Vpin/1024

The value 1024 is because it is a 10 bit AD on the PIC.

Run Down Test

The battery voltage for LiIon/LiPO batteries follows a known curve, but it is slightly different for each battery model. I am using a Nokia type BL-5B battery (890 mAh). The graph below shows the battery voltage vs. time. In this test I connected to my PC test program via Bluetooth and let it run. From 'full' charge at about 4.16V it takes about 17 hours to get to 3.6V, which for practical purposes I will use as zero charge. It is possible to squeeze a little more from the battery, but to preserve battery health it makes sense to recharge the battery at that point. In the prototype it will continue to run past that point. I am not yet sure what I will do for production devices (auto shutdown or keep running).

Charge level

To get charge level from battery voltage I use a piecewise linear function. The pink line on the graph below is the piecewise linear approximation of % charge vs. time. It is just the same data as above with 3.6V equals 0%. The Android app uses this function to give charge level for a particular battery voltage.

Thursday, 2 August 2012

The Circut

Below is a picture of the current circuit I am using for the prototypes. I will spend a little time describing how it work and how to make it better. (Click on the picture for a full size one).

Battery Management

U1 (MCP73831) is a LiPo charge controller. The value of R2 controls the circuitry to charge the LiPo at 500mA. C1 and C2 stabilise the output and input voltage. R1 limits the current of LED1, which switches on when 5V comes in through the USB connector and sets the Status Pin (1) high. Note that the data lines of the USB connecter do nothing. With the switch S1 off, nothing no power is being drawn and nothing works.

Power Management

U2 (TC1015) is a 3V low voltage dropout regulator. C3 and C4 stabilise the output. R3 and R6 form a voltage divider so the voltage of the battery can be measured at a microcontroller input (configured as an AD converter). The input range for the PIN is 0 to 3V, the battery range is 3.30 to 4.20V. Splitting it to 1.65 to 2.10V allows the 10 bit AD to measure to about two decimal places, which is good enough as a battery monitor. I have updated the PIC code to output a battery measurement once every ten seconds. The exact value of R3 and R6 is not critical, but they must be matched as closely as possible. If the ohmmeter matches to two decimal places that is good enough. Generally you need to test about ten to get two which match that closely. As soon as power is applied U4, U3 and U6 all start working.


The PIC24F16KA101 has a simple circuit for basic operation. C6 is the standard decoupling cap between VDD and GND. C7 and R4 stabilise MCLR.  JP1 is currently a five pin right angle 0.1" header for programming via ISCP. I am planning to replace it with pogo pads to make it less clunky. I use LED 2 connected to pin 6 for microcontroller feedback. Currently it just flashes to let me know the microcontroller is working correctly, except when the RN42 is connected to a bluetooth host.

The PIC's pins 4 and 5 are connected to the UART on the RN42 for transmitting characters back and forth. PIC pin 14 is connected to the RN42 PIO2, which goes high when the RN42 is connected to let the microcontroller start sending data.

The PIC's pins 10, 11, 12 and 13 are connected to the MS5611 which uses the SPI interface.

RN42 Bluetooth transmitter

C5 is the standard decoupling cap between VDD and GND. RN42 pins 1, 12, 28 and 28 are all connected to GND. Pins 15 and 16 are connected for UART CTS and RTS feedback. This is not necessary, but is a legacy from some earlier testing. Pin 21 (PIO5) is connected to a status LED, which flashes to indicate connection state (flashing once a second - not connected, solid on - connected, solid off - not working, flashing faster - in special command mode).

MS5611 Pressure Sensor

Pin 2 (PS) is connected to GND to put the MS5611 into SPI mode (rather than I2C). C9, L1 and C8 work together provide the most stable power input possible. They form a pi filter. I think that I can further mess with these values to get it more stable, but really need an oscilloscope to see what frequencies the noise is.

Further work

There are a couple of changes that I might implement in future designs:
  • PIO4 (pin 22) of the RN42 should really have a exposed pad somewhere to allow me to factory reset the device.
  • I should connect RESET (pin 5) of the RN42 to a spare microcontroller pin so I can hold it low once battery power gets below a certain level (I think 3.5V).
  • The form factors of LED2, C9, C3, C1 and C2 could be smaller, particularly the caps. I used what I had. There are cheaper smaller options that will work just as well.

Prototype 2 and 3

Below are pictures of BFV prototypes 2 and 3. They both work just as well as the initial alpha prototype. You can probably see that prototype 2 was hand soldered using an iron and hot air, and has many 'green wire' hacks as I fiddled with the circuit design. Prototype 3 is the one that was soldered with the paste stencil and it is much neater.

I chose this size for the PCB as it fits perfectly in a tic-tac box. I chose the Nokia BL-5B battery form factor as this ~800 mAh battery is widely available, cheap (less than $3 including shipping from ebay), and has easily accessible electrodes. The SMD side switch I chose is also readily available from ebay.

Cost update

I did a quick analysis of the raw component cost to get this far. These costs are all in Australian Dollars but US Dollars are about the same (currently). The cost, including shipping of components to me and consumables used in prototype manufacture, adds up to about $47. This is less than the prediction of $55 I made year ago, and less than my target of $50. It includes battery, box (with free candy), pcb (from SeeedStudio - if that works out), and all components. The two most expensive components, the RN-42 and MS5611, together cost about $27 base price (about $35 with shipping to me).

Shipping of prototypes from me to Australian customers is about $5, but $10 -$15 to the rest of the world. Each one will take me a few hours to assemble, program and test. I am planning for $70 to be 'unit cost price' to have 10 prototypes shipped to testers. I would love to do it for free but there is no big company to pay.

I think I can reduce component cost by about 30% down to $30 to $35 if I was to make 100, and perhaps down below $25 if I was to make 1000+. But I am going to start with 10 if there is enough tester interest.

Below is a better picture of Prototype 3.

DIY Solder Paste Stencil - Etched soda can

Sparkfun have a great tutorial on how to use a solder stencil to make placing SMD components easier prior to using the skillet reflow method. It is awesome just how well this works. However, getting a stencil made and shipped takes time, and it is not cheap for one off prototypes. This post describes what worked very well for me. If I was going to do hundreds of boards I might use steel, but this is cheap and easy. The soda can aluminium can thickness is also about perfect to put just the right amount of paste on. Read the following like a tutorial. I assume you can do toner transfer and you know how to handle chemicals safely.

You will need: A soda can (full helps), scotchbrite scourer, toner transfer stuff (see above), Phosphoric Acid (sold as rust or aluminium cleaner from a hardware store), Hydrochloric Acid.

Step 1: Make sure you select an un-dented soda can, scour off the paint on the outside of the can until it is smooth aluminium and clean with water. This is easier when the can is full. Empty out the soda (don't drink it - that stuff will kill you!)

Step 2: Carefully cut the can to get a sheet of aluminium. Try really hard not to bend it. You want a smooth sheet. Flatten it by pulling across the edge of a table, or under a ruler smoothly. Cut out a bit about 2cm larger all around than the PCB. Use the scotchbrite again to remove the coating from the inside of the can to get to bare aluminium. You might be tempted to leave the inside on as a resist, but it will probably have micro holes in it by the time you etch. Also it is more difficult to remove after etching.

Step 3: Prepare the artwork. Ensure you come in from the edge of your pads by 4 mil all around. The etched area will be larger than your artwork, especially in fine areas. In eagle you can use the design rule setting Cream|Masks to change the tCream layer to be smaller than the pads. Export the artwork, make it negative (using MS Paint), and mirrored. The last part is important. You might think you can just flip the stencil over, but the etched hole walls are at an angle and smoothing on the paste works best if the holes are larger on the top than the bottom.

Step 4. Transfer toner like you are used to.

Step 5. To prepare for the etch mask the bottom side of the board and around the edges of the toner with clear tape. It needs to be clear so you can judge the end of the etch properly.

Step 6. Prepare the enchant. I use a 50:50 mix of Phosphoric Acid (mine is about 600g/L) and HCl (30%). The exact proportions do not matter. This etch works because the Phosphoric acid removes the oxidation, while the HCl attacks the bare metal. I dilute the etch mix with water to about half strength to slow the etch. I think diluting with methylated sprits is probably a better idea. That would help to reduce the foaming I think.

Step 7. Etch. It will start really slow, then gradually speed up as the Phosphoric Acid removes the oxide layer. Soon you will see bubbles forming and it will start to foam. Constant agitation is your friend. For me it takes about 10 minutes to etch through the thickness of the soda can. As it progresses make sure to regularly check for the end point (like every 30 seconds or so). If you etch for too long the undercut will make your paste stencil holes to big and join up. For most pads you will see that they etch faster near the edges. The trick is to stop as soon as the edge of each pad is 'cut' by the etch. Check by dunking in water and looking at the bottom with light from behind. Do not worry about the middle of each pad, the bottom tape will pull that away when it is removed.

Step 8. Remove all of the tape carefully then remove the toner with toluene or xylene.

Step 9. Dry and check. Follow the Sparkfun tutorial to do the pasting. I smooth the paste on with a razor blade. I got my paste from DealExtreme, it seems to work with fine pitch SMD components.

Below is a picture of one of my stencils. Note the fine pitch SSOP components.

Playing with PCB's

For most of the last few months of messing around with the development of the BlueFlyVario I have been playing with prototyping PCB's. Before I go on I have some important advice:

DON'T DO THIS! At one point I figured it would be a good idea to be able to produce PCB's myself for a run of about 10 to 50 prototypes. After a few months of fiddling around, trying all kinds of different methods, I have one PCB that I am happy with. Just one. I think it has cost me quite a bit to produce it. I am about 50% confident I could produce another in about two hours, but I might screw it up. In this post I am going to describe what worked for me and what didn't. The bottom line is that I recommend getting PCB's produced in a fab house. I have just ordered a batch from SeeedStudio to check them out.


I used Eagle. It is pretty common amongst hobbyists. After a few hours I got used to the interface. Sparkfun has some good tutorials.

Substrate and Etching

I started with standard double sided 1.6mm FR4, the 1 oz copper kind. After screwing up quite a few times I now understand how important it is to prepare the surface very carefully. The method that works best for me involves using wet 400 grit sandpaper in a random fashion. This works best with a small sanding block to ensure the surface is completely flat.

I tried all kinds of methods for etch resist. Drawing using a sharpie is useful only in patching up areas where fine detail is not important. I spent some time messing with dry film negative acting photo resist (the DuPont stuff you can get in small quantities on ebay). This is used in professional fab houses and I thought would be a great idea. It comes with the promise of being able to get 6mil traces in optimised production environments. In practice I was able to get 16 mil traces, but with most boards there were always errors. The obstacles to overcome include:
  • Getting the film to stick with no bubbles. This is tricker than trying to get a screen protector on with no bubbles. Just one small bubble with screw things up as the etch gets under the resist in the wrong places. Being very careful and using a pouch laminator helps a lot.
  • Producing artwork thick enough. Toner on clear film worked best.
  • Getting exposure right. I used a BugZapper lamp (40W I think) at 30cm for three minutes. That worked well.
I have ended up relying on toner transfer. I can now get 10mil traces and spaces with no problem. There are tutorials all over the net on how to do this. Some pointers that worked for me:
  • I use a cheap HP mono laser printer. The toner seems to be heavy enough, even on ground plane pours, and it melts at the right temperature.
  • I tried lots of different paper. In the end paper from an Australian Who magazine works best. The idea is to get the glossiest possible paper that is very thin and breaks down well in water. Glossiness prevents the toner getting too intertwined with the paper fibres, thinness ensures the heat and pressure gets through the paper to remelt the toner, and being easily dissolvable in water helps the paper come away.
  • I used a cheap A4 pouch laminator. It takes 4 to 12 passes to get the board hot enough to melt the toner. It is all about the right temperature, not the number of passes. If you do one pass, then wait until the board cools down, you need to start again. It is also important to ensure the paper does not move around. The best method I found was to ensure the paper was a little smaller than the board (so it does not hang over the side and get stretched in funny ways, attaching only one side with a piece of tape (the side fed into the laminator first).
  • To release the magazine paper it just needs a few minutes soaking in warm water, then very carefully pealing off the paper. Some will stick to the toner which is stuck to the board. I used light rubbing with my thumb under water to carefully remove the paper from between fine SSOP pads. If any toner comes off the fine bits you will need to start again. If the board is too dirty or too smooth the toner will not stick. This is tricky to get right.
This bit is dangerous if you do not know what you are doing. I use an etch consisting of one part HCl at 30% strength (Mutaric acid or Hydrochloric Acid from the hardware store) and two parts 3% H2O2 (Hydrogen Peroxide from the chemist). Constant agitation should see the exposed copper come off in a few minutes.
To remove the toner I use toluene/xylene based paint thinners. Any strong non-polar aprotic solvent will work better than acetone, which for some strange reason seems to be the standard.

Holes and vias

I thought it might be a good idea to have a crack at through hole plating the vias. This in theory involves drilling holes prior to etching, and some electrochemistry. I failed at the hole wall activation stage, mostly because I could not source a fine enough graphite powder without forking out a wad of cash and waiting weeks for delivery. I figured a really good hole wall activation mix would be toluene, graphite powder, and polystyrene. Polystyrene dissolves in toluene well, the resulting mix is not very viscous and flows well into the holes, it also allows a fine suspension of graphite powder to be maintained. Once dry, a very thin film of polystyrene holds the graphite in place. It further smooths if heated and forms a thin film of very conductive polymer, provided the graphite powder is thin enough. I gave up once I worked out that wire is good enough.

Quality fine PCB drill bits can be got on ebay for about $1 each. My solution for working diy vias involves drilling with a 20mil bit (after etching). I make the via pads 70mil in diameter which helps to ensure that even the two copper sides are not perfectly aligned, then it might still be ok. I then put a small copper wire through the hole (I use single core wire from stripped down CAT 5 cable - it is just about the perfect size). I make the wire flush on top, but with about 0.2 to 0.4 mm of protrusion on the bottom side which is stamped flat with a modified hole punch prior to a small flat dab of solder on the bottom side only. After SMD components are in place I then put a dab of solder on top.