**Note, version the version 1.2.3 PCB is now the standard version.
This is a minor update that adds status LEDs and improves USB connection reliability and it is otherwise compatible with older boards.
Older 1.2 boards will still be supported.**

# DStat Hardware
This is the documentation for the DStat hardware.

### Table of Contents:

* [Design Files](#design-files)
* [Materials](#materials)
    * [Printed Circuit Board](#printed-circuit-board-pcb)
    * [Components](#components)
	    * [Reference Key](#reference-key)
    * [Tools](#tools)
* [PCB assembly](#pcb-assembly)
* [Enclosure](#enclosure)
* [Connections](#connections)
    * [Voltammetry/Amperometry](#voltammetry-amperometry)
* [License Information](#license-information)

## Design Files
The hardware design files were created and can be edited in [KiCAD](http://www.kicad-pcb.org).
PDF versions of the electrical schematic and PCB layout can be found in the root directory: `dstat-mainboard-sch.pdf` and `dstat-mainboard-pcb.pdf`. The git repository can be cloned, or [click here](http://microfluidics.utoronto.ca/gitlab/dstat/dstat-hardware/repository/archive.zip?ref=master) to download the latest version.

## Materials
### Printed Circuit Board (PCB)
![full PCB](images/Full_PCB.jpg)

One DStat mainboard PCB is required for each potentiostat.
The specifications of the PCB are tuned for the [Pentalogix](http://www.pentalogix.com) US Quickturn Prototype PCB service, but many other companies are capable of fabricating the board.
Fabrication files can be generated with KiCAD or can be found in the `gbr` directory as standard Gerber files.
All files use mm as base units.
### Components
The list of electronic components required to build the DStat can be found in the `dstat-mainboard.csv` file, along with some suggested components (Vendor stock fluctuates constantly and you may have to replace things like resistors and capacitors with other parts if the suggested ones aren not in stock).
All components apart from pin headers are surface mount.
Take note of the package size in the `Footprint` column as most components come in multiples sizes.
The naming of the references in the file and notes regarding component selection follow:

#### Reference Key
| Reference | Component Type| Selection Notes |
| --------- | --------- | --------- |
| C | Non-polarized capacitor | Unless otherwise specified, 47u, 10u, 1u, 100n, 10n, 4.7n values can be wide tolerance parts |
| CON | PDI connector | 2x3 2.54x2.54mm pin header for programming µC |
| COUNTER | Counter electrode connection | Single hole for soldering wire or connector |
| FB | Ferrite bead | At least 40 Ω @ 100 MHz. DC resistance < 100 mΩ |
| IC | Microcontroller | Make sure this is not the QFN package |
| L | Inductor | |
| P | Various connectors | 2.54x2.54 mm pin headers |
| R | Resistor | unless otherwise specified, 100 values can be wide tolerance parts (5%) all others should be 2% or better |
| REFERENCE | Reference electrode connection | Single hole for soldering wire or connector |
| RSHIELD | Reference electrode shield connection | Single hole for soldering wire or connector |
| U | Integrated circuit | |
| UR | Integrated voltage divider | Need 1:1 divider |
| USB | USB mini B connector | PCB has holes drilled for connectors with alignment pins, but connectors without them will also fit. |
| WORKING | Working electrode connection | Single hole for soldering wire or connector |
| WSHIELD | Working electrode shield connection | Single hole for soldering wire or connector |
| X | Quartz crystal resonator | Surface mount HC49 package |

### Tools
![solder paste](images/paste.jpg)

To assemble the PCB, a few tools are recommended:
 * soldering iron
 * inspection microscope or magnifier
 * solder wick
 * tweezers
 * multimeter or continuity tester
 * solder paste
 * cotton or foam swabs
 * solvent suitable for removing flux (depends on type of solder paste, usually water or isopropanol)

## PCB assembly
A simple way to speed up assembly of the PCB is to use a small scale reflow technique in which solder paste is applied to the PCB, then heated with a hotplate to connect the components.
The mainboard can be soldered by hand but the fine pitch components make this difficult.

![bare pcb](images/PCB-bare.jpg)

1. Apply a small quantity of solder paste to each pad on the front of the PCB.
Pads for fine-pitch components can be covered with a continuous line of paste for each side—the surface tension of the melted solder will remove most solder bridges once heated.

    ![PCB with paste](images/PCB_paste1.jpg)
    ![PCB with paste](images/PCB_paste2.jpg)

1. Using tweezers, carefully populate the front of the PCB with surface mount components, making sure of the correct orientation of ICs. (Match the corner of the IC marked with a dot with the corresponding mark on the PCB)
The solder paste will help keep the components in place.
Perfect alignment isn't necessary as the surface tension of the solder will centre the components once melted.

    ![PCB with components](images/PCB_parts.jpg)

1. Heat the PCB on a hotplate following the recommended temperature profile for your soldermask.
Remove once cooled.

    ![PCB on hotplate](images/PCB_hotplate.jpg)

1. Inspect the front of the PCB for solder paste which has not completely melted, components that are not soldered to their pads, and pins on components that are bridged together with excess solder. (optical magnification is useful)
Defects can be corrected with a soldering iron by applying heat to single pins or removing excess solder with solder wick.

    ![IC with bridged pins](images/PCB_bridged_pins.jpg)

1. Solder the remaining components to the PCB by hand.
These include surface mount components on the back of the PCB and components that sit in holes (pin headers).

    ![Pin headers](images/PCB_through_hole.jpg)
    ![Back components](images/PCB_back.jpg)

1. Clean flux off the PCB using a suitable solvent, rubbing the surface of the board with a swab.
Especially if using water, ensure the board is completely dry before proceeding.

    ![PCB cleaning](images/PCB_clean.jpg)

1. Before attempting connection of the instrument, check for shorts from the power rails to ground using the multimeter. (The P8 connector provides both power rails and ground)
If any shorts are found, inspect components for solder bridges.

    ![Finished Board](images/PCB_finished.jpg)

## Enclosure
![Enclosure](images/dstat1.jpg)

AutoCAD drawings and stereolithography files for a simple 3D printed enclosure can be found in the [/enclosure](http://microfluidics.utoronto.ca/gitlab/dstat/dstat-hardware/tree/master/enclosure) directory. Five Pomona 2854-0 banana plug connectors are required and can be wired to the connections needed. Print one box, one USB_end, and one banana_end. No screws are needed, the two end pieces snap into the box.

## Connections
| Connector | Function |
| --------- | -------- |
| Counter | Output of potentiostatic amplifier. Drives counter electrode to control WE potential |
| Reference | Reference electrode input. Provides potential feedback near WE. |
| Working | Working electrode. Held on virtual ground by i-V converter—can sink or source current up to limit of op amp and current measurement is analytical signal. |
| Reference Shield | Follows Reference input. Can be connected to shield of Reference electrode coaxial cable or triaxial shield. |
| Working Shield | Follows virtual ground. Can be connected to shield of Working electrode coaxial cable or triaxial shield. |
| AVR-PDI | Programming connection for microcontroller. |
| 40-pin connector  | Provides access to unused microcontroller ports for connecting with other instruments or building expansion boards |
| P7 connector | Provides ground and virtual gound connections for testing and measurements |
| P8 connector | Provides ground, +3.3V, and +5V connections for external devices |
| USB | Provides power and data connection with a computer |

| Switches | Function (when closed) |
| -------- | -------- |
| U3A | Connects output of potentiostatic amplifier to Counter electrode connector. |
| U3B | Connects potentiostatic amplifier output to Reference electrode input. |
| U3C | Connects Working electrode input to transimpedance amplifier (i–V converter). |
| U3D | Connects Reference electrode buffer to potentiostatic amplifier input. |
| U12 (X0–7) | Selects between feedback components of transimpedance amplifier. |

### Voltammetry/Amperometry

*This information is for general reference and those interested in making changes to the firmware—the switches are automatically set by the firmware during normal operation*

For a standard 3-electrode cell, Working, Counter, and Reference electrodes connect to the corresponding connection points.
Switches U3A, U3C, and U3D should be closed during measurements.

For a 2-electrode cell, the Reference and Counter electrode connectors can be connected together externally or can be connected on the PCB by closing switch U3B.
For a standard 3-electrode cell, Working, Counter, and Reference electrodes connect to the corresponding connection points.
Switches U3A, U3C, and U3D should be closed during measurements.

## License Information
This wiki, the hardware schematics and layouts, and all other documentation describing the DStat hardware are licensed under the [CERN OHL v. 1.2.](LICENSE/LICENSE.pdf)
©Michael D. M. Dryden 2014

You may redistribute and modify this documentation under the terms of the CERN OHL v.1.2. (http://ohwr.org/cernohl).
This documentation is distributed WITHOUT ANY EXPRESS OR IMPLIED WARRANTY, INCLUDING OF MERCHANTABILITY, SATISFACTORY QUALITY AND FITNESS FOR A PARTICULAR PURPOSE.
Please see the CERN OHL v.1.2 for applicable conditions.