micro-controller based potentiostatgopinath

83
MICRO-CONTROLLER BASED POTENTIOSTAT by Ashwini Vittal Gopinath A thesis submitted in partial fulfillment of the requirements for the degree of Master of Science, Computer Engineering Boise State University September, 2004

Upload: mageswaran1989

Post on 26-Dec-2014

1.153 views

Category:

Documents


2 download

TRANSCRIPT

Page 1: Micro-controller based Potentiostatgopinath

MICRO-CONTROLLER BASED POTENTIOSTAT

by Ashwini Vittal Gopinath

A thesis

submitted in partial fulfillment

of the requirements for the degree of

Master of Science, Computer Engineering

Boise State University

September, 2004

Page 2: Micro-controller based Potentiostatgopinath

The thesis presented by Ashwini Vittal Gopinath entitled “Micro-controller based

Potentiostat” is hereby approved:

____________________________________ Advisor Date

____________________________________ Committee Member Date

____________________________________

Committee Member Date

____________________________________

Dean, Graduate College Date

ii

Page 3: Micro-controller based Potentiostatgopinath

DEDICATION

To my grandparents Sri V.H. Vittal Narasimhaiah and Smt. Ratnamma. I thank my

parents Sri V. Gopinath and Smt. C.N. Nagalakshmi for giving me the opportunity to

come and study at Boise.

iii

Page 4: Micro-controller based Potentiostatgopinath

ABSTRACT

Remote detection and monitoring of environmental contaminants is a fast growing field

as it alleviates human interaction and decreases cost of operation. An embedded

potentiostat to detect the concentration of a chemical was built as part of an effort to

remotely detect and monitor environmental contaminants. A potentiostat is an electronic

instrument that allows the application of voltage waveforms of various shapes on a 3 or 4

electrode set-up and determine the current through the cell. In this work, the potentiostat

was used to perform cyclic voltammetry. Cyclic voltammetry is a technique in which a

triangular voltage is imposed on the electrochemical cell and the current through the cell

is analyzed. The current versus voltage curve of an electro-active chemical species that

undergoes red-ox behavior displays two prominent peaks, one in each direction of the

sweep voltage. The current peaks are indicative of the concentration of the chemical and

also provide other useful information. An embedded potentiostat system that extracts

the concentration of the chemical from the peak measurements was built. The entire

system was integrated on a printed circuit board of dimensions 3 cm X 13cm. The

correlation factor between concentration of chemical and current peak using the

embedded sensor system was found to be greater than 0.99.

iv

Page 5: Micro-controller based Potentiostatgopinath

TABLE OF CONTENTS

DEDICATION.................................................................................................................. III

TABLE OF CONTENTS................................................................................................... V

LIST OF FIGURES .........................................................................................................VII

LIST OF TABLES......................................................................................................... VIII

LIST OF FLOWCHARTS................................................................................................ IX

CHAPTER 1: INTRODUCTION....................................................................................... 1

CHAPTER 2: OVERVIEW................................................................................................ 3

2-2 SENSOR ELECTRODES.......................................................................................... 5

CHAPTER 3: PEAK CURRENT MEASUREMENT .................................................... 2

3-1 EXTRAPOLATION OF BASE LINE CURRENT............................................................ 5

3-1.1 L-method for finding the knee of a curve ....................................................... 5

3-2 REGRESSIVE LINE FITTING ................................................................................... 8

CHAPTER 4: INTERFACE DESIGN.............................................................................. 10

4-1 SCHEMATIC ....................................................................................................... 10

4-2 CIRCUIT OPERATION ........................................................................................ 13

4-2.1 Interface with serial D/A converter............................................................... 14

v

Page 6: Micro-controller based Potentiostatgopinath

CHAPTER 5: MICRO-CONTROLLER SETTINGS AND SOFTWARE ...................... 16

5-1 MODULE SETTINGS............................................................................................ 18

5-1.1 ADC settings................................................................................................. 19

5-1.2 Timer and CCP Module settings.................................................................. 22

5-1.3 SPI (Serial Peripheral Interface) module settings......................................... 23

5-2 ALGORITHMS .................................................................................................... 24

5-2.1 Control Flow for the system (the Main Subroutine)..................................... 25

5-2.2 Enable High Priority Interrupts..................................................................... 28

5-2.3 High Level Interrupt ..................................................................................... 29

5-2.5 Slope calculation........................................................................................... 32

CHAPTER 6: EXPERIMENTAL SET-UP...................................................................... 36

CHAPTER 7: RESULTS.................................................................................................. 38

CHAPTER 7: FUTURE WORK ...................................................................................... 51

APPENDIX A: CODE...................................................................................................... 52

APPENDIX B: PCB LAYOUT....................................................................................... 63

APPENDIX C: PARTS LIST ........................................................................................... 64

REFERENCES ................................................................................................................. 65

vi

Page 7: Micro-controller based Potentiostatgopinath

LIST OF FIGURES

Figure 1: Block Diagram of Potentiostat Circuit ................................................................ 3

Figure 2: i-E curve of cyclic voltammetry measurements with varying scan rates ............ 6

Figure 3: Schematic of interface between micro-controller and electrochemical cell...... 11

Figure 4: Flow diagram for potentiostat control system................................................... 17

Figure 5: Equivalent R-C network of electrode solution interface ..................................... 2

Figure 6: Baseline current and anodic peak current measurement with respect to baseline

current........................................................................................................................... 4

Figure 7: i-E curve for 5mM concentration at 100 mV/s.................................................. 39

Figure 8: i-E curve for 2mM concentration at 100 mV/s.................................................. 40

Figure 9: i-E curve for 1mM concentration at 100 mV/s.................................................. 41

Figure 10: i-E curve for 0.5mM concentration at 100 mV/s............................................. 42

Figure 11: i-E curve for 0.2mM concentration at 100 mV/s............................................. 43

Figure 12: i-E curve for 0.1mM concentration at 100 mV/s............................................. 44

Figure 13: Alternate circuit............................................................................................... 46

Figure 14: Calibration curve of anode peaks for potassium ferri cyanide........................ 49

Figure 15: Calibration curve for cathode peaks of potassium ferri cyanide ..................... 50

Figure 16: i-E curves for potassium ferri cyanide at 100 mV/s....... Error! Bookmark not

defined.

vii

Page 8: Micro-controller based Potentiostatgopinath

LIST OF TABLES

Table 1: List of parts ......................................................................................................... 12

Table 2: ADCON0 register settings.................................................................................. 20

Table 3: ADCON1 register settings.................................................................................. 20

Table 4: T3CON register settings ..................................................................................... 22

Table 5: CCP2CON register settings ................................................................................ 22

Table 6: SSPSTAT register settings ................................................................................. 23

Table 7: SSPCON1 register settings ................................................................................. 23

Table 8: Configuration of MAX5354 ............................................................................... 14

Table 9: Anode peaks after baseline current extraction.................................................... 48

viii

Page 9: Micro-controller based Potentiostatgopinath

LIST OF FLOWCHARTS

Flowchart 1: Main Sub-Routine........................................................................................ 26

Flowchart 2: High Priority Interrupts .............................................................................. 28

Flowchart 3: High level interrupt handle .......................................................................... 29

Flowchart 4: Interrupt service sub-routine (ADC handle)................................................ 31

Flowchart 5: Slope Calculation......................................................................................... 33

ix

Page 10: Micro-controller based Potentiostatgopinath

1

CHAPTER 1: INTRODUCTION

A potentiostat is an electronic instrument that imposes potential waveforms of

various shapes on an electrochemical cell and measures the resultant current through the

cell. A potentiostat uses a three or four electrode interface. In a three electrode system the

potentiostat controls the potential between the reference electrode and the working

electrode; the counter electrode provides the current through the cell but the amount of

current is limited by the electrochemical activity at the working electrode. The current

through the electrochemical cell is a function of the concentration of the electro-active

species, the voltage at the working electrode (with respect to reference electrode) and the

area of the working electrode. In this work, the potentiostat was used to carry out cyclic

voltammetric measurements. Cyclic voltammetry is a technique in which a triangular

voltage waveform is applied between the reference and working electrodes. An electro-

active chemical species that undergoes reduction-oxidation behavior produces a peak in

each scan direction; the peaks are called anodic and cathodic peaks. The current versus

voltage graph of a cyclic voltammamogram for a red-ox species resembles a duck curve;

the current builds to a peak, falls and levels off in each direction of voltage sweep. The

location of the current peak along the voltage axis is unique to a chemical and the height

of the current peak gives a measure of the concentration of chemical, provided the scan

rate and the area of working electrode remain constant.

Mageswaran
Highlight
Mageswaran
Highlight
Mageswaran
Highlight
Mageswaran
Highlight
Mageswaran
Highlight
Mageswaran
Highlight
Mageswaran
Highlight
Page 11: Micro-controller based Potentiostatgopinath

2

Potentiostats currently in use are laboratory desktop equipment with relatively

large footprints, bulky and costing thousands of dollars. There has been a lot of research

to miniaturize potentiostats in the last decade. Richard & others [REAY94] have built an

integrated CMOS potentiostat , which they later used to determine heavy metal

concentration [REAY95]. Mark & others [SHUL94] built an implantable potentiostat

radiotelemetry system that used enzyme electrodes to indirectly measure glucose

concentration in animals; a similar effort was carried out by Richard & others [BEAC99].

In all these cases, data has been processed offline and in some cases off-site, there has not

been an attempt to analyze the data in-situ during chronoamperometric or voltammetric

measurements. A miniaturized potentiostat that performs in-situ data analysis and

transmits an 8-bit word corresponding to the concentration of the chemical is built in this

work. The entire system is integrated on a printed circuit board.

Page 12: Micro-controller based Potentiostatgopinath

3

CHAPTER 2: OVERVIEW

A miniaturized potentiostat that uses cyclic voltammetric techniques to analyze

electro-chemically active red-ox chemical species was designed and built. The block

diagram of the potentiostat set-up is presented in figure 1.

MICRO- CONTROLLER

(Section 2-1)

OP-AMP CIRCUITRY (Section 2-1)

SENSOR ELECTRODES

(Section 2-2)

VOLTAGE CONTROL

CURRENT MONITOR

Figure 1: Block Diagram of Potentiostat Circuit

The micro-controller provides the control system for the potentiostat. There are two

interfaces between the micro-controller and sensor electrodes; the first interfaces is used

to apply the triangular voltage waveform to the electrochemical cell and the second

interface is used to apply analyze the current through the electrochemical cell. The op-

amp circuitry provides the interface between the micro-controller and sensor electrodes.

Page 13: Micro-controller based Potentiostatgopinath

4

2-1 Micro-controller & Op-Amp circuitry

The micro-controller controls the voltage applied between the reference and

working electrodes and takes periodic current measurements. The current values are

averaged to improve signal to noise ratio. The micro-controller extracts the baseline

current in both directions (explained in detail in “Chapter 3: Peak current

measurement”) by determining the knee of the curve between the beginning of sweep in

each direction and the respective peak in that direction. The micro-controller then

determines the peak of the curve with respect to the baseline current in each direction, the

concentration of the chemical is determined from the calibration tables stored in the

micro-controller.

A 10-bit up-down counter is implemented in the micro-controller to generate a

triangular voltage. The 10-bit counter value is fed to a serial D/A converter using the

serial peripheral interface (SPI) of the micro-controller. The triangular voltage is level-

shifted to the requisite range [-0.1 to +0.4V for potassium ferri cyanide] by an op-amp

circuit and then applied to the electrochemical cell. The current through the

electrochemical cell is fed to a current to voltage converter and then level-shifted and

amplified/attenuated to meet the input voltage ratings of the analog port of the micro-

controller. For every increment in voltage (every increment in the 10 bit up-down

counter) a corresponding current reading is recorded; 8 consecutive current readings are

averaged to improve the signal to noise ratio of the current readings.

Mageswaran
Highlight
Mageswaran
Highlight
Mageswaran
Highlight
Mageswaran
Highlight
Mageswaran
Highlight
Page 14: Micro-controller based Potentiostatgopinath

5

The op-amp circuits provide the signal processing necessary to interface the

voltage waveform from the micro-controller to the electrode interface. They also provide

the necessary signal processing to interface the current from the electrochemical cell to

the analog to digital (A/D) circuitry of the micro-controller.

2-2 Sensor Electrodes

The potentiostat interfaces with a platinum working electrode, a platinum counter

electrode and a silver reference electrode. The reference electrode is used to establish an

unchanging, constant potential in the electrochemical cell, against which other potentials

may be determined with relatively high precision. This is critical because the delta

change in peak location of 0.5mV can be important in precise electrochemical

measurements e.g. when determining thermodynamic or kinetic parameters for a red-ox

system. The working electrode is where the electron transfer of interest occurs. The

counter is usually a somewhat “sacrificial” electrode that merely serves to complete the

circuit. As long as the products of any electron transfer at this electrode do not interfere

at the working electrode, we don’t care what happens at this electrode. The counter

platinum electrode is larger in size compared to the platinum-working electrode so as to

prevent the limiting of current at the working electrode by the counter electrode. The

red-ox behavior observed during cyclic-voltammetry looks like a duck curve and is

shown in figure 2.

Page 15: Micro-controller based Potentiostatgopinath

6

Figure 2: i-E curve of cyclic voltammetry measurements with varying scan rates

Page 16: Micro-controller based Potentiostatgopinath

1

The location of the peak along the voltage axis is unique to a species; the height

of the peak correlates to the concentration of the electro-active species. The current peak

at 25 degrees centigrade is defined by the Randles Sevick equation:

ip = 2.69 * 105 * n3/2 * A * D1/2 * v1/2 * C amperes

where

n number of electrons transferred

A area of working electrode (cm2)

D diffusion co-efficient (cm/s)

V scan rate (V/s)

C concentration of chemical (M/cm3)

For a given set-up and electro-active species if the number of electrons, the area

of the working electrode and the diffusion co-efficient remain constant, then the peak

current can be varied either by varying scan rate or by varying concentration of electro-

active species. In this work, only the effects of change in concentration of electro-active

species are documented.

Mageswaran
Highlight
Page 17: Micro-controller based Potentiostatgopinath

2

CHAPTER 3: PEAK CURRENT MEASUREMENT

In chrono-amperometric and voltammetric measurements, there is a baseline

current due to capacitive charging between the electrodes and the bulk solution. The

impedance due to the solution and due to the interface between the electrodes and bulk

solution can be modeled as an R-C network [BOCK23] shown in figure 3.

Figure 3: Equivalent R-C network of electrode solution interface

where

Rc + Ruc – solution resistance

Ruc – uncompensated resistance

Cd – double-layer capacitance

Page 18: Micro-controller based Potentiostatgopinath

3

The charging current does not derive from any electron transfer process involving

the electro-active species and hence must be subtracted for proper estimation of anodic

and cathodic peak currents. The charging current also limits the detection limit of cyclic

voltammamogram to about 10-5M [KATZ04]. The baseline current and the anodic peak

current with respect to baseline current are shown in Figure 4.

Page 19: Micro-controller based Potentiostatgopinath

4

Figure 4: Baseline current and anodic peak current measurement with respect to baseline current

Page 20: Micro-controller based Potentiostatgopinath

5

3-1 Extrapolation of base line current

The baseline current in both anodic and cathodic sweeps is found by finding the

point of maximum curvature between the beginning of sweep and the corresponding

peak; a line is then fit through all the points on the left hand side of the point of

maximum curvature. The L-method [SALV__] is used to find the point of maximum

curvature or knee of a curve.

3-1.1 L-method for finding the knee of a curve

In the L-method, the knee of a curve is determined by fitting a pair of lines to the

data that produces the least root mean square error. The point at which the two lines

intersect is the knee of the curve.

Let the total number of data points be ‘b’; the partitioning the of the data points be

‘c’, i.e., the left hand set of data points are described by the points 1,..c and the right hand

set of data points are described by the points c+1,..b. The total root mean square error is

given by equation 2.

Page 21: Micro-controller based Potentiostatgopinath

6

RMSEc = 1/b {c * RMSE (Lc) + (b-c) * RMSE (Rc)} Equation 1 Where

RMSEc is the total root mean square error

RMSE (Lc) is the total root mean square error of the left hand side line

RMSE (Rc) is the total root mean square error of the right hand side line.

Since only the minimum of the root mean square value is used, root mean square

can be replaced with mean square error and since the divisor ‘1/b’ is a constant this also

can be removed, i.e. equation 2 can be simplified to equation 3

MSEc = c * MSE (Lc) + (b-c) * MSE (Rc) Equation 2

Where

MSEc is the total mean square error

MSE (Lc) is the total mean square error of the left hand side line

MSE (Rc) is the total mean square error of the right hand side line.

Page 22: Micro-controller based Potentiostatgopinath

7

The steps involved in finding the knee of the curve are described below.

• Vary ‘c’ from 2 to ‘b-1’

• Fit the left hand line to points 1,..c and the right hand line to points c+1,..b

• Calculate the total mean square error for each value of ‘c’

The least mean square error gives the point of maximum curvature or ‘knee’ of the

curve. Regressive line fitting is used to fit a line to the given data set.

Page 23: Micro-controller based Potentiostatgopinath

8

3-2 Regressive line fitting

In regressive line fitting, the slope and y-intercept of the line is found by

minimizing the mean square error between the data points and the line describing the data

points.

To find the slope and y-intercept of the best fit line through the given data points

The mean square error between expected and obtained values of data points has to

be minimized; i.e. (y - ỹ)2 has to be minimized, where ‘y’ is the given data set and ‘ỹ’ is

the expected data points or the values of the best fit line through the data points and is

given by equation 4.

ỹ = ax + b Equation 3 Where

‘a’ is the slope of the line

‘b’ is the ‘y-intercept’

To find the best fit line, we have to solve the set of simultaneous equations given below.

∂z / ∂a = 2 {a ∑x2 + b ∑x - ∑xy) = 0 Equation 4

∂z / ∂b = 2 {a ∑x + ∑b - ∑y) = 0 Equation 5

Page 24: Micro-controller based Potentiostatgopinath

9

solving for ‘a’ and ‘b’ from the above simultaneous equations

a = covariance (xy) / {variance (x) – mean(x) mean(y)} Equation 6

b = a * mean(x) – mean(y) Equation 7

The peak with respect to the baseline current is calculated in both directions. The

concentration of the electro active chemical species is then extracted from the calibration

curve. The calibration curve is formed using a set of standard solutions covering the

entire range of possible (or expected) concentrations.

Page 25: Micro-controller based Potentiostatgopinath

10

CHAPTER 4: INTERFACE DESIGN

4-1 Schematic

The micro-controller is interfaced to the electrode set-up of the electrochemical

cell using op-amp circuits. The op-amp circuitry provides the necessary signal

processing before feeding the triangular voltage signal to the electrode set-up as well as

the voltage equivalent current to the micro-controller. The schematic diagram of the

potentiostat showing the interconnections between the micro-controller and the op-amp

circuitry and between the op-amp circuit and the electrode set-up is shown in Figure 3.

Page 26: Micro-controller based Potentiostatgopinath

11

Figure 3: Schematic of interface between micro-controller and electrochemical cell

Page 27: Micro-controller based Potentiostatgopinath

12

A list of the components and a brief description of the components used in the

schematic are presented in table 1. The components can be acquired through Digikey and

more information is provided in Appendix C.

Part Part No. Description

U1 MAX5354 10 bit serial D/A converter

U2 CTX144 4 MHz ceramic resonator

U3 D6C 90 Push button for external resetting of micro-controller

U4 PT5061 Single input dual output voltage regulator

U5 LM148 Quad op-amp package

U6 LM741 Op-amp chip

U7 PIC18F452 Micro-controller

Table 1: List of parts

Page 28: Micro-controller based Potentiostatgopinath

13

4-2 Circuit Operation

This section is divided into two parts, the voltage control between the micro-

controller and the electrode set-up is presented in the first part and the current monitoring

between the electrode set-up and the micro-controller is presented in the second part.

The micro-controller generates a triangular voltage waveform to be fed to the

electrochemical cell using a 10 bit up-down counter. The digital output word from the

micro-controller is fed to a serial D/A converter using serial peripheral interface of the

micro-controller. The output voltage swing of the serial D/A converter is variable and

depends on the voltage on the reference pin (Vref pin of the MAX5354). A

potentiometer is connected to the Vref pin and the output voltage swing of the D/A

converter is controlled by changing the potentiometer settings. The output voltage of the

serial D/A converter is given by

Vout = Vref * cnt / 1023

where

Vout – output voltage of serial D/A converter

cnt – 10 bit up-down counter value loaded in the serial D/A register

(The counter value varies between 0 and 1023)

Vref – voltage on reference pin of serial D/A

Page 29: Micro-controller based Potentiostatgopinath

14

4-2.1 Interface with serial D/A converter

The serial D/A converter used in this work is MAX5354. The MAX5354 is a 10

bit serial D/A converter and uses a 16 bit serial word to update its registers. The 16 bit

serial word can be loaded in one block or it can be transmitted as two 8 bit words. The

16 bit serial word configuration is presented in table 2 from the MAX 5354 datasheet.

Table 2: Configuration of MAX5354

Page 30: Micro-controller based Potentiostatgopinath

15

When the MAX5354 register contents are being updated, the CS pin needs to be

held low. The control to the serial DAC is provided by the port C pins of the micro-

controller. The RC3 pin of the micro-controller provides the serial clock, the RC5 pin

provides the serial data and the RC0 provides the CS for the MAX5354 DAC. The

micro-controller sends out the 16 bit configuration as two 8-bit words. The CS signal is

held low during valid data transmission. The detailed software interface with the serial

DAC is presented in [MAXI97]

The output of the serial D/A is unipolar; to change the output voltage to bipolar an

op-amp level shifter circuit is used. A buffer is inserted between the counter electrode

and the level-shifted voltage; the buffer prevents loading of earlier op-amp stages by the

current drawn by the electrochemical cell. The reference electrode is connected to the

non-inverting terminal of a voltage follower circuit. The voltage follower circuit helps in

maintaining a constant potential at the reference electrode without drawing much current.

The working electrode is connected to the inverting terminal of a current to voltage

converter; this in effect keeps the working electrode tied to ground and also produces a

voltage equivalent of the electrochemical current at the output of the voltage converter.

The electrochemical current, now converted to a voltage is level shifted and

attenuated/amplified to bring the voltage into the 0-5V range acceptable by the micro-

controller and fed to the analog input port of the micro-controller.

Page 31: Micro-controller based Potentiostatgopinath

16

CHAPTER 5: MICRO-CONTROLLER SETTINGS AND SOFTWARE

The micro-controller used in this work is “PIC18F452”; the PIC18F452 was

chosen to provide the control system for miniaturized sensor systems under this grant in

an earlier work by Wesley A. Prouty [PROU03]. The PIC18F452 is a flash micro-

controller with 10 bit A/D converter and some of the features of the PIC18F452

[MICR04 b] are

• 32 KB program memory

• 1.5KB data memory

• Timer & Capture modules

• Serial interface module

• Interrupt priority levels

• Sleep mode of operation

Page 32: Micro-controller based Potentiostatgopinath

17

The micro-controller uses the timer-capture module to provide interrupts at

periodic intervals, during an interrupt the 10 bit up-down converter values are updated;

the A/D measurements are taken and the serial D/A contents are updated. The heart of

this project is the determination of the anode and cathode peaks with respect to baseline

current (explained in detail in Chapter 3). The micro-controller takes periodic current

measurements, extracts baseline current and determines peak of the current curve and

then extracts the concentration of the chemical. A flow-diagram of the control system for

the potentiostat is presented in figure 4.

Figure 4: Flow diagram for potentiostat control system

CONFIGURE A/D MODULE (Section 4-1.1)

CONFIGURE TIMER MODULE

(Section 4-1.2)

CONFIGURE SPI MODULE (Section 4-1.3)

ENABLE INTERRUPT & COLLECT DATA

PEAK DETECTION & BASELINE CURRENT

EXTRACTION (Section 4-2)

Page 33: Micro-controller based Potentiostatgopinath

18

The modules used and the algorithms implemented to design this functionality in

the micro-controller are presented in the following sections.

5-1 Module settings

The special events mode of the timer compare module is used for taking periodic

analog to digital measurements. The time period between two consecutive A/D

measurements is changed by loading different values into the compare register. When

the timer count equals the contents of the compare register, the go/done bit of the analog

to digital converter is set, thus initiating an A/D measurement. After the completion of a

A/D conversion, a high-level interrupt is generated. In the interrupt service routine, the

analog to digital value is read from the A/D conversion registers; 8 contiguous values are

averaged to remove noise and are stored in an array of length 256. After completion of a

scan (2048 counts, 1024 up counts and 1024 down counts), the interrupt is disabled and

the peak in both directions is computed. The knee of the curve [SALV__] in each

direction is computed and the slope of the left hand side of the curve is calculated. The

peak with respect to slope in each direction is calculated. The micro-controller stores the

calibration data of the curves in terms of slope and y-intercept of the best-fit line. The

concentration corresponding to the peak current value is determined by using the slope

and y-intercept of the calibration curve and an 8-bit data bit value corresponding to the

current is generated. The settings of the analog to digital module, timer module, compare

capture pulse width modulation module and master synchronous slave module are listed

here.

Page 34: Micro-controller based Potentiostatgopinath

19

5-1.1 ADC settings

The micro-controller A/D converter module has 4 registers

• A/D control register 0 – ADCON0

• A/D control register 1 – ADCON1

• A/D result high register – ADRESH

• A/D result low register – ADRESL

ADCON0 and ADCON1 are the control registers used to power up the analog to

digital conversion circuitry, select the analog input port and initiate analog to digital

conversion. The ADRESH and ADRESL registers hold the upper and lower bytes of the

analog to digital conversion results.

Page 35: Micro-controller based Potentiostatgopinath

20

The ADCON0 register bit settings used in this work are as shown in table 3, the bit

definition in detail can be found in the PIC18F452 datasheet [MICR04 b]. ADCON0

register powers up the A/D circuitry, selects the analog port for conversion and selects

the clock frequency for conversion.

Bit position 7 6 5 4 3 2 1 0 Function of bit ADCS1 ADCS0 CHS2 CHS1 CHS0 GO/DONE — ADON Setting 0 1 0 0 1 — 1

Table 3: ADCON0 register settings

The go/done bit is set at the start of a new analog to digital conversion; the bit is

cleared by the micro-controller upon completion of an ADC measurement.

The ADCON1 register settings are as in table 4. The ADCON1 configures the

reference voltage for the A/D module and selects the output format of the 10 bit A/D

result.

Bit position 7 6 5 4 3 2 1 0 Function of bit ADFM ADCS2 — — PCFG3 PCFG2 PCFG1 PCFG0 Setting 1 0 — — 0 0 0 0

Table 4: ADCON1 register settings

Page 36: Micro-controller based Potentiostatgopinath

21

The ADC conversion result is only 10 bits long and two formats are available to

store it – most significant 8 bits in ADRESH register and two least significant bits in

ADRESL register or 2 most significant bits in ADRESH register and the least significant

bye in the ADRESL register. The ADFM selects the format in which the ADC result is

stored; a ‘1’ indicates that the first 6 most significant bits in ADRESH are zeros. The

ADC result is stored in the registers ADRESH and ADRESL in the format shown below:

ADRESH 7 6 5 4 3 2 1 0 0 0 0 0 0 0 b9 b8

ADRESL 7 6 5 4 3 2 1 0 b7 b6 b5 b4 b3 b2 b1 b0

Page 37: Micro-controller based Potentiostatgopinath

22

5-1.2 Timer and CCP Module settings

The micro-controller 16 bit timer is an up counter which can be run either with

the internal (micro-controller) oscillator or from an external trigger source. The timer is

used in conjunction with the compare facility of the compare capture pulse width

modulate (CCP) register to generate a “special event trigger”. The “special event trigger”

sets the GO/DONE bit in the ADCON0 bit that starts an A/D measurement; it also resets

the timer. The TIMER3 register settings are shown in table 5. T3CON register powers

up the timer, chooses the trigger source for the time and also pairs the timer with capture

3 module.

T3CON Bit position

7 6 5 4 3 2 1 0

Function of bit

RD16

T3CCP2

T3CKPS1

T3CKPS0

T3CCP1

T3SYNC

TMR3CS

TMR3ON

Setting 1 0 1 1 0 X 0 1

Table 5: T3CON register settings

The compare/capture/pulse width module register settings are shown in table 6. The

CCP2CON register chooses between the compare/capture/PWM facilities of the module

and also enables special events mode.

CCP2CON Bit position 7 6 5 4 3 2 1 0 Function of bit

-

-

DC2B1

DC2B0

CCP2M3

CCPM2

CCP2M1 CCP2M0

Setting X X X X 1 0 1 1

Table 6: CCP2CON register settings

Page 38: Micro-controller based Potentiostatgopinath

23

5-1.3 SPI (Serial Peripheral Interface) module settings

The serial peripheral interface is used to send the 10 bit up-down counter values

to the serial analog to digital converter. The Master Synchronous Serial Port (SPI/I2C

module) has three registers – two control registers (SSPCON1 and SSPCON2) and a

status register (SSPSTAT). In SPI mode, the Master Synchronous Serial Port has four

registers – MSSP Control Register1 (SSPCON1), MSSP Status Register (SSPSTAT),

Serial Receive/Transmit Buffer (SSPBUF) and MSSP Shift Register (non-user

accessible). The settings of SSPCON1 and SSPSTAT register settings are detailed in

tables 7 and 8.

The SSPSTAT sets the clock edge for data transfer and other control information

for serial peripheral interface module.

SSPSTAT Bit position 7 6 5 4 3 2 1 0 Function of bit

SMP CKE D/A P S R/W UA BF

Setting X 0 X X X X X X

Table 7: SSPSTAT register settings The SSPCON1 register settings presented in table 8 selects the master/slave mode of

operation of the SPi.

SSPCON1 Bit position

7 6 5 4 3 2 1 0

Function of bit

WCOL SSPOV SSPEN CKP SSPM3 SSPM2 SSPM1 SSPM0

Setting 1 X 1 1 0 0 0 0

Table 8: SSPCON1 register settings

Page 39: Micro-controller based Potentiostatgopinath

24

5-2 Algorithms

The configurations of the different modules, the interrupts, the algorithms used to

implement the potentiostat control system in the micro-controller are detailed in this

section. The algorithms are presented in the form of flowcharts with a brief description

on each section; the software codes is presented in Appendix A.

Page 40: Micro-controller based Potentiostatgopinath

25

5-2.1 Control Flow for the system (the Main Subroutine)

The main sub-routine provides the control flow for the entire program. The

PIC18F452 micro-controller has one analog port – PORTA and four general digital

input/output (I/O) ports – PORTA, PORTB, PORTC and PORTD. Some of the ports

have special functions - PORTA is used for A/D conversions, PORTB is used for

hardware interrupts and PORTC is used for serial communications. For each cyclic

voltammetric measurement, the (I/O) ports of the micro-controller are configured. The

PORTC pins are configured as outputs, the serial peripheral interface uses PORTC pins

1, 3 and 5 for communication with the serial D/A converter. The PORTA pins are

configured as inputs, PORTA pin 1 is used for A/D conversion by the micro-controller.

The A/D conversions at periodic intervals are activated by enabling the special

events mode of the timer/capture module. The settings of all the modules - A/D module,

SPI module, and timer & capture modules are configured and then the interrupts for the

control system are enabled. The interrupt is disabled by the interrupt handler upon

reaching 2048 counts; the control is passed from the main program to the slope and peak

calculation sub-routine. Upon calculating the peaks in both directions and determining

the concentration of chemicals, the micro-controller switches off all the modules and

goes into sleep mode. In the sleep mode the micro-controller consumes less power and

thus helps conserve battery charge. The micro-controller configuration and the control

flow for the potentiostat is presented in flowchart 1.

Page 41: Micro-controller based Potentiostatgopinath

26

Flowchart 1: Main Sub-Routine

Start

Configure port C as output Configure port A1 as analog input

Enable special events mode for CCP2/Timer2 combination

Enable High Interrupts

Configure Timer

Configure ADC

Configure SPI

Load variables

Enable ADC peripheral interrupt

2

Page 42: Micro-controller based Potentiostatgopinath

27

2

Slope_area_peak

Wait for the A/D interrupt to be disabled

Close ADC

Close Timer3

Close SPI

Sleep

Disable all interrupts

Start

Stop

Flowchart 1b: Main Sub-Routine

Page 43: Micro-controller based Potentiostatgopinath

28

5-2.2 Enable High Priority Interrupts

The High Priority Interrupt Enable subroutine presented in flowchart 2 enables

the global interrupts, configures different levels of priority and enables both low and high

priority interrupts.

Start

Enable interrupt priority (Enable high and low priority

interrupts)

Enable all high priority interrupts

Enable all low priority interrupts

Stop

Flowchart 2: High Priority Interrupts

Page 44: Micro-controller based Potentiostatgopinath

29

5-2.3 High Level Interrupt

The high level interrupt vector is located 0x008. Upon receiving an interrupt, the

program counter is loaded with the value of the interrupt service sub-routine; the control

flow is presented in flowchart 3.

Start

ADC_handle

Stop

Flowchart 3: High level interrupt handle

Page 45: Micro-controller based Potentiostatgopinath

30

5-2.4 Interrupt service sub-routine (ADC handle)

The ADC handle sub-routine updates the contents of the 10 bit up-down counter

used to generate the triangular voltage waveform. The ADC handle also averages 8

contiguous current values and stores the result in a 256-byte array. Upon filling all the

elements in the 256 byte array, the ADC handle disables the interrupt. The control for the

ADC handle is presented in flowchart 4.

Page 46: Micro-controller based Potentiostatgopinath

31

Start

Clear interrupt flag

Send 10 bit up-down counter values padded with control information to serial peripheral

interface

Add ADC value to avg_ad_temp Increment cnt

Is cnt % 8 =0?

Divide avg_ad_temp by 8 and store in y_data array of size 256

Is cnt < 8?

Decrement up-down counter mem Increment up-down counter mem

Is cnt =2048?

Load up-down counter with all 1’s Disable ADC interrupt enable

Stop

Flowchart 4: Interrupt service sub-routine (ADC handle)

Page 47: Micro-controller based Potentiostatgopinath

32

5-2.5 Slope calculation

The Slope and Peak Calculation sub-routine calculates the peak in both anodic

and cathodic directions and finds the knee of the curve in both directions. It then

calculates the anodic and cathodic peak in both directions with respect to the left hand

side slope of the knee and is presented in flowchart 5.

Page 48: Micro-controller based Potentiostatgopinath

33

Start

i = 0;i < 256; i++

Declare variables

Is i = 0?

Initialize values for calculating peak in each direction

an_peak_loc <= 0 an_peak <= y_data [0]

Is y_data > an_peak?

an_peak_loc <= i an_peak <= y_data[i]

i=128;i <256; i++

Is i = 256?

Initialize values for calculating peak in each direction

cat_peak_loc <= 128 cat_peak <= y_data [128]

Is y_data < cat_peak?

cat_peak_loc <= i cat_peak <= y_data[i]

2

Flowchart 5: Slope Calculation

Page 49: Micro-controller based Potentiostatgopinath

34

Flowchart 5b: Slope calculation

2

peak_loc <= an_peak_loc increment <= 0

Knee

i = 2 + incr; i <peak_loc; i++

Initialize x_mean, y_mean, var_x & cov_xy to zero

j = 0+incr; j <= peak_loc; j++

x_mean <= x_mean + x_data[j] y_mean <= y_mean + y_data[j] var_x <= var_x + x_data[j] 2

cov_xy <= cov_xy + x_data[j] * y_data[j]

Loop i

Loop j

3

Page 50: Micro-controller based Potentiostatgopinath

35

Calculate peak with respect to slope

3

Is j = i-1?

Calculate left hand slope and y interface

Calculate right hand slope and y interface

Initialize x_mean, y_mean, var_x, cov_xy to zero

Calculate root mean square error of both left hand and right hand slope and add them to get total root

mean square error

Calculate least mean square error among all the iterations of i.

Store the left hand side slope and y interface at the point of least mean square

error in slope and y_int

Is incr = 0?

peak_loc <= cat_peak_loc incr <= 128

Store slope and y_int in an_slope and an_y_int

Store slope and y_int in cat_slope and cat_y_int

Loop j

Loop i

Stop

Flowchart 5c: Slope calculation

Page 51: Micro-controller based Potentiostatgopinath

36

CHAPTER 6: EXPERIMENTAL SET-UP

For testing the potentiostat, potassium ferri cyanide solution was used. The

potassium ferri cyanide solution was formed by dissolving potassium ferri cyanide

crystals in 0.1M potassium nitrate solution; a 1mL 0.1mM sodium hydroxide was added

to it. The potassium nitrate solution acts as an electrolyte to suppress migration so the

electron transfer in the electrochemical cell is only by diffusion. The potassium ferri

cyanide crystals were manufactured by Mallinkrodt supplies and were of analytical

reagent grade, the sodium hydroxide was manufactured by Fischer Scientific and was a

certified A.C.S. grade, the potassium nitrate was manufactured by Mallinkrodt supplies

and was of analytical reagent grade. Acid wash was used to clean the glassware and was

manufactured by Fisher Certified ACS plus grade and was diluted with 10:1 de-ionised

water. The silver electrode was manufactured by Alfa Aesar and was 0.5 mm Premion,

99.9985% metal basis, the platinum used for counter and working electrodes were 0.004

inches (0.1 mm) thick Premion manufactured by Alfa Aesar and has 99.998% metal

basis. All dilutions were carried out using de-ionised water and the solutions were stored

in cleaned poly bottles.

Page 52: Micro-controller based Potentiostatgopinath

37

The micro-controller was programmed using the MPLAB ICD2 in-circuit debugger

[MICR03]. The in-circuit debugger was also used to observe variables and extract data

from the micro-controller.

Page 53: Micro-controller based Potentiostatgopinath

38

CHAPTER 7: RESULTS

The potentiostat testing was carried out by applying cyclic voltammetric

technique on potassium ferri cyanide solutions of various concentrations. Potassium ferri

cyanide was used as it exhibits a reversible one electron red-ox process with rapid

kinetics. The potentiostat was tested with 100µM, 200µM, 500µM, 1mM, 2mM and

5mM solutions. The solutions were tested at 100 mV/s (milli volts/second) scan rate and

the triangular voltage was varied between +0.4V and -0.1V. The i-E curves for the

different concentrations and the baseline currents in anode and cathode directions are

presented in figures 7 - 12. The figures 7 - 12 are not true current versus voltage curves,

they are actually the plots of the data points for voltage and current stored in the micro-

controller and hence the axes are named equivalent voltage and equivalent current. There

are 256 data points for current with values in the range 0 to 1023. The A/D converter in

the micro-controller has 10 bit resolution; hence the range of current data points is

between 0 and 1023. The triangular voltage waveform applied between the reference and

working electrode is updated 1024 times and the current readings are taken every time the

voltage is updated. 8 contiguous current data points are averaged in the micro-controller

to improve signal to noise ratio; hence there are 256 current data points. The current data

points stored in the micro-controller were extracted by using the MPLAB ICD2 In-

Circuit Debugger [MICR03].

Page 54: Micro-controller based Potentiostatgopinath

39

0

200

400

600

800

1000

1200

020

4060

8010

012

0

equi

vale

nt v

olta

ge

equivalent current

5mM

duc

k cu

rve

Figure 5: i-E curve for 5mM concentration at 100 mV/s

anod

e sl

ope

cath

ode

slop

e

Page 55: Micro-controller based Potentiostatgopinath

40

0

200

400

600

800

1000

1200

020

4060

8010

012

0

equi

vale

nt v

olta

ge

equivalent current

2mM

duc

k cu

rve

Figure 6: i-E curve for 2mM concentration at 100 mV/s

anod

e sl

ope

cath

ode

slop

e

Page 56: Micro-controller based Potentiostatgopinath

41

1mM

con

cent

ratio

n

0

100

200

300

400

500

600

700

800

900

1000

020

4060

8010

012

0

equi

vale

nt v

olta

ge

equivalent current

Figure 7: i-E curve for 1mM concentration at 100 mV/s

i-E c

urve

anod

e sl

ope

cath

ode

slop

e

Page 57: Micro-controller based Potentiostatgopinath

42

50

0 uM

con

cent

ratio

n

0

100

200

300

400

500

600

700

800

020

4060

8010

012

0

equi

vale

nt v

olta

ge

equivalent current

500

uM d

uck

curv

e

Figure 8: i-E curve for 0.5mM concentration at 100 mV/s

anod

e sl

ope

cath

ode

slop

e

Page 58: Micro-controller based Potentiostatgopinath

43

200

uM c

once

ntra

tion

0

100

200

300

400

500

600

700

020

4060

8010

012

0

equi

vale

nt v

olta

ge

equivalent current

200

uM d

uck

curv

e

Figure 9: i-E curve for 0.2mM concentration at 100 mV/s

anod

e sl

ope

cath

ode

slop

e

Page 59: Micro-controller based Potentiostatgopinath

44

400

420

440

460

480

500

520

540

560

580

020

4060

8010

012

0

equi

vale

nt v

olta

ge

equivalent current

100

uM d

uck

curv

e

Figure 10: i-E curve for 0.1mM concentration at 100 mV/s

anod

e sl

ope

cath

ode

slop

e

Page 60: Micro-controller based Potentiostatgopinath

45

The i-E curves for 5mM and 2mM concentrations show chopped current curves,

this is because the current through the electrochemical cell is high enough to saturate the

op-amp circuits. To cover a wide range of concentrations, the potentiostat needs to have

different ranges of operation; a suggestion for the implementation of a potentiostat with

different ranges is presented in Figure 13. The important change in this schematic from

figure 3 is the insertion of a digitally controlled current switch [EG&G93]. The output

voltage of the current to voltage follower circuit depends on the value of the resistor

between the inverting terminal and the output of the op-amp. The digitally controlled

current switch, in effect changes the value of the resistance, thus providing the

potentiostat with different current ranges. The switch control is handled by the micro-

controller; the micro-controller has to determine current saturation and then switch to the

lower resistance.

Page 61: Micro-controller based Potentiostatgopinath

46

Figure 11: Alternate circuit

Page 62: Micro-controller based Potentiostatgopinath

47

The anode and cathode peaks for the 0.1mM concentration are masked by the

charging current of the electro-chemical cell; hence the lower limit for this potentiostat is

10-4 M concentration. The minimum detectable limit for cyclic voltammetric technique is

10-5 [KATZ04].

The potentiostat in this work has been optimized to work for the range between

0.1mM and 2mM (excluding extreme data points). The anode and cathode peaks after

baseline current extraction are tabulated in tables 3 and 4. The calibration curve for the

anode peak currents in the range 0.2mM to 1mM is presented in figure 14. The cathode

peak for the 2mM concentration does not result in saturation; hence the cathode peak for

the 2mM concentration is also included in the calibration curve for the cathode peak

currents in the range 0.2mM to 2mM range and is presented in figure 15. The correlation

factor between the current peaks and concentration of chemical for both anodic and

cathodic directions was found to be greater than 0.99.

Page 63: Micro-controller based Potentiostatgopinath

48

Concentration of chemical Anode peak with respect to baseline

Anode peak location

100 uM 36 127

200 uM 70 80

500 uM 179 81

1 mM 351 81

2 mM 504 81

Table 9: Anode peaks after baseline current extraction Concentration of chemical Cathode peak with respect

to baseline Cathode peak location

100 uM 51 195

200 uM 102 191

500 uM 225 191

1 mM 433 191

2 mM 507 191

Table 10: Cathode peaks after baseline current extraction

Page 64: Micro-controller based Potentiostatgopinath

49

Anod

e pe

aks

vers

us c

once

ntra

tion

050100

150

200

250

300

350

00.

20.

40.

60.

81

1.2

conc

entr

atio

n in

mM

equivalent current

Figure 12: Calibration curve of anode peaks for potassium ferri cyanide

Page 65: Micro-controller based Potentiostatgopinath

50

Cat

hode

pea

ks v

ersu

s co

ncen

trat

ion

0

100

200

300

400

500

600

00.

51

1.5

22.

5

conc

entr

atio

n in

mM

equivalent current

Figure 13: Calibration curve for cathode peaks of potassium ferri cyanide

Page 66: Micro-controller based Potentiostatgopinath

51

CHAPTER 7: FUTURE WORK

Future work will be to incorporate temperature and conductivity sensors,

determine effects of temperature and conductivity on measurements and incorporate the

same into calibration curves. A calibration look-up table can then be constructed with

respect to temperature and conductivity.

Page 67: Micro-controller based Potentiostatgopinath

52

APPENDIX A: CODE

//author: ashwini

//filename: potentio.c

//created on: 13th aug 2003

#include "potentio.h"

#include <adc.h>

#include <timers.h>

unsigned int cnt, ad_temp, avg_ad_temp, peak_avg, loop_cnt;

ram int mem;

unsigned int peak_loc, an_peak, an_peak_loc,

cat_peak, cat_peak_loc, no_elements, data_out, peak, area, timer_count;

float an_slope, an_y_int, cat_slope, cat_y_int;

float rms_err_least, rms_err_left, rms_err_right, rms_err;

unsigned char incr;

#pragma idata my_data

ram unsigned int y_data[256];

char x_data[256];

#pragma idata

Page 68: Micro-controller based Potentiostatgopinath

53

void ADC_handle(void); /*function prototype needed for goto below*/

void slope_area_peak(void);

#pragma code HIGH_INTERRUPT_VECTOR = 0x08

void high_ISR(void)

{

_asm

goto ADC_handle

_endasm

}

#pragma code

void slope_area_peak(void)

{

unsigned int peak, peak_loc;

int i, j, k, l;

float x,y, x_mean, y_mean, cov_xy, var_x, slope, y_int, left_slope, left_y_int,

right_slope, right_y_int;

Page 69: Micro-controller based Potentiostatgopinath

54

//calculate anode peak

for(i = 0; i < 128; i++)

{

x_data[i] = i + 1;

if (i == 0)

{

an_peak_loc = i;

an_peak = y_data[i];

}

else

if (y_data[i] > an_peak)

{

an_peak_loc = i;

an_peak = y_data[i];

}

}

for (i = 128; i < 256; i++) //calculate cathode peak

{

x_data[i] = 255 - i;

if (i == 128)

{

cat_peak_loc = i;

Page 70: Micro-controller based Potentiostatgopinath

55

cat_peak = y_data[i];

}

else

if (y_data[i] < cat_peak)

{

cat_peak_loc = i;

cat_peak = y_data[i];

}

}

peak_loc = an_peak_loc; incr = 0;

//calculate the knee of the curve for anode sweep

knee:for (i = (2 + incr); i < peak_loc; i++) //the first co-ordinate of right line runs through

2 and (peak_loc - 1)

{

x_mean = 0.0; y_mean = 0.0; var_x = 0.0; cov_xy = 0.0;

for (j = (0+incr); j <= peak_loc; j++) //calculate left and right slopes

{

x = x_data[j]; y = y_data[j];

x_mean += x; y_mean += y; var_x += x*x;

cov_xy += x*y;

if (j == (i-1))

{

Page 71: Micro-controller based Potentiostatgopinath

56

x_mean /= (i - incr); y_mean /= (i - incr); var_x -= (i -

incr)*x_mean * x_mean; var_x /= (i - incr);

cov_xy -=(i - incr)*x_mean*y_mean; cov_xy /= (i - incr);

left_slope = cov_xy/var_x;

left_y_int = y_mean - left_slope * x_mean ;

x_mean = 0.0; y_mean = 0.0; var_x = 0.0; cov_xy = 0.0;

}

else

if (j == peak_loc)

{

x_mean /= (peak_loc+1 - i); y_mean /= (peak_loc+1

- i); var_x -= (peak_loc+1 - i)* x_mean * x_mean;

var_x /= (peak_loc+1 - i); cov_xy -= (peak_loc+1 -

i)*x_mean*y_mean; cov_xy /= (peak_loc+1 - i);

right_slope = cov_xy/var_x;

right_y_int = y_mean - right_slope * x_mean ;

x_mean = 0.0; y_mean = 0.0; var_x = 0.0; cov_xy =

0.0;

}

}

rms_err_left = 0.0; rms_err_right = 0.0;

for (k = (0 + incr); k <= peak_loc; k++) //calculate rmse

{

Page 72: Micro-controller based Potentiostatgopinath

57

if (k < i)

rms_err_left += (y_data[k] - (left_slope * x_data [k] +

left_y_int)) * (y_data[k] - (left_slope * x_data [k]+ left_y_int));

else

rms_err_right += (y_data[k] - (right_slope * x_data [k] +

right_y_int)) * (y_data[k] - (right_slope * x_data [k]+ right_y_int));

}

rms_err_left = rms_err_left/(i-incr); rms_err_right =

rms_err_right/(peak_loc+1 - i);

rms_err = ((i - incr) - 1) * rms_err_left + (peak_loc -i +1)* rms_err_right;

rms_err /= (peak_loc - incr);

if (i == (2 + incr))

{

rms_err_least = rms_err;

slope = lef t_slope;

y_int = left_y_int;

}

else

if (rms_err < rms_err_least)

{

rms_err_least = rms_err;

slope = left_slope;

Page 73: Micro-controller based Potentiostatgopinath

58

y_int = left_y_int;

}

}

if (incr == 0)

{

peak_loc = cat_peak_loc;

incr = 128;

an_slope = slope;

an_y_int = y_int;

goto knee;

}

else

if (incr == 128)

{

cat_slope = slope;

cat_y_int = y_int;

}

an_peak = an_peak - (an_slope * an_peak_loc + an_y_int);

cat_peak = (cat_slope * (256 - cat_peak_loc) + cat_y_int) - cat_peak;

}

Page 74: Micro-controller based Potentiostatgopinath

59

#pragma interrupt ADC_handle

void ADC_handle(void)

{

PIR1bits.ADIF = 0; //clear interrupt flag

ad_temp = ReadADC();

//------------------------------------------------------------------

//update DAC contents-----------------------------------------------

//------------------------------------------------------------------

PORTCbits.RC1 = 0;

data_out = mem>>8; //upper 8 bits

putcSPI(data_out);

data_out = mem; //lower 8 bits

putcSPI(data_out);

PORTCbits.RC1 = 1;

//for testing purpose - update second DAC

PORTCbits.RC2 = 0;

data_out = ad_temp>>5; //first 3 ctrl bits = 000

putcSPI(data_out);

data_out = ad_temp<<3; //last 3 bits = 000

putcSPI(data_out);

PORTCbits.RC2 = 1;

//------------------------------------------------------------------

avg_ad_temp += ad_temp;

Page 75: Micro-controller based Potentiostatgopinath

60

cnt++;

if ((cnt%8) == 0) //average 8 values

{

y_data[cnt/8 - 1] = avg_ad_temp/8;//take the average of the values

avg_ad_temp = 0;

}

if (cnt < 1024)

mem = mem - 0x08;

else

mem = mem + 0x08;

if (cnt == 2048)

{

mem = 0x1ff8;

PIE1bits.ADIE = 0;

}

}

void EnableHighInterrupts (void)

{

RCONbits.IPEN = 1; //enable interrupt priority levels

INTCONbits.GIEH = 1; // enable all high priority interrupts

INTCONbits.PEIE = 1; //enable all unmasked peripheral interrupts

}

Page 76: Micro-controller based Potentiostatgopinath

61

void main(void)

{

start:

TRISC = 0x00; //configure ports C as output

TRISD = 0xF0; //configure pins 0 to 3 of PORT D as output and pins 4 to 7 as

input

CCP2CON = 0X0B; //Sp. events mode

CCPR2L = 0xC4;

CCPR2H = 0x04;

EnableHighInterrupts(); //enable global interrupt

OpenTimer3(TIMER_INT_OFF &

T3_16BIT_RW &

T3_SOURCE_INT &

T3_PS_1_4 &

T3_SYNC_EXT_OFF &

T1_CCP1_T3_CCP2); //configure timer3

OpenADC( ADC_FOSC_8 & ADC_RIGHT_JUST & ADC_8ANA_0REF,

ADC_CH1 & ADC_INT_OFF ); //configure ADC

OpenSPI(FOSC_4, MODE_01, SMPMID); //configure serial peripheral interface

mem = 0x1ff8; cnt = 0; avg_ad_temp = 0; peak_avg = 0; loop_cnt = 0; area = 0;

PORTCbits.RC1 = 1; //D/A conv i/p side

PORTCbits.RC2 = 1; //only for testing D/A

Page 77: Micro-controller based Potentiostatgopinath

62

PORTCbits.RC1 = 0;

data_out = mem>>8; //upper 8 bits

putcSPI(data_out);

data_out = mem; //lower 8 bits

putcSPI(data_out);

PORTCbits.RC1 = 1;

//Delay10KTCYx(256000);

//Delay10KTCYx(256000);

//Delay10KTCYx(256000);

//Delay10KTCYx(256000);

//Delay10KTCYx(256000);

//Delay10KTCYx(256000);

//Delay10KTCYx(256000);

//Delay10KTCYx(256000);

PIE1bits.ADIE = 1; //enable adc interrupt

while(PIE1bits.ADIE == 1);

slope_area_peak();

Delay10KTCYx(256000);

goto start;

}

Page 78: Micro-controller based Potentiostatgopinath

63

APPENDIX B: PCB LAYOUT

Page 79: Micro-controller based Potentiostatgopinath

64

APPENDIX C: PARTS LIST

PART NO.

DESCRIPTION

DIGIKEY CATALOG INFO [DIGI04]

COST

MAX5354 10 bit serial D/A converter

Pg. no.573 $7.61

CTX144 4 MHz oscillator Pg. no.722 $2.78

D6C 90 DPST switch Pg. no.1089 $0.94

PT5061 Single input dual output voltage regulator

Pg. no.1319 $16.2

LM148 Quad op-amp package

Pg. no.522 $2.98

LM741 Op-amp - -

PIC18F452 Micro-controller - $9.38

Resistors

Potentiometers

Capacitors

Page 80: Micro-controller based Potentiostatgopinath

65

REFERENCES

BAND02 Abhishek Bandyopadhyay, Grant Mulliken, Gert Cauwenberghs and Nitish

Thakor. "Vlsi Potentiostat Array for Distributed Electrochemical Neural Recording" Circuits and Systems, 2002. ISCAS 2002. IEEE International Symposium on, pg. no. II-740 - II-43.

BARD80 Allen J. Bard, Larry R. Faulkner. Electrochemical Methods - Fundamentals

and Applications, 1980. BEAC99 Richard D. Beach, Falko v. Kuster, and Frances Moussy, December 1999.

"Subminiature Implantable Potentiostat and Modified Commercial Telemetry Device for Remote Glucose Monitoring." IEEE Transactions of Instrumentation and Measurement , 1999, pg.no. 937-942 Vol. 48, No.6.

BOCK23 John O.M. Bockris, Amulya K.N. Reddy, Maria Gamboa-Aldeco. Modern

Electrochemistry. second edition, 1923. EG&G93 EG&G Instruments Corporation, “MODEL273A Potentiostat/Galvenostat

User’s Guide”, 1993. KATZ04 “Biosensors & Bioelectronics Home page of Eugenii Katz”. Available at:

http://chem.ch.huji.ac.il/~eugeniik/faq.htm KAKE95 Ralf G. Kakerow, Holger Kappert, Egbert Spiegel and Yiannos Manoli.

"Low-Power Single-Chip Cmos Potentiostat." The 8th International Conference on Solid-Sate Sensors and Actuators, and Eurosensors IX. Stockholm, Sweden, 1995. pg. no. 142-45. Vol. 1.

Page 81: Micro-controller based Potentiostatgopinath

66

MAXI97 MAXIM, “MAX5354 10-Bit Voltage-Output DACs in 8-Pin μMAX”, 1997.

Available at: http://ww1.microchip.com/downloads/en/DeviceDoc/39564b.pdf

MICR02 Microchip Technology, Inc. "Microchip Mplab C18 C Compiler Libraries".

2002. Available at: http://ww1.microchip.com/downloads/en/DeviceDoc/51297c.pdf

MICR03 Microchip Technology, Inc. “Microchip MPLAB ICD-2 In-Circuit Debugger

Quick Start Guide”, 2003. Available at http://ww1.microchip.com/downloads/en/DeviceDoc/51331a.pdf

MICR04

a) Microchip Technology, Inc. "Microchip Mplab C18 C User's Guide". 2004. Available at: http://ww1.microchip.com/downloads/en/DeviceDoc/51288c.pdf

b) Microchip Technology, Inc. “Microchip PIC18FXX2 Datasheet”, 2004. Available at:

http://ww1.microchip.com/downloads/en/DeviceDoc/39564b.pdf c) Microchip Technology, Inc. “Microchip PICDEM 2 PLUS User’s Guide”,

2004. Available at: http://ww1.microchip.com/downloads/en/DeviceDoc/51275b.pdf

NATI00 National Semiconductor, "LM741 Operational Amplifier", 2000. Available at:

http://www.national.com/ds/LM/LM148.pdf NATI03 National Semiconductor, “LM148/LM248/LM348 Quad 741 Op Amps",

2003. Available at: http://www.national.com/ds/LM/LM148.pdf

PEAT03 John B. Peatman. Embedded Design with the PIC18F452 Micro-controller.

Prentice Hall, 2003.

Page 82: Micro-controller based Potentiostatgopinath

67

PROU03 Wesley A. Prouty, “Embedded system design for multi-purpose sensors to detect and analyze environmental contaminants”, 2003.

REAY94 Richard J. Reay, Samuel P. Kounaves, Gregory T.A.Kovacs. "An Integrated

Cmos Potentiostat for Miniaturized Electroanalytic Instrumentation." IEEE International Solid-State Circuits Conference.: IEEE, 1994, pg.no.162-63.

REAY95 Richard J. Reay, Samuel P. Kounaves, Gregory T.A.Kovacs. "Microfabricated

Electrochemical Analysis System for Heavy Metal Detection." The 8th International Conference on Solid-State Sensors and Actuators, and Eurosensors IX. Stockholm, Sweden, 1995, pg. no.932-35, vol. 2.

Page 83: Micro-controller based Potentiostatgopinath

68

SALV__ Stan Salvador and Philip Chan. Determining the Number of Clusters/Segments in Hierarchical Clustering/Segmentation Algorithms. Florida: Florida Institute of Technology.

SAWY84 Donald T. Sawyer, William R. Heineman, Janice M. Beebe. "Chemistry

Experiments for Instrumentation Method”, 1984. SHUL94 Mark C. Shults, Rathbun K. Rhodes, Stuart J. Updike, Barbara J. Gilligan,

and William N. Reining. "A Telemetry-Instrumentation System for Monitoring Multiple Subcutaneously Implanted Glucose Sensors." IEEE transactions on biomedial engineering, 1994, pg. no. 937-42.

TEXA01 Texas Instruments, "PT5060 Series, 9-W, +5V Input Dual-Output Integrated

Switching Regulator", 2001. Available at: http://dkc3.digikey.com/PDF/T042/1247.pdf