<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
		<id>https://airwiki.deib.polimi.it/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=PaoloVilla</id>
		<title>AIRWiki - User contributions [en]</title>
		<link rel="self" type="application/atom+xml" href="https://airwiki.deib.polimi.it/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=PaoloVilla"/>
		<link rel="alternate" type="text/html" href="https://airwiki.deib.polimi.it/index.php/Special:Contributions/PaoloVilla"/>
		<updated>2026-04-13T09:21:07Z</updated>
		<subtitle>User contributions</subtitle>
		<generator>MediaWiki 1.25.6</generator>

	<entry>
		<id>https://airwiki.deib.polimi.it/index.php?title=File:WAD_UARTMux.jpg&amp;diff=9588</id>
		<title>File:WAD UARTMux.jpg</title>
		<link rel="alternate" type="text/html" href="https://airwiki.deib.polimi.it/index.php?title=File:WAD_UARTMux.jpg&amp;diff=9588"/>
				<updated>2009-12-12T09:55:11Z</updated>
		
		<summary type="html">&lt;p&gt;PaoloVilla: uploaded a new version of &amp;quot;Image:WAD UARTMux.jpg&amp;quot;&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>PaoloVilla</name></author>	</entry>

	<entry>
		<id>https://airwiki.deib.polimi.it/index.php?title=File:WADWireless_Pub.jpg&amp;diff=9587</id>
		<title>File:WADWireless Pub.jpg</title>
		<link rel="alternate" type="text/html" href="https://airwiki.deib.polimi.it/index.php?title=File:WADWireless_Pub.jpg&amp;diff=9587"/>
				<updated>2009-12-12T09:54:33Z</updated>
		
		<summary type="html">&lt;p&gt;PaoloVilla: uploaded a new version of &amp;quot;Image:WADWireless Pub.jpg&amp;quot;&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>PaoloVilla</name></author>	</entry>

	<entry>
		<id>https://airwiki.deib.polimi.it/index.php?title=Wireless_Affective_Devices&amp;diff=9586</id>
		<title>Wireless Affective Devices</title>
		<link rel="alternate" type="text/html" href="https://airwiki.deib.polimi.it/index.php?title=Wireless_Affective_Devices&amp;diff=9586"/>
				<updated>2009-12-12T09:53:52Z</updated>
		
		<summary type="html">&lt;p&gt;PaoloVilla: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{Project&lt;br /&gt;
|title=Wireless Affective Devices&lt;br /&gt;
|tutor=SimoneTognetti;MatteoMatteucci&lt;br /&gt;
|students=PaoloVilla&lt;br /&gt;
|resarea=BioSignal Analysis&lt;br /&gt;
|restopic=Affective Computing&lt;br /&gt;
|start=2008/01/08&lt;br /&gt;
|end=2009/12/30&lt;br /&gt;
|status=Active&lt;br /&gt;
|level=Ms&lt;br /&gt;
|type=Thesis&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Project aims ==&lt;br /&gt;
&lt;br /&gt;
 ”''Everyone knows what an emotion is, until asked to give a definition''”&lt;br /&gt;
                                         &lt;br /&gt;
                                                                 Beverly Fehr and James Russell&lt;br /&gt;
&lt;br /&gt;
Research on Human-Computer-Interfaces has recently begun to take into account the affective state of the user. By appropriately reacting to the affective user state, interfaces could not only become more pleasant or entertaining, but also more effective or safer.&lt;br /&gt;
It is known that affective states have bodily correlates, and thus physiological signals could provide the necessary information for acquiring the affective user state. In contrast to other sources of information about the affective user state such as speech or facial expression, most physiological signals are not under voluntary control, and thus cannot be masked up to the same extent. Furthermore, it can be presumed that the signs of affective states in physiological signals are less dependent on individual and contextual factors: this is because the signals correspond to internal physiology, largely related to the autonomous nervous and limbic systems, rather than to external expressions that can be manipulated easily.&lt;br /&gt;
Recently, the issue of emotion regulation drew interests from several fields including neuroscience, psychology, education, computer science, etc. Possible applications are e-learningin, human computer interaction, development of communicative technologies for use by people with autism, car infotainment system, lie detection tests, cognitive workload, multimodal user interfaces MMUI (allow users to control computers using speech and gesture), etc.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The project is aimed at developing a device, connected to a PC, to acquire biological signals (such as GSR, BVP, Temperature and Head orientation) in a way that is less invasive for the subject. The term invasive is related to how much the sensors we use compromise the normal interaction between subject and machine.&lt;br /&gt;
Through these biological signal the PC is able o understand emotion in people who wear the device.&lt;br /&gt;
&lt;br /&gt;
An affective device should be weared easily, should not have cables and should acquire as much sensors as possible. We relax some constraint on the quality of signal but we add constraint on way they are acquired(i.e. the subject can put it on easily, the usual movements are not influenced..). The aim of the resulting device is not to replace the standard medical devices usually used to acquire that signals, but is to be much more suitable for industrial application in which the medical requirement are replaced by invasivity requirement.&lt;br /&gt;
&lt;br /&gt;
It is composed by:&lt;br /&gt;
&lt;br /&gt;
* Low power, high efficiency, battery powered design&lt;br /&gt;
* Wireless comunication with a PC&lt;br /&gt;
* Blood Volume Pressure Sensor (Preliminary release by Mattia Colombo)&lt;br /&gt;
* Galvanic Skin Response Sensor (Preliminary release by Sala Mirko e Alessia Cornaggia)&lt;br /&gt;
* Temperature Sensor&lt;br /&gt;
* 3 Way Accelerometer&lt;br /&gt;
* Possibility of further extension&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''GSR (or EDR or EDA)'''&lt;br /&gt;
&lt;br /&gt;
An often misunderstood and difficult technique, GSR (also known as the electrodermal response EDR or electrodermal activity EDA) has gone through many phases of interest and rejection since the early 1900's and is very popular in psychophysiological studies since Carl Jung and his students (1907) described it as a mean to&lt;br /&gt;
enter the “sea of the unconscious” because “every stimulus accompanied by an emotion produced a deviation of the galvanometer” directly proportional to the strength of the emotion aroused. It has been used in important research on anxiety and stress levels (Fenz &amp;amp; Epstein, ' 67); and it has been a part of lie detection (Raskin, ' 73). Controversy has centered around the technique, underlying mechanisms, and the meaning of the responses obtained from the skin. &lt;br /&gt;
There has been a long history of electrodermal activity research, even if most investigators accept the phenomenon without understanding exactly what it means (Hume, ' 76).&lt;br /&gt;
The resistance of the skin is usually large, approximately 1M; however, momentary changes in the level of the sweat gland activity causes changes in resistance (up to approximately 950K).&lt;br /&gt;
Physiology, the GSR reflescts sweat gland activity and changes in the sympathetic nervous system and measurement variables. The activity of the sweat glands in response to sympathetic nervous stimulation ( Increased sympathetic activation ) results in an increase in the level of conductance. There ia a relationship between sympathetic activity and emotional arousal, although one cannot identify the specific emotion being elicited. &lt;br /&gt;
Basically there are two techniques in the history of Electrodermal measurement. In one a current is passed thru the skin and the the resistance to passage is measured; in the other no current is used externally and the skin itself is the source of electrical activity.&lt;br /&gt;
By applying a conventional 0.5 Volts across the skin and measuring changes in the&lt;br /&gt;
corresponding conductance, the emotional state of the subject can be inferred. In general, the electrodes used are of the Ag/AgCl type which are recessed from the skin and require the use of a suitable electrode paste.&lt;br /&gt;
It is important to note, however, that fluctuations in skin conductivity are resultant of many types of arousal.&lt;br /&gt;
By observing only these changes, it is impossible to deduce without prior knowledge whether&lt;br /&gt;
the subject has become happy, startled, physically active, etcetera.&lt;br /&gt;
EDA consists of two components: tonic and phasic. The tonic component is a low&lt;br /&gt;
frequency baseline conductivity level, which can oscillate over the course of days. The phasic&lt;br /&gt;
component rides on top of the tonic component, exhibits more rapid fluctuations, and&lt;br /&gt;
generally increases when a person is aroused. Problematically, each person has a different&lt;br /&gt;
tonic conductivity, so in order to infer the arousal level of the subject, the relative changes in&lt;br /&gt;
EDA must be analyzed over a period of time. Furthermore, skin conductance (measured in&lt;br /&gt;
units of siemens; formerly mhos) depends on the skin path length between the two electrodes&lt;br /&gt;
contacts, even for subjects with identical skin conductivity (measured in units of&lt;br /&gt;
siemens/meter). It is for these reasons that it is crucial to analyze the temporal variations of&lt;br /&gt;
the EDA signal.&lt;br /&gt;
&lt;br /&gt;
'''BVP'''&lt;br /&gt;
&lt;br /&gt;
The cardiovascular system is in charge to keep us alive by maintaining the vital blood flow throughout the body, providing nutrients and oxygen to our cells. The SNS controls this system&lt;br /&gt;
by shifting the flow in response to exercise, temperature,postural and emotional changes.&lt;br /&gt;
Blood Volume Pulse (BVP) is the most common measure of vasomotor activity because it reflects the phasic pumping of the heart, the vasodilation of vessels that changes in the amount of acral blood delivered.&lt;br /&gt;
The Blood Volume Pulse (BVP) waveform is an important indicator of circulatory function that can be obtained noninvasively through a photoplethysmographic transducer (a PPG is often obtained by using a pulse oximeter, Shelley and Shelley, 2001) applied to the finger or the earlobe of human subjects. In particular, this signal may be useful in determining the degree of cardiovascular change undergone by a subject through an exercise session. &lt;br /&gt;
&lt;br /&gt;
''Principles of photoplethysmographic Technology:''&lt;br /&gt;
&lt;br /&gt;
The principle of photoplethysmographic (That is the same of pulse oximetry) is based on the red and infrared light absorption characteristics of oxygenated and deoxygenated hemoglobin. Oxygenated hemoglobin absorbs more infrared light and allows more red light to pass through. Deoxygenated (or reduced) hemoglobin absorbs more red light and allows more infrared light to pass through. Red light is in the 600-750 nm wavelength light band.&lt;br /&gt;
Pulse oximetry uses a light emitter with red and infrared LEDs that shines through a reasonably translucent site with good blood flow. Opposite the emitter is a photodetector that receives the light that passes through the measuring site.&lt;br /&gt;
There are two methods of sending light through the measuring site: transmission and reflectance. In the transmission the emitter and photodetector are opposite of each other with the measuring site in-between. The light can then pass through the site. In the reflectance method, the emitter and photodetector are next to each other on top the measuring site. The light bounces from the emitter to the detector across the site. The transmission method is the most common type used.&lt;br /&gt;
While pulse oximeters are a commonly used medical device the PPG derived from them is rarely displayed, and is nominally only processed to determine heart rate. &lt;br /&gt;
&lt;br /&gt;
'''Temperature'''&lt;br /&gt;
&lt;br /&gt;
The temperatures of peripheral limbs vary as a consequence of changes in blood flow.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== '''Previous work''' ==&lt;br /&gt;
&lt;br /&gt;
Here is a preliminary release of the headset produced before 2008/08/08&lt;br /&gt;
&lt;br /&gt;
[[Image:Wd1.jpg]]&lt;br /&gt;
&lt;br /&gt;
If you are interested on the making of the headset please see [[making rubber models]]&lt;br /&gt;
&lt;br /&gt;
'''* Blood Volume pressure'''&lt;br /&gt;
First graph showing a signal acquired with the wireless sensor. &lt;br /&gt;
[[Image:Bvp.png]]&lt;br /&gt;
&lt;br /&gt;
'''* Skin galvanic response''' (Sala Mirko e Alessia Cornaggia[http://airwiki.elet.polimi.it/mediawiki/index.php/User:AlessiaCornaggia])&lt;br /&gt;
Galvanic skin response (GSR), also known as electrodermal response (EDR), psychogalvanic reflex (PGR), or skin conductance response (SCR), is a method of measuring the electrical resistance of the skin.  There is a relationship between sympathetic activity and emotional arousal, although one cannot identify the specific emotion being elicited. The GSR is highly sensitive to emotions in some people. Fear, anger, startle response, orienting response and sexual feelings are all among the emotions which may produce similar GSR responses.&lt;br /&gt;
Response of the skin to the passage of a small electric current. The ease with which the current flows between two points on the skin can be used to indicate stress. When a person is tense or emotional, the sweat glands become more active, increasing moisture on the skin; this allows the electric current to flow more readily. &lt;br /&gt;
The response may also be used in relaxation training: information about the galvanic skin response is fed back aurally or visually to the subject who can, with practice, learn to increase or decrease sweating on the skin by learning to relax or tense muscles.&lt;br /&gt;
We measure the galvanic skin response using two electrodes attached to the skin. The optimal placement is the palm of the hands, but we are experimenting other places like on the forehead.&lt;br /&gt;
The circuit we are creating is the one below.&lt;br /&gt;
&lt;br /&gt;
[[Image:circuito.jpg]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== '''Project the device''' ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== '''Re-definition of the complete work''' ===&lt;br /&gt;
&lt;br /&gt;
Sensors are an important part of an Affective Computing System because they provide information about the wearer's physical state or behavior. They can gather data in a continuous way without having to interrupt the user. &lt;br /&gt;
To define in detail electronic specifications and requirements it's necessary a preliminary research/study (in literature and web) about state of art of sensor type used to monitor each type of biological signals we are interested about.&lt;br /&gt;
In this way it's possible both understand problematics related to interaction between biological and electonical worlds and improve or re-desig existing prototype.&lt;br /&gt;
&lt;br /&gt;
About Sensors: &lt;br /&gt;
&lt;br /&gt;
BVP will be acquire by an IR transmitter-receiver measuring light reflected from skin (photoplethysmography). Particular attention will be put on position, geometry and power absorption of this stage. &lt;br /&gt;
&lt;br /&gt;
GSR will be acquiret by a couple of electrodes forcing a low current (or voltage) and reading voltage (or current) through electrodes. Particular attention will be put on electrodes position and material. In addition is possible to foresee some problems in amplifier stage due to large range of skin resistance. Problem consist in chosing a correct amplification to overwork ADC full scale with a signal affected by little variation but huge possible range. &lt;br /&gt;
&lt;br /&gt;
Temperature will be acquired by thermocouple or PTC/NTC. Slowly variable signal, possible problems with noise due to resolution required. &lt;br /&gt;
&lt;br /&gt;
Head orientation will be acquired by an accelerometer and a gyroscope, problably integrated in the same chip. Two possibilities: analog output (need to digitalize up to six line) or digital output (like displaied in schematic block diagram). &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
This was the preliminary simplified schematic block diagram of the complete instrumentation setup:&lt;br /&gt;
&lt;br /&gt;
[[Image:WADSchematicDiagram01.jpg]]&lt;br /&gt;
&lt;br /&gt;
 NOTE:&lt;br /&gt;
 &lt;br /&gt;
 * In schematic is not present Power Supply Module: it will be based on a rechargeable Li-ion&lt;br /&gt;
 battery. It must satisfy requirements of high efficiency, logn life and low weight.&lt;br /&gt;
 &lt;br /&gt;
 * ADC and Microcontroller could be unified using a microcontroller with internal ADC and&lt;br /&gt;
 internal or external multiplexer to select lines.&lt;br /&gt;
 &lt;br /&gt;
 * Wireless section could be implemeted in Bluetooth (instead of using a XBee module like in&lt;br /&gt;
 preliminary release) due to it's diffusion in cellular phones, notebooks, MP3 reader...&lt;br /&gt;
 without necessity of external modules.&lt;br /&gt;
&lt;br /&gt;
It was based on a theoretical approach to any single part. Any sensing device was designed in &amp;quot;conventional&amp;quot; way founded on analog electronic (a bridge with a NTC resisistance as sensing element, discrete IR led and some photodiode around to capture the most reflefted light as possible, GSR electrodes on the gain arm of a non-inverting amplifier...).&lt;br /&gt;
Unfortunatly a deep analysis on signal physiology, signal transduction, noise vs required accurancy, forced us to a completely different approach implementing everywhere possible a digital interface.&lt;br /&gt;
&lt;br /&gt;
=== '''Sensors Design''' ===&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''BVP'''&lt;br /&gt;
&lt;br /&gt;
Discrete IR leds and phototransistor, used in the first realize (see fig.), had been replaced first with a single led and one or more photodiodes to optimize power consumption in case of non-planar sensor positioning. Subsequently an integrated Reflective Object Sensor was introduced, with benefits about space saving, transmitter-receiver matching and power consumption.&lt;br /&gt;
To ensure light power stability, led is powered through a linear led drive LDO (Low Drop-Out). The choise of linear LDO is necessary to ensure no noise or spikes would be generated by charge pump systems or boost converters. In addition, the linear drive utilized requires only one external resitor to set led current and a decoupling capacitor, reducing part counts and board space occupation.&lt;br /&gt;
The couple factor of the reflex sensors is relatively small, even in the case of good reflecting surfaces. Therefore an additional amplifier is necessary at the sensor output: classic trans-impedance amplifier used with photo-diodes and photo-transistors was introduced. This circuit features an output voltage that is a linear function of the light level on the photo-transistor. The gain is set by the feedback resistor which could be in the millions of ohms. Linear operation is achieved by operating the photo device with a fixed voltage drop across it.&lt;br /&gt;
Trans-impedance amplifier is followed by an active fourth order band-pass filter (0.5Hz-5Hz): it's composed cascading two second order bandpass cells. In first project session only a single cell was used, but a deeper study combined with previous experiences suggests to use a 4th order filter to reduce 50Hz interference (50Hz interference produced by mains is placed only a decade after the filter pole).&lt;br /&gt;
Filter is followed by a VGA (Variable Gain Amplifier) digitally controlled through I2C Bus that allows to optimize dinamically ADC input signal amplitude directly during acquisition session, obtaining the best performance from ADC.&lt;br /&gt;
The resulting circuit is quite compact (led drive, reflective sensor, trans-impedence amplifier, active filter and variable-gain amplifier), doesn't require much power and represents a good mix between analog and digital approach: analog front-end with acquisition and first conditioning, and at the chain-end a digital controlled amplifier to ensure flexibility.&lt;br /&gt;
&lt;br /&gt;
[[Image:WADBVPComparison_Pub.jpg]]&lt;br /&gt;
&lt;br /&gt;
'''GSR'''&lt;br /&gt;
&lt;br /&gt;
GSR will be acquired by a couple of electrodes forcing a low voltage and reading current through electrodes. First designs and implementations were based on literature study: best solution appears to put GSR electrodes on the gain arm of a non-inverting amplifier (see fig.) rather than using a Wheatstone bridge due to week signal produced by this solution.&lt;br /&gt;
Putting GSR electrodes on the gain arm produces a sort of gain modulation of the constant voltage applied between electrodes but doesn't solve problems in amplifier stage due to large range of skin resistance.&lt;br /&gt;
Problems in chosing correct amplification to overwork ADC full scale with a signal affected by little variation but huge possible range could be reduced usign a variable resistor on gain arm (for example a digital potentiometer controlled by the microcontroller), but cannot be completely removed. In addition little signals are easily deteriorated by noise.&lt;br /&gt;
Solution is provided considering a new point of view: measure of unknown skin resistence is extremely similar to measure unknown electrical impedence with an auto-range multimeter!&lt;br /&gt;
Solution consist in a digital Converter which combines an on-board frequency generator with a analog-to-digital converter (ADC).&lt;br /&gt;
The resulting circuit is compact, provides a system accuracy of 0.5% and connects to microcontroller using I2C interface, ensuring an high flexibility and the possibility to modify acquisition settings after board production (through microcontroller firmware).&lt;br /&gt;
&lt;br /&gt;
[[Image:WADGSRComparison_Pub.jpg]]&lt;br /&gt;
&lt;br /&gt;
'''Temperature'''&lt;br /&gt;
&lt;br /&gt;
First idea was to acquire temperature by a NTC connected in a Wheatstone bridge. Trying to reduce noise, bridge was powered by an oscillator circuit with a frequency of some KHerz, to translate signal out of 1/f noise region. Bridge outputs were connected to an INA amplifier wich also implements signal filtering (see fig.).&lt;br /&gt;
Weak signal, noise and resolution required (0.1°C) put in crisis the system. In addition other unsolved problems were the optimization of thermal and mechanical contact between sensor and body and the sensor large thermic constant. Unstable thermic contact produces unreliable measures, whereas high sensor thermic constant hampers a fast sensor response (needed to detect short peak due to emotional reactions).&lt;br /&gt;
Possible solutions to problems of weak signal and noise arrive from digital integrated temperature sensor (for example LM35 or LM74), but these don't solve the problem of thermal contact and thermal constant. In addition none of the sensors take in consideration provides the required resolution.&lt;br /&gt;
High resolution required, noise immunity, fast response and thermal contact immunity problems had been solved using a digital optical infrared thermometer. Small size, no external component requirements and power saving mode allow us to obtain a perfect matching between required performances and space saving.&lt;br /&gt;
&lt;br /&gt;
[[Image:WADTemperatureComparison_Pub.jpg]]&lt;br /&gt;
&lt;br /&gt;
'''Accelerometer'''&lt;br /&gt;
&lt;br /&gt;
Head orientation and movements will be acquired by an accelerometer. First we think to utilize an ST Microelectronic LIS3L02AS4, due to the availability in the Lab of the evaluation board STEVAL-MKI001. It is a 3-axis ±2g/±6g linear accelerometer with 3 analog outputs, so it requires an external ADC to digitalize the three axis acceleration values. The conversion could be performed by a microcontroller with internal ADC.&lt;br /&gt;
A fast Internet research reveled this sensor is now obsolete and out of production. The choise had been to substitute the old chip with the new one: the LIS302DL (still produced by ST Microelectronic). It's a 3-axis, ± 2g/± 8g smart digital output accelerometer with I2C/SPI digital output interface and really small package. The device is capable of measuring accelerations with an output data rate of 100 Hz or 400 Hz and the self-test capability allows the user to check the functioning of the sensor in the final application.&lt;br /&gt;
In addition it may be configured to generate inertial wake-up/free-fall interrupt signals when a programmable acceleration threshold is crossed at least in one of the three axes. Thresholds and timing of interrupt generators are programmable by the end user on the fly.&lt;br /&gt;
This device, providing a digital output, doesn't need signals conversion, guaranteing better noise immunity; programmable interrupts and test interface allow greater fexibility in project. In addition wery small package, only one external resistor requirement (plus baypass capacitor) reduce significantly board space requirements.&lt;br /&gt;
&lt;br /&gt;
[[Image:WADAccelerometer.jpg]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
 NOTE:&lt;br /&gt;
 &lt;br /&gt;
 * In previous schematics, components phisical dimensions are not in scale.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== '''Microcontroller''' ===&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Foundamental requirements:&lt;br /&gt;
&lt;br /&gt;
- High speed to ensure high data output rate even in presence of a large number af sensing elemets;&lt;br /&gt;
&lt;br /&gt;
- Fast Internal ADC with multiple inputs;&lt;br /&gt;
&lt;br /&gt;
- (At Least) One I2C interface;&lt;br /&gt;
&lt;br /&gt;
- (At Least) One SPI interface;&lt;br /&gt;
&lt;br /&gt;
- (At Least) One UART interface;&lt;br /&gt;
&lt;br /&gt;
- (At Least) Three Timers;&lt;br /&gt;
&lt;br /&gt;
- (At Least) Three External Interrrupts;&lt;br /&gt;
&lt;br /&gt;
- Low-power consumption;&lt;br /&gt;
&lt;br /&gt;
- Power supply 3.3V;&lt;br /&gt;
&lt;br /&gt;
- Small package;&lt;br /&gt;
&lt;br /&gt;
In addition microcontroller was chosen between Microchip PIC family devices, due to positive previous experiences and availability of software and programmer in the Lab.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
PIC24HJ256GP206 is a 16 bit microcontroller capable of 40 MIPS speed. It provides 256KB of Flash memory, 16KB of Ram, a 10-bit 1.1Msps or 12-bit 500Ksps ADC, UART, SPI and I2C interface in a 64 pin TQFP package (10mmX10mm) powerd between 3.0V and 3.6V.&lt;br /&gt;
Power core is provided by an internal regulator reducing parts count on the board.&lt;br /&gt;
&lt;br /&gt;
The device is able to provide at the same time one I2C interface, two SPI interface and one UART interface: another UART port shares pins with an SPI port and a second I2C port shares pins with the second UART interface.&lt;br /&gt;
Findig a device that provides at the same time, on indipendent pins, an I2C, a SPI and an UART interface reduces considerably possible choises and suggests to chose a high performance microcontroller.&lt;br /&gt;
At the same time, high performance solutions have a larger pin counts than standard microcontroller, but this characteristic can be used to ensure further expansibility to the system. The second SPI interface can be used to connect another &amp;quot;intelligent&amp;quot; device or a mass storage device, for example a SD (Secure Digital) card to storage acquired data (see fig.).&lt;br /&gt;
&lt;br /&gt;
[[Image:WADSDCard.jpg]]&lt;br /&gt;
&lt;br /&gt;
Input pins connected to ADC and not used at the moment could be collected to a connector for further extension modules (for example an EMG or ECG peripheral or any other analog signal interesting in a particolar application).&lt;br /&gt;
For the same reason any other pin non used at the current stage is reported to an extension connector.&lt;br /&gt;
To guarante maximum flexibility an further update, board provides both ICD and JTAG connections (allowing on-board programming and debugging) through a couple of indipendent dedicated connectors fully compatibles with Microchip programmers and evaluation boards.&lt;br /&gt;
&lt;br /&gt;
[[Image:WADMicro.jpg]]&lt;br /&gt;
&lt;br /&gt;
=== '''Wireless Connection''' ===&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Wireless connection is based on Bluetooth 2.0+EDR (Enhanced Data Rates) module containing all the necessary elements from Bluetooth radio to antenna and a fully implemented protocol stack.&lt;br /&gt;
Module is equipped with firmware that enables users to access Bluetooth functionality with simple ASCII commands delivered to the module over serial interface like a Bluetooth modem.&lt;br /&gt;
The dedicated onboard microcontroller (MCU) acts as interrupt controller and event timer run the Bluetooth software stack and control the radio and host interfaces. A 16-bit reduced instruction set computer (RISC) microcontroller is used for low power consumption and efficient use of memory.&lt;br /&gt;
Module support USB, SPI and UART interface and UART interface is used in this project to connect PIC microcontroller to wireless transmitter (see fig.).&lt;br /&gt;
&lt;br /&gt;
[[Image:WADWireless_Pub.jpg]]&lt;br /&gt;
&lt;br /&gt;
One of the most important characteristic is the high integration between all parts needed for efficent Bluetooth transmission: user interface, controller, radio circuits and antenna, all included in a low power, low size board (25.6mmx15mm) that requires a minimum number of external components.&lt;br /&gt;
Many other bluetooth components ara available, such as LMX9830, produced by National Semiconductor. It's an extremely small device (only 6.1mm×9.1 mm), but requires a number of external components (see fig.) like oscillators, resistors, capacitors, inductors and the antenna, in addition to an high competence in radio frequency layout circuits.&lt;br /&gt;
&lt;br /&gt;
[[Image:WADLMX9830.jpg]]&lt;br /&gt;
&lt;br /&gt;
Lack of experience in radio frequency circuit suggests to chose a ready-to-use module, factory optimized for best performance and easy to integrate in our board.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
This is the updated simplified schematic block diagram:&lt;br /&gt;
&lt;br /&gt;
[[Image:WADSchematicDiagram02.jpg]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== '''Prototype realization [WIP (Work in Progress)]''' ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Fist stage plans to realize a board using, where possible, through-hole (TH) compenents soldered on a prototyping board (100x160mm) powered from a laboratory power supply (instead of Li-on battery) and not implementing bluetooth wireless transmission. Parts not available on TH package are used with special SMD-&amp;gt;TH adapter boards or simply fixing and soldering them to the PCB by wires.&lt;br /&gt;
&lt;br /&gt;
Second stage plans to realize microcontoller firmware and test it acquiring biological signals from a patient. Firmware will be developed by subsequently steps, implementing and testing only a single peripheral at each time: only at the end single pheripheral softwares will be merged together.&lt;br /&gt;
&lt;br /&gt;
Third stage will be bluetooth interface (hardware and software) implementation and integration on the board with transmission test.&lt;br /&gt;
&lt;br /&gt;
Fourth stage will consider power supply optimization with battery management and recharge interface.&lt;br /&gt;
&lt;br /&gt;
Finally, only after a successful full board test, the last stage will be the circuit layout design with an electronic CAD, using where possible, Surface Mount Devices (SMD) to reduce board area.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== '''Main board''' ===&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Main board include power supply regulator with led power-on indicator, PIC microcontroller (mounted on a SMD-&amp;gt;TH adapeter board) with basic circuitry (decoupling capacitors, oscillator and programming-debugging ICD interface), a status led connected to PIC to verify basic microcontroller function, a series of connectors for add-on modules (BVP, GSR, temperature and accelerometer) and a USB PC interface not considered before.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== '''USB interface''' ===&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
USB interface, not projected before, replaces in developing stage Bluetooth interface, allowing a direct control/communication with a PC. In this prototype PIC UART, althought being connected to Bluettoth module, is connected to a FTDI FT232RL chip. The FT232RL is the latest device to be added to FTDI’s range of USB UART interface Integrated Circuit Devices. USB to serial designs using the FT232RL have been further simplified by fully integrating the external EEPROM, clock circuit and USB resistors onto the device.&lt;br /&gt;
The FT232RL is available in Pb-free (RoHS compliant) compact 28-Lead SSOP, so this require another SMD-&amp;gt;TH board adapter but the circuit design is very simple, including two status led for TX and RX operations. An USB B female connector was eputated the best choise for PC connection allowing to use a simple USB printer cable.&lt;br /&gt;
&lt;br /&gt;
[[Image:WADUSBInterface.jpg]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Note that USB and Bluetooth must not be connected to the board at the same time! USB port has only a developent function.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== '''BVP''' ===&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Circuit designed for BVP acquisition (refer to previous schematic) doesn't meet the expected results. Week signal hanged by noise suggested us to re-design the circuit simplifying it and reducing the number of components. For this design also sensing element has been substitute. Instead of an integrated reflective IR sensor (SFH9202), new project use a couple af discrete IR led and photothansistor matched: SFH487 and SFH309FA.&lt;br /&gt;
SFH487 is a very highly efficient GaAlAs infrared emitter (880 nm) and SFH309FA is a silicon NPN phototransistor especially suitable for applications of 880 nm with an high linearity. Both have a 3 mm led plastic package, are spectrum-matched and receiver is ambient-light shilded. After a series of positive test without the led driver (not used due to the really reduced mechanical dimensions), also led drive circuit was removed and replaced with a resistance connected directly to a PIC pin.&lt;br /&gt;
This choise reduces parts count and board space required without making worse sistem performance, allowing (like led driver) to turn off the sensor led when not used to reduce power consumption.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Figure show the signal measured directly on filtering stage output (TS952 pin 7) before the VGA with a Tektronix scopemeter TDS2014B. No particular triks had been used: signal has been recorded the first time circuit was assembled on a protoboard.&lt;br /&gt;
&lt;br /&gt;
[[Image:WADBVPScope03.jpg]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== '''GSR''' ===&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
First approach with digital Converter resulted really hard due to some errors occurred in control software in relation with internal chip complexity and I2C bus protocol. &lt;br /&gt;
After a start session GSR hardware acquisition interface was further simplified replacing the digital converter with a similar (same pinout and functions) one with inegrated internal oscillator.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
First dataset acquired whith the correct control software and the correct data reading routine, has shown all the potentiality of this chip, providing data comparables with RAW data acquired with a bigger and very expensive professional equipement produced by ProComp.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== '''Acceleration''' ===&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Lis302DL datasheet gives a short definition of this chip as &amp;quot;MEMS motion sensor 3-axis - ± 2g/± 8g smart digital output “piccolo” accelerometer&amp;quot; and it is really very, very small for human-working. For this space saving quality this accelerometer is also use in third generation Apple i-phone.&lt;br /&gt;
The major problem with this sensor had been to solder it to a sort of adapter to connect it to the circuit, but after that it works fine, with a good sensitivity and accuracy. Because of free fall and double click recognition at not required (at the moment) in this application, software routines for setting configuration registers and reading data resulted simplified.&lt;br /&gt;
A usefull caracteristic of this sensor, not previously noticed, is the presence of internal pull-up resistors that allows no necessity of external I2C bus pull-up resistors, reducing space occupation and components count.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== '''Temperature''' ===&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The choice to use a digital optical infrared thermometer due to his characteristics (non contact measure, 0.02°C resolution with accuracy of ±0.1°C for medical applications version) creates a really serious supplies problem: sensor manufacture wasn't able to give us a sample and no one in Italy can sell us only a pair of theese sensors to try them. A single piece was bought from Future Electronics, ordering it via web and paying it via credit card. Fortunately the sensor, that cames directly from USA, arrived in Italy few days later the payment in excellent conditions.&lt;br /&gt;
Problems occurred interfacing this sensor on I2C bus with other devices (GSR digital Converter and LIS302) connected. Sensor has a 2 wire serial SMBus compatible protocol: I2C bus and  SMBus are popular 2-wire buses that are essentially compatible with each other, but are not the same.&lt;br /&gt;
The buses operate at the same speed, up to 100kHz, but the I2C bus has both 400kHz and 2MHz versions. Complete compatibility between both buses is ensured only below 100kHz.&lt;br /&gt;
Timeout and (as a consequence of timeout) minimum clock speed are the most important differences between the I2C bus and the SMBus:&lt;br /&gt;
&lt;br /&gt;
I2C Bus = DC (no timeout)&lt;br /&gt;
&lt;br /&gt;
SMBus = 10kHz (35mS timeout)&lt;br /&gt;
&lt;br /&gt;
Despite differences in logic-level specifications between the two buses, generally devices can be mixed and matched with abandon.&lt;br /&gt;
Level Specifications for the I2C Bus and the SMBus are shown below (VDD is typically expected to be between 3 volts and 5 volts):&lt;br /&gt;
&lt;br /&gt;
[[Image:WADTable1.jpg]]&lt;br /&gt;
&lt;br /&gt;
What wasn't readily evident in the discussion of voltage levels is that these levels are also specified with different currents between the buses. The SMBus specifies a minimum sink current of 100microA, and a maximum of 350microA, compared to 3mA for the I2C bus. This in turn would determine the lowest acceptable value of the pullup resistor, examples of which are shown in the table below.&lt;br /&gt;
&lt;br /&gt;
[[Image:WADTable2.jpg]]&lt;br /&gt;
&lt;br /&gt;
In reality, it is not unusual to encounter pullup resistor values in SMBus systems, which violate this specification by being lower than recommended. A very popular range for pullup resistor values, even in some SMBus systems, seems to be 2.4k to 3.9k.&lt;br /&gt;
&lt;br /&gt;
These reasons, in adition to clear ideas about close developments, suggest a general review of schematic to re-distribute microcontroller resources.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== '''Part 6: final review [WIP (Work in Progress)]''' ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== '''Microcontroller''' ===&lt;br /&gt;
&lt;br /&gt;
Referring to previous schematic, some chenges had been applied:&lt;br /&gt;
&lt;br /&gt;
- Programmer/Debugger interface is now PGD1/EMUD1 and PGC1/EMUC1 instead of PGD1/EMUD2 and PGC1/EMUC2;&lt;br /&gt;
&lt;br /&gt;
- JTAG interface had been removed;&lt;br /&gt;
&lt;br /&gt;
- UART2 is no more available so UART1 has replaced UART2 as communication port;&lt;br /&gt;
&lt;br /&gt;
- SPI2 is no more available so SPI1 is now used to control both VGA (Variable Gain Amplifier) and SD Storage Card;&lt;br /&gt;
&lt;br /&gt;
- RG12, RG13, RG14 pins had been connected to three status led for a machine visual state detection;&lt;br /&gt;
&lt;br /&gt;
- I2C1 interface is now connected to accelerometer (LIS302) and GSR Converter only;&lt;br /&gt;
&lt;br /&gt;
- I2C2 interface is dedicated to temperature sensor, enabling I/O pin thresholds compliant with SMBus specification;&lt;br /&gt;
&lt;br /&gt;
- Connectors for I2C, SMBus and SPI expansion modules had been added to the board;&lt;br /&gt;
&lt;br /&gt;
- Test point pads had been added to the board to simplify debugging.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== '''Data link''' ===&lt;br /&gt;
&lt;br /&gt;
During developing stages, an USB port had replaced Bluetooth wireless transmission, allowing a direct control/communication with a PC. This interfaced, based on a FT232RL, prove to be very usefull and simple to use.&lt;br /&gt;
The choice to use an usb port to charge internal battery, in addition to availability of a UART multiplexer inside the Bluetooth, suggest to implement both USB and Bluetooth interface.&lt;br /&gt;
&lt;br /&gt;
That's the Bluetooth internal UART multiplexer schematic:&lt;br /&gt;
&lt;br /&gt;
[[Image:WAD_UARTMux.jpg]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== '''Battery Charge &amp;amp; MonitorPower On''' ===&lt;br /&gt;
&lt;br /&gt;
Device is powered by a single cell Li-on battery (3.7V, 1080mAh): this is the same unit used in IPod(TM) from Apple.&lt;br /&gt;
&lt;br /&gt;
[[Image:WAD_Battery.jpg]]&lt;br /&gt;
&lt;br /&gt;
Battery charge is executed by a Maxim's device: it is a really compact single-cell lithium-ion (Li+) battery charger that can be powered directly from a USB port or from an external supply up to 6.5V. It has a 0.5% overall battery regulation voltage accuracy to allow maximum utilization of the battery capacity.&lt;br /&gt;
The charger uses an internal FET to deliver up to 500mA charging current to the battery. The device can be configured for either a 4.1V or 4.2V battery, using the SELV input. The SELI input sets the charge current to either 100mA or 500mA. An open-drain output indicates charge status.&lt;br /&gt;
It has preconditioning that soft-starts a near-dead battery cell before charging. Other safety features include continuous monitoring of voltage and current and initial checking for fault conditions before charging.&lt;br /&gt;
&lt;br /&gt;
White battery wire (see photo) is connected to internal NTC thermistor (10KOhm@+25°C). In this way it's posible to implement an over/under charge temperature detector using a couple af operational amplifier as comparator.&lt;br /&gt;
With a resistence network it had been possible to set an upper temperature threshold of 47.5°C (corresponding to 3.97K NTC value) and a down thresold of 2.5°C (corresponding to &lt;br /&gt;
28.7K NTC value). Out of this range comparators output go low disabling battery charger.&lt;br /&gt;
This function allows to prevent battery demage or explosion during charge.&lt;br /&gt;
&lt;br /&gt;
Battery voltage monitor is hardware implemented by a CMOS micropower voltage detector that warn microprocessors/microcontroller of power failures. It contains a comparator, a 1.5V bandgap reference, and an open-drain n-channel output driver. Two external resistors are used in conjunction with the internal reference to set the trip voltage to the desired level. A hysteresis output is also included, allowing the user to apply positive feedback for noise-free output switching.&lt;br /&gt;
Using a couple of these device is possible to set two treshold: one for low battery and another for end battery detection. Low battery detection allow communicate the user battery level; end battery detection allow microprocessor shut down the device before battery voltage fall down under 3.4V that is the minimun input voltage allowed by linear regulator MCP1700.&lt;br /&gt;
If battery level fall down under 3.4V, MCP1700 is not able to guarantee line regulation.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== '''Power On &amp;amp; Selection''' ===&lt;br /&gt;
&lt;br /&gt;
Power-up and shut-down were implemented using a Maxim's MAX16054 connected with an ADG801 by Analog Device.&lt;br /&gt;
MAX16054 is a pushbutton on/off controller with a single switch debouncer and built-in latch. It accepts a noisy input from a mechanical switch and produces a clean latched digital output after a factory-fixed qualification delay.&lt;br /&gt;
The state of the output changes only when triggered by the falling edge of the debounced switch input; the output remains unchanged on the rising edge of the input.An asynchronous CLEAR input allows an external signal to force the output flip-flop low.&lt;br /&gt;
ADG801 is a monolithic CMOS, single-pole, single throw (SPST), normally open (NO) switch with on resistance of less than 0.4Ohm. This switch conducts equally well in both directions when on.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== '''MicroSD Storage Card ''' ===&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== '''RTC ''' ===&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Students that have worked on the project==&lt;br /&gt;
&lt;br /&gt;
* Mattia Colombo (Blood Volume Pressure sensor)&lt;br /&gt;
* Alessia Cornaggia (Galvanic skin response sensor)&lt;br /&gt;
* Sala Mirko (Galvanic skin response sensor)&lt;br /&gt;
&lt;br /&gt;
== Laboratory work and risk analysis ==&lt;br /&gt;
&lt;br /&gt;
Laboratory work for this project will be mainly performed at AIRLab/Lambrate. It will include electrical and electronic activity. Potentially risky activities are the following:&lt;br /&gt;
* Use of mechanical tools. Standard safety measures described in [http://airlab.elet.polimi.it/index.php/airlab/content/download/461/4110/file/documento_valutazione_rischi_AIRLab.pdf Safety norms] will be followed.&lt;br /&gt;
* Use of soldering iron. Standard safety measures described in [http://airlab.elet.polimi.it/index.php/airlab/content/download/461/4110/file/documento_valutazione_rischi_AIRLab.pdf Safety norms] will be followed.&lt;br /&gt;
* Use of high-voltage circuits. Special gloves and a current limiter will be used. Standard safety measures described in [http://airlab.elet.polimi.it/index.php/airlab/content/download/461/4110/file/documento_valutazione_rischi_AIRLab.pdf Safety norms] will be followed.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
 Detailed Information and Schematics available in the Discussion page.&lt;/div&gt;</summary>
		<author><name>PaoloVilla</name></author>	</entry>

	<entry>
		<id>https://airwiki.deib.polimi.it/index.php?title=Wireless_Affective_Devices&amp;diff=9585</id>
		<title>Wireless Affective Devices</title>
		<link rel="alternate" type="text/html" href="https://airwiki.deib.polimi.it/index.php?title=Wireless_Affective_Devices&amp;diff=9585"/>
				<updated>2009-12-12T09:48:55Z</updated>
		
		<summary type="html">&lt;p&gt;PaoloVilla: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{Project&lt;br /&gt;
|title=Wireless Affective Devices&lt;br /&gt;
|tutor=SimoneTognetti;MatteoMatteucci&lt;br /&gt;
|students=PaoloVilla&lt;br /&gt;
|resarea=BioSignal Analysis&lt;br /&gt;
|restopic=Affective Computing&lt;br /&gt;
|start=2008/01/08&lt;br /&gt;
|end=2009/12/30&lt;br /&gt;
|status=Active&lt;br /&gt;
|level=Ms&lt;br /&gt;
|type=Thesis&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Project aims ==&lt;br /&gt;
&lt;br /&gt;
 ”''Everyone knows what an emotion is, until asked to give a definition''”&lt;br /&gt;
                                         &lt;br /&gt;
                                                                 Beverly Fehr and James Russell&lt;br /&gt;
&lt;br /&gt;
Research on Human-Computer-Interfaces has recently begun to take into account the affective state of the user. By appropriately reacting to the affective user state, interfaces could not only become more pleasant or entertaining, but also more effective or safer.&lt;br /&gt;
It is known that affective states have bodily correlates, and thus physiological signals could provide the necessary information for acquiring the affective user state. In contrast to other sources of information about the affective user state such as speech or facial expression, most physiological signals are not under voluntary control, and thus cannot be masked up to the same extent. Furthermore, it can be presumed that the signs of affective states in physiological signals are less dependent on individual and contextual factors: this is because the signals correspond to internal physiology, largely related to the autonomous nervous and limbic systems, rather than to external expressions that can be manipulated easily.&lt;br /&gt;
Recently, the issue of emotion regulation drew interests from several fields including neuroscience, psychology, education, computer science, etc. Possible applications are e-learningin, human computer interaction, development of communicative technologies for use by people with autism, car infotainment system, lie detection tests, cognitive workload, multimodal user interfaces MMUI (allow users to control computers using speech and gesture), etc.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The project is aimed at developing a device, connected to a PC, to acquire biological signals (such as GSR, BVP, Temperature and Head orientation) in a way that is less invasive for the subject. The term invasive is related to how much the sensors we use compromise the normal interaction between subject and machine.&lt;br /&gt;
Through these biological signal the PC is able o understand emotion in people who wear the device.&lt;br /&gt;
&lt;br /&gt;
An affective device should be weared easily, should not have cables and should acquire as much sensors as possible. We relax some constraint on the quality of signal but we add constraint on way they are acquired(i.e. the subject can put it on easily, the usual movements are not influenced..). The aim of the resulting device is not to replace the standard medical devices usually used to acquire that signals, but is to be much more suitable for industrial application in which the medical requirement are replaced by invasivity requirement.&lt;br /&gt;
&lt;br /&gt;
It is composed by:&lt;br /&gt;
&lt;br /&gt;
* Low power, high efficiency, battery powered design&lt;br /&gt;
* Wireless comunication with a PC&lt;br /&gt;
* Blood Volume Pressure Sensor (Preliminary release by Mattia Colombo)&lt;br /&gt;
* Galvanic Skin Response Sensor (Preliminary release by Sala Mirko e Alessia Cornaggia)&lt;br /&gt;
* Temperature Sensor&lt;br /&gt;
* 3 Way Accelerometer&lt;br /&gt;
* Possibility of further extension&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''GSR (or EDR or EDA)'''&lt;br /&gt;
&lt;br /&gt;
An often misunderstood and difficult technique, GSR (also known as the electrodermal response EDR or electrodermal activity EDA) has gone through many phases of interest and rejection since the early 1900's and is very popular in psychophysiological studies since Carl Jung and his students (1907) described it as a mean to&lt;br /&gt;
enter the “sea of the unconscious” because “every stimulus accompanied by an emotion produced a deviation of the galvanometer” directly proportional to the strength of the emotion aroused. It has been used in important research on anxiety and stress levels (Fenz &amp;amp; Epstein, ' 67); and it has been a part of lie detection (Raskin, ' 73). Controversy has centered around the technique, underlying mechanisms, and the meaning of the responses obtained from the skin. &lt;br /&gt;
There has been a long history of electrodermal activity research, even if most investigators accept the phenomenon without understanding exactly what it means (Hume, ' 76).&lt;br /&gt;
The resistance of the skin is usually large, approximately 1M; however, momentary changes in the level of the sweat gland activity causes changes in resistance (up to approximately 950K).&lt;br /&gt;
Physiology, the GSR reflescts sweat gland activity and changes in the sympathetic nervous system and measurement variables. The activity of the sweat glands in response to sympathetic nervous stimulation ( Increased sympathetic activation ) results in an increase in the level of conductance. There ia a relationship between sympathetic activity and emotional arousal, although one cannot identify the specific emotion being elicited. &lt;br /&gt;
Basically there are two techniques in the history of Electrodermal measurement. In one a current is passed thru the skin and the the resistance to passage is measured; in the other no current is used externally and the skin itself is the source of electrical activity.&lt;br /&gt;
By applying a conventional 0.5 Volts across the skin and measuring changes in the&lt;br /&gt;
corresponding conductance, the emotional state of the subject can be inferred. In general, the electrodes used are of the Ag/AgCl type which are recessed from the skin and require the use of a suitable electrode paste.&lt;br /&gt;
It is important to note, however, that fluctuations in skin conductivity are resultant of many types of arousal.&lt;br /&gt;
By observing only these changes, it is impossible to deduce without prior knowledge whether&lt;br /&gt;
the subject has become happy, startled, physically active, etcetera.&lt;br /&gt;
EDA consists of two components: tonic and phasic. The tonic component is a low&lt;br /&gt;
frequency baseline conductivity level, which can oscillate over the course of days. The phasic&lt;br /&gt;
component rides on top of the tonic component, exhibits more rapid fluctuations, and&lt;br /&gt;
generally increases when a person is aroused. Problematically, each person has a different&lt;br /&gt;
tonic conductivity, so in order to infer the arousal level of the subject, the relative changes in&lt;br /&gt;
EDA must be analyzed over a period of time. Furthermore, skin conductance (measured in&lt;br /&gt;
units of siemens; formerly mhos) depends on the skin path length between the two electrodes&lt;br /&gt;
contacts, even for subjects with identical skin conductivity (measured in units of&lt;br /&gt;
siemens/meter). It is for these reasons that it is crucial to analyze the temporal variations of&lt;br /&gt;
the EDA signal.&lt;br /&gt;
&lt;br /&gt;
'''BVP'''&lt;br /&gt;
&lt;br /&gt;
The cardiovascular system is in charge to keep us alive by maintaining the vital blood flow throughout the body, providing nutrients and oxygen to our cells. The SNS controls this system&lt;br /&gt;
by shifting the flow in response to exercise, temperature,postural and emotional changes.&lt;br /&gt;
Blood Volume Pulse (BVP) is the most common measure of vasomotor activity because it reflects the phasic pumping of the heart, the vasodilation of vessels that changes in the amount of acral blood delivered.&lt;br /&gt;
The Blood Volume Pulse (BVP) waveform is an important indicator of circulatory function that can be obtained noninvasively through a photoplethysmographic transducer (a PPG is often obtained by using a pulse oximeter, Shelley and Shelley, 2001) applied to the finger or the earlobe of human subjects. In particular, this signal may be useful in determining the degree of cardiovascular change undergone by a subject through an exercise session. &lt;br /&gt;
&lt;br /&gt;
''Principles of photoplethysmographic Technology:''&lt;br /&gt;
&lt;br /&gt;
The principle of photoplethysmographic (That is the same of pulse oximetry) is based on the red and infrared light absorption characteristics of oxygenated and deoxygenated hemoglobin. Oxygenated hemoglobin absorbs more infrared light and allows more red light to pass through. Deoxygenated (or reduced) hemoglobin absorbs more red light and allows more infrared light to pass through. Red light is in the 600-750 nm wavelength light band.&lt;br /&gt;
Pulse oximetry uses a light emitter with red and infrared LEDs that shines through a reasonably translucent site with good blood flow. Opposite the emitter is a photodetector that receives the light that passes through the measuring site.&lt;br /&gt;
There are two methods of sending light through the measuring site: transmission and reflectance. In the transmission the emitter and photodetector are opposite of each other with the measuring site in-between. The light can then pass through the site. In the reflectance method, the emitter and photodetector are next to each other on top the measuring site. The light bounces from the emitter to the detector across the site. The transmission method is the most common type used.&lt;br /&gt;
While pulse oximeters are a commonly used medical device the PPG derived from them is rarely displayed, and is nominally only processed to determine heart rate. &lt;br /&gt;
&lt;br /&gt;
'''Temperature'''&lt;br /&gt;
&lt;br /&gt;
The temperatures of peripheral limbs vary as a consequence of changes in blood flow.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== '''Previous work''' ==&lt;br /&gt;
&lt;br /&gt;
Here is a preliminary release of the headset produced before 2008/08/08&lt;br /&gt;
&lt;br /&gt;
[[Image:Wd1.jpg]]&lt;br /&gt;
&lt;br /&gt;
If you are interested on the making of the headset please see [[making rubber models]]&lt;br /&gt;
&lt;br /&gt;
'''* Blood Volume pressure'''&lt;br /&gt;
First graph showing a signal acquired with the wireless sensor. &lt;br /&gt;
[[Image:Bvp.png]]&lt;br /&gt;
&lt;br /&gt;
'''* Skin galvanic response''' (Sala Mirko e Alessia Cornaggia[http://airwiki.elet.polimi.it/mediawiki/index.php/User:AlessiaCornaggia])&lt;br /&gt;
Galvanic skin response (GSR), also known as electrodermal response (EDR), psychogalvanic reflex (PGR), or skin conductance response (SCR), is a method of measuring the electrical resistance of the skin.  There is a relationship between sympathetic activity and emotional arousal, although one cannot identify the specific emotion being elicited. The GSR is highly sensitive to emotions in some people. Fear, anger, startle response, orienting response and sexual feelings are all among the emotions which may produce similar GSR responses.&lt;br /&gt;
Response of the skin to the passage of a small electric current. The ease with which the current flows between two points on the skin can be used to indicate stress. When a person is tense or emotional, the sweat glands become more active, increasing moisture on the skin; this allows the electric current to flow more readily. &lt;br /&gt;
The response may also be used in relaxation training: information about the galvanic skin response is fed back aurally or visually to the subject who can, with practice, learn to increase or decrease sweating on the skin by learning to relax or tense muscles.&lt;br /&gt;
We measure the galvanic skin response using two electrodes attached to the skin. The optimal placement is the palm of the hands, but we are experimenting other places like on the forehead.&lt;br /&gt;
The circuit we are creating is the one below.&lt;br /&gt;
&lt;br /&gt;
[[Image:circuito.jpg]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== '''Project the device''' ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== '''Re-definition of the complete work''' ===&lt;br /&gt;
&lt;br /&gt;
Sensors are an important part of an Affective Computing System because they provide information about the wearer's physical state or behavior. They can gather data in a continuous way without having to interrupt the user. &lt;br /&gt;
To define in detail electronic specifications and requirements it's necessary a preliminary research/study (in literature and web) about state of art of sensor type used to monitor each type of biological signals we are interested about.&lt;br /&gt;
In this way it's possible both understand problematics related to interaction between biological and electonical worlds and improve or re-desig existing prototype.&lt;br /&gt;
&lt;br /&gt;
About Sensors: &lt;br /&gt;
&lt;br /&gt;
BVP will be acquire by an IR transmitter-receiver measuring light reflected from skin (photoplethysmography). Particular attention will be put on position, geometry and power absorption of this stage. &lt;br /&gt;
&lt;br /&gt;
GSR will be acquiret by a couple of electrodes forcing a low current (or voltage) and reading voltage (or current) through electrodes. Particular attention will be put on electrodes position and material. In addition is possible to foresee some problems in amplifier stage due to large range of skin resistance. Problem consist in chosing a correct amplification to overwork ADC full scale with a signal affected by little variation but huge possible range. &lt;br /&gt;
&lt;br /&gt;
Temperature will be acquired by thermocouple or PTC/NTC. Slowly variable signal, possible problems with noise due to resolution required. &lt;br /&gt;
&lt;br /&gt;
Head orientation will be acquired by an accelerometer and a gyroscope, problably integrated in the same chip. Two possibilities: analog output (need to digitalize up to six line) or digital output (like displaied in schematic block diagram). &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
This was the preliminary simplified schematic block diagram of the complete instrumentation setup:&lt;br /&gt;
&lt;br /&gt;
[[Image:WADSchematicDiagram01.jpg]]&lt;br /&gt;
&lt;br /&gt;
 NOTE:&lt;br /&gt;
 &lt;br /&gt;
 * In schematic is not present Power Supply Module: it will be based on a rechargeable Li-ion&lt;br /&gt;
 battery. It must satisfy requirements of high efficiency, logn life and low weight.&lt;br /&gt;
 &lt;br /&gt;
 * ADC and Microcontroller could be unified using a microcontroller with internal ADC and&lt;br /&gt;
 internal or external multiplexer to select lines.&lt;br /&gt;
 &lt;br /&gt;
 * Wireless section could be implemeted in Bluetooth (instead of using a XBee module like in&lt;br /&gt;
 preliminary release) due to it's diffusion in cellular phones, notebooks, MP3 reader...&lt;br /&gt;
 without necessity of external modules.&lt;br /&gt;
&lt;br /&gt;
It was based on a theoretical approach to any single part. Any sensing device was designed in &amp;quot;conventional&amp;quot; way founded on analog electronic (a bridge with a NTC resisistance as sensing element, discrete IR led and some photodiode around to capture the most reflefted light as possible, GSR electrodes on the gain arm of a non-inverting amplifier...).&lt;br /&gt;
Unfortunatly a deep analysis on signal physiology, signal transduction, noise vs required accurancy, forced us to a completely different approach implementing everywhere possible a digital interface.&lt;br /&gt;
&lt;br /&gt;
=== '''Sensors Design''' ===&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''BVP'''&lt;br /&gt;
&lt;br /&gt;
Discrete IR leds and phototransistor, used in the first realize (see fig.), had been replaced first with a single led and one or more photodiodes to optimize power consumption in case of non-planar sensor positioning. Subsequently an integrated Reflective Object Sensor was introduced, with benefits about space saving, transmitter-receiver matching and power consumption.&lt;br /&gt;
To ensure light power stability, led is powered through a linear led drive LDO (Low Drop-Out). The choise of linear LDO is necessary to ensure no noise or spikes would be generated by charge pump systems or boost converters. In addition, the linear drive utilized requires only one external resitor to set led current and a decoupling capacitor, reducing part counts and board space occupation.&lt;br /&gt;
The couple factor of the reflex sensors is relatively small, even in the case of good reflecting surfaces. Therefore an additional amplifier is necessary at the sensor output: classic trans-impedance amplifier used with photo-diodes and photo-transistors was introduced. This circuit features an output voltage that is a linear function of the light level on the photo-transistor. The gain is set by the feedback resistor which could be in the millions of ohms. Linear operation is achieved by operating the photo device with a fixed voltage drop across it.&lt;br /&gt;
Trans-impedance amplifier is followed by an active fourth order band-pass filter (0.5Hz-5Hz): it's composed cascading two second order bandpass cells. In first project session only a single cell was used, but a deeper study combined with previous experiences suggests to use a 4th order filter to reduce 50Hz interference (50Hz interference produced by mains is placed only a decade after the filter pole).&lt;br /&gt;
Filter is followed by a VGA (Variable Gain Amplifier) digitally controlled through I2C Bus that allows to optimize dinamically ADC input signal amplitude directly during acquisition session, obtaining the best performance from ADC.&lt;br /&gt;
The resulting circuit is quite compact (led drive, reflective sensor, trans-impedence amplifier, active filter and variable-gain amplifier), doesn't require much power and represents a good mix between analog and digital approach: analog front-end with acquisition and first conditioning, and at the chain-end a digital controlled amplifier to ensure flexibility.&lt;br /&gt;
&lt;br /&gt;
[[Image:WADBVPComparison_Pub.jpg]]&lt;br /&gt;
&lt;br /&gt;
'''GSR'''&lt;br /&gt;
&lt;br /&gt;
GSR will be acquired by a couple of electrodes forcing a low voltage and reading current through electrodes. First designs and implementations were based on literature study: best solution appears to put GSR electrodes on the gain arm of a non-inverting amplifier (see fig.) rather than using a Wheatstone bridge due to week signal produced by this solution.&lt;br /&gt;
Putting GSR electrodes on the gain arm produces a sort of gain modulation of the constant voltage applied between electrodes but doesn't solve problems in amplifier stage due to large range of skin resistance.&lt;br /&gt;
Problems in chosing correct amplification to overwork ADC full scale with a signal affected by little variation but huge possible range could be reduced usign a variable resistor on gain arm (for example a digital potentiometer controlled by the microcontroller), but cannot be completely removed. In addition little signals are easily deteriorated by noise.&lt;br /&gt;
Solution is provided considering a new point of view: measure of unknown skin resistence is extremely similar to measure unknown electrical impedence with an auto-range multimeter!&lt;br /&gt;
Solution consist in a digital Converter which combines an on-board frequency generator with a analog-to-digital converter (ADC).&lt;br /&gt;
The resulting circuit is compact, provides a system accuracy of 0.5% and connects to microcontroller using I2C interface, ensuring an high flexibility and the possibility to modify acquisition settings after board production (through microcontroller firmware).&lt;br /&gt;
&lt;br /&gt;
[[Image:WADGSRComparison_Pub.jpg]]&lt;br /&gt;
&lt;br /&gt;
'''Temperature'''&lt;br /&gt;
&lt;br /&gt;
First idea was to acquire temperature by a NTC connected in a Wheatstone bridge. Trying to reduce noise, bridge was powered by an oscillator circuit with a frequency of some KHerz, to translate signal out of 1/f noise region. Bridge outputs were connected to an INA amplifier wich also implements signal filtering (see fig.).&lt;br /&gt;
Weak signal, noise and resolution required (0.1°C) put in crisis the system. In addition other unsolved problems were the optimization of thermal and mechanical contact between sensor and body and the sensor large thermic constant. Unstable thermic contact produces unreliable measures, whereas high sensor thermic constant hampers a fast sensor response (needed to detect short peak due to emotional reactions).&lt;br /&gt;
Possible solutions to problems of weak signal and noise arrive from digital integrated temperature sensor (for example LM35 or LM74), but these don't solve the problem of thermal contact and thermal constant. In addition none of the sensors take in consideration provides the required resolution.&lt;br /&gt;
High resolution required, noise immunity, fast response and thermal contact immunity problems had been solved using a digital optical infrared thermometer. Small size, no external component requirements and power saving mode allow us to obtain a perfect matching between required performances and space saving.&lt;br /&gt;
&lt;br /&gt;
[[Image:WADTemperatureComparison_Pub.jpg]]&lt;br /&gt;
&lt;br /&gt;
'''Accelerometer'''&lt;br /&gt;
&lt;br /&gt;
Head orientation and movements will be acquired by an accelerometer. First we think to utilize an ST Microelectronic LIS3L02AS4, due to the availability in the Lab of the evaluation board STEVAL-MKI001. It is a 3-axis ±2g/±6g linear accelerometer with 3 analog outputs, so it requires an external ADC to digitalize the three axis acceleration values. The conversion could be performed by a microcontroller with internal ADC.&lt;br /&gt;
A fast Internet research reveled this sensor is now obsolete and out of production. The choise had been to substitute the old chip with the new one: the LIS302DL (still produced by ST Microelectronic). It's a 3-axis, ± 2g/± 8g smart digital output accelerometer with I2C/SPI digital output interface and really small package. The device is capable of measuring accelerations with an output data rate of 100 Hz or 400 Hz and the self-test capability allows the user to check the functioning of the sensor in the final application.&lt;br /&gt;
In addition it may be configured to generate inertial wake-up/free-fall interrupt signals when a programmable acceleration threshold is crossed at least in one of the three axes. Thresholds and timing of interrupt generators are programmable by the end user on the fly.&lt;br /&gt;
This device, providing a digital output, doesn't need signals conversion, guaranteing better noise immunity; programmable interrupts and test interface allow greater fexibility in project. In addition wery small package, only one external resistor requirement (plus baypass capacitor) reduce significantly board space requirements.&lt;br /&gt;
&lt;br /&gt;
[[Image:WADAccelerometer.jpg]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
 NOTE:&lt;br /&gt;
 &lt;br /&gt;
 * In previous schematics, components phisical dimensions are not in scale.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== '''Microcontroller''' ===&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Foundamental requirements:&lt;br /&gt;
&lt;br /&gt;
- High speed to ensure high data output rate even in presence of a large number af sensing elemets;&lt;br /&gt;
&lt;br /&gt;
- Fast Internal ADC with multiple inputs;&lt;br /&gt;
&lt;br /&gt;
- (At Least) One I2C interface;&lt;br /&gt;
&lt;br /&gt;
- (At Least) One SPI interface;&lt;br /&gt;
&lt;br /&gt;
- (At Least) One UART interface;&lt;br /&gt;
&lt;br /&gt;
- (At Least) Three Timers;&lt;br /&gt;
&lt;br /&gt;
- (At Least) Three External Interrrupts;&lt;br /&gt;
&lt;br /&gt;
- Low-power consumption;&lt;br /&gt;
&lt;br /&gt;
- Power supply 3.3V;&lt;br /&gt;
&lt;br /&gt;
- Small package;&lt;br /&gt;
&lt;br /&gt;
In addition microcontroller was chosen between Microchip PIC family devices, due to positive previous experiences and availability of software and programmer in the Lab.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
PIC24HJ256GP206 is a 16 bit microcontroller capable of 40 MIPS speed. It provides 256KB of Flash memory, 16KB of Ram, a 10-bit 1.1Msps or 12-bit 500Ksps ADC, UART, SPI and I2C interface in a 64 pin TQFP package (10mmX10mm) powerd between 3.0V and 3.6V.&lt;br /&gt;
Power core is provided by an internal regulator reducing parts count on the board.&lt;br /&gt;
&lt;br /&gt;
The device is able to provide at the same time one I2C interface, two SPI interface and one UART interface: another UART port shares pins with an SPI port and a second I2C port shares pins with the second UART interface.&lt;br /&gt;
Findig a device that provides at the same time, on indipendent pins, an I2C, a SPI and an UART interface reduces considerably possible choises and suggests to chose a high performance microcontroller.&lt;br /&gt;
At the same time, high performance solutions have a larger pin counts than standard microcontroller, but this characteristic can be used to ensure further expansibility to the system. The second SPI interface can be used to connect another &amp;quot;intelligent&amp;quot; device or a mass storage device, for example a SD (Secure Digital) card to storage acquired data (see fig.).&lt;br /&gt;
&lt;br /&gt;
[[Image:WADSDCard.jpg]]&lt;br /&gt;
&lt;br /&gt;
Input pins connected to ADC and not used at the moment could be collected to a connector for further extension modules (for example an EMG or ECG peripheral or any other analog signal interesting in a particolar application).&lt;br /&gt;
For the same reason any other pin non used at the current stage is reported to an extension connector.&lt;br /&gt;
To guarante maximum flexibility an further update, board provides both ICD and JTAG connections (allowing on-board programming and debugging) through a couple of indipendent dedicated connectors fully compatibles with Microchip programmers and evaluation boards.&lt;br /&gt;
&lt;br /&gt;
[[Image:WADMicro_.jpg]]&lt;br /&gt;
&lt;br /&gt;
=== '''Wireless Connection''' ===&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Wireless connection is based on Bluetooth 2.0+EDR (Enhanced Data Rates) module containing all the necessary elements from Bluetooth radio to antenna and a fully implemented protocol stack.&lt;br /&gt;
Module is equipped with firmware that enables users to access Bluetooth functionality with simple ASCII commands delivered to the module over serial interface like a Bluetooth modem.&lt;br /&gt;
The dedicated onboard microcontroller (MCU) acts as interrupt controller and event timer run the Bluetooth software stack and control the radio and host interfaces. A 16-bit reduced instruction set computer (RISC) microcontroller is used for low power consumption and efficient use of memory.&lt;br /&gt;
Module support USB, SPI and UART interface and UART interface is used in this project to connect PIC microcontroller to wireless transmitter (see fig.).&lt;br /&gt;
&lt;br /&gt;
[[Image:WADWireless_Pub.jpg]]&lt;br /&gt;
&lt;br /&gt;
One of the most important characteristic is the high integration between all parts needed for efficent Bluetooth transmission: user interface, controller, radio circuits and antenna, all included in a low power, low size board (25.6mmx15mm) that requires a minimum number of external components.&lt;br /&gt;
Many other bluetooth components ara available, such as LMX9830, produced by National Semiconductor. It's an extremely small device (only 6.1mm×9.1 mm), but requires a number of external components (see fig.) like oscillators, resistors, capacitors, inductors and the antenna, in addition to an high competence in radio frequency layout circuits.&lt;br /&gt;
&lt;br /&gt;
[[Image:WADLMX9830.jpg]]&lt;br /&gt;
&lt;br /&gt;
Lack of experience in radio frequency circuit suggests to chose a ready-to-use module, factory optimized for best performance and easy to integrate in our board.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
This is the updated simplified schematic block diagram:&lt;br /&gt;
&lt;br /&gt;
[[Image:WADSchematicDiagram02.jpg]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== '''Prototype realization [WIP (Work in Progress)]''' ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Fist stage plans to realize a board using, where possible, through-hole (TH) compenents soldered on a prototyping board (100x160mm) powered from a laboratory power supply (instead of Li-on battery) and not implementing bluetooth wireless transmission. Parts not available on TH package are used with special SMD-&amp;gt;TH adapter boards or simply fixing and soldering them to the PCB by wires.&lt;br /&gt;
&lt;br /&gt;
Second stage plans to realize microcontoller firmware and test it acquiring biological signals from a patient. Firmware will be developed by subsequently steps, implementing and testing only a single peripheral at each time: only at the end single pheripheral softwares will be merged together.&lt;br /&gt;
&lt;br /&gt;
Third stage will be bluetooth interface (hardware and software) implementation and integration on the board with transmission test.&lt;br /&gt;
&lt;br /&gt;
Fourth stage will consider power supply optimization with battery management and recharge interface.&lt;br /&gt;
&lt;br /&gt;
Finally, only after a successful full board test, the last stage will be the circuit layout design with an electronic CAD, using where possible, Surface Mount Devices (SMD) to reduce board area.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== '''Main board''' ===&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Main board include power supply regulator with led power-on indicator, PIC microcontroller (mounted on a SMD-&amp;gt;TH adapeter board) with basic circuitry (decoupling capacitors, oscillator and programming-debugging ICD interface), a status led connected to PIC to verify basic microcontroller function, a series of connectors for add-on modules (BVP, GSR, temperature and accelerometer) and a USB PC interface not considered before.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== '''USB interface''' ===&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
USB interface, not projected before, replaces in developing stage Bluetooth interface, allowing a direct control/communication with a PC. In this prototype PIC UART, althought being connected to Bluettoth module, is connected to a FTDI FT232RL chip. The FT232RL is the latest device to be added to FTDI’s range of USB UART interface Integrated Circuit Devices. USB to serial designs using the FT232RL have been further simplified by fully integrating the external EEPROM, clock circuit and USB resistors onto the device.&lt;br /&gt;
The FT232RL is available in Pb-free (RoHS compliant) compact 28-Lead SSOP, so this require another SMD-&amp;gt;TH board adapter but the circuit design is very simple, including two status led for TX and RX operations. An USB B female connector was eputated the best choise for PC connection allowing to use a simple USB printer cable.&lt;br /&gt;
&lt;br /&gt;
[[Image:WADUSBInterface.jpg]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Note that USB and Bluetooth must not be connected to the board at the same time! USB port has only a developent function.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== '''BVP''' ===&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Circuit designed for BVP acquisition (refer to previous schematic) doesn't meet the expected results. Week signal hanged by noise suggested us to re-design the circuit simplifying it and reducing the number of components. For this design also sensing element has been substitute. Instead of an integrated reflective IR sensor (SFH9202), new project use a couple af discrete IR led and photothansistor matched: SFH487 and SFH309FA.&lt;br /&gt;
SFH487 is a very highly efficient GaAlAs infrared emitter (880 nm) and SFH309FA is a silicon NPN phototransistor especially suitable for applications of 880 nm with an high linearity. Both have a 3 mm led plastic package, are spectrum-matched and receiver is ambient-light shilded. After a series of positive test without the led driver (not used due to the really reduced mechanical dimensions), also led drive circuit was removed and replaced with a resistance connected directly to a PIC pin.&lt;br /&gt;
This choise reduces parts count and board space required without making worse sistem performance, allowing (like led driver) to turn off the sensor led when not used to reduce power consumption.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Figure show the signal measured directly on filtering stage output (TS952 pin 7) before the VGA with a Tektronix scopemeter TDS2014B. No particular triks had been used: signal has been recorded the first time circuit was assembled on a protoboard.&lt;br /&gt;
&lt;br /&gt;
[[Image:WADBVPScope03.jpg]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== '''GSR''' ===&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
First approach with digital Converter resulted really hard due to some errors occurred in control software in relation with internal chip complexity and I2C bus protocol. &lt;br /&gt;
After a start session GSR hardware acquisition interface was further simplified replacing the digital converter with a similar (same pinout and functions) one with inegrated internal oscillator.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
First dataset acquired whith the correct control software and the correct data reading routine, has shown all the potentiality of this chip, providing data comparables with RAW data acquired with a bigger and very expensive professional equipement produced by ProComp.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== '''Acceleration''' ===&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Lis302DL datasheet gives a short definition of this chip as &amp;quot;MEMS motion sensor 3-axis - ± 2g/± 8g smart digital output “piccolo” accelerometer&amp;quot; and it is really very, very small for human-working. For this space saving quality this accelerometer is also use in third generation Apple i-phone.&lt;br /&gt;
The major problem with this sensor had been to solder it to a sort of adapter to connect it to the circuit, but after that it works fine, with a good sensitivity and accuracy. Because of free fall and double click recognition at not required (at the moment) in this application, software routines for setting configuration registers and reading data resulted simplified.&lt;br /&gt;
A usefull caracteristic of this sensor, not previously noticed, is the presence of internal pull-up resistors that allows no necessity of external I2C bus pull-up resistors, reducing space occupation and components count.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== '''Temperature''' ===&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The choice to use a digital optical infrared thermometer due to his characteristics (non contact measure, 0.02°C resolution with accuracy of ±0.1°C for medical applications version) creates a really serious supplies problem: sensor manufacture wasn't able to give us a sample and no one in Italy can sell us only a pair of theese sensors to try them. A single piece was bought from Future Electronics, ordering it via web and paying it via credit card. Fortunately the sensor, that cames directly from USA, arrived in Italy few days later the payment in excellent conditions.&lt;br /&gt;
Problems occurred interfacing this sensor on I2C bus with other devices (GSR digital Converter and LIS302) connected. Sensor has a 2 wire serial SMBus compatible protocol: I2C bus and  SMBus are popular 2-wire buses that are essentially compatible with each other, but are not the same.&lt;br /&gt;
The buses operate at the same speed, up to 100kHz, but the I2C bus has both 400kHz and 2MHz versions. Complete compatibility between both buses is ensured only below 100kHz.&lt;br /&gt;
Timeout and (as a consequence of timeout) minimum clock speed are the most important differences between the I2C bus and the SMBus:&lt;br /&gt;
&lt;br /&gt;
I2C Bus = DC (no timeout)&lt;br /&gt;
&lt;br /&gt;
SMBus = 10kHz (35mS timeout)&lt;br /&gt;
&lt;br /&gt;
Despite differences in logic-level specifications between the two buses, generally devices can be mixed and matched with abandon.&lt;br /&gt;
Level Specifications for the I2C Bus and the SMBus are shown below (VDD is typically expected to be between 3 volts and 5 volts):&lt;br /&gt;
&lt;br /&gt;
[[Image:WADTable1.jpg]]&lt;br /&gt;
&lt;br /&gt;
What wasn't readily evident in the discussion of voltage levels is that these levels are also specified with different currents between the buses. The SMBus specifies a minimum sink current of 100microA, and a maximum of 350microA, compared to 3mA for the I2C bus. This in turn would determine the lowest acceptable value of the pullup resistor, examples of which are shown in the table below.&lt;br /&gt;
&lt;br /&gt;
[[Image:WADTable2.jpg]]&lt;br /&gt;
&lt;br /&gt;
In reality, it is not unusual to encounter pullup resistor values in SMBus systems, which violate this specification by being lower than recommended. A very popular range for pullup resistor values, even in some SMBus systems, seems to be 2.4k to 3.9k.&lt;br /&gt;
&lt;br /&gt;
These reasons, in adition to clear ideas about close developments, suggest a general review of schematic to re-distribute microcontroller resources.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== '''Part 6: final review [WIP (Work in Progress)]''' ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== '''Microcontroller''' ===&lt;br /&gt;
&lt;br /&gt;
Referring to previous schematic, some chenges had been applied:&lt;br /&gt;
&lt;br /&gt;
- Programmer/Debugger interface is now PGD1/EMUD1 and PGC1/EMUC1 instead of PGD1/EMUD2 and PGC1/EMUC2;&lt;br /&gt;
&lt;br /&gt;
- JTAG interface had been removed;&lt;br /&gt;
&lt;br /&gt;
- UART2 is no more available so UART1 has replaced UART2 as communication port;&lt;br /&gt;
&lt;br /&gt;
- SPI2 is no more available so SPI1 is now used to control both VGA (Variable Gain Amplifier) and SD Storage Card;&lt;br /&gt;
&lt;br /&gt;
- RG12, RG13, RG14 pins had been connected to three status led for a machine visual state detection;&lt;br /&gt;
&lt;br /&gt;
- I2C1 interface is now connected to accelerometer (LIS302) and GSR Converter only;&lt;br /&gt;
&lt;br /&gt;
- I2C2 interface is dedicated to temperature sensor, enabling I/O pin thresholds compliant with SMBus specification;&lt;br /&gt;
&lt;br /&gt;
- Connectors for I2C, SMBus and SPI expansion modules had been added to the board;&lt;br /&gt;
&lt;br /&gt;
- Test point pads had been added to the board to simplify debugging.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== '''Data link''' ===&lt;br /&gt;
&lt;br /&gt;
During developing stages, an USB port had replaced Bluetooth wireless transmission, allowing a direct control/communication with a PC. This interfaced, based on a FT232RL, prove to be very usefull and simple to use.&lt;br /&gt;
The choice to use an usb port to charge internal battery, in addition to availability of a UART multiplexer inside the Bluetooth, suggest to implement both USB and Bluetooth interface.&lt;br /&gt;
&lt;br /&gt;
That's the Bluetooth internal UART multiplexer schematic:&lt;br /&gt;
&lt;br /&gt;
[[Image:WAD_UARTMux.jpg]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== '''Battery Charge &amp;amp; MonitorPower On''' ===&lt;br /&gt;
&lt;br /&gt;
Device is powered by a single cell Li-on battery (3.7V, 1080mAh): this is the same unit used in IPod(TM) from Apple.&lt;br /&gt;
&lt;br /&gt;
[[Image:WAD_Battery.jpg]]&lt;br /&gt;
&lt;br /&gt;
Battery charge is executed by a Maxim's device: it is a really compact single-cell lithium-ion (Li+) battery charger that can be powered directly from a USB port or from an external supply up to 6.5V. It has a 0.5% overall battery regulation voltage accuracy to allow maximum utilization of the battery capacity.&lt;br /&gt;
The charger uses an internal FET to deliver up to 500mA charging current to the battery. The device can be configured for either a 4.1V or 4.2V battery, using the SELV input. The SELI input sets the charge current to either 100mA or 500mA. An open-drain output indicates charge status.&lt;br /&gt;
It has preconditioning that soft-starts a near-dead battery cell before charging. Other safety features include continuous monitoring of voltage and current and initial checking for fault conditions before charging.&lt;br /&gt;
&lt;br /&gt;
White battery wire (see photo) is connected to internal NTC thermistor (10KOhm@+25°C). In this way it's posible to implement an over/under charge temperature detector using a couple af operational amplifier as comparator.&lt;br /&gt;
With a resistence network it had been possible to set an upper temperature threshold of 47.5°C (corresponding to 3.97K NTC value) and a down thresold of 2.5°C (corresponding to &lt;br /&gt;
28.7K NTC value). Out of this range comparators output go low disabling battery charger.&lt;br /&gt;
This function allows to prevent battery demage or explosion during charge.&lt;br /&gt;
&lt;br /&gt;
Battery voltage monitor is hardware implemented by a CMOS micropower voltage detector that warn microprocessors/microcontroller of power failures. It contains a comparator, a 1.5V bandgap reference, and an open-drain n-channel output driver. Two external resistors are used in conjunction with the internal reference to set the trip voltage to the desired level. A hysteresis output is also included, allowing the user to apply positive feedback for noise-free output switching.&lt;br /&gt;
Using a couple of these device is possible to set two treshold: one for low battery and another for end battery detection. Low battery detection allow communicate the user battery level; end battery detection allow microprocessor shut down the device before battery voltage fall down under 3.4V that is the minimun input voltage allowed by linear regulator MCP1700.&lt;br /&gt;
If battery level fall down under 3.4V, MCP1700 is not able to guarantee line regulation.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== '''Power On &amp;amp; Selection''' ===&lt;br /&gt;
&lt;br /&gt;
Power-up and shut-down were implemented using a Maxim's MAX16054 connected with an ADG801 by Analog Device.&lt;br /&gt;
MAX16054 is a pushbutton on/off controller with a single switch debouncer and built-in latch. It accepts a noisy input from a mechanical switch and produces a clean latched digital output after a factory-fixed qualification delay.&lt;br /&gt;
The state of the output changes only when triggered by the falling edge of the debounced switch input; the output remains unchanged on the rising edge of the input.An asynchronous CLEAR input allows an external signal to force the output flip-flop low.&lt;br /&gt;
ADG801 is a monolithic CMOS, single-pole, single throw (SPST), normally open (NO) switch with on resistance of less than 0.4Ohm. This switch conducts equally well in both directions when on.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== '''MicroSD Storage Card ''' ===&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== '''RTC ''' ===&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Students that have worked on the project==&lt;br /&gt;
&lt;br /&gt;
* Mattia Colombo (Blood Volume Pressure sensor)&lt;br /&gt;
* Alessia Cornaggia (Galvanic skin response sensor)&lt;br /&gt;
* Sala Mirko (Galvanic skin response sensor)&lt;br /&gt;
&lt;br /&gt;
== Laboratory work and risk analysis ==&lt;br /&gt;
&lt;br /&gt;
Laboratory work for this project will be mainly performed at AIRLab/Lambrate. It will include electrical and electronic activity. Potentially risky activities are the following:&lt;br /&gt;
* Use of mechanical tools. Standard safety measures described in [http://airlab.elet.polimi.it/index.php/airlab/content/download/461/4110/file/documento_valutazione_rischi_AIRLab.pdf Safety norms] will be followed.&lt;br /&gt;
* Use of soldering iron. Standard safety measures described in [http://airlab.elet.polimi.it/index.php/airlab/content/download/461/4110/file/documento_valutazione_rischi_AIRLab.pdf Safety norms] will be followed.&lt;br /&gt;
* Use of high-voltage circuits. Special gloves and a current limiter will be used. Standard safety measures described in [http://airlab.elet.polimi.it/index.php/airlab/content/download/461/4110/file/documento_valutazione_rischi_AIRLab.pdf Safety norms] will be followed.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
 Detailed Information and Schematics available in the Discussion page.&lt;/div&gt;</summary>
		<author><name>PaoloVilla</name></author>	</entry>

	<entry>
		<id>https://airwiki.deib.polimi.it/index.php?title=Talk:Wireless_Affective_Devices&amp;diff=9584</id>
		<title>Talk:Wireless Affective Devices</title>
		<link rel="alternate" type="text/html" href="https://airwiki.deib.polimi.it/index.php?title=Talk:Wireless_Affective_Devices&amp;diff=9584"/>
				<updated>2009-12-12T09:46:14Z</updated>
		
		<summary type="html">&lt;p&gt;PaoloVilla: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt; This &amp;quot;private&amp;quot; layer is similar to the &amp;quot;public&amp;quot; one but with detailed information and shematics.&lt;br /&gt;
{{Project&lt;br /&gt;
|title=Wireless Affective Devices&lt;br /&gt;
|tutor=SimoneTognetti;MatteoMatteucci&lt;br /&gt;
|students=PaoloVilla&lt;br /&gt;
|resarea=BioSignal Analysis&lt;br /&gt;
|restopic=Affective Computing&lt;br /&gt;
|start=2008/01/08&lt;br /&gt;
|end=2009/12/30&lt;br /&gt;
|status=Active&lt;br /&gt;
|level=Ms&lt;br /&gt;
|type=Thesis&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Project aims ==&lt;br /&gt;
&lt;br /&gt;
 ”''Everyone knows what an emotion is, until asked to give a definition''”&lt;br /&gt;
                                         &lt;br /&gt;
                                                                 Beverly Fehr and James Russell&lt;br /&gt;
&lt;br /&gt;
Research on Human-Computer-Interfaces has recently begun to take into account the affective state of the user. By appropriately reacting to the affective user state, interfaces could not only become more pleasant or entertaining, but also more effective or safer.&lt;br /&gt;
It is known that affective states have bodily correlates, and thus physiological signals could provide the necessary information for acquiring the affective user state. In contrast to other sources of information about the affective user state such as speech or facial expression, most physiological signals are not under voluntary control, and thus cannot be masked up to the same extent. Furthermore, it can be presumed that the signs of affective states in physiological signals are less dependent on individual and contextual factors: this is because the signals correspond to internal physiology, largely related to the autonomous nervous and limbic systems, rather than to external expressions that can be manipulated easily.&lt;br /&gt;
Recently, the issue of emotion regulation drew interests from several fields including neuroscience, psychology, education, computer science, etc. Possible applications are e-learningin, human computer interaction, development of communicative technologies for use by people with autism, car infotainment system, lie detection tests, cognitive workload, multimodal user interfaces MMUI (allow users to control computers using speech and gesture), etc.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The project is aimed at developing a device, connected to a PC, to acquire biological signals (such as GSR, BVP, Temperature and Head orientation) in a way that is less invasive for the subject. The term invasive is related to how much the sensors we use compromise the normal interaction between subject and machine.&lt;br /&gt;
Through these biological signal the PC is able o understand emotion in people who wear the device.&lt;br /&gt;
&lt;br /&gt;
An affective device should be weared easily, should not have cables and should acquire as much sensors as possible. We relax some constraint on the quality of signal but we add constraint on way they are acquired(i.e. the subject can put it on easily, the usual movements are not influenced..). The aim of the resulting device is not to replace the standard medical devices usually used to acquire that signals, but is to be much more suitable for industrial application in which the medical requirement are replaced by invasivity requirement.&lt;br /&gt;
&lt;br /&gt;
It is composed by:&lt;br /&gt;
&lt;br /&gt;
* Low power, high efficiency, battery powered design&lt;br /&gt;
* Wireless comunication with a PC&lt;br /&gt;
* Blood Volume Pressure Sensor (Preliminary release by Mattia Colombo)&lt;br /&gt;
* Galvanic Skin Response Sensor (Preliminary release by Sala Mirko e Alessia Cornaggia)&lt;br /&gt;
* Temperature Sensor&lt;br /&gt;
* 3 Way Accelerometer&lt;br /&gt;
* Possibility of further extension&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''GSR (or EDR or EDA)'''&lt;br /&gt;
&lt;br /&gt;
An often misunderstood and difficult technique, GSR (also known as the electrodermal response EDR or electrodermal activity EDA) has gone through many phases of interest and rejection since the early 1900's and is very popular in psychophysiological studies since Carl Jung and his students (1907) described it as a mean to&lt;br /&gt;
enter the “sea of the unconscious” because “every stimulus accompanied by an emotion produced a deviation of the galvanometer” directly proportional to the strength of the emotion aroused. It has been used in important research on anxiety and stress levels (Fenz &amp;amp; Epstein, ' 67); and it has been a part of lie detection (Raskin, ' 73). Controversy has centered around the technique, underlying mechanisms, and the meaning of the responses obtained from the skin. &lt;br /&gt;
There has been a long history of electrodermal activity research, even if most investigators accept the phenomenon without understanding exactly what it means (Hume, ' 76).&lt;br /&gt;
The resistance of the skin is usually large, approximately 1M; however, momentary changes in the level of the sweat gland activity causes changes in resistance (up to approximately 950K).&lt;br /&gt;
Physiology, the GSR reflescts sweat gland activity and changes in the sympathetic nervous system and measurement variables. The activity of the sweat glands in response to sympathetic nervous stimulation ( Increased sympathetic activation ) results in an increase in the level of conductance. There ia a relationship between sympathetic activity and emotional arousal, although one cannot identify the specific emotion being elicited. &lt;br /&gt;
Basically there are two techniques in the history of Electrodermal measurement. In one a current is passed thru the skin and the the resistance to passage is measured; in the other no current is used externally and the skin itself is the source of electrical activity.&lt;br /&gt;
By applying a conventional 0.5 Volts across the skin and measuring changes in the&lt;br /&gt;
corresponding conductance, the emotional state of the subject can be inferred. In general, the electrodes used are of the Ag/AgCl type which are recessed from the skin and require the use of a suitable electrode paste.&lt;br /&gt;
It is important to note, however, that fluctuations in skin conductivity are resultant of many types of arousal.&lt;br /&gt;
By observing only these changes, it is impossible to deduce without prior knowledge whether&lt;br /&gt;
the subject has become happy, startled, physically active, etcetera.&lt;br /&gt;
EDA consists of two components: tonic and phasic. The tonic component is a low&lt;br /&gt;
frequency baseline conductivity level, which can oscillate over the course of days. The phasic&lt;br /&gt;
component rides on top of the tonic component, exhibits more rapid fluctuations, and&lt;br /&gt;
generally increases when a person is aroused. Problematically, each person has a different&lt;br /&gt;
tonic conductivity, so in order to infer the arousal level of the subject, the relative changes in&lt;br /&gt;
EDA must be analyzed over a period of time. Furthermore, skin conductance (measured in&lt;br /&gt;
units of siemens; formerly mhos) depends on the skin path length between the two electrodes&lt;br /&gt;
contacts, even for subjects with identical skin conductivity (measured in units of&lt;br /&gt;
siemens/meter). It is for these reasons that it is crucial to analyze the temporal variations of&lt;br /&gt;
the EDA signal.&lt;br /&gt;
&lt;br /&gt;
'''BVP'''&lt;br /&gt;
&lt;br /&gt;
The cardiovascular system is in charge to keep us alive by maintaining the vital blood flow throughout the body, providing nutrients and oxygen to our cells. The SNS controls this system&lt;br /&gt;
by shifting the flow in response to exercise, temperature,postural and emotional changes.&lt;br /&gt;
Blood Volume Pulse (BVP) is the most common measure of vasomotor activity because it reflects the phasic pumping of the heart, the vasodilation of vessels that changes in the amount of acral blood delivered.&lt;br /&gt;
The Blood Volume Pulse (BVP) waveform is an important indicator of circulatory function that can be obtained noninvasively through a photoplethysmographic transducer (a PPG is often obtained by using a pulse oximeter, Shelley and Shelley, 2001) applied to the finger or the earlobe of human subjects. In particular, this signal may be useful in determining the degree of cardiovascular change undergone by a subject through an exercise session. &lt;br /&gt;
&lt;br /&gt;
''Principles of photoplethysmographic Technology:''&lt;br /&gt;
&lt;br /&gt;
The principle of photoplethysmographic (That is the same of pulse oximetry) is based on the red and infrared light absorption characteristics of oxygenated and deoxygenated hemoglobin. Oxygenated hemoglobin absorbs more infrared light and allows more red light to pass through. Deoxygenated (or reduced) hemoglobin absorbs more red light and allows more infrared light to pass through. Red light is in the 600-750 nm wavelength light band.&lt;br /&gt;
Pulse oximetry uses a light emitter with red and infrared LEDs that shines through a reasonably translucent site with good blood flow. Opposite the emitter is a photodetector that receives the light that passes through the measuring site.&lt;br /&gt;
There are two methods of sending light through the measuring site: transmission and reflectance. In the transmission the emitter and photodetector are opposite of each other with the measuring site in-between. The light can then pass through the site. In the reflectance method, the emitter and photodetector are next to each other on top the measuring site. The light bounces from the emitter to the detector across the site. The transmission method is the most common type used.&lt;br /&gt;
While pulse oximeters are a commonly used medical device the PPG derived from them is rarely displayed, and is nominally only processed to determine heart rate. &lt;br /&gt;
&lt;br /&gt;
'''Temperature'''&lt;br /&gt;
&lt;br /&gt;
The temperatures of peripheral limbs vary as a consequence of changes in blood flow.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== '''Previous work''' ==&lt;br /&gt;
&lt;br /&gt;
Here is a preliminary release of the headset produced before 2008/08/08&lt;br /&gt;
&lt;br /&gt;
[[Image:Wd1.jpg]]&lt;br /&gt;
&lt;br /&gt;
If you are interested on the making of the headset please see [[making rubber models]]&lt;br /&gt;
&lt;br /&gt;
'''* Blood Volume pressure'''&lt;br /&gt;
First graph showing a signal acquired with the wireless sensor. &lt;br /&gt;
[[Image:Bvp.png]]&lt;br /&gt;
&lt;br /&gt;
'''* Skin galvanic response''' (Sala Mirko e Alessia Cornaggia[http://airwiki.elet.polimi.it/mediawiki/index.php/User:AlessiaCornaggia])&lt;br /&gt;
Galvanic skin response (GSR), also known as electrodermal response (EDR), psychogalvanic reflex (PGR), or skin conductance response (SCR), is a method of measuring the electrical resistance of the skin.  There is a relationship between sympathetic activity and emotional arousal, although one cannot identify the specific emotion being elicited. The GSR is highly sensitive to emotions in some people. Fear, anger, startle response, orienting response and sexual feelings are all among the emotions which may produce similar GSR responses.&lt;br /&gt;
Response of the skin to the passage of a small electric current. The ease with which the current flows between two points on the skin can be used to indicate stress. When a person is tense or emotional, the sweat glands become more active, increasing moisture on the skin; this allows the electric current to flow more readily. &lt;br /&gt;
The response may also be used in relaxation training: information about the galvanic skin response is fed back aurally or visually to the subject who can, with practice, learn to increase or decrease sweating on the skin by learning to relax or tense muscles.&lt;br /&gt;
We measure the galvanic skin response using two electrodes attached to the skin. The optimal placement is the palm of the hands, but we are experimenting other places like on the forehead.&lt;br /&gt;
The circuit we are creating is the one below.&lt;br /&gt;
&lt;br /&gt;
[[Image:circuito.jpg]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== '''Project the device''' ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== '''Re-definition of the complete work''' ===&lt;br /&gt;
&lt;br /&gt;
Sensors are an important part of an Affective Computing System because they provide information about the wearer's physical state or behavior. They can gather data in a continuous way without having to interrupt the user. &lt;br /&gt;
To define in detail electronic specifications and requirements it's necessary a preliminary research/study (in literature and web) about state of art of sensor type used to monitor each type of biological signals we are interested about.&lt;br /&gt;
In this way it's possible both understand problematics related to interaction between biological and electonical worlds and improve or re-desig existing prototype.&lt;br /&gt;
&lt;br /&gt;
About Sensors: &lt;br /&gt;
&lt;br /&gt;
BVP will be acquire by an IR transmitter-receiver measuring light reflected from skin (photoplethysmography). Particular attention will be put on position, geometry and power absorption of this stage. &lt;br /&gt;
&lt;br /&gt;
GSR will be acquiret by a couple of electrodes forcing a low current (or voltage) and reading voltage (or current) through electrodes. Particular attention will be put on electrodes position and material. In addition is possible to foresee some problems in amplifier stage due to large range of skin resistance. Problem consist in chosing a correct amplification to overwork ADC full scale with a signal affected by little variation but huge possible range. &lt;br /&gt;
&lt;br /&gt;
Temperature will be acquired by thermocouple or PTC/NTC. Slowly variable signal, possible problems with noise due to resolution required. &lt;br /&gt;
&lt;br /&gt;
Head orientation will be acquired by an accelerometer and a gyroscope, problably integrated in the same chip. Two possibilities: analog output (need to digitalize up to six line) or digital output (like displaied in schematic block diagram). &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
This was the preliminary simplified schematic block diagram of the complete instrumentation setup:&lt;br /&gt;
&lt;br /&gt;
[[Image:WADSchematicDiagram01.jpg]]&lt;br /&gt;
&lt;br /&gt;
 NOTE:&lt;br /&gt;
 &lt;br /&gt;
 * In schematic is not present Power Supply Module: it will be based on a rechargeable Li-ion&lt;br /&gt;
 battery. It must satisfy requirements of high efficiency, logn life and low weight.&lt;br /&gt;
 &lt;br /&gt;
 * ADC and Microcontroller could be unified using a microcontroller with internal ADC and&lt;br /&gt;
 internal or external multiplexer to select lines.&lt;br /&gt;
 &lt;br /&gt;
 * Wireless section could be implemeted in Bluetooth (instead of using a XBee module like in&lt;br /&gt;
 preliminary release) due to it's diffusion in cellular phones, notebooks, MP3 reader...&lt;br /&gt;
 without necessity of external modules.&lt;br /&gt;
&lt;br /&gt;
It was based on a theoretical approach to any single part. Any sensing device was designed in &amp;quot;conventional&amp;quot; way founded on analog electronic (a bridge with a NTC resisistance as sensing element, discrete IR led and some photodiode around to capture the most reflefted light as possible, GSR electrodes on the gain arm of a non-inverting amplifier...).&lt;br /&gt;
Unfortunatly a deep analysis on signal physiology, signal transduction, noise vs required accurancy, forced us to a completely different approach implementing everywhere possible a digital interface.&lt;br /&gt;
&lt;br /&gt;
=== '''Sensors Design''' ===&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''BVP'''&lt;br /&gt;
&lt;br /&gt;
Discrete IR leds and phototransistor, used in the first realize (see fig.), had been replaced first with a single led and one or more photodiodes to optimize power consumption in case of non-planar sensor positioning. Subsequently an integrated Reflective Object Sensor was introduced, with benefits about space saving, transmitter-receiver matching and power consumption.&lt;br /&gt;
To ensure light power stability, led is powered through a linear led drive LDO (Low Drop-Out). The choise of linear LDO is necessary to ensure no noise or spikes would be generated by charge pump systems or boost converters. In addition, the linear drive utilized requires only one external resitor to set led current and a decoupling capacitor, reducing part counts and board space occupation.&lt;br /&gt;
The couple factor of the reflex sensors is relatively small, even in the case of good reflecting surfaces. Therefore an additional amplifier is necessary at the sensor output: classic trans-impedance amplifier used with photo-diodes and photo-transistors was introduced. This circuit features an output voltage that is a linear function of the light level on the photo-transistor. The gain is set by the feedback resistor which could be in the millions of ohms. Linear operation is achieved by operating the photo device with a fixed voltage drop across it.&lt;br /&gt;
Trans-impedance amplifier is followed by an active fourth order band-pass filter (0.5Hz-5Hz): it's composed cascading two second order bandpass cells. In first project session only a single cell was used, but a deeper study combined with previous experiences suggests to use a 4th order filter to reduce 50Hz interference (50Hz interference produced by mains is placed only a decade after the filter pole).&lt;br /&gt;
Filter is followed by a VGA (Variable Gain Amplifier) digitally controlled through I2C Bus that allows to optimize dinamically ADC input signal amplitude directly during acquisition session, obtaining the best performance from ADC.&lt;br /&gt;
The resulting circuit is quite compact (led drive, reflective sensor, trans-impedence amplifier, active filter and variable-gain amplifier), doesn't require much power and represents a good mix between analog and digital approach: analog front-end with acquisition and first conditioning, and at the chain-end a digital controlled amplifier to ensure flexibility.&lt;br /&gt;
&lt;br /&gt;
[[Image:WADBVPComparison.jpg]]&lt;br /&gt;
&lt;br /&gt;
'''GSR'''&lt;br /&gt;
&lt;br /&gt;
GSR will be acquired by a couple of electrodes forcing a low voltage and reading current through electrodes. First designs and implementations were based on literature study: best solution appears to put GSR electrodes on the gain arm of a non-inverting amplifier (see fig.) rather than using a Wheatstone bridge due to week signal produced by this solution.&lt;br /&gt;
Putting GSR electrodes on the gain arm produces a sort of gain modulation of the constant voltage applied between electrodes but doesn't solve problems in amplifier stage due to large range of skin resistance.&lt;br /&gt;
Problems in chosing correct amplification to overwork ADC full scale with a signal affected by little variation but huge possible range could be reduced usign a variable resistor on gain arm (for example a digital potentiometer controlled by the microcontroller), but cannot be completely removed. In addition little signals are easily deteriorated by noise.&lt;br /&gt;
Solution is provided considering a new point of view: measure of unknown skin resistence is extremely similar to measure unknown electrical impedence with an auto-range multimeter!&lt;br /&gt;
Solution consist in a digital Impedance Converter: AD5934 is a high precision impedance converter system which combines an on-board frequency generator with a 12-bit, 250 kSPS, analog-to-digital converter (ADC). The frequency generator allows an external complex impedance to be excited with a known frequency; the response signal from the impedance is sampled by the on-board ADC and a discrete Fourier transform (DFT) is processed by an on-board DSP engine. The DFT algorithm returns a real (R) and imaginary (I) data-word at each output frequency. This solution not only allows to measure impedence range from 100 Ohm to 10 MOhm, but in adition allow to investigate it across a wide range of frequency, producing a noise-free digital output.&lt;br /&gt;
The resulting circuit is extremely compact (converter chip, one setting resistor and bypass capacitors), provides a system accuracy of 0.5% and connects to microcontroller using I2C interface, ensuring an high flexibility and the possibility to modify acquisition settings after board production (through microcontroller firmware).&lt;br /&gt;
&lt;br /&gt;
[[Image:WADGSRComparison.jpg]]&lt;br /&gt;
&lt;br /&gt;
'''Temperature'''&lt;br /&gt;
&lt;br /&gt;
First idea was to acquire temperature by a NTC connected in a Wheatstone bridge. Trying to reduce noise, bridge was powered by an oscillator circuit with a frequency of some KHerz, to translate signal out of 1/f noise region. Bridge outputs were connected to an INA amplifier wich also implements signal filtering (see fig.).&lt;br /&gt;
Weak signal, noise and resolution required (0.1°C) put in crisis the system. In addition other unsolved problems were the optimization of thermal and mechanical contact between sensor and body and the sensor large thermic constant. Unstable thermic contact produces unreliable measures, whereas high sensor thermic constant hampers a fast sensor response (needed to detect short peak due to emotional reactions).&lt;br /&gt;
Possible solutions to problems of weak signal and noise arrive from digital integrated temperature sensor (for example LM35 or LM74), but these don't solve the problem of thermal contact and thermal constant. In addition none of the sensors take in consideration provides the required resolution.&lt;br /&gt;
High resolution required, noise immunity, fast response and thermal contact immunity problems had been solved using a digital optical infra red thermometer. The MLX90614 is an infra red thermometer for non contact temperature measurements based on a thermopile detector chip including signal conditioning in the same TO-39 package. Thanks to its low noise amplifier, 17-bit ADC and powerful DSP unit, a high accuracy and resolution of the thermometer is achieved.&lt;br /&gt;
The calculated object and ambient temperatures are available in RAM of MLX90614 with 0.02°C resolution: they are accessible by 2 wire serial SMBus compatible protocol. A special version for medical applications offers an accuracy of ±0.1ºC in a limited temperature range around the human body temperature.&lt;br /&gt;
Small size, no external component requirements and power saving mode allow us to obtain a perfect matching between required performances and space saving.&lt;br /&gt;
&lt;br /&gt;
[[Image:WADTemperatureComparison.jpg]]&lt;br /&gt;
&lt;br /&gt;
'''Accelerometer'''&lt;br /&gt;
&lt;br /&gt;
Head orientation and movements will be acquired by an accelerometer. First we think to utilize an ST Microelectronic LIS3L02AS4, due to the availability in the Lab of the evaluation board STEVAL-MKI001. It is a 3-axis ±2g/±6g linear accelerometer with 3 analog outputs, so it requires an external ADC to digitalize the three axis acceleration values. The conversion could be performed by a microcontroller with internal ADC.&lt;br /&gt;
A fast Internet research reveled this sensor is now obsolete and out of production. The choise had been to substitute the old chip with the new one: the LIS302DL (still produced by ST Microelectronic). It's a 3-axis, ± 2g/± 8g smart digital output accelerometer with I2C/SPI digital output interface and really small package. The device is capable of measuring accelerations with an output data rate of 100 Hz or 400 Hz and the self-test capability allows the user to check the functioning of the sensor in the final application.&lt;br /&gt;
In addition it may be configured to generate inertial wake-up/free-fall interrupt signals when a programmable acceleration threshold is crossed at least in one of the three axes. Thresholds and timing of interrupt generators are programmable by the end user on the fly.&lt;br /&gt;
This device, providing a digital output, doesn't need signals conversion, guaranteing better noise immunity; programmable interrupts and test interface allow greater fexibility in project. In addition wery small package, only one external resistor requirement (plus baypass capacitor) reduce significantly board space requirements.&lt;br /&gt;
&lt;br /&gt;
[[Image:WADAccelerometer.jpg]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
 NOTE:&lt;br /&gt;
 &lt;br /&gt;
 * In previous schematics, components phisical dimensions are not in scale.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== '''Microcontroller''' ===&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Foundamental requirements:&lt;br /&gt;
&lt;br /&gt;
- High speed to ensure high data output rate even in presence of a large number af sensing elemets;&lt;br /&gt;
&lt;br /&gt;
- Fast Internal ADC with multiple inputs;&lt;br /&gt;
&lt;br /&gt;
- (At Least) One I2C interface;&lt;br /&gt;
&lt;br /&gt;
- (At Least) One SPI interface;&lt;br /&gt;
&lt;br /&gt;
- (At Least) One UART interface;&lt;br /&gt;
&lt;br /&gt;
- (At Least) Three Timers;&lt;br /&gt;
&lt;br /&gt;
- (At Least) Three External Interrrupts;&lt;br /&gt;
&lt;br /&gt;
- Low-power consumption;&lt;br /&gt;
&lt;br /&gt;
- Power supply 3.3V;&lt;br /&gt;
&lt;br /&gt;
- Small package;&lt;br /&gt;
&lt;br /&gt;
In addition microcontroller was chosen between Microchip PIC family devices, due to positive previous experiences and availability of software and programmer in the Lab.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
PIC24HJ256GP206 is a 16 bit microcontroller capable of 40 MIPS speed. It provides 256KB of Flash memory, 16KB of Ram, a 10-bit 1.1Msps or 12-bit 500Ksps ADC, UART, SPI and I2C interface in a 64 pin TQFP package (10mmX10mm) powerd between 3.0V and 3.6V.&lt;br /&gt;
Power core is provided by an internal regulator reducing parts count on the board.&lt;br /&gt;
&lt;br /&gt;
The device is able to provide at the same time one I2C interface, two SPI interface and one UART interface: another UART port shares pins with an SPI port and a second I2C port shares pins with the second UART interface.&lt;br /&gt;
Findig a device that provides at the same time, on indipendent pins, an I2C, a SPI and an UART interface reduces considerably possible choises and suggests to chose a high performance microcontroller.&lt;br /&gt;
At the same time, high performance solutions have a larger pin counts than standard microcontroller, but this characteristic can be used to ensure further expansibility to the system. The second SPI interface can be used to connect another &amp;quot;intelligent&amp;quot; device or a mass storage device, for example a SD (Secure Digital) card to storage acquired data (see fig.).&lt;br /&gt;
&lt;br /&gt;
[[Image:WADSDCard.jpg]]&lt;br /&gt;
&lt;br /&gt;
Input pins connected to ADC and not used at the moment could be collected to a connector for further extension modules (for example an EMG or ECG peripheral or any other analog signal interesting in a particolar application).&lt;br /&gt;
For the same reason any other pin non used at the current stage is reported to an extension connector.&lt;br /&gt;
To guarante maximum flexibility an further update, board provides both ICD and JTAG connections (allowing on-board programming and debugging) through a couple of indipendent dedicated connectors fully compatibles with Microchip programmers and evaluation boards.&lt;br /&gt;
&lt;br /&gt;
[[Image:WADMicro.jpg]]&lt;br /&gt;
&lt;br /&gt;
=== '''Wireless Connection''' ===&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Wireless connection is based on BlueGiga WT12 module: it's a next-generation, class 2, Bluetooth 2.0+EDR (Enhanced Data Rates) module containing all the necessary elements from Bluetooth radio to antenna and a fully implemented protocol stack.&lt;br /&gt;
By default WT12 module is equipped with powerful and easy-to-use iWRAP firmware that enables users to access Bluetooth functionality with simple ASCII commands delivered to the module over serial interface like a Bluetooth modem.&lt;br /&gt;
The dedicated onboard microcontroller (MCU) acts as interrupt controller and event timer run the Bluetooth software stack and control the radio and host interfaces. A 16-bit reduced instruction set computer (RISC) microcontroller is used for low power consumption and efficient use of memory.&lt;br /&gt;
WT12 module support USB, SPI and UART interface and UART interface is used in this project to connect PIC microcontroller to wireless transmitter (see fig.).&lt;br /&gt;
&lt;br /&gt;
[[Image:WADWireless.jpg]]&lt;br /&gt;
&lt;br /&gt;
One of the most important WT12 characteristic is the high integration between all parts needed for efficent Bluetooth transmission: user interface, controller, radio circuits and antenna, all included in a low power, low size board (25.6mmx15mm) that requires a minimum number of external components.&lt;br /&gt;
Many other bluetooth components ara available, such as LMX9830, produced by National Semiconductor. It's an extremely small device (only 6.1mm×9.1 mm), but requires a number of external components (see fig.) like oscillators, resistors, capacitors, inductors and the antenna, in addition to an high competence in radio frequency layout circuits.&lt;br /&gt;
&lt;br /&gt;
[[Image:WADLMX9830.jpg]]&lt;br /&gt;
&lt;br /&gt;
Lack of experience in radio frequency circuit suggests to chose a ready-to-use module, factory optimized for best performance and easy to integrate in our board.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
This is the updated simplified schematic block diagram:&lt;br /&gt;
&lt;br /&gt;
[[Image:WADSchematicDiagram02.jpg]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== '''Prototype realization [WIP (Work in Progress)]''' ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Fist stage plans to realize a board using, where possible, through-hole (TH) compenents soldered on a prototyping board (100x160mm) powered from a laboratory power supply (instead of Li-on battery) and not implementing bluetooth wireless transmission. Parts not available on TH package are used with special SMD-&amp;gt;TH adapter boards or simply fixing and soldering them to the PCB by wires.&lt;br /&gt;
&lt;br /&gt;
Second stage plans to realize microcontoller firmware and test it acquiring biological signals from a patient. Firmware will be developed by subsequently steps, implementing and testing only a single peripheral at each time: only at the end single pheripheral softwares will be merged together.&lt;br /&gt;
&lt;br /&gt;
Third stage will be bluetooth interface (hardware and software) implementation and integration on the board with transmission test.&lt;br /&gt;
&lt;br /&gt;
Fourth stage will consider power supply optimization with battery management and recharge interface.&lt;br /&gt;
&lt;br /&gt;
Finally, only after a successful full board test, the last stage will be the circuit layout design with an electronic CAD, using where possible, Surface Mount Devices (SMD) to reduce board area.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== '''Main board''' ===&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Main board include power supply regulator with led power-on indicator, PIC microcontroller (mounted on a SMD-&amp;gt;TH adapeter board) with basic circuitry (decoupling capacitors, oscillator and programming-debugging ICD interface), a status led connected to PIC to verify basic microcontroller function, a series of connectors for add-on modules (BVP, GSR, temperature and accelerometer) and a USB PC interface not considered before.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== '''USB interface''' ===&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
USB interface, not projected before, replaces in developing stage Bluetooth interface, allowing a direct control/communication with a PC. In this prototype PIC UART, althought being connected to Bluettoth module, is connected to a FTDI FT232RL chip. The FT232RL is the latest device to be added to FTDI’s range of USB UART interface Integrated Circuit Devices. USB to serial designs using the FT232RL have been further simplified by fully integrating the external EEPROM, clock circuit and USB resistors onto the device.&lt;br /&gt;
The FT232RL is available in Pb-free (RoHS compliant) compact 28-Lead SSOP, so this require another SMD-&amp;gt;TH board adapter but the circuit design is very simple, including two status led for TX and RX operations. An USB B female connector was eputated the best choise for PC connection allowing to use a simple USB printer cable.&lt;br /&gt;
&lt;br /&gt;
[[Image:WADUSBInterface.jpg]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Note that USB and Bluetooth must not be connected to the board at the same time! USB port has only a developent function.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== '''BVP''' ===&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Circuit designed for BVP acquisition (refer to previous schematic) doesn't meet the expected results. Week signal hanged by noise suggested us to re-design the circuit simplifying it and reducing the number of components. For this design also sensing element has been substitute. Instead of an integrated reflective IR sensor (SFH9202), new project use a couple af discrete IR led and photothansistor matched: SFH487 and SFH309FA.&lt;br /&gt;
SFH487 is a very highly efficient GaAlAs infrared emitter (880 nm) and SFH309FA is a silicon NPN phototransistor especially suitable for applications of 880 nm with an high linearity. Both have a 3 mm led plastic package, are spectrum-matched and receiver is ambient-light shilded. After a series of positive test without the led driver (not used due to the really reduced mechanical dimensions), also led drive circuit was removed and replaced with a resistance connected directly to a PIC pin.&lt;br /&gt;
This choise reduces parts count and board space required without making worse sistem performance, allowing (like led driver) to turn off the sensor led when not used to reduce power consumption.&lt;br /&gt;
&lt;br /&gt;
[[Image:WADBVPNew.jpg]]&lt;br /&gt;
&lt;br /&gt;
Even if operation amplifier used are half of before, double second-order filter stage is manteined. In addition to filtering, these opamp privide a first gain (note that in previous design filtering stages works as a unitary buffer in pass-band) allowing a high signal at VGA (variable gain amplifier) input stage allowing a better SNR.&lt;br /&gt;
1N4148 diode provides a sort of ofsetted virtual ground, shifting up all signals but not being amplified through the amplification chain.&lt;br /&gt;
Figure show the signal measured directly on filtering stage output (TS952 pin 7) before the VGA with a Tektronix scopemeter TDS2014B. No particular triks had been used: signal has been recorded the first time circuit was assembled on a protoboard.&lt;br /&gt;
&lt;br /&gt;
[[Image:WADBVPScope03.jpg]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== '''GSR''' ===&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
First approach with AD5934 resulted really hard due to some errors occurred in control software in relation with internal chip complexity and I2C bus protocol. &lt;br /&gt;
After a start session with the AD5934, GSR hardware acquisition interface was further simplified replacing it with AD5933 (refer to schematic). AD5933 has the same pinout and functions of AD5934 but provides also an internal oscillator at 16.776MHz allowing no external crystal connection. A temperature sensor that allow the user to measure chip temperature and 1 MSPS Converter (instad of a 250KSPS one) are the only other differences between the tho integrated semiconductor produced by Analog Devices.&lt;br /&gt;
On the other hand AD5934 has a larger impedance measurement range that goes from 100 Ohm to 10 MOhm in opposition to AD5933 that can only measure impedences between 1 Ohm and 10 MOhm. Because of the high skin impedence values (in the range of MOhm for dry fingers skin), this is not a problem in our application.&lt;br /&gt;
&lt;br /&gt;
[[Image:WADGSRNew.jpg]]&lt;br /&gt;
&lt;br /&gt;
First dataset acquired whith the correct control software and the correct data reading routine, has shown all the potentiality of this chip, providing data comparables with RAW data acquired with a bigger and very expensive professional equipement produced by ProComp.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== '''Acceleration''' ===&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Lis302DL datasheet gives a short definition of this chip as &amp;quot;MEMS motion sensor 3-axis - ± 2g/± 8g smart digital output “piccolo” accelerometer&amp;quot; and it is really very, very small for human-working. For this space saving quality this accelerometer is also use in third generation Apple i-phone.&lt;br /&gt;
The major problem with this sensor had been to solder it to a sort of adapter to connect it to the circuit, but after that it works fine, with a good sensitivity and accuracy. Because of free fall and double click recognition at not required (at the moment) in this application, software routines for setting configuration registers and reading data resulted simplified.&lt;br /&gt;
A usefull caracteristic of this sensor, not previously noticed, is the presence of internal pull-up resistors that allows no necessity of external I2C bus pull-up resistors, reducing space occupation and components count.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== '''Temperature''' ===&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The choice to use MLX90614 due to his characteristics (non contact measure, 0.02°C resolution with accuracy of ±0.1°C for medical applications version) creates a really serious supplies problem: Melexis (sensor manufacture) wasn't able to give us a sample and no one in Italy can sell us only a pair of theese sensors to try them. A single piece was bought from Future Electronics, ordering it via web and paying it via credit card. Fortunately the sensor, that cames directly from USA, arrived in Italy few days later the payment in excellent conditions.&lt;br /&gt;
&lt;br /&gt;
[[Image:WADMLX90614.jpg]]&lt;br /&gt;
&lt;br /&gt;
Problems occurred interfacing this sensor on I2C bus with other devices (AD5933 and LIS302) connected. MLX90614 has a 2 wire serial SMBus compatible protocol: I2C bus and  SMBus are popular 2-wire buses that are essentially compatible with each other, but are not the same.&lt;br /&gt;
The buses operate at the same speed, up to 100kHz, but the I2C bus has both 400kHz and 2MHz versions. Complete compatibility between both buses is ensured only below 100kHz.&lt;br /&gt;
Timeout and (as a consequence of timeout) minimum clock speed are the most important differences between the I2C bus and the SMBus:&lt;br /&gt;
&lt;br /&gt;
I2C Bus = DC (no timeout)&lt;br /&gt;
&lt;br /&gt;
SMBus = 10kHz (35mS timeout)&lt;br /&gt;
&lt;br /&gt;
Despite differences in logic-level specifications between the two buses, generally devices can be mixed and matched with abandon.&lt;br /&gt;
Level Specifications for the I2C Bus and the SMBus are shown below (VDD is typically expected to be between 3 volts and 5 volts):&lt;br /&gt;
&lt;br /&gt;
[[Image:WADTable1.jpg]]&lt;br /&gt;
&lt;br /&gt;
What wasn't readily evident in the discussion of voltage levels is that these levels are also specified with different currents between the buses. The SMBus specifies a minimum sink current of 100microA, and a maximum of 350microA, compared to 3mA for the I2C bus. This in turn would determine the lowest acceptable value of the pullup resistor, examples of which are shown in the table below.&lt;br /&gt;
&lt;br /&gt;
[[Image:WADTable2.jpg]]&lt;br /&gt;
&lt;br /&gt;
In reality, it is not unusual to encounter pullup resistor values in SMBus systems, which violate this specification by being lower than recommended. A very popular range for pullup resistor values, even in some SMBus systems, seems to be 2.4k to 3.9k.&lt;br /&gt;
&lt;br /&gt;
These reasons, in adition to clear ideas about close developments, suggest a general review of schematic to re-distribute microcontroller resources.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== '''Final review [WIP (Work in Progress)]''' ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== '''Microcontroller''' ===&lt;br /&gt;
&lt;br /&gt;
Referring to previous schematic, some chenges had been applied:&lt;br /&gt;
&lt;br /&gt;
- Programmer/Debugger interface is now PGD1/EMUD1 and PGC1/EMUC1 instead of PGD1/EMUD2 and PGC1/EMUC2;&lt;br /&gt;
&lt;br /&gt;
- JTAG interface had been removed;&lt;br /&gt;
&lt;br /&gt;
- UART2 is no more available so UART1 has replaced UART2 as communication port;&lt;br /&gt;
&lt;br /&gt;
- SPI2 is no more available so SPI1 is now used to control both LMP8100 VGA (Variable Gain Amplifier) and SD Storage Card;&lt;br /&gt;
&lt;br /&gt;
- RG12, RG13, RG14 pins had been connected to three status led for a machine visual state detection;&lt;br /&gt;
&lt;br /&gt;
- I2C1 interface is now connected to accelerometer (LIS302) and GSR (AD5933) only;&lt;br /&gt;
&lt;br /&gt;
- I2C2 interface is dedicated to temperature sensor (MLX90614), enabling I/O pin thresholds compliant with SMBus specification;&lt;br /&gt;
&lt;br /&gt;
- Connectors for I2C, SMBus and SPI expansion modules had been added to the board;&lt;br /&gt;
&lt;br /&gt;
- Test point pads had been added to the board to simplify debugging.&lt;br /&gt;
&lt;br /&gt;
That's the complete microcontroller schematic diagram:&lt;br /&gt;
&lt;br /&gt;
[[Image:WAD_Micro_Final.jpg]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== '''Data link''' ===&lt;br /&gt;
&lt;br /&gt;
During developing stages, an USB port had replaced Bluetooth wireless transmission, allowing a direct control/communication with a PC. This interfaced, based on a FT232RL, prove to be very usefull and simple to use.&lt;br /&gt;
The choice to use an usb port to charge internal battery, in addition to availability of a UART multiplexer inside the Bluetooth module BlueGiga WT12, suggest to implement both USB and Bluetooth interface.&lt;br /&gt;
&lt;br /&gt;
That's the BlueGiga WT12 internal UART multiplexer schematic:&lt;br /&gt;
&lt;br /&gt;
[[Image:WAD_UARTMux.jpg]]&lt;br /&gt;
&lt;br /&gt;
The complete data link schematic diagram:&lt;br /&gt;
&lt;br /&gt;
[[Image:WAD_USB+Bluetooth_Final.jpg]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== '''Battery Charge, Monitor &amp;amp; Power On''' ===&lt;br /&gt;
&lt;br /&gt;
Device is powered by a single cell Li-on battery (3.7V, 1080mAh): this is the same unit used in IPod(TM) from Apple.&lt;br /&gt;
&lt;br /&gt;
[[Image:WAD_Battery.jpg]]&lt;br /&gt;
&lt;br /&gt;
Battery charge is executed by Maxim's MAX1811: it is a really compact single-cell lithium-ion (Li+) battery charger that can be powered directly from a USB port or from an external supply up to 6.5V. It has a 0.5% overall battery regulation voltage accuracy to allow maximum utilization of the battery capacity.&lt;br /&gt;
The charger uses an internal FET to deliver up to 500mA charging current to the battery. The device can be configured for either a 4.1V or 4.2V battery, using the SELV input. The SELI input sets the charge current to either 100mA or 500mA. An open-drain output indicates charge status.&lt;br /&gt;
MAX1811 has preconditioning that soft-starts a near-dead battery cell before charging. Other safety features include continuous monitoring of voltage and current and initial checking for fault conditions before charging.&lt;br /&gt;
&lt;br /&gt;
[[Image:WAD_Battery_Charge&amp;amp;PowerOn_Final.jpg]]&lt;br /&gt;
&lt;br /&gt;
White battery wire (see photo) is connected to internal NTC thermistor (10KOhm@+25°C). In this way it's posible to implement an over/under charge temperature detector using a couple af operational amplifier as comparator.&lt;br /&gt;
With the resistence network in schematic it had been possible to set an upper temperature threshold of 47.5°C (corresponding to 3.97K NTC value) and a down thresold of 2.5°C (corresponding to &lt;br /&gt;
28.7K NTC value). Out of this range comparators output go low disabling battery charger.&lt;br /&gt;
This function allows to prevent battery demage or explosion during charge.&lt;br /&gt;
&lt;br /&gt;
Battery voltage monitor is hardware implemented by another Maxim's device: MAX8212.&lt;br /&gt;
MAX8212 is a CMOS micropower voltage detector that warn microprocessors/microcontroller of power failures. It contains a comparator, a 1.5V bandgap reference, and an open-drain n-channel output driver. Two external resistors are used in conjunction with the internal reference to set the trip voltage to the desired level. A hysteresis output is also included, allowing the user to apply positive feedback for noise-free output switching.&lt;br /&gt;
Using a couple of these device is possible to set two treshold: one for low battery and another for end battery detection. Low battery detection allow communicate the user battery level; end battery detection allow microprocessor shut down the device before battery voltage fall down under 3.4V that is the minimun input voltage allowed by linear regulator MCP1700.&lt;br /&gt;
If battery level fall down under 3.4V, MCP1700 is not able to guarantee line regulation. &lt;br /&gt;
&lt;br /&gt;
[[Image:WAD_Battery_Monitor_Final.jpg]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== '''Power On &amp;amp; Selection''' ===&lt;br /&gt;
&lt;br /&gt;
Power-up and shut-down were implemented using a Maxim's MAX16054 connected with an ADG801 by Analog Device.&lt;br /&gt;
MAX16054 is a pushbutton on/off controller with a single switch debouncer and built-in latch. It accepts a noisy input from a mechanical switch and produces a clean latched digital output after a factory-fixed qualification delay.&lt;br /&gt;
The state of the output changes only when triggered by the falling edge of the debounced switch input; the output remains unchanged on the rising edge of the input.An asynchronous CLEAR input allows an external signal to force the output flip-flop low.&lt;br /&gt;
1 MOhm resistor and 10 uF capacitor connected to power-on pushbutton  (in addition to internal 63KOhm pullup resistor) allow to obtain a delay of about 3 seconds.&lt;br /&gt;
ADG801 is a monolithic CMOS, single-pole, single throw (SPST), normally open (NO) switch with on resistance of less than 0.4Ohm. This switch conducts equally well in both directions when on.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== '''MicroSD Storage Card ''' ===&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== '''RTC ''' ===&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Students that have worked on the project==&lt;br /&gt;
&lt;br /&gt;
* Mattia Colombo (Blood Volume Pressure sensor)&lt;br /&gt;
* Alessia Cornaggia (Galvanic skin response sensor)&lt;br /&gt;
* Sala Mirko (Galvanic skin response sensor)&lt;br /&gt;
&lt;br /&gt;
== Laboratory work and risk analysis ==&lt;br /&gt;
&lt;br /&gt;
Laboratory work for this project will be mainly performed at AIRLab/Lambrate. It will include electrical and electronic activity. Potentially risky activities are the following:&lt;br /&gt;
* Use of mechanical tools. Standard safety measures described in [http://airlab.elet.polimi.it/index.php/airlab/content/download/461/4110/file/documento_valutazione_rischi_AIRLab.pdf Safety norms] will be followed.&lt;br /&gt;
* Use of soldering iron. Standard safety measures described in [http://airlab.elet.polimi.it/index.php/airlab/content/download/461/4110/file/documento_valutazione_rischi_AIRLab.pdf Safety norms] will be followed.&lt;br /&gt;
* Use of high-voltage circuits. Special gloves and a current limiter will be used. Standard safety measures described in [http://airlab.elet.polimi.it/index.php/airlab/content/download/461/4110/file/documento_valutazione_rischi_AIRLab.pdf Safety norms] will be followed.&lt;/div&gt;</summary>
		<author><name>PaoloVilla</name></author>	</entry>

	<entry>
		<id>https://airwiki.deib.polimi.it/index.php?title=File:WADWireless_Pub.jpg&amp;diff=9583</id>
		<title>File:WADWireless Pub.jpg</title>
		<link rel="alternate" type="text/html" href="https://airwiki.deib.polimi.it/index.php?title=File:WADWireless_Pub.jpg&amp;diff=9583"/>
				<updated>2009-12-12T09:44:32Z</updated>
		
		<summary type="html">&lt;p&gt;PaoloVilla: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>PaoloVilla</name></author>	</entry>

	<entry>
		<id>https://airwiki.deib.polimi.it/index.php?title=Talk:Wireless_Affective_Devices&amp;diff=9582</id>
		<title>Talk:Wireless Affective Devices</title>
		<link rel="alternate" type="text/html" href="https://airwiki.deib.polimi.it/index.php?title=Talk:Wireless_Affective_Devices&amp;diff=9582"/>
				<updated>2009-12-12T09:44:12Z</updated>
		
		<summary type="html">&lt;p&gt;PaoloVilla: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt; This &amp;quot;private&amp;quot; layer is similar to the &amp;quot;public&amp;quot; one but with detailed information and shematics.&lt;br /&gt;
&lt;br /&gt;
{{Project&lt;br /&gt;
|title=Wireless Affective Devices&lt;br /&gt;
|tutor=SimoneTognetti;MatteoMatteucci&lt;br /&gt;
|students=PaoloVilla&lt;br /&gt;
|resarea=BioSignal Analysis&lt;br /&gt;
|restopic=Affective Computing&lt;br /&gt;
|start=2008/01/08&lt;br /&gt;
|end=2009/12/30&lt;br /&gt;
|status=Active&lt;br /&gt;
|level=Ms&lt;br /&gt;
|type=Thesis&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Project aims ==&lt;br /&gt;
&lt;br /&gt;
 ”''Everyone knows what an emotion is, until asked to give a definition''”&lt;br /&gt;
                                         &lt;br /&gt;
                                                                 Beverly Fehr and James Russell&lt;br /&gt;
&lt;br /&gt;
Research on Human-Computer-Interfaces has recently begun to take into account the affective state of the user. By appropriately reacting to the affective user state, interfaces could not only become more pleasant or entertaining, but also more effective or safer.&lt;br /&gt;
It is known that affective states have bodily correlates, and thus physiological signals could provide the necessary information for acquiring the affective user state. In contrast to other sources of information about the affective user state such as speech or facial expression, most physiological signals are not under voluntary control, and thus cannot be masked up to the same extent. Furthermore, it can be presumed that the signs of affective states in physiological signals are less dependent on individual and contextual factors: this is because the signals correspond to internal physiology, largely related to the autonomous nervous and limbic systems, rather than to external expressions that can be manipulated easily.&lt;br /&gt;
Recently, the issue of emotion regulation drew interests from several fields including neuroscience, psychology, education, computer science, etc. Possible applications are e-learningin, human computer interaction, development of communicative technologies for use by people with autism, car infotainment system, lie detection tests, cognitive workload, multimodal user interfaces MMUI (allow users to control computers using speech and gesture), etc.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The project is aimed at developing a device, connected to a PC, to acquire biological signals (such as GSR, BVP, Temperature and Head orientation) in a way that is less invasive for the subject. The term invasive is related to how much the sensors we use compromise the normal interaction between subject and machine.&lt;br /&gt;
Through these biological signal the PC is able o understand emotion in people who wear the device.&lt;br /&gt;
&lt;br /&gt;
An affective device should be weared easily, should not have cables and should acquire as much sensors as possible. We relax some constraint on the quality of signal but we add constraint on way they are acquired(i.e. the subject can put it on easily, the usual movements are not influenced..). The aim of the resulting device is not to replace the standard medical devices usually used to acquire that signals, but is to be much more suitable for industrial application in which the medical requirement are replaced by invasivity requirement.&lt;br /&gt;
&lt;br /&gt;
It is composed by:&lt;br /&gt;
&lt;br /&gt;
* Low power, high efficiency, battery powered design&lt;br /&gt;
* Wireless comunication with a PC&lt;br /&gt;
* Blood Volume Pressure Sensor (Preliminary release by Mattia Colombo)&lt;br /&gt;
* Galvanic Skin Response Sensor (Preliminary release by Sala Mirko e Alessia Cornaggia)&lt;br /&gt;
* Temperature Sensor&lt;br /&gt;
* 3 Way Accelerometer&lt;br /&gt;
* Possibility of further extension&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''GSR (or EDR or EDA)'''&lt;br /&gt;
&lt;br /&gt;
An often misunderstood and difficult technique, GSR (also known as the electrodermal response EDR or electrodermal activity EDA) has gone through many phases of interest and rejection since the early 1900's and is very popular in psychophysiological studies since Carl Jung and his students (1907) described it as a mean to&lt;br /&gt;
enter the “sea of the unconscious” because “every stimulus accompanied by an emotion produced a deviation of the galvanometer” directly proportional to the strength of the emotion aroused. It has been used in important research on anxiety and stress levels (Fenz &amp;amp; Epstein, ' 67); and it has been a part of lie detection (Raskin, ' 73). Controversy has centered around the technique, underlying mechanisms, and the meaning of the responses obtained from the skin. &lt;br /&gt;
There has been a long history of electrodermal activity research, even if most investigators accept the phenomenon without understanding exactly what it means (Hume, ' 76).&lt;br /&gt;
The resistance of the skin is usually large, approximately 1M; however, momentary changes in the level of the sweat gland activity causes changes in resistance (up to approximately 950K).&lt;br /&gt;
Physiology, the GSR reflescts sweat gland activity and changes in the sympathetic nervous system and measurement variables. The activity of the sweat glands in response to sympathetic nervous stimulation ( Increased sympathetic activation ) results in an increase in the level of conductance. There ia a relationship between sympathetic activity and emotional arousal, although one cannot identify the specific emotion being elicited. &lt;br /&gt;
Basically there are two techniques in the history of Electrodermal measurement. In one a current is passed thru the skin and the the resistance to passage is measured; in the other no current is used externally and the skin itself is the source of electrical activity.&lt;br /&gt;
By applying a conventional 0.5 Volts across the skin and measuring changes in the&lt;br /&gt;
corresponding conductance, the emotional state of the subject can be inferred. In general, the electrodes used are of the Ag/AgCl type which are recessed from the skin and require the use of a suitable electrode paste.&lt;br /&gt;
It is important to note, however, that fluctuations in skin conductivity are resultant of many types of arousal.&lt;br /&gt;
By observing only these changes, it is impossible to deduce without prior knowledge whether&lt;br /&gt;
the subject has become happy, startled, physically active, etcetera.&lt;br /&gt;
EDA consists of two components: tonic and phasic. The tonic component is a low&lt;br /&gt;
frequency baseline conductivity level, which can oscillate over the course of days. The phasic&lt;br /&gt;
component rides on top of the tonic component, exhibits more rapid fluctuations, and&lt;br /&gt;
generally increases when a person is aroused. Problematically, each person has a different&lt;br /&gt;
tonic conductivity, so in order to infer the arousal level of the subject, the relative changes in&lt;br /&gt;
EDA must be analyzed over a period of time. Furthermore, skin conductance (measured in&lt;br /&gt;
units of siemens; formerly mhos) depends on the skin path length between the two electrodes&lt;br /&gt;
contacts, even for subjects with identical skin conductivity (measured in units of&lt;br /&gt;
siemens/meter). It is for these reasons that it is crucial to analyze the temporal variations of&lt;br /&gt;
the EDA signal.&lt;br /&gt;
&lt;br /&gt;
'''BVP'''&lt;br /&gt;
&lt;br /&gt;
The cardiovascular system is in charge to keep us alive by maintaining the vital blood flow throughout the body, providing nutrients and oxygen to our cells. The SNS controls this system&lt;br /&gt;
by shifting the flow in response to exercise, temperature,postural and emotional changes.&lt;br /&gt;
Blood Volume Pulse (BVP) is the most common measure of vasomotor activity because it reflects the phasic pumping of the heart, the vasodilation of vessels that changes in the amount of acral blood delivered.&lt;br /&gt;
The Blood Volume Pulse (BVP) waveform is an important indicator of circulatory function that can be obtained noninvasively through a photoplethysmographic transducer (a PPG is often obtained by using a pulse oximeter, Shelley and Shelley, 2001) applied to the finger or the earlobe of human subjects. In particular, this signal may be useful in determining the degree of cardiovascular change undergone by a subject through an exercise session. &lt;br /&gt;
&lt;br /&gt;
''Principles of photoplethysmographic Technology:''&lt;br /&gt;
&lt;br /&gt;
The principle of photoplethysmographic (That is the same of pulse oximetry) is based on the red and infrared light absorption characteristics of oxygenated and deoxygenated hemoglobin. Oxygenated hemoglobin absorbs more infrared light and allows more red light to pass through. Deoxygenated (or reduced) hemoglobin absorbs more red light and allows more infrared light to pass through. Red light is in the 600-750 nm wavelength light band.&lt;br /&gt;
Pulse oximetry uses a light emitter with red and infrared LEDs that shines through a reasonably translucent site with good blood flow. Opposite the emitter is a photodetector that receives the light that passes through the measuring site.&lt;br /&gt;
There are two methods of sending light through the measuring site: transmission and reflectance. In the transmission the emitter and photodetector are opposite of each other with the measuring site in-between. The light can then pass through the site. In the reflectance method, the emitter and photodetector are next to each other on top the measuring site. The light bounces from the emitter to the detector across the site. The transmission method is the most common type used.&lt;br /&gt;
While pulse oximeters are a commonly used medical device the PPG derived from them is rarely displayed, and is nominally only processed to determine heart rate. &lt;br /&gt;
&lt;br /&gt;
'''Temperature'''&lt;br /&gt;
&lt;br /&gt;
The temperatures of peripheral limbs vary as a consequence of changes in blood flow.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== '''Previous work''' ==&lt;br /&gt;
&lt;br /&gt;
Here is a preliminary release of the headset produced before 2008/08/08&lt;br /&gt;
&lt;br /&gt;
[[Image:Wd1.jpg]]&lt;br /&gt;
&lt;br /&gt;
If you are interested on the making of the headset please see [[making rubber models]]&lt;br /&gt;
&lt;br /&gt;
'''* Blood Volume pressure'''&lt;br /&gt;
First graph showing a signal acquired with the wireless sensor. &lt;br /&gt;
[[Image:Bvp.png]]&lt;br /&gt;
&lt;br /&gt;
'''* Skin galvanic response''' (Sala Mirko e Alessia Cornaggia[http://airwiki.elet.polimi.it/mediawiki/index.php/User:AlessiaCornaggia])&lt;br /&gt;
Galvanic skin response (GSR), also known as electrodermal response (EDR), psychogalvanic reflex (PGR), or skin conductance response (SCR), is a method of measuring the electrical resistance of the skin.  There is a relationship between sympathetic activity and emotional arousal, although one cannot identify the specific emotion being elicited. The GSR is highly sensitive to emotions in some people. Fear, anger, startle response, orienting response and sexual feelings are all among the emotions which may produce similar GSR responses.&lt;br /&gt;
Response of the skin to the passage of a small electric current. The ease with which the current flows between two points on the skin can be used to indicate stress. When a person is tense or emotional, the sweat glands become more active, increasing moisture on the skin; this allows the electric current to flow more readily. &lt;br /&gt;
The response may also be used in relaxation training: information about the galvanic skin response is fed back aurally or visually to the subject who can, with practice, learn to increase or decrease sweating on the skin by learning to relax or tense muscles.&lt;br /&gt;
We measure the galvanic skin response using two electrodes attached to the skin. The optimal placement is the palm of the hands, but we are experimenting other places like on the forehead.&lt;br /&gt;
The circuit we are creating is the one below.&lt;br /&gt;
&lt;br /&gt;
[[Image:circuito.jpg]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== '''Project the device''' ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== '''Re-definition of the complete work''' ===&lt;br /&gt;
&lt;br /&gt;
Sensors are an important part of an Affective Computing System because they provide information about the wearer's physical state or behavior. They can gather data in a continuous way without having to interrupt the user. &lt;br /&gt;
To define in detail electronic specifications and requirements it's necessary a preliminary research/study (in literature and web) about state of art of sensor type used to monitor each type of biological signals we are interested about.&lt;br /&gt;
In this way it's possible both understand problematics related to interaction between biological and electonical worlds and improve or re-desig existing prototype.&lt;br /&gt;
&lt;br /&gt;
About Sensors: &lt;br /&gt;
&lt;br /&gt;
BVP will be acquire by an IR transmitter-receiver measuring light reflected from skin (photoplethysmography). Particular attention will be put on position, geometry and power absorption of this stage. &lt;br /&gt;
&lt;br /&gt;
GSR will be acquiret by a couple of electrodes forcing a low current (or voltage) and reading voltage (or current) through electrodes. Particular attention will be put on electrodes position and material. In addition is possible to foresee some problems in amplifier stage due to large range of skin resistance. Problem consist in chosing a correct amplification to overwork ADC full scale with a signal affected by little variation but huge possible range. &lt;br /&gt;
&lt;br /&gt;
Temperature will be acquired by thermocouple or PTC/NTC. Slowly variable signal, possible problems with noise due to resolution required. &lt;br /&gt;
&lt;br /&gt;
Head orientation will be acquired by an accelerometer and a gyroscope, problably integrated in the same chip. Two possibilities: analog output (need to digitalize up to six line) or digital output (like displaied in schematic block diagram). &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
This was the preliminary simplified schematic block diagram of the complete instrumentation setup:&lt;br /&gt;
&lt;br /&gt;
[[Image:WADSchematicDiagram01.jpg]]&lt;br /&gt;
&lt;br /&gt;
 NOTE:&lt;br /&gt;
 &lt;br /&gt;
 * In schematic is not present Power Supply Module: it will be based on a rechargeable Li-ion&lt;br /&gt;
 battery. It must satisfy requirements of high efficiency, logn life and low weight.&lt;br /&gt;
 &lt;br /&gt;
 * ADC and Microcontroller could be unified using a microcontroller with internal ADC and&lt;br /&gt;
 internal or external multiplexer to select lines.&lt;br /&gt;
 &lt;br /&gt;
 * Wireless section could be implemeted in Bluetooth (instead of using a XBee module like in&lt;br /&gt;
 preliminary release) due to it's diffusion in cellular phones, notebooks, MP3 reader...&lt;br /&gt;
 without necessity of external modules.&lt;br /&gt;
&lt;br /&gt;
It was based on a theoretical approach to any single part. Any sensing device was designed in &amp;quot;conventional&amp;quot; way founded on analog electronic (a bridge with a NTC resisistance as sensing element, discrete IR led and some photodiode around to capture the most reflefted light as possible, GSR electrodes on the gain arm of a non-inverting amplifier...).&lt;br /&gt;
Unfortunatly a deep analysis on signal physiology, signal transduction, noise vs required accurancy, forced us to a completely different approach implementing everywhere possible a digital interface.&lt;br /&gt;
&lt;br /&gt;
=== '''Sensors Design''' ===&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''BVP'''&lt;br /&gt;
&lt;br /&gt;
Discrete IR leds and phototransistor, used in the first realize (see fig.), had been replaced first with a single led and one or more photodiodes to optimize power consumption in case of non-planar sensor positioning. Subsequently an integrated Reflective Object Sensor was introduced, with benefits about space saving, transmitter-receiver matching and power consumption.&lt;br /&gt;
To ensure light power stability, led is powered through a linear led drive LDO (Low Drop-Out). The choise of linear LDO is necessary to ensure no noise or spikes would be generated by charge pump systems or boost converters. In addition, the linear drive utilized requires only one external resitor to set led current and a decoupling capacitor, reducing part counts and board space occupation.&lt;br /&gt;
The couple factor of the reflex sensors is relatively small, even in the case of good reflecting surfaces. Therefore an additional amplifier is necessary at the sensor output: classic trans-impedance amplifier used with photo-diodes and photo-transistors was introduced. This circuit features an output voltage that is a linear function of the light level on the photo-transistor. The gain is set by the feedback resistor which could be in the millions of ohms. Linear operation is achieved by operating the photo device with a fixed voltage drop across it.&lt;br /&gt;
Trans-impedance amplifier is followed by an active fourth order band-pass filter (0.5Hz-5Hz): it's composed cascading two second order bandpass cells. In first project session only a single cell was used, but a deeper study combined with previous experiences suggests to use a 4th order filter to reduce 50Hz interference (50Hz interference produced by mains is placed only a decade after the filter pole).&lt;br /&gt;
Filter is followed by a VGA (Variable Gain Amplifier) digitally controlled through I2C Bus that allows to optimize dinamically ADC input signal amplitude directly during acquisition session, obtaining the best performance from ADC.&lt;br /&gt;
The resulting circuit is quite compact (led drive, reflective sensor, trans-impedence amplifier, active filter and variable-gain amplifier), doesn't require much power and represents a good mix between analog and digital approach: analog front-end with acquisition and first conditioning, and at the chain-end a digital controlled amplifier to ensure flexibility.&lt;br /&gt;
&lt;br /&gt;
[[Image:WADBVPComparison.jpg]]&lt;br /&gt;
&lt;br /&gt;
'''GSR'''&lt;br /&gt;
&lt;br /&gt;
GSR will be acquired by a couple of electrodes forcing a low voltage and reading current through electrodes. First designs and implementations were based on literature study: best solution appears to put GSR electrodes on the gain arm of a non-inverting amplifier (see fig.) rather than using a Wheatstone bridge due to week signal produced by this solution.&lt;br /&gt;
Putting GSR electrodes on the gain arm produces a sort of gain modulation of the constant voltage applied between electrodes but doesn't solve problems in amplifier stage due to large range of skin resistance.&lt;br /&gt;
Problems in chosing correct amplification to overwork ADC full scale with a signal affected by little variation but huge possible range could be reduced usign a variable resistor on gain arm (for example a digital potentiometer controlled by the microcontroller), but cannot be completely removed. In addition little signals are easily deteriorated by noise.&lt;br /&gt;
Solution is provided considering a new point of view: measure of unknown skin resistence is extremely similar to measure unknown electrical impedence with an auto-range multimeter!&lt;br /&gt;
Solution consist in a digital Impedance Converter: AD5934 is a high precision impedance converter system which combines an on-board frequency generator with a 12-bit, 250 kSPS, analog-to-digital converter (ADC). The frequency generator allows an external complex impedance to be excited with a known frequency; the response signal from the impedance is sampled by the on-board ADC and a discrete Fourier transform (DFT) is processed by an on-board DSP engine. The DFT algorithm returns a real (R) and imaginary (I) data-word at each output frequency. This solution not only allows to measure impedence range from 100 Ohm to 10 MOhm, but in adition allow to investigate it across a wide range of frequency, producing a noise-free digital output.&lt;br /&gt;
The resulting circuit is extremely compact (converter chip, one setting resistor and bypass capacitors), provides a system accuracy of 0.5% and connects to microcontroller using I2C interface, ensuring an high flexibility and the possibility to modify acquisition settings after board production (through microcontroller firmware).&lt;br /&gt;
&lt;br /&gt;
[[Image:WADGSRComparison.jpg]]&lt;br /&gt;
&lt;br /&gt;
'''Temperature'''&lt;br /&gt;
&lt;br /&gt;
First idea was to acquire temperature by a NTC connected in a Wheatstone bridge. Trying to reduce noise, bridge was powered by an oscillator circuit with a frequency of some KHerz, to translate signal out of 1/f noise region. Bridge outputs were connected to an INA amplifier wich also implements signal filtering (see fig.).&lt;br /&gt;
Weak signal, noise and resolution required (0.1°C) put in crisis the system. In addition other unsolved problems were the optimization of thermal and mechanical contact between sensor and body and the sensor large thermic constant. Unstable thermic contact produces unreliable measures, whereas high sensor thermic constant hampers a fast sensor response (needed to detect short peak due to emotional reactions).&lt;br /&gt;
Possible solutions to problems of weak signal and noise arrive from digital integrated temperature sensor (for example LM35 or LM74), but these don't solve the problem of thermal contact and thermal constant. In addition none of the sensors take in consideration provides the required resolution.&lt;br /&gt;
High resolution required, noise immunity, fast response and thermal contact immunity problems had been solved using a digital optical infra red thermometer. The MLX90614 is an infra red thermometer for non contact temperature measurements based on a thermopile detector chip including signal conditioning in the same TO-39 package. Thanks to its low noise amplifier, 17-bit ADC and powerful DSP unit, a high accuracy and resolution of the thermometer is achieved.&lt;br /&gt;
The calculated object and ambient temperatures are available in RAM of MLX90614 with 0.02°C resolution: they are accessible by 2 wire serial SMBus compatible protocol. A special version for medical applications offers an accuracy of ±0.1ºC in a limited temperature range around the human body temperature.&lt;br /&gt;
Small size, no external component requirements and power saving mode allow us to obtain a perfect matching between required performances and space saving.&lt;br /&gt;
&lt;br /&gt;
[[Image:WADTemperatureComparison.jpg]]&lt;br /&gt;
&lt;br /&gt;
'''Accelerometer'''&lt;br /&gt;
&lt;br /&gt;
Head orientation and movements will be acquired by an accelerometer. First we think to utilize an ST Microelectronic LIS3L02AS4, due to the availability in the Lab of the evaluation board STEVAL-MKI001. It is a 3-axis ±2g/±6g linear accelerometer with 3 analog outputs, so it requires an external ADC to digitalize the three axis acceleration values. The conversion could be performed by a microcontroller with internal ADC.&lt;br /&gt;
A fast Internet research reveled this sensor is now obsolete and out of production. The choise had been to substitute the old chip with the new one: the LIS302DL (still produced by ST Microelectronic). It's a 3-axis, ± 2g/± 8g smart digital output accelerometer with I2C/SPI digital output interface and really small package. The device is capable of measuring accelerations with an output data rate of 100 Hz or 400 Hz and the self-test capability allows the user to check the functioning of the sensor in the final application.&lt;br /&gt;
In addition it may be configured to generate inertial wake-up/free-fall interrupt signals when a programmable acceleration threshold is crossed at least in one of the three axes. Thresholds and timing of interrupt generators are programmable by the end user on the fly.&lt;br /&gt;
This device, providing a digital output, doesn't need signals conversion, guaranteing better noise immunity; programmable interrupts and test interface allow greater fexibility in project. In addition wery small package, only one external resistor requirement (plus baypass capacitor) reduce significantly board space requirements.&lt;br /&gt;
&lt;br /&gt;
[[Image:WADAccelerometer.jpg]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
 NOTE:&lt;br /&gt;
 &lt;br /&gt;
 * In previous schematics, components phisical dimensions are not in scale.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== '''Microcontroller''' ===&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Foundamental requirements:&lt;br /&gt;
&lt;br /&gt;
- High speed to ensure high data output rate even in presence of a large number af sensing elemets;&lt;br /&gt;
&lt;br /&gt;
- Fast Internal ADC with multiple inputs;&lt;br /&gt;
&lt;br /&gt;
- (At Least) One I2C interface;&lt;br /&gt;
&lt;br /&gt;
- (At Least) One SPI interface;&lt;br /&gt;
&lt;br /&gt;
- (At Least) One UART interface;&lt;br /&gt;
&lt;br /&gt;
- (At Least) Three Timers;&lt;br /&gt;
&lt;br /&gt;
- (At Least) Three External Interrrupts;&lt;br /&gt;
&lt;br /&gt;
- Low-power consumption;&lt;br /&gt;
&lt;br /&gt;
- Power supply 3.3V;&lt;br /&gt;
&lt;br /&gt;
- Small package;&lt;br /&gt;
&lt;br /&gt;
In addition microcontroller was chosen between Microchip PIC family devices, due to positive previous experiences and availability of software and programmer in the Lab.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
PIC24HJ256GP206 is a 16 bit microcontroller capable of 40 MIPS speed. It provides 256KB of Flash memory, 16KB of Ram, a 10-bit 1.1Msps or 12-bit 500Ksps ADC, UART, SPI and I2C interface in a 64 pin TQFP package (10mmX10mm) powerd between 3.0V and 3.6V.&lt;br /&gt;
Power core is provided by an internal regulator reducing parts count on the board.&lt;br /&gt;
&lt;br /&gt;
The device is able to provide at the same time one I2C interface, two SPI interface and one UART interface: another UART port shares pins with an SPI port and a second I2C port shares pins with the second UART interface.&lt;br /&gt;
Findig a device that provides at the same time, on indipendent pins, an I2C, a SPI and an UART interface reduces considerably possible choises and suggests to chose a high performance microcontroller.&lt;br /&gt;
At the same time, high performance solutions have a larger pin counts than standard microcontroller, but this characteristic can be used to ensure further expansibility to the system. The second SPI interface can be used to connect another &amp;quot;intelligent&amp;quot; device or a mass storage device, for example a SD (Secure Digital) card to storage acquired data (see fig.).&lt;br /&gt;
&lt;br /&gt;
[[Image:WADSDCard.jpg]]&lt;br /&gt;
&lt;br /&gt;
Input pins connected to ADC and not used at the moment could be collected to a connector for further extension modules (for example an EMG or ECG peripheral or any other analog signal interesting in a particolar application).&lt;br /&gt;
For the same reason any other pin non used at the current stage is reported to an extension connector.&lt;br /&gt;
To guarante maximum flexibility an further update, board provides both ICD and JTAG connections (allowing on-board programming and debugging) through a couple of indipendent dedicated connectors fully compatibles with Microchip programmers and evaluation boards.&lt;br /&gt;
&lt;br /&gt;
[[Image:WADMicro.jpg]]&lt;br /&gt;
&lt;br /&gt;
=== '''Wireless Connection''' ===&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Wireless connection is based on BlueGiga WT12 module: it's a next-generation, class 2, Bluetooth 2.0+EDR (Enhanced Data Rates) module containing all the necessary elements from Bluetooth radio to antenna and a fully implemented protocol stack.&lt;br /&gt;
By default WT12 module is equipped with powerful and easy-to-use iWRAP firmware that enables users to access Bluetooth functionality with simple ASCII commands delivered to the module over serial interface like a Bluetooth modem.&lt;br /&gt;
The dedicated onboard microcontroller (MCU) acts as interrupt controller and event timer run the Bluetooth software stack and control the radio and host interfaces. A 16-bit reduced instruction set computer (RISC) microcontroller is used for low power consumption and efficient use of memory.&lt;br /&gt;
WT12 module support USB, SPI and UART interface and UART interface is used in this project to connect PIC microcontroller to wireless transmitter (see fig.).&lt;br /&gt;
&lt;br /&gt;
[[Image:WADWireless.jpg]]&lt;br /&gt;
&lt;br /&gt;
One of the most important WT12 characteristic is the high integration between all parts needed for efficent Bluetooth transmission: user interface, controller, radio circuits and antenna, all included in a low power, low size board (25.6mmx15mm) that requires a minimum number of external components.&lt;br /&gt;
Many other bluetooth components ara available, such as LMX9830, produced by National Semiconductor. It's an extremely small device (only 6.1mm×9.1 mm), but requires a number of external components (see fig.) like oscillators, resistors, capacitors, inductors and the antenna, in addition to an high competence in radio frequency layout circuits.&lt;br /&gt;
&lt;br /&gt;
[[Image:WADLMX9830.jpg]]&lt;br /&gt;
&lt;br /&gt;
Lack of experience in radio frequency circuit suggests to chose a ready-to-use module, factory optimized for best performance and easy to integrate in our board.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
This is the updated simplified schematic block diagram:&lt;br /&gt;
&lt;br /&gt;
[[Image:WADSchematicDiagram02.jpg]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== '''Prototype realization [WIP (Work in Progress)]''' ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Fist stage plans to realize a board using, where possible, through-hole (TH) compenents soldered on a prototyping board (100x160mm) powered from a laboratory power supply (instead of Li-on battery) and not implementing bluetooth wireless transmission. Parts not available on TH package are used with special SMD-&amp;gt;TH adapter boards or simply fixing and soldering them to the PCB by wires.&lt;br /&gt;
&lt;br /&gt;
Second stage plans to realize microcontoller firmware and test it acquiring biological signals from a patient. Firmware will be developed by subsequently steps, implementing and testing only a single peripheral at each time: only at the end single pheripheral softwares will be merged together.&lt;br /&gt;
&lt;br /&gt;
Third stage will be bluetooth interface (hardware and software) implementation and integration on the board with transmission test.&lt;br /&gt;
&lt;br /&gt;
Fourth stage will consider power supply optimization with battery management and recharge interface.&lt;br /&gt;
&lt;br /&gt;
Finally, only after a successful full board test, the last stage will be the circuit layout design with an electronic CAD, using where possible, Surface Mount Devices (SMD) to reduce board area.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== '''Main board''' ===&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Main board include power supply regulator with led power-on indicator, PIC microcontroller (mounted on a SMD-&amp;gt;TH adapeter board) with basic circuitry (decoupling capacitors, oscillator and programming-debugging ICD interface), a status led connected to PIC to verify basic microcontroller function, a series of connectors for add-on modules (BVP, GSR, temperature and accelerometer) and a USB PC interface not considered before.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== '''USB interface''' ===&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
USB interface, not projected before, replaces in developing stage Bluetooth interface, allowing a direct control/communication with a PC. In this prototype PIC UART, althought being connected to Bluettoth module, is connected to a FTDI FT232RL chip. The FT232RL is the latest device to be added to FTDI’s range of USB UART interface Integrated Circuit Devices. USB to serial designs using the FT232RL have been further simplified by fully integrating the external EEPROM, clock circuit and USB resistors onto the device.&lt;br /&gt;
The FT232RL is available in Pb-free (RoHS compliant) compact 28-Lead SSOP, so this require another SMD-&amp;gt;TH board adapter but the circuit design is very simple, including two status led for TX and RX operations. An USB B female connector was eputated the best choise for PC connection allowing to use a simple USB printer cable.&lt;br /&gt;
&lt;br /&gt;
[[Image:WADUSBInterface.jpg]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Note that USB and Bluetooth must not be connected to the board at the same time! USB port has only a developent function.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== '''BVP''' ===&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Circuit designed for BVP acquisition (refer to previous schematic) doesn't meet the expected results. Week signal hanged by noise suggested us to re-design the circuit simplifying it and reducing the number of components. For this design also sensing element has been substitute. Instead of an integrated reflective IR sensor (SFH9202), new project use a couple af discrete IR led and photothansistor matched: SFH487 and SFH309FA.&lt;br /&gt;
SFH487 is a very highly efficient GaAlAs infrared emitter (880 nm) and SFH309FA is a silicon NPN phototransistor especially suitable for applications of 880 nm with an high linearity. Both have a 3 mm led plastic package, are spectrum-matched and receiver is ambient-light shilded. After a series of positive test without the led driver (not used due to the really reduced mechanical dimensions), also led drive circuit was removed and replaced with a resistance connected directly to a PIC pin.&lt;br /&gt;
This choise reduces parts count and board space required without making worse sistem performance, allowing (like led driver) to turn off the sensor led when not used to reduce power consumption.&lt;br /&gt;
&lt;br /&gt;
[[Image:WADBVPNew.jpg]]&lt;br /&gt;
&lt;br /&gt;
Even if operation amplifier used are half of before, double second-order filter stage is manteined. In addition to filtering, these opamp privide a first gain (note that in previous design filtering stages works as a unitary buffer in pass-band) allowing a high signal at VGA (variable gain amplifier) input stage allowing a better SNR.&lt;br /&gt;
1N4148 diode provides a sort of ofsetted virtual ground, shifting up all signals but not being amplified through the amplification chain.&lt;br /&gt;
Figure show the signal measured directly on filtering stage output (TS952 pin 7) before the VGA with a Tektronix scopemeter TDS2014B. No particular triks had been used: signal has been recorded the first time circuit was assembled on a protoboard.&lt;br /&gt;
&lt;br /&gt;
[[Image:WADBVPScope03.jpg]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== '''GSR''' ===&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
First approach with AD5934 resulted really hard due to some errors occurred in control software in relation with internal chip complexity and I2C bus protocol. &lt;br /&gt;
After a start session with the AD5934, GSR hardware acquisition interface was further simplified replacing it with AD5933 (refer to schematic). AD5933 has the same pinout and functions of AD5934 but provides also an internal oscillator at 16.776MHz allowing no external crystal connection. A temperature sensor that allow the user to measure chip temperature and 1 MSPS Converter (instad of a 250KSPS one) are the only other differences between the tho integrated semiconductor produced by Analog Devices.&lt;br /&gt;
On the other hand AD5934 has a larger impedance measurement range that goes from 100 Ohm to 10 MOhm in opposition to AD5933 that can only measure impedences between 1 Ohm and 10 MOhm. Because of the high skin impedence values (in the range of MOhm for dry fingers skin), this is not a problem in our application.&lt;br /&gt;
&lt;br /&gt;
[[Image:WADGSRNew.jpg]]&lt;br /&gt;
&lt;br /&gt;
First dataset acquired whith the correct control software and the correct data reading routine, has shown all the potentiality of this chip, providing data comparables with RAW data acquired with a bigger and very expensive professional equipement produced by ProComp.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== '''Acceleration''' ===&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Lis302DL datasheet gives a short definition of this chip as &amp;quot;MEMS motion sensor 3-axis - ± 2g/± 8g smart digital output “piccolo” accelerometer&amp;quot; and it is really very, very small for human-working. For this space saving quality this accelerometer is also use in third generation Apple i-phone.&lt;br /&gt;
The major problem with this sensor had been to solder it to a sort of adapter to connect it to the circuit, but after that it works fine, with a good sensitivity and accuracy. Because of free fall and double click recognition at not required (at the moment) in this application, software routines for setting configuration registers and reading data resulted simplified.&lt;br /&gt;
A usefull caracteristic of this sensor, not previously noticed, is the presence of internal pull-up resistors that allows no necessity of external I2C bus pull-up resistors, reducing space occupation and components count.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== '''Temperature''' ===&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The choice to use MLX90614 due to his characteristics (non contact measure, 0.02°C resolution with accuracy of ±0.1°C for medical applications version) creates a really serious supplies problem: Melexis (sensor manufacture) wasn't able to give us a sample and no one in Italy can sell us only a pair of theese sensors to try them. A single piece was bought from Future Electronics, ordering it via web and paying it via credit card. Fortunately the sensor, that cames directly from USA, arrived in Italy few days later the payment in excellent conditions.&lt;br /&gt;
&lt;br /&gt;
[[Image:WADMLX90614.jpg]]&lt;br /&gt;
&lt;br /&gt;
Problems occurred interfacing this sensor on I2C bus with other devices (AD5933 and LIS302) connected. MLX90614 has a 2 wire serial SMBus compatible protocol: I2C bus and  SMBus are popular 2-wire buses that are essentially compatible with each other, but are not the same.&lt;br /&gt;
The buses operate at the same speed, up to 100kHz, but the I2C bus has both 400kHz and 2MHz versions. Complete compatibility between both buses is ensured only below 100kHz.&lt;br /&gt;
Timeout and (as a consequence of timeout) minimum clock speed are the most important differences between the I2C bus and the SMBus:&lt;br /&gt;
&lt;br /&gt;
I2C Bus = DC (no timeout)&lt;br /&gt;
&lt;br /&gt;
SMBus = 10kHz (35mS timeout)&lt;br /&gt;
&lt;br /&gt;
Despite differences in logic-level specifications between the two buses, generally devices can be mixed and matched with abandon.&lt;br /&gt;
Level Specifications for the I2C Bus and the SMBus are shown below (VDD is typically expected to be between 3 volts and 5 volts):&lt;br /&gt;
&lt;br /&gt;
[[Image:WADTable1.jpg]]&lt;br /&gt;
&lt;br /&gt;
What wasn't readily evident in the discussion of voltage levels is that these levels are also specified with different currents between the buses. The SMBus specifies a minimum sink current of 100microA, and a maximum of 350microA, compared to 3mA for the I2C bus. This in turn would determine the lowest acceptable value of the pullup resistor, examples of which are shown in the table below.&lt;br /&gt;
&lt;br /&gt;
[[Image:WADTable2.jpg]]&lt;br /&gt;
&lt;br /&gt;
In reality, it is not unusual to encounter pullup resistor values in SMBus systems, which violate this specification by being lower than recommended. A very popular range for pullup resistor values, even in some SMBus systems, seems to be 2.4k to 3.9k.&lt;br /&gt;
&lt;br /&gt;
These reasons, in adition to clear ideas about close developments, suggest a general review of schematic to re-distribute microcontroller resources.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== '''Part 6: final review [WIP (Work in Progress)]''' ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== '''Microcontroller''' ===&lt;br /&gt;
&lt;br /&gt;
Referring to previous schematic, some chenges had been applied:&lt;br /&gt;
&lt;br /&gt;
- Programmer/Debugger interface is now PGD1/EMUD1 and PGC1/EMUC1 instead of PGD1/EMUD2 and PGC1/EMUC2;&lt;br /&gt;
&lt;br /&gt;
- JTAG interface had been removed;&lt;br /&gt;
&lt;br /&gt;
- UART2 is no more available so UART1 has replaced UART2 as communication port;&lt;br /&gt;
&lt;br /&gt;
- SPI2 is no more available so SPI1 is now used to control both LMP8100 VGA (Variable Gain Amplifier) and SD Storage Card;&lt;br /&gt;
&lt;br /&gt;
- RG12, RG13, RG14 pins had been connected to three status led for a machine visual state detection;&lt;br /&gt;
&lt;br /&gt;
- I2C1 interface is now connected to accelerometer (LIS302) and GSR (AD5933) only;&lt;br /&gt;
&lt;br /&gt;
- I2C2 interface is dedicated to temperature sensor (MLX90614), enabling I/O pin thresholds compliant with SMBus specification;&lt;br /&gt;
&lt;br /&gt;
- Connectors for I2C, SMBus and SPI expansion modules had been added to the board;&lt;br /&gt;
&lt;br /&gt;
- Test point pads had been added to the board to simplify debugging.&lt;br /&gt;
&lt;br /&gt;
That's the complete microcontroller schematic diagram:&lt;br /&gt;
&lt;br /&gt;
[[Image:WAD_Micro_Final.jpg]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== '''Data link''' ===&lt;br /&gt;
&lt;br /&gt;
During developing stages, an USB port had replaced Bluetooth wireless transmission, allowing a direct control/communication with a PC. This interfaced, based on a FT232RL, prove to be very usefull and simple to use.&lt;br /&gt;
The choice to use an usb port to charge internal battery, in addition to availability of a UART multiplexer inside the Bluetooth module BlueGiga WT12, suggest to implement both USB and Bluetooth interface.&lt;br /&gt;
&lt;br /&gt;
That's the BlueGiga WT12 internal UART multiplexer schematic:&lt;br /&gt;
&lt;br /&gt;
[[Image:WAD_UARTMux.jpg]]&lt;br /&gt;
&lt;br /&gt;
The complete data link schematic diagram:&lt;br /&gt;
&lt;br /&gt;
[[Image:WAD_USB+Bluetooth_Final.jpg]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== '''Battery Charge, Monitor &amp;amp; Power On''' ===&lt;br /&gt;
&lt;br /&gt;
Device is powered by a single cell Li-on battery (3.7V, 1080mAh): this is the same unit used in IPod(TM) from Apple.&lt;br /&gt;
&lt;br /&gt;
[[Image:WAD_Battery.jpg]]&lt;br /&gt;
&lt;br /&gt;
Battery charge is executed by Maxim's MAX1811: it is a really compact single-cell lithium-ion (Li+) battery charger that can be powered directly from a USB port or from an external supply up to 6.5V. It has a 0.5% overall battery regulation voltage accuracy to allow maximum utilization of the battery capacity.&lt;br /&gt;
The charger uses an internal FET to deliver up to 500mA charging current to the battery. The device can be configured for either a 4.1V or 4.2V battery, using the SELV input. The SELI input sets the charge current to either 100mA or 500mA. An open-drain output indicates charge status.&lt;br /&gt;
MAX1811 has preconditioning that soft-starts a near-dead battery cell before charging. Other safety features include continuous monitoring of voltage and current and initial checking for fault conditions before charging.&lt;br /&gt;
&lt;br /&gt;
[[Image:WAD_Battery_Charge&amp;amp;PowerOn_Final.jpg]]&lt;br /&gt;
&lt;br /&gt;
White battery wire (see photo) is connected to internal NTC thermistor (10KOhm@+25°C). In this way it's posible to implement an over/under charge temperature detector using a couple af operational amplifier as comparator.&lt;br /&gt;
With the resistence network in schematic it had been possible to set an upper temperature threshold of 47.5°C (corresponding to 3.97K NTC value) and a down thresold of 2.5°C (corresponding to &lt;br /&gt;
28.7K NTC value). Out of this range comparators output go low disabling battery charger.&lt;br /&gt;
This function allows to prevent battery demage or explosion during charge.&lt;br /&gt;
&lt;br /&gt;
Battery voltage monitor is hardware implemented by another Maxim's device: MAX8212.&lt;br /&gt;
MAX8212 is a CMOS micropower voltage detector that warn microprocessors/microcontroller of power failures. It contains a comparator, a 1.5V bandgap reference, and an open-drain n-channel output driver. Two external resistors are used in conjunction with the internal reference to set the trip voltage to the desired level. A hysteresis output is also included, allowing the user to apply positive feedback for noise-free output switching.&lt;br /&gt;
Using a couple of these device is possible to set two treshold: one for low battery and another for end battery detection. Low battery detection allow communicate the user battery level; end battery detection allow microprocessor shut down the device before battery voltage fall down under 3.4V that is the minimun input voltage allowed by linear regulator MCP1700.&lt;br /&gt;
If battery level fall down under 3.4V, MCP1700 is not able to guarantee line regulation. &lt;br /&gt;
&lt;br /&gt;
[[Image:WAD_Battery_Monitor_Final.jpg]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== '''Power On &amp;amp; Selection''' ===&lt;br /&gt;
&lt;br /&gt;
Power-up and shut-down were implemented using a Maxim's MAX16054 connected with an ADG801 by Analog Device.&lt;br /&gt;
MAX16054 is a pushbutton on/off controller with a single switch debouncer and built-in latch. It accepts a noisy input from a mechanical switch and produces a clean latched digital output after a factory-fixed qualification delay.&lt;br /&gt;
The state of the output changes only when triggered by the falling edge of the debounced switch input; the output remains unchanged on the rising edge of the input.An asynchronous CLEAR input allows an external signal to force the output flip-flop low.&lt;br /&gt;
1 MOhm resistor and 10 uF capacitor connected to power-on pushbutton  (in addition to internal 63KOhm pullup resistor) allow to obtain a delay of about 3 seconds.&lt;br /&gt;
ADG801 is a monolithic CMOS, single-pole, single throw (SPST), normally open (NO) switch with on resistance of less than 0.4Ohm. This switch conducts equally well in both directions when on.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== '''MicroSD Storage Card ''' ===&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== '''RTC ''' ===&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Students that have worked on the project==&lt;br /&gt;
&lt;br /&gt;
* Mattia Colombo (Blood Volume Pressure sensor)&lt;br /&gt;
* Alessia Cornaggia (Galvanic skin response sensor)&lt;br /&gt;
* Sala Mirko (Galvanic skin response sensor)&lt;br /&gt;
&lt;br /&gt;
== Laboratory work and risk analysis ==&lt;br /&gt;
&lt;br /&gt;
Laboratory work for this project will be mainly performed at AIRLab/Lambrate. It will include electrical and electronic activity. Potentially risky activities are the following:&lt;br /&gt;
* Use of mechanical tools. Standard safety measures described in [http://airlab.elet.polimi.it/index.php/airlab/content/download/461/4110/file/documento_valutazione_rischi_AIRLab.pdf Safety norms] will be followed.&lt;br /&gt;
* Use of soldering iron. Standard safety measures described in [http://airlab.elet.polimi.it/index.php/airlab/content/download/461/4110/file/documento_valutazione_rischi_AIRLab.pdf Safety norms] will be followed.&lt;br /&gt;
* Use of high-voltage circuits. Special gloves and a current limiter will be used. Standard safety measures described in [http://airlab.elet.polimi.it/index.php/airlab/content/download/461/4110/file/documento_valutazione_rischi_AIRLab.pdf Safety norms] will be followed.&lt;/div&gt;</summary>
		<author><name>PaoloVilla</name></author>	</entry>

	<entry>
		<id>https://airwiki.deib.polimi.it/index.php?title=File:WADTemperatureComparison_Pub.jpg&amp;diff=9581</id>
		<title>File:WADTemperatureComparison Pub.jpg</title>
		<link rel="alternate" type="text/html" href="https://airwiki.deib.polimi.it/index.php?title=File:WADTemperatureComparison_Pub.jpg&amp;diff=9581"/>
				<updated>2009-12-12T09:43:59Z</updated>
		
		<summary type="html">&lt;p&gt;PaoloVilla: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>PaoloVilla</name></author>	</entry>

	<entry>
		<id>https://airwiki.deib.polimi.it/index.php?title=Talk:Wireless_Affective_Devices&amp;diff=9580</id>
		<title>Talk:Wireless Affective Devices</title>
		<link rel="alternate" type="text/html" href="https://airwiki.deib.polimi.it/index.php?title=Talk:Wireless_Affective_Devices&amp;diff=9580"/>
				<updated>2009-12-12T09:41:48Z</updated>
		
		<summary type="html">&lt;p&gt;PaoloVilla: New page: {{Project |title=Wireless Affective Devices |tutor=SimoneTognetti;MatteoMatteucci |students=PaoloVilla |resarea=BioSignal Analysis |restopic=Affective Computing |start=2008/01/08 |end=2009...&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{Project&lt;br /&gt;
|title=Wireless Affective Devices&lt;br /&gt;
|tutor=SimoneTognetti;MatteoMatteucci&lt;br /&gt;
|students=PaoloVilla&lt;br /&gt;
|resarea=BioSignal Analysis&lt;br /&gt;
|restopic=Affective Computing&lt;br /&gt;
|start=2008/01/08&lt;br /&gt;
|end=2009/12/30&lt;br /&gt;
|status=Active&lt;br /&gt;
|level=Ms&lt;br /&gt;
|type=Thesis&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
This &amp;quot;private&amp;quot; layer is similar to the &amp;quot;public&amp;quot; one but with detailed information and schematics.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Project aims ==&lt;br /&gt;
&lt;br /&gt;
 ”''Everyone knows what an emotion is, until asked to give a definition''”&lt;br /&gt;
                                         &lt;br /&gt;
                                                                 Beverly Fehr and James Russell&lt;br /&gt;
&lt;br /&gt;
Research on Human-Computer-Interfaces has recently begun to take into account the affective state of the user. By appropriately reacting to the affective user state, interfaces could not only become more pleasant or entertaining, but also more effective or safer.&lt;br /&gt;
It is known that affective states have bodily correlates, and thus physiological signals could provide the necessary information for acquiring the affective user state. In contrast to other sources of information about the affective user state such as speech or facial expression, most physiological signals are not under voluntary control, and thus cannot be masked up to the same extent. Furthermore, it can be presumed that the signs of affective states in physiological signals are less dependent on individual and contextual factors: this is because the signals correspond to internal physiology, largely related to the autonomous nervous and limbic systems, rather than to external expressions that can be manipulated easily.&lt;br /&gt;
Recently, the issue of emotion regulation drew interests from several fields including neuroscience, psychology, education, computer science, etc. Possible applications are e-learningin, human computer interaction, development of communicative technologies for use by people with autism, car infotainment system, lie detection tests, cognitive workload, multimodal user interfaces MMUI (allow users to control computers using speech and gesture), etc.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The project is aimed at developing a device, connected to a PC, to acquire biological signals (such as GSR, BVP, Temperature and Head orientation) in a way that is less invasive for the subject. The term invasive is related to how much the sensors we use compromise the normal interaction between subject and machine.&lt;br /&gt;
Through these biological signal the PC is able o understand emotion in people who wear the device.&lt;br /&gt;
&lt;br /&gt;
An affective device should be weared easily, should not have cables and should acquire as much sensors as possible. We relax some constraint on the quality of signal but we add constraint on way they are acquired(i.e. the subject can put it on easily, the usual movements are not influenced..). The aim of the resulting device is not to replace the standard medical devices usually used to acquire that signals, but is to be much more suitable for industrial application in which the medical requirement are replaced by invasivity requirement.&lt;br /&gt;
&lt;br /&gt;
It is composed by:&lt;br /&gt;
&lt;br /&gt;
* Low power, high efficiency, battery powered design&lt;br /&gt;
* Wireless comunication with a PC&lt;br /&gt;
* Blood Volume Pressure Sensor (Preliminary release by Mattia Colombo)&lt;br /&gt;
* Galvanic Skin Response Sensor (Preliminary release by Sala Mirko e Alessia Cornaggia)&lt;br /&gt;
* Temperature Sensor&lt;br /&gt;
* 3 Way Accelerometer&lt;br /&gt;
* Possibility of further extension&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''GSR (or EDR or EDA)'''&lt;br /&gt;
&lt;br /&gt;
An often misunderstood and difficult technique, GSR (also known as the electrodermal response EDR or electrodermal activity EDA) has gone through many phases of interest and rejection since the early 1900's and is very popular in psychophysiological studies since Carl Jung and his students (1907) described it as a mean to&lt;br /&gt;
enter the “sea of the unconscious” because “every stimulus accompanied by an emotion produced a deviation of the galvanometer” directly proportional to the strength of the emotion aroused. It has been used in important research on anxiety and stress levels (Fenz &amp;amp; Epstein, ' 67); and it has been a part of lie detection (Raskin, ' 73). Controversy has centered around the technique, underlying mechanisms, and the meaning of the responses obtained from the skin. &lt;br /&gt;
There has been a long history of electrodermal activity research, even if most investigators accept the phenomenon without understanding exactly what it means (Hume, ' 76).&lt;br /&gt;
The resistance of the skin is usually large, approximately 1M; however, momentary changes in the level of the sweat gland activity causes changes in resistance (up to approximately 950K).&lt;br /&gt;
Physiology, the GSR reflescts sweat gland activity and changes in the sympathetic nervous system and measurement variables. The activity of the sweat glands in response to sympathetic nervous stimulation ( Increased sympathetic activation ) results in an increase in the level of conductance. There ia a relationship between sympathetic activity and emotional arousal, although one cannot identify the specific emotion being elicited. &lt;br /&gt;
Basically there are two techniques in the history of Electrodermal measurement. In one a current is passed thru the skin and the the resistance to passage is measured; in the other no current is used externally and the skin itself is the source of electrical activity.&lt;br /&gt;
By applying a conventional 0.5 Volts across the skin and measuring changes in the&lt;br /&gt;
corresponding conductance, the emotional state of the subject can be inferred. In general, the electrodes used are of the Ag/AgCl type which are recessed from the skin and require the use of a suitable electrode paste.&lt;br /&gt;
It is important to note, however, that fluctuations in skin conductivity are resultant of many types of arousal.&lt;br /&gt;
By observing only these changes, it is impossible to deduce without prior knowledge whether&lt;br /&gt;
the subject has become happy, startled, physically active, etcetera.&lt;br /&gt;
EDA consists of two components: tonic and phasic. The tonic component is a low&lt;br /&gt;
frequency baseline conductivity level, which can oscillate over the course of days. The phasic&lt;br /&gt;
component rides on top of the tonic component, exhibits more rapid fluctuations, and&lt;br /&gt;
generally increases when a person is aroused. Problematically, each person has a different&lt;br /&gt;
tonic conductivity, so in order to infer the arousal level of the subject, the relative changes in&lt;br /&gt;
EDA must be analyzed over a period of time. Furthermore, skin conductance (measured in&lt;br /&gt;
units of siemens; formerly mhos) depends on the skin path length between the two electrodes&lt;br /&gt;
contacts, even for subjects with identical skin conductivity (measured in units of&lt;br /&gt;
siemens/meter). It is for these reasons that it is crucial to analyze the temporal variations of&lt;br /&gt;
the EDA signal.&lt;br /&gt;
&lt;br /&gt;
'''BVP'''&lt;br /&gt;
&lt;br /&gt;
The cardiovascular system is in charge to keep us alive by maintaining the vital blood flow throughout the body, providing nutrients and oxygen to our cells. The SNS controls this system&lt;br /&gt;
by shifting the flow in response to exercise, temperature,postural and emotional changes.&lt;br /&gt;
Blood Volume Pulse (BVP) is the most common measure of vasomotor activity because it reflects the phasic pumping of the heart, the vasodilation of vessels that changes in the amount of acral blood delivered.&lt;br /&gt;
The Blood Volume Pulse (BVP) waveform is an important indicator of circulatory function that can be obtained noninvasively through a photoplethysmographic transducer (a PPG is often obtained by using a pulse oximeter, Shelley and Shelley, 2001) applied to the finger or the earlobe of human subjects. In particular, this signal may be useful in determining the degree of cardiovascular change undergone by a subject through an exercise session. &lt;br /&gt;
&lt;br /&gt;
''Principles of photoplethysmographic Technology:''&lt;br /&gt;
&lt;br /&gt;
The principle of photoplethysmographic (That is the same of pulse oximetry) is based on the red and infrared light absorption characteristics of oxygenated and deoxygenated hemoglobin. Oxygenated hemoglobin absorbs more infrared light and allows more red light to pass through. Deoxygenated (or reduced) hemoglobin absorbs more red light and allows more infrared light to pass through. Red light is in the 600-750 nm wavelength light band.&lt;br /&gt;
Pulse oximetry uses a light emitter with red and infrared LEDs that shines through a reasonably translucent site with good blood flow. Opposite the emitter is a photodetector that receives the light that passes through the measuring site.&lt;br /&gt;
There are two methods of sending light through the measuring site: transmission and reflectance. In the transmission the emitter and photodetector are opposite of each other with the measuring site in-between. The light can then pass through the site. In the reflectance method, the emitter and photodetector are next to each other on top the measuring site. The light bounces from the emitter to the detector across the site. The transmission method is the most common type used.&lt;br /&gt;
While pulse oximeters are a commonly used medical device the PPG derived from them is rarely displayed, and is nominally only processed to determine heart rate. &lt;br /&gt;
&lt;br /&gt;
'''Temperature'''&lt;br /&gt;
&lt;br /&gt;
The temperatures of peripheral limbs vary as a consequence of changes in blood flow.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== '''Previous work''' ==&lt;br /&gt;
&lt;br /&gt;
Here is a preliminary release of the headset produced before 2008/08/08&lt;br /&gt;
&lt;br /&gt;
[[Image:Wd1.jpg]]&lt;br /&gt;
&lt;br /&gt;
If you are interested on the making of the headset please see [[making rubber models]]&lt;br /&gt;
&lt;br /&gt;
'''* Blood Volume pressure'''&lt;br /&gt;
First graph showing a signal acquired with the wireless sensor. &lt;br /&gt;
[[Image:Bvp.png]]&lt;br /&gt;
&lt;br /&gt;
'''* Skin galvanic response''' (Sala Mirko e Alessia Cornaggia[http://airwiki.elet.polimi.it/mediawiki/index.php/User:AlessiaCornaggia])&lt;br /&gt;
Galvanic skin response (GSR), also known as electrodermal response (EDR), psychogalvanic reflex (PGR), or skin conductance response (SCR), is a method of measuring the electrical resistance of the skin.  There is a relationship between sympathetic activity and emotional arousal, although one cannot identify the specific emotion being elicited. The GSR is highly sensitive to emotions in some people. Fear, anger, startle response, orienting response and sexual feelings are all among the emotions which may produce similar GSR responses.&lt;br /&gt;
Response of the skin to the passage of a small electric current. The ease with which the current flows between two points on the skin can be used to indicate stress. When a person is tense or emotional, the sweat glands become more active, increasing moisture on the skin; this allows the electric current to flow more readily. &lt;br /&gt;
The response may also be used in relaxation training: information about the galvanic skin response is fed back aurally or visually to the subject who can, with practice, learn to increase or decrease sweating on the skin by learning to relax or tense muscles.&lt;br /&gt;
We measure the galvanic skin response using two electrodes attached to the skin. The optimal placement is the palm of the hands, but we are experimenting other places like on the forehead.&lt;br /&gt;
The circuit we are creating is the one below.&lt;br /&gt;
&lt;br /&gt;
[[Image:circuito.jpg]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== '''Project the device''' ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== '''Re-definition of the complete work''' ===&lt;br /&gt;
&lt;br /&gt;
Sensors are an important part of an Affective Computing System because they provide information about the wearer's physical state or behavior. They can gather data in a continuous way without having to interrupt the user. &lt;br /&gt;
To define in detail electronic specifications and requirements it's necessary a preliminary research/study (in literature and web) about state of art of sensor type used to monitor each type of biological signals we are interested about.&lt;br /&gt;
In this way it's possible both understand problematics related to interaction between biological and electonical worlds and improve or re-desig existing prototype.&lt;br /&gt;
&lt;br /&gt;
About Sensors: &lt;br /&gt;
&lt;br /&gt;
BVP will be acquire by an IR transmitter-receiver measuring light reflected from skin (photoplethysmography). Particular attention will be put on position, geometry and power absorption of this stage. &lt;br /&gt;
&lt;br /&gt;
GSR will be acquiret by a couple of electrodes forcing a low current (or voltage) and reading voltage (or current) through electrodes. Particular attention will be put on electrodes position and material. In addition is possible to foresee some problems in amplifier stage due to large range of skin resistance. Problem consist in chosing a correct amplification to overwork ADC full scale with a signal affected by little variation but huge possible range. &lt;br /&gt;
&lt;br /&gt;
Temperature will be acquired by thermocouple or PTC/NTC. Slowly variable signal, possible problems with noise due to resolution required. &lt;br /&gt;
&lt;br /&gt;
Head orientation will be acquired by an accelerometer and a gyroscope, problably integrated in the same chip. Two possibilities: analog output (need to digitalize up to six line) or digital output (like displaied in schematic block diagram). &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
This was the preliminary simplified schematic block diagram of the complete instrumentation setup:&lt;br /&gt;
&lt;br /&gt;
[[Image:WADSchematicDiagram01.jpg]]&lt;br /&gt;
&lt;br /&gt;
 NOTE:&lt;br /&gt;
 &lt;br /&gt;
 * In schematic is not present Power Supply Module: it will be based on a rechargeable Li-ion&lt;br /&gt;
 battery. It must satisfy requirements of high efficiency, logn life and low weight.&lt;br /&gt;
 &lt;br /&gt;
 * ADC and Microcontroller could be unified using a microcontroller with internal ADC and&lt;br /&gt;
 internal or external multiplexer to select lines.&lt;br /&gt;
 &lt;br /&gt;
 * Wireless section could be implemeted in Bluetooth (instead of using a XBee module like in&lt;br /&gt;
 preliminary release) due to it's diffusion in cellular phones, notebooks, MP3 reader...&lt;br /&gt;
 without necessity of external modules.&lt;br /&gt;
&lt;br /&gt;
It was based on a theoretical approach to any single part. Any sensing device was designed in &amp;quot;conventional&amp;quot; way founded on analog electronic (a bridge with a NTC resisistance as sensing element, discrete IR led and some photodiode around to capture the most reflefted light as possible, GSR electrodes on the gain arm of a non-inverting amplifier...).&lt;br /&gt;
Unfortunatly a deep analysis on signal physiology, signal transduction, noise vs required accurancy, forced us to a completely different approach implementing everywhere possible a digital interface.&lt;br /&gt;
&lt;br /&gt;
=== '''Sensors Design''' ===&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''BVP'''&lt;br /&gt;
&lt;br /&gt;
Discrete IR leds and phototransistor, used in the first realize (see fig.), had been replaced first with a single led and one or more photodiodes to optimize power consumption in case of non-planar sensor positioning. Subsequently an integrated Reflective Object Sensor was introduced, with benefits about space saving, transmitter-receiver matching and power consumption.&lt;br /&gt;
To ensure light power stability, led is powered through a linear led drive LDO (Low Drop-Out). The choise of linear LDO is necessary to ensure no noise or spikes would be generated by charge pump systems or boost converters. In addition, the linear drive utilized requires only one external resitor to set led current and a decoupling capacitor, reducing part counts and board space occupation.&lt;br /&gt;
The couple factor of the reflex sensors is relatively small, even in the case of good reflecting surfaces. Therefore an additional amplifier is necessary at the sensor output: classic trans-impedance amplifier used with photo-diodes and photo-transistors was introduced. This circuit features an output voltage that is a linear function of the light level on the photo-transistor. The gain is set by the feedback resistor which could be in the millions of ohms. Linear operation is achieved by operating the photo device with a fixed voltage drop across it.&lt;br /&gt;
Trans-impedance amplifier is followed by an active fourth order band-pass filter (0.5Hz-5Hz): it's composed cascading two second order bandpass cells. In first project session only a single cell was used, but a deeper study combined with previous experiences suggests to use a 4th order filter to reduce 50Hz interference (50Hz interference produced by mains is placed only a decade after the filter pole).&lt;br /&gt;
Filter is followed by a VGA (Variable Gain Amplifier) digitally controlled through I2C Bus that allows to optimize dinamically ADC input signal amplitude directly during acquisition session, obtaining the best performance from ADC.&lt;br /&gt;
The resulting circuit is quite compact (led drive, reflective sensor, trans-impedence amplifier, active filter and variable-gain amplifier), doesn't require much power and represents a good mix between analog and digital approach: analog front-end with acquisition and first conditioning, and at the chain-end a digital controlled amplifier to ensure flexibility.&lt;br /&gt;
&lt;br /&gt;
[[Image:WADBVPComparison.jpg]]&lt;br /&gt;
&lt;br /&gt;
'''GSR'''&lt;br /&gt;
&lt;br /&gt;
GSR will be acquired by a couple of electrodes forcing a low voltage and reading current through electrodes. First designs and implementations were based on literature study: best solution appears to put GSR electrodes on the gain arm of a non-inverting amplifier (see fig.) rather than using a Wheatstone bridge due to week signal produced by this solution.&lt;br /&gt;
Putting GSR electrodes on the gain arm produces a sort of gain modulation of the constant voltage applied between electrodes but doesn't solve problems in amplifier stage due to large range of skin resistance.&lt;br /&gt;
Problems in chosing correct amplification to overwork ADC full scale with a signal affected by little variation but huge possible range could be reduced usign a variable resistor on gain arm (for example a digital potentiometer controlled by the microcontroller), but cannot be completely removed. In addition little signals are easily deteriorated by noise.&lt;br /&gt;
Solution is provided considering a new point of view: measure of unknown skin resistence is extremely similar to measure unknown electrical impedence with an auto-range multimeter!&lt;br /&gt;
Solution consist in a digital Impedance Converter: AD5934 is a high precision impedance converter system which combines an on-board frequency generator with a 12-bit, 250 kSPS, analog-to-digital converter (ADC). The frequency generator allows an external complex impedance to be excited with a known frequency; the response signal from the impedance is sampled by the on-board ADC and a discrete Fourier transform (DFT) is processed by an on-board DSP engine. The DFT algorithm returns a real (R) and imaginary (I) data-word at each output frequency. This solution not only allows to measure impedence range from 100 Ohm to 10 MOhm, but in adition allow to investigate it across a wide range of frequency, producing a noise-free digital output.&lt;br /&gt;
The resulting circuit is extremely compact (converter chip, one setting resistor and bypass capacitors), provides a system accuracy of 0.5% and connects to microcontroller using I2C interface, ensuring an high flexibility and the possibility to modify acquisition settings after board production (through microcontroller firmware).&lt;br /&gt;
&lt;br /&gt;
[[Image:WADGSRComparison.jpg]]&lt;br /&gt;
&lt;br /&gt;
'''Temperature'''&lt;br /&gt;
&lt;br /&gt;
First idea was to acquire temperature by a NTC connected in a Wheatstone bridge. Trying to reduce noise, bridge was powered by an oscillator circuit with a frequency of some KHerz, to translate signal out of 1/f noise region. Bridge outputs were connected to an INA amplifier wich also implements signal filtering (see fig.).&lt;br /&gt;
Weak signal, noise and resolution required (0.1°C) put in crisis the system. In addition other unsolved problems were the optimization of thermal and mechanical contact between sensor and body and the sensor large thermic constant. Unstable thermic contact produces unreliable measures, whereas high sensor thermic constant hampers a fast sensor response (needed to detect short peak due to emotional reactions).&lt;br /&gt;
Possible solutions to problems of weak signal and noise arrive from digital integrated temperature sensor (for example LM35 or LM74), but these don't solve the problem of thermal contact and thermal constant. In addition none of the sensors take in consideration provides the required resolution.&lt;br /&gt;
High resolution required, noise immunity, fast response and thermal contact immunity problems had been solved using a digital optical infra red thermometer. The MLX90614 is an infra red thermometer for non contact temperature measurements based on a thermopile detector chip including signal conditioning in the same TO-39 package. Thanks to its low noise amplifier, 17-bit ADC and powerful DSP unit, a high accuracy and resolution of the thermometer is achieved.&lt;br /&gt;
The calculated object and ambient temperatures are available in RAM of MLX90614 with 0.02°C resolution: they are accessible by 2 wire serial SMBus compatible protocol. A special version for medical applications offers an accuracy of ±0.1ºC in a limited temperature range around the human body temperature.&lt;br /&gt;
Small size, no external component requirements and power saving mode allow us to obtain a perfect matching between required performances and space saving.&lt;br /&gt;
&lt;br /&gt;
[[Image:WADTemperatureComparison.jpg]]&lt;br /&gt;
&lt;br /&gt;
'''Accelerometer'''&lt;br /&gt;
&lt;br /&gt;
Head orientation and movements will be acquired by an accelerometer. First we think to utilize an ST Microelectronic LIS3L02AS4, due to the availability in the Lab of the evaluation board STEVAL-MKI001. It is a 3-axis ±2g/±6g linear accelerometer with 3 analog outputs, so it requires an external ADC to digitalize the three axis acceleration values. The conversion could be performed by a microcontroller with internal ADC.&lt;br /&gt;
A fast Internet research reveled this sensor is now obsolete and out of production. The choise had been to substitute the old chip with the new one: the LIS302DL (still produced by ST Microelectronic). It's a 3-axis, ± 2g/± 8g smart digital output accelerometer with I2C/SPI digital output interface and really small package. The device is capable of measuring accelerations with an output data rate of 100 Hz or 400 Hz and the self-test capability allows the user to check the functioning of the sensor in the final application.&lt;br /&gt;
In addition it may be configured to generate inertial wake-up/free-fall interrupt signals when a programmable acceleration threshold is crossed at least in one of the three axes. Thresholds and timing of interrupt generators are programmable by the end user on the fly.&lt;br /&gt;
This device, providing a digital output, doesn't need signals conversion, guaranteing better noise immunity; programmable interrupts and test interface allow greater fexibility in project. In addition wery small package, only one external resistor requirement (plus baypass capacitor) reduce significantly board space requirements.&lt;br /&gt;
&lt;br /&gt;
[[Image:WADAccelerometer.jpg]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
 NOTE:&lt;br /&gt;
 &lt;br /&gt;
 * In previous schematics, components phisical dimensions are not in scale.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== '''Microcontroller''' ===&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Foundamental requirements:&lt;br /&gt;
&lt;br /&gt;
- High speed to ensure high data output rate even in presence of a large number af sensing elemets;&lt;br /&gt;
&lt;br /&gt;
- Fast Internal ADC with multiple inputs;&lt;br /&gt;
&lt;br /&gt;
- (At Least) One I2C interface;&lt;br /&gt;
&lt;br /&gt;
- (At Least) One SPI interface;&lt;br /&gt;
&lt;br /&gt;
- (At Least) One UART interface;&lt;br /&gt;
&lt;br /&gt;
- (At Least) Three Timers;&lt;br /&gt;
&lt;br /&gt;
- (At Least) Three External Interrrupts;&lt;br /&gt;
&lt;br /&gt;
- Low-power consumption;&lt;br /&gt;
&lt;br /&gt;
- Power supply 3.3V;&lt;br /&gt;
&lt;br /&gt;
- Small package;&lt;br /&gt;
&lt;br /&gt;
In addition microcontroller was chosen between Microchip PIC family devices, due to positive previous experiences and availability of software and programmer in the Lab.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
PIC24HJ256GP206 is a 16 bit microcontroller capable of 40 MIPS speed. It provides 256KB of Flash memory, 16KB of Ram, a 10-bit 1.1Msps or 12-bit 500Ksps ADC, UART, SPI and I2C interface in a 64 pin TQFP package (10mmX10mm) powerd between 3.0V and 3.6V.&lt;br /&gt;
Power core is provided by an internal regulator reducing parts count on the board.&lt;br /&gt;
&lt;br /&gt;
The device is able to provide at the same time one I2C interface, two SPI interface and one UART interface: another UART port shares pins with an SPI port and a second I2C port shares pins with the second UART interface.&lt;br /&gt;
Findig a device that provides at the same time, on indipendent pins, an I2C, a SPI and an UART interface reduces considerably possible choises and suggests to chose a high performance microcontroller.&lt;br /&gt;
At the same time, high performance solutions have a larger pin counts than standard microcontroller, but this characteristic can be used to ensure further expansibility to the system. The second SPI interface can be used to connect another &amp;quot;intelligent&amp;quot; device or a mass storage device, for example a SD (Secure Digital) card to storage acquired data (see fig.).&lt;br /&gt;
&lt;br /&gt;
[[Image:WADSDCard.jpg]]&lt;br /&gt;
&lt;br /&gt;
Input pins connected to ADC and not used at the moment could be collected to a connector for further extension modules (for example an EMG or ECG peripheral or any other analog signal interesting in a particolar application).&lt;br /&gt;
For the same reason any other pin non used at the current stage is reported to an extension connector.&lt;br /&gt;
To guarante maximum flexibility an further update, board provides both ICD and JTAG connections (allowing on-board programming and debugging) through a couple of indipendent dedicated connectors fully compatibles with Microchip programmers and evaluation boards.&lt;br /&gt;
&lt;br /&gt;
[[Image:WADMicro.jpg]]&lt;br /&gt;
&lt;br /&gt;
=== '''Wireless Connection''' ===&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Wireless connection is based on BlueGiga WT12 module: it's a next-generation, class 2, Bluetooth 2.0+EDR (Enhanced Data Rates) module containing all the necessary elements from Bluetooth radio to antenna and a fully implemented protocol stack.&lt;br /&gt;
By default WT12 module is equipped with powerful and easy-to-use iWRAP firmware that enables users to access Bluetooth functionality with simple ASCII commands delivered to the module over serial interface like a Bluetooth modem.&lt;br /&gt;
The dedicated onboard microcontroller (MCU) acts as interrupt controller and event timer run the Bluetooth software stack and control the radio and host interfaces. A 16-bit reduced instruction set computer (RISC) microcontroller is used for low power consumption and efficient use of memory.&lt;br /&gt;
WT12 module support USB, SPI and UART interface and UART interface is used in this project to connect PIC microcontroller to wireless transmitter (see fig.).&lt;br /&gt;
&lt;br /&gt;
[[Image:WADWireless.jpg]]&lt;br /&gt;
&lt;br /&gt;
One of the most important WT12 characteristic is the high integration between all parts needed for efficent Bluetooth transmission: user interface, controller, radio circuits and antenna, all included in a low power, low size board (25.6mmx15mm) that requires a minimum number of external components.&lt;br /&gt;
Many other bluetooth components ara available, such as LMX9830, produced by National Semiconductor. It's an extremely small device (only 6.1mm×9.1 mm), but requires a number of external components (see fig.) like oscillators, resistors, capacitors, inductors and the antenna, in addition to an high competence in radio frequency layout circuits.&lt;br /&gt;
&lt;br /&gt;
[[Image:WADLMX9830.jpg]]&lt;br /&gt;
&lt;br /&gt;
Lack of experience in radio frequency circuit suggests to chose a ready-to-use module, factory optimized for best performance and easy to integrate in our board.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
This is the updated simplified schematic block diagram:&lt;br /&gt;
&lt;br /&gt;
[[Image:WADSchematicDiagram02.jpg]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== '''Prototype realization [WIP (Work in Progress)]''' ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Fist stage plans to realize a board using, where possible, through-hole (TH) compenents soldered on a prototyping board (100x160mm) powered from a laboratory power supply (instead of Li-on battery) and not implementing bluetooth wireless transmission. Parts not available on TH package are used with special SMD-&amp;gt;TH adapter boards or simply fixing and soldering them to the PCB by wires.&lt;br /&gt;
&lt;br /&gt;
Second stage plans to realize microcontoller firmware and test it acquiring biological signals from a patient. Firmware will be developed by subsequently steps, implementing and testing only a single peripheral at each time: only at the end single pheripheral softwares will be merged together.&lt;br /&gt;
&lt;br /&gt;
Third stage will be bluetooth interface (hardware and software) implementation and integration on the board with transmission test.&lt;br /&gt;
&lt;br /&gt;
Fourth stage will consider power supply optimization with battery management and recharge interface.&lt;br /&gt;
&lt;br /&gt;
Finally, only after a successful full board test, the last stage will be the circuit layout design with an electronic CAD, using where possible, Surface Mount Devices (SMD) to reduce board area.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== '''Main board''' ===&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Main board include power supply regulator with led power-on indicator, PIC microcontroller (mounted on a SMD-&amp;gt;TH adapeter board) with basic circuitry (decoupling capacitors, oscillator and programming-debugging ICD interface), a status led connected to PIC to verify basic microcontroller function, a series of connectors for add-on modules (BVP, GSR, temperature and accelerometer) and a USB PC interface not considered before.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== '''USB interface''' ===&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
USB interface, not projected before, replaces in developing stage Bluetooth interface, allowing a direct control/communication with a PC. In this prototype PIC UART, althought being connected to Bluettoth module, is connected to a FTDI FT232RL chip. The FT232RL is the latest device to be added to FTDI’s range of USB UART interface Integrated Circuit Devices. USB to serial designs using the FT232RL have been further simplified by fully integrating the external EEPROM, clock circuit and USB resistors onto the device.&lt;br /&gt;
The FT232RL is available in Pb-free (RoHS compliant) compact 28-Lead SSOP, so this require another SMD-&amp;gt;TH board adapter but the circuit design is very simple, including two status led for TX and RX operations. An USB B female connector was eputated the best choise for PC connection allowing to use a simple USB printer cable.&lt;br /&gt;
&lt;br /&gt;
[[Image:WADUSBInterface.jpg]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Note that USB and Bluetooth must not be connected to the board at the same time! USB port has only a developent function.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== '''BVP''' ===&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Circuit designed for BVP acquisition (refer to previous schematic) doesn't meet the expected results. Week signal hanged by noise suggested us to re-design the circuit simplifying it and reducing the number of components. For this design also sensing element has been substitute. Instead of an integrated reflective IR sensor (SFH9202), new project use a couple af discrete IR led and photothansistor matched: SFH487 and SFH309FA.&lt;br /&gt;
SFH487 is a very highly efficient GaAlAs infrared emitter (880 nm) and SFH309FA is a silicon NPN phototransistor especially suitable for applications of 880 nm with an high linearity. Both have a 3 mm led plastic package, are spectrum-matched and receiver is ambient-light shilded. After a series of positive test without the led driver (not used due to the really reduced mechanical dimensions), also led drive circuit was removed and replaced with a resistance connected directly to a PIC pin.&lt;br /&gt;
This choise reduces parts count and board space required without making worse sistem performance, allowing (like led driver) to turn off the sensor led when not used to reduce power consumption.&lt;br /&gt;
&lt;br /&gt;
[[Image:WADBVPNew.jpg]]&lt;br /&gt;
&lt;br /&gt;
Even if operation amplifier used are half of before, double second-order filter stage is manteined. In addition to filtering, these opamp privide a first gain (note that in previous design filtering stages works as a unitary buffer in pass-band) allowing a high signal at VGA (variable gain amplifier) input stage allowing a better SNR.&lt;br /&gt;
1N4148 diode provides a sort of ofsetted virtual ground, shifting up all signals but not being amplified through the amplification chain.&lt;br /&gt;
Figure show the signal measured directly on filtering stage output (TS952 pin 7) before the VGA with a Tektronix scopemeter TDS2014B. No particular triks had been used: signal has been recorded the first time circuit was assembled on a protoboard.&lt;br /&gt;
&lt;br /&gt;
[[Image:WADBVPScope03.jpg]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== '''GSR''' ===&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
First approach with AD5934 resulted really hard due to some errors occurred in control software in relation with internal chip complexity and I2C bus protocol. &lt;br /&gt;
After a start session with the AD5934, GSR hardware acquisition interface was further simplified replacing it with AD5933 (refer to schematic). AD5933 has the same pinout and functions of AD5934 but provides also an internal oscillator at 16.776MHz allowing no external crystal connection. A temperature sensor that allow the user to measure chip temperature and 1 MSPS Converter (instad of a 250KSPS one) are the only other differences between the tho integrated semiconductor produced by Analog Devices.&lt;br /&gt;
On the other hand AD5934 has a larger impedance measurement range that goes from 100 Ohm to 10 MOhm in opposition to AD5933 that can only measure impedences between 1 Ohm and 10 MOhm. Because of the high skin impedence values (in the range of MOhm for dry fingers skin), this is not a problem in our application.&lt;br /&gt;
&lt;br /&gt;
[[Image:WADGSRNew.jpg]]&lt;br /&gt;
&lt;br /&gt;
First dataset acquired whith the correct control software and the correct data reading routine, has shown all the potentiality of this chip, providing data comparables with RAW data acquired with a bigger and very expensive professional equipement produced by ProComp.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== '''Acceleration''' ===&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Lis302DL datasheet gives a short definition of this chip as &amp;quot;MEMS motion sensor 3-axis - ± 2g/± 8g smart digital output “piccolo” accelerometer&amp;quot; and it is really very, very small for human-working. For this space saving quality this accelerometer is also use in third generation Apple i-phone.&lt;br /&gt;
The major problem with this sensor had been to solder it to a sort of adapter to connect it to the circuit, but after that it works fine, with a good sensitivity and accuracy. Because of free fall and double click recognition at not required (at the moment) in this application, software routines for setting configuration registers and reading data resulted simplified.&lt;br /&gt;
A usefull caracteristic of this sensor, not previously noticed, is the presence of internal pull-up resistors that allows no necessity of external I2C bus pull-up resistors, reducing space occupation and components count.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== '''Temperature''' ===&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The choice to use MLX90614 due to his characteristics (non contact measure, 0.02°C resolution with accuracy of ±0.1°C for medical applications version) creates a really serious supplies problem: Melexis (sensor manufacture) wasn't able to give us a sample and no one in Italy can sell us only a pair of theese sensors to try them. A single piece was bought from Future Electronics, ordering it via web and paying it via credit card. Fortunately the sensor, that cames directly from USA, arrived in Italy few days later the payment in excellent conditions.&lt;br /&gt;
&lt;br /&gt;
[[Image:WADMLX90614.jpg]]&lt;br /&gt;
&lt;br /&gt;
Problems occurred interfacing this sensor on I2C bus with other devices (AD5933 and LIS302) connected. MLX90614 has a 2 wire serial SMBus compatible protocol: I2C bus and  SMBus are popular 2-wire buses that are essentially compatible with each other, but are not the same.&lt;br /&gt;
The buses operate at the same speed, up to 100kHz, but the I2C bus has both 400kHz and 2MHz versions. Complete compatibility between both buses is ensured only below 100kHz.&lt;br /&gt;
Timeout and (as a consequence of timeout) minimum clock speed are the most important differences between the I2C bus and the SMBus:&lt;br /&gt;
&lt;br /&gt;
I2C Bus = DC (no timeout)&lt;br /&gt;
&lt;br /&gt;
SMBus = 10kHz (35mS timeout)&lt;br /&gt;
&lt;br /&gt;
Despite differences in logic-level specifications between the two buses, generally devices can be mixed and matched with abandon.&lt;br /&gt;
Level Specifications for the I2C Bus and the SMBus are shown below (VDD is typically expected to be between 3 volts and 5 volts):&lt;br /&gt;
&lt;br /&gt;
[[Image:WADTable1.jpg]]&lt;br /&gt;
&lt;br /&gt;
What wasn't readily evident in the discussion of voltage levels is that these levels are also specified with different currents between the buses. The SMBus specifies a minimum sink current of 100microA, and a maximum of 350microA, compared to 3mA for the I2C bus. This in turn would determine the lowest acceptable value of the pullup resistor, examples of which are shown in the table below.&lt;br /&gt;
&lt;br /&gt;
[[Image:WADTable2.jpg]]&lt;br /&gt;
&lt;br /&gt;
In reality, it is not unusual to encounter pullup resistor values in SMBus systems, which violate this specification by being lower than recommended. A very popular range for pullup resistor values, even in some SMBus systems, seems to be 2.4k to 3.9k.&lt;br /&gt;
&lt;br /&gt;
These reasons, in adition to clear ideas about close developments, suggest a general review of schematic to re-distribute microcontroller resources.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== '''Part 6: final review [WIP (Work in Progress)]''' ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== '''Microcontroller''' ===&lt;br /&gt;
&lt;br /&gt;
Referring to previous schematic, some chenges had been applied:&lt;br /&gt;
&lt;br /&gt;
- Programmer/Debugger interface is now PGD1/EMUD1 and PGC1/EMUC1 instead of PGD1/EMUD2 and PGC1/EMUC2;&lt;br /&gt;
&lt;br /&gt;
- JTAG interface had been removed;&lt;br /&gt;
&lt;br /&gt;
- UART2 is no more available so UART1 has replaced UART2 as communication port;&lt;br /&gt;
&lt;br /&gt;
- SPI2 is no more available so SPI1 is now used to control both LMP8100 VGA (Variable Gain Amplifier) and SD Storage Card;&lt;br /&gt;
&lt;br /&gt;
- RG12, RG13, RG14 pins had been connected to three status led for a machine visual state detection;&lt;br /&gt;
&lt;br /&gt;
- I2C1 interface is now connected to accelerometer (LIS302) and GSR (AD5933) only;&lt;br /&gt;
&lt;br /&gt;
- I2C2 interface is dedicated to temperature sensor (MLX90614), enabling I/O pin thresholds compliant with SMBus specification;&lt;br /&gt;
&lt;br /&gt;
- Connectors for I2C, SMBus and SPI expansion modules had been added to the board;&lt;br /&gt;
&lt;br /&gt;
- Test point pads had been added to the board to simplify debugging.&lt;br /&gt;
&lt;br /&gt;
That's the complete microcontroller schematic diagram:&lt;br /&gt;
&lt;br /&gt;
[[Image:WAD_Micro_Final.jpg]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== '''Data link''' ===&lt;br /&gt;
&lt;br /&gt;
During developing stages, an USB port had replaced Bluetooth wireless transmission, allowing a direct control/communication with a PC. This interfaced, based on a FT232RL, prove to be very usefull and simple to use.&lt;br /&gt;
The choice to use an usb port to charge internal battery, in addition to availability of a UART multiplexer inside the Bluetooth module BlueGiga WT12, suggest to implement both USB and Bluetooth interface.&lt;br /&gt;
&lt;br /&gt;
That's the BlueGiga WT12 internal UART multiplexer schematic:&lt;br /&gt;
&lt;br /&gt;
[[Image:WAD_UARTMux.jpg]]&lt;br /&gt;
&lt;br /&gt;
The complete data link schematic diagram:&lt;br /&gt;
&lt;br /&gt;
[[Image:WAD_USB+Bluetooth_Final.jpg]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== '''Battery Charge, Monitor &amp;amp; Power On''' ===&lt;br /&gt;
&lt;br /&gt;
Device is powered by a single cell Li-on battery (3.7V, 1080mAh): this is the same unit used in IPod(TM) from Apple.&lt;br /&gt;
&lt;br /&gt;
[[Image:WAD_Battery.jpg]]&lt;br /&gt;
&lt;br /&gt;
Battery charge is executed by Maxim's MAX1811: it is a really compact single-cell lithium-ion (Li+) battery charger that can be powered directly from a USB port or from an external supply up to 6.5V. It has a 0.5% overall battery regulation voltage accuracy to allow maximum utilization of the battery capacity.&lt;br /&gt;
The charger uses an internal FET to deliver up to 500mA charging current to the battery. The device can be configured for either a 4.1V or 4.2V battery, using the SELV input. The SELI input sets the charge current to either 100mA or 500mA. An open-drain output indicates charge status.&lt;br /&gt;
MAX1811 has preconditioning that soft-starts a near-dead battery cell before charging. Other safety features include continuous monitoring of voltage and current and initial checking for fault conditions before charging.&lt;br /&gt;
&lt;br /&gt;
[[Image:WAD_Battery_Charge&amp;amp;PowerOn_Final.jpg]]&lt;br /&gt;
&lt;br /&gt;
White battery wire (see photo) is connected to internal NTC thermistor (10KOhm@+25°C). In this way it's posible to implement an over/under charge temperature detector using a couple af operational amplifier as comparator.&lt;br /&gt;
With the resistence network in schematic it had been possible to set an upper temperature threshold of 47.5°C (corresponding to 3.97K NTC value) and a down thresold of 2.5°C (corresponding to &lt;br /&gt;
28.7K NTC value). Out of this range comparators output go low disabling battery charger.&lt;br /&gt;
This function allows to prevent battery demage or explosion during charge.&lt;br /&gt;
&lt;br /&gt;
Battery voltage monitor is hardware implemented by another Maxim's device: MAX8212.&lt;br /&gt;
MAX8212 is a CMOS micropower voltage detector that warn microprocessors/microcontroller of power failures. It contains a comparator, a 1.5V bandgap reference, and an open-drain n-channel output driver. Two external resistors are used in conjunction with the internal reference to set the trip voltage to the desired level. A hysteresis output is also included, allowing the user to apply positive feedback for noise-free output switching.&lt;br /&gt;
Using a couple of these device is possible to set two treshold: one for low battery and another for end battery detection. Low battery detection allow communicate the user battery level; end battery detection allow microprocessor shut down the device before battery voltage fall down under 3.4V that is the minimun input voltage allowed by linear regulator MCP1700.&lt;br /&gt;
If battery level fall down under 3.4V, MCP1700 is not able to guarantee line regulation. &lt;br /&gt;
&lt;br /&gt;
[[Image:WAD_Battery_Monitor_Final.jpg]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== '''Power On &amp;amp; Selection''' ===&lt;br /&gt;
&lt;br /&gt;
Power-up and shut-down were implemented using a Maxim's MAX16054 connected with an ADG801 by Analog Device.&lt;br /&gt;
MAX16054 is a pushbutton on/off controller with a single switch debouncer and built-in latch. It accepts a noisy input from a mechanical switch and produces a clean latched digital output after a factory-fixed qualification delay.&lt;br /&gt;
The state of the output changes only when triggered by the falling edge of the debounced switch input; the output remains unchanged on the rising edge of the input.An asynchronous CLEAR input allows an external signal to force the output flip-flop low.&lt;br /&gt;
1 MOhm resistor and 10 uF capacitor connected to power-on pushbutton  (in addition to internal 63KOhm pullup resistor) allow to obtain a delay of about 3 seconds.&lt;br /&gt;
ADG801 is a monolithic CMOS, single-pole, single throw (SPST), normally open (NO) switch with on resistance of less than 0.4Ohm. This switch conducts equally well in both directions when on.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== '''MicroSD Storage Card ''' ===&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== '''RTC ''' ===&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Students that have worked on the project==&lt;br /&gt;
&lt;br /&gt;
* Mattia Colombo (Blood Volume Pressure sensor)&lt;br /&gt;
* Alessia Cornaggia (Galvanic skin response sensor)&lt;br /&gt;
* Sala Mirko (Galvanic skin response sensor)&lt;br /&gt;
&lt;br /&gt;
== Laboratory work and risk analysis ==&lt;br /&gt;
&lt;br /&gt;
Laboratory work for this project will be mainly performed at AIRLab/Lambrate. It will include electrical and electronic activity. Potentially risky activities are the following:&lt;br /&gt;
* Use of mechanical tools. Standard safety measures described in [http://airlab.elet.polimi.it/index.php/airlab/content/download/461/4110/file/documento_valutazione_rischi_AIRLab.pdf Safety norms] will be followed.&lt;br /&gt;
* Use of soldering iron. Standard safety measures described in [http://airlab.elet.polimi.it/index.php/airlab/content/download/461/4110/file/documento_valutazione_rischi_AIRLab.pdf Safety norms] will be followed.&lt;br /&gt;
* Use of high-voltage circuits. Special gloves and a current limiter will be used. Standard safety measures described in [http://airlab.elet.polimi.it/index.php/airlab/content/download/461/4110/file/documento_valutazione_rischi_AIRLab.pdf Safety norms] will be followed.&lt;/div&gt;</summary>
		<author><name>PaoloVilla</name></author>	</entry>

	<entry>
		<id>https://airwiki.deib.polimi.it/index.php?title=File:WADGSRComparison_Pub.jpg&amp;diff=9579</id>
		<title>File:WADGSRComparison Pub.jpg</title>
		<link rel="alternate" type="text/html" href="https://airwiki.deib.polimi.it/index.php?title=File:WADGSRComparison_Pub.jpg&amp;diff=9579"/>
				<updated>2009-12-12T09:41:39Z</updated>
		
		<summary type="html">&lt;p&gt;PaoloVilla: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>PaoloVilla</name></author>	</entry>

	<entry>
		<id>https://airwiki.deib.polimi.it/index.php?title=File:WADBVPComparison_Pub.jpg&amp;diff=9578</id>
		<title>File:WADBVPComparison Pub.jpg</title>
		<link rel="alternate" type="text/html" href="https://airwiki.deib.polimi.it/index.php?title=File:WADBVPComparison_Pub.jpg&amp;diff=9578"/>
				<updated>2009-12-12T09:41:07Z</updated>
		
		<summary type="html">&lt;p&gt;PaoloVilla: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>PaoloVilla</name></author>	</entry>

	<entry>
		<id>https://airwiki.deib.polimi.it/index.php?title=Wireless_Affective_Devices&amp;diff=9470</id>
		<title>Wireless Affective Devices</title>
		<link rel="alternate" type="text/html" href="https://airwiki.deib.polimi.it/index.php?title=Wireless_Affective_Devices&amp;diff=9470"/>
				<updated>2009-11-26T13:57:31Z</updated>
		
		<summary type="html">&lt;p&gt;PaoloVilla: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{Project&lt;br /&gt;
|title=Wireless Affective Devices&lt;br /&gt;
|tutor=SimoneTognetti;MatteoMatteucci&lt;br /&gt;
|students=PaoloVilla&lt;br /&gt;
|resarea=BioSignal Analysis&lt;br /&gt;
|restopic=Affective Computing&lt;br /&gt;
|start=2008/01/08&lt;br /&gt;
|end=2009/12/30&lt;br /&gt;
|status=Active&lt;br /&gt;
|level=Ms&lt;br /&gt;
|type=Thesis&lt;br /&gt;
}}&lt;br /&gt;
==Project aims ==&lt;br /&gt;
&lt;br /&gt;
 ”''Everyone knows what an emotion is, until asked to give a definition''”&lt;br /&gt;
                                         &lt;br /&gt;
                                                                 Beverly Fehr and James Russell&lt;br /&gt;
&lt;br /&gt;
Research on Human-Computer-Interfaces has recently begun to take into account the affective state of the user. By appropriately reacting to the affective user state, interfaces could not only become more pleasant or entertaining, but also more effective or safer.&lt;br /&gt;
It is known that affective states have bodily correlates, and thus physiological signals could provide the necessary information for acquiring the affective user state. In contrast to other sources of information about the affective user state such as speech or facial expression, most physiological signals are not under voluntary control, and thus cannot be masked up to the same extent. Furthermore, it can be presumed that the signs of affective states in physiological signals are less dependent on individual and contextual factors: this is because the signals correspond to internal physiology, largely related to the autonomous nervous and limbic systems, rather than to external expressions that can be manipulated easily.&lt;br /&gt;
Recently, the issue of emotion regulation drew interests from several fields including neuroscience, psychology, education, computer science, etc. Possible applications are e-learningin, human computer interaction, development of communicative technologies for use by people with autism, car infotainment system, lie detection tests, cognitive workload, multimodal user interfaces MMUI (allow users to control computers using speech and gesture), etc.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The project is aimed at developing a device, connected to a PC, to acquire biological signals (such as GSR, BVP, Temperature and Head orientation) in a way that is less invasive for the subject. The term invasive is related to how much the sensors we use compromise the normal interaction between subject and machine.&lt;br /&gt;
Through these biological signal the PC is able o understand emotion in people who wear the device.&lt;br /&gt;
&lt;br /&gt;
An affective device should be weared easily, should not have cables and should acquire as much sensors as possible. We relax some constraint on the quality of signal but we add constraint on way they are acquired(i.e. the subject can put it on easily, the usual movements are not influenced..). The aim of the resulting device is not to replace the standard medical devices usually used to acquire that signals, but is to be much more suitable for industrial application in which the medical requirement are replaced by invasivity requirement.&lt;br /&gt;
&lt;br /&gt;
It is composed by:&lt;br /&gt;
&lt;br /&gt;
* Low power, high efficiency, battery powered design&lt;br /&gt;
* Wireless comunication with a PC&lt;br /&gt;
* Blood Volume Pressure Sensor (Preliminary release by Mattia Colombo)&lt;br /&gt;
* Galvanic Skin Response Sensor (Preliminary release by Sala Mirko e Alessia Cornaggia)&lt;br /&gt;
* Temperature Sensor&lt;br /&gt;
* 3 Way Accelerometer&lt;br /&gt;
* Possibility of further extension&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''GSR (or EDR or EDA)'''&lt;br /&gt;
&lt;br /&gt;
An often misunderstood and difficult technique, GSR (also known as the electrodermal response EDR or electrodermal activity EDA) has gone through many phases of interest and rejection since the early 1900's and is very popular in psychophysiological studies since Carl Jung and his students (1907) described it as a mean to&lt;br /&gt;
enter the “sea of the unconscious” because “every stimulus accompanied by an emotion produced a deviation of the galvanometer” directly proportional to the strength of the emotion aroused. It has been used in important research on anxiety and stress levels (Fenz &amp;amp; Epstein, ' 67); and it has been a part of lie detection (Raskin, ' 73). Controversy has centered around the technique, underlying mechanisms, and the meaning of the responses obtained from the skin. &lt;br /&gt;
There has been a long history of electrodermal activity research, even if most investigators accept the phenomenon without understanding exactly what it means (Hume, ' 76).&lt;br /&gt;
The resistance of the skin is usually large, approximately 1M; however, momentary changes in the level of the sweat gland activity causes changes in resistance (up to approximately 950K).&lt;br /&gt;
Physiology, the GSR reflescts sweat gland activity and changes in the sympathetic nervous system and measurement variables. The activity of the sweat glands in response to sympathetic nervous stimulation ( Increased sympathetic activation ) results in an increase in the level of conductance. There ia a relationship between sympathetic activity and emotional arousal, although one cannot identify the specific emotion being elicited. &lt;br /&gt;
Basically there are two techniques in the history of Electrodermal measurement. In one a current is passed thru the skin and the the resistance to passage is measured; in the other no current is used externally and the skin itself is the source of electrical activity.&lt;br /&gt;
By applying a conventional 0.5 Volts across the skin and measuring changes in the&lt;br /&gt;
corresponding conductance, the emotional state of the subject can be inferred. In general, the electrodes used are of the Ag/AgCl type which are recessed from the skin and require the use of a suitable electrode paste.&lt;br /&gt;
It is important to note, however, that fluctuations in skin conductivity are resultant of many types of arousal.&lt;br /&gt;
By observing only these changes, it is impossible to deduce without prior knowledge whether&lt;br /&gt;
the subject has become happy, startled, physically active, etcetera.&lt;br /&gt;
EDA consists of two components: tonic and phasic. The tonic component is a low&lt;br /&gt;
frequency baseline conductivity level, which can oscillate over the course of days. The phasic&lt;br /&gt;
component rides on top of the tonic component, exhibits more rapid fluctuations, and&lt;br /&gt;
generally increases when a person is aroused. Problematically, each person has a different&lt;br /&gt;
tonic conductivity, so in order to infer the arousal level of the subject, the relative changes in&lt;br /&gt;
EDA must be analyzed over a period of time. Furthermore, skin conductance (measured in&lt;br /&gt;
units of siemens; formerly mhos) depends on the skin path length between the two electrodes&lt;br /&gt;
contacts, even for subjects with identical skin conductivity (measured in units of&lt;br /&gt;
siemens/meter). It is for these reasons that it is crucial to analyze the temporal variations of&lt;br /&gt;
the EDA signal.&lt;br /&gt;
&lt;br /&gt;
'''BVP'''&lt;br /&gt;
&lt;br /&gt;
The cardiovascular system is in charge to keep us alive by maintaining the vital blood flow throughout the body, providing nutrients and oxygen to our cells. The SNS controls this system&lt;br /&gt;
by shifting the flow in response to exercise, temperature,postural and emotional changes.&lt;br /&gt;
Blood Volume Pulse (BVP) is the most common measure of vasomotor activity because it reflects the phasic pumping of the heart, the vasodilation of vessels that changes in the amount of acral blood delivered.&lt;br /&gt;
The Blood Volume Pulse (BVP) waveform is an important indicator of circulatory function that can be obtained noninvasively through a photoplethysmographic transducer (a PPG is often obtained by using a pulse oximeter, Shelley and Shelley, 2001) applied to the finger or the earlobe of human subjects. In particular, this signal may be useful in determining the degree of cardiovascular change undergone by a subject through an exercise session. &lt;br /&gt;
&lt;br /&gt;
''Principles of photoplethysmographic Technology:''&lt;br /&gt;
&lt;br /&gt;
The principle of photoplethysmographic (That is the same of pulse oximetry) is based on the red and infrared light absorption characteristics of oxygenated and deoxygenated hemoglobin. Oxygenated hemoglobin absorbs more infrared light and allows more red light to pass through. Deoxygenated (or reduced) hemoglobin absorbs more red light and allows more infrared light to pass through. Red light is in the 600-750 nm wavelength light band.&lt;br /&gt;
Pulse oximetry uses a light emitter with red and infrared LEDs that shines through a reasonably translucent site with good blood flow. Opposite the emitter is a photodetector that receives the light that passes through the measuring site.&lt;br /&gt;
There are two methods of sending light through the measuring site: transmission and reflectance. In the transmission the emitter and photodetector are opposite of each other with the measuring site in-between. The light can then pass through the site. In the reflectance method, the emitter and photodetector are next to each other on top the measuring site. The light bounces from the emitter to the detector across the site. The transmission method is the most common type used.&lt;br /&gt;
While pulse oximeters are a commonly used medical device the PPG derived from them is rarely displayed, and is nominally only processed to determine heart rate. &lt;br /&gt;
&lt;br /&gt;
'''Temperature'''&lt;br /&gt;
&lt;br /&gt;
The temperatures of peripheral limbs vary as a consequence of changes in blood flow.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== '''Previous work''' ==&lt;br /&gt;
&lt;br /&gt;
Here is a preliminary release of the headset produced before 2008/08/08&lt;br /&gt;
&lt;br /&gt;
[[Image:Wd1.jpg]]&lt;br /&gt;
&lt;br /&gt;
If you are interested on the making of the headset please see [[making rubber models]]&lt;br /&gt;
&lt;br /&gt;
'''* Blood Volume pressure'''&lt;br /&gt;
First graph showing a signal acquired with the wireless sensor. &lt;br /&gt;
[[Image:Bvp.png]]&lt;br /&gt;
&lt;br /&gt;
'''* Skin galvanic response''' (Sala Mirko e Alessia Cornaggia[http://airwiki.elet.polimi.it/mediawiki/index.php/User:AlessiaCornaggia])&lt;br /&gt;
Galvanic skin response (GSR), also known as electrodermal response (EDR), psychogalvanic reflex (PGR), or skin conductance response (SCR), is a method of measuring the electrical resistance of the skin.  There is a relationship between sympathetic activity and emotional arousal, although one cannot identify the specific emotion being elicited. The GSR is highly sensitive to emotions in some people. Fear, anger, startle response, orienting response and sexual feelings are all among the emotions which may produce similar GSR responses.&lt;br /&gt;
Response of the skin to the passage of a small electric current. The ease with which the current flows between two points on the skin can be used to indicate stress. When a person is tense or emotional, the sweat glands become more active, increasing moisture on the skin; this allows the electric current to flow more readily. &lt;br /&gt;
The response may also be used in relaxation training: information about the galvanic skin response is fed back aurally or visually to the subject who can, with practice, learn to increase or decrease sweating on the skin by learning to relax or tense muscles.&lt;br /&gt;
We measure the galvanic skin response using two electrodes attached to the skin. The optimal placement is the palm of the hands, but we are experimenting other places like on the forehead.&lt;br /&gt;
The circuit we are creating is the one below.&lt;br /&gt;
&lt;br /&gt;
[[Image:circuito.jpg]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== '''Project the device''' ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== '''Re-definition of the complete work''' ===&lt;br /&gt;
&lt;br /&gt;
Sensors are an important part of an Affective Computing System because they provide information about the wearer's physical state or behavior. They can gather data in a continuous way without having to interrupt the user. &lt;br /&gt;
To define in detail electronic specifications and requirements it's necessary a preliminary research/study (in literature and web) about state of art of sensor type used to monitor each type of biological signals we are interested about.&lt;br /&gt;
In this way it's possible both understand problematics related to interaction between biological and electonical worlds and improve or re-desig existing prototype.&lt;br /&gt;
&lt;br /&gt;
About Sensors: &lt;br /&gt;
&lt;br /&gt;
BVP will be acquire by an IR transmitter-receiver measuring light reflected from skin (photoplethysmography). Particular attention will be put on position, geometry and power absorption of this stage. &lt;br /&gt;
&lt;br /&gt;
GSR will be acquiret by a couple of electrodes forcing a low current (or voltage) and reading voltage (or current) through electrodes. Particular attention will be put on electrodes position and material. In addition is possible to foresee some problems in amplifier stage due to large range of skin resistance. Problem consist in chosing a correct amplification to overwork ADC full scale with a signal affected by little variation but huge possible range. &lt;br /&gt;
&lt;br /&gt;
Temperature will be acquired by thermocouple or PTC/NTC. Slowly variable signal, possible problems with noise due to resolution required. &lt;br /&gt;
&lt;br /&gt;
Head orientation will be acquired by an accelerometer and a gyroscope, problably integrated in the same chip. Two possibilities: analog output (need to digitalize up to six line) or digital output (like displaied in schematic block diagram). &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
This was the preliminary simplified schematic block diagram of the complete instrumentation setup:&lt;br /&gt;
&lt;br /&gt;
[[Image:WADSchematicDiagram01.jpg]]&lt;br /&gt;
&lt;br /&gt;
 NOTE:&lt;br /&gt;
 &lt;br /&gt;
 * In schematic is not present Power Supply Module: it will be based on a rechargeable Li-ion&lt;br /&gt;
 battery. It must satisfy requirements of high efficiency, logn life and low weight.&lt;br /&gt;
 &lt;br /&gt;
 * ADC and Microcontroller could be unified using a microcontroller with internal ADC and&lt;br /&gt;
 internal or external multiplexer to select lines.&lt;br /&gt;
 &lt;br /&gt;
 * Wireless section could be implemeted in Bluetooth (instead of using a XBee module like in&lt;br /&gt;
 preliminary release) due to it's diffusion in cellular phones, notebooks, MP3 reader...&lt;br /&gt;
 without necessity of external modules.&lt;br /&gt;
&lt;br /&gt;
It was based on a theoretical approach to any single part. Any sensing device was designed in &amp;quot;conventional&amp;quot; way founded on analog electronic (a bridge with a NTC resisistance as sensing element, discrete IR led and some photodiode around to capture the most reflefted light as possible, GSR electrodes on the gain arm of a non-inverting amplifier...).&lt;br /&gt;
Unfortunatly a deep analysis on signal physiology, signal transduction, noise vs required accurancy, forced us to a completely different approach implementing everywhere possible a digital interface.&lt;br /&gt;
&lt;br /&gt;
=== '''Sensors Design''' ===&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''BVP'''&lt;br /&gt;
&lt;br /&gt;
Discrete IR leds and phototransistor, used in the first realize (see fig.), had been replaced first with a single led and one or more photodiodes to optimize power consumption in case of non-planar sensor positioning. Subsequently an integrated Reflective Object Sensor was introduced, with benefits about space saving, transmitter-receiver matching and power consumption.&lt;br /&gt;
To ensure light power stability, led is powered through a linear led drive LDO (Low Drop-Out). The choise of linear LDO is necessary to ensure no noise or spikes would be generated by charge pump systems or boost converters. In addition, the linear drive utilized requires only one external resitor to set led current and a decoupling capacitor, reducing part counts and board space occupation.&lt;br /&gt;
The couple factor of the reflex sensors is relatively small, even in the case of good reflecting surfaces. Therefore an additional amplifier is necessary at the sensor output: classic trans-impedance amplifier used with photo-diodes and photo-transistors was introduced. This circuit features an output voltage that is a linear function of the light level on the photo-transistor. The gain is set by the feedback resistor which could be in the millions of ohms. Linear operation is achieved by operating the photo device with a fixed voltage drop across it.&lt;br /&gt;
Trans-impedance amplifier is followed by an active fourth order band-pass filter (0.5Hz-5Hz): it's composed cascading two second order bandpass cells. In first project session only a single cell was used, but a deeper study combined with previous experiences suggests to use a 4th order filter to reduce 50Hz interference (50Hz interference produced by mains is placed only a decade after the filter pole).&lt;br /&gt;
Filter is followed by a VGA (Variable Gain Amplifier) digitally controlled through I2C Bus that allows to optimize dinamically ADC input signal amplitude directly during acquisition session, obtaining the best performance from ADC.&lt;br /&gt;
The resulting circuit is quite compact (led drive, reflective sensor, trans-impedence amplifier, active filter and variable-gain amplifier), doesn't require much power and represents a good mix between analog and digital approach: analog front-end with acquisition and first conditioning, and at the chain-end a digital controlled amplifier to ensure flexibility.&lt;br /&gt;
&lt;br /&gt;
[[Image:WADBVPComparison.jpg]]&lt;br /&gt;
&lt;br /&gt;
'''GSR'''&lt;br /&gt;
&lt;br /&gt;
GSR will be acquired by a couple of electrodes forcing a low voltage and reading current through electrodes. First designs and implementations were based on literature study: best solution appears to put GSR electrodes on the gain arm of a non-inverting amplifier (see fig.) rather than using a Wheatstone bridge due to week signal produced by this solution.&lt;br /&gt;
Putting GSR electrodes on the gain arm produces a sort of gain modulation of the constant voltage applied between electrodes but doesn't solve problems in amplifier stage due to large range of skin resistance.&lt;br /&gt;
Problems in chosing correct amplification to overwork ADC full scale with a signal affected by little variation but huge possible range could be reduced usign a variable resistor on gain arm (for example a digital potentiometer controlled by the microcontroller), but cannot be completely removed. In addition little signals are easily deteriorated by noise.&lt;br /&gt;
Solution is provided considering a new point of view: measure of unknown skin resistence is extremely similar to measure unknown electrical impedence with an auto-range multimeter!&lt;br /&gt;
Solution consist in a digital Impedance Converter: AD5934 is a high precision impedance converter system which combines an on-board frequency generator with a 12-bit, 250 kSPS, analog-to-digital converter (ADC). The frequency generator allows an external complex impedance to be excited with a known frequency; the response signal from the impedance is sampled by the on-board ADC and a discrete Fourier transform (DFT) is processed by an on-board DSP engine. The DFT algorithm returns a real (R) and imaginary (I) data-word at each output frequency. This solution not only allows to measure impedence range from 100 Ohm to 10 MOhm, but in adition allow to investigate it across a wide range of frequency, producing a noise-free digital output.&lt;br /&gt;
The resulting circuit is extremely compact (converter chip, one setting resistor and bypass capacitors), provides a system accuracy of 0.5% and connects to microcontroller using I2C interface, ensuring an high flexibility and the possibility to modify acquisition settings after board production (through microcontroller firmware).&lt;br /&gt;
&lt;br /&gt;
[[Image:WADGSRComparison.jpg]]&lt;br /&gt;
&lt;br /&gt;
'''Temperature'''&lt;br /&gt;
&lt;br /&gt;
First idea was to acquire temperature by a NTC connected in a Wheatstone bridge. Trying to reduce noise, bridge was powered by an oscillator circuit with a frequency of some KHerz, to translate signal out of 1/f noise region. Bridge outputs were connected to an INA amplifier wich also implements signal filtering (see fig.).&lt;br /&gt;
Weak signal, noise and resolution required (0.1°C) put in crisis the system. In addition other unsolved problems were the optimization of thermal and mechanical contact between sensor and body and the sensor large thermic constant. Unstable thermic contact produces unreliable measures, whereas high sensor thermic constant hampers a fast sensor response (needed to detect short peak due to emotional reactions).&lt;br /&gt;
Possible solutions to problems of weak signal and noise arrive from digital integrated temperature sensor (for example LM35 or LM74), but these don't solve the problem of thermal contact and thermal constant. In addition none of the sensors take in consideration provides the required resolution.&lt;br /&gt;
High resolution required, noise immunity, fast response and thermal contact immunity problems had been solved using a digital optical infra red thermometer. The MLX90614 is an infra red thermometer for non contact temperature measurements based on a thermopile detector chip including signal conditioning in the same TO-39 package. Thanks to its low noise amplifier, 17-bit ADC and powerful DSP unit, a high accuracy and resolution of the thermometer is achieved.&lt;br /&gt;
The calculated object and ambient temperatures are available in RAM of MLX90614 with 0.02°C resolution: they are accessible by 2 wire serial SMBus compatible protocol. A special version for medical applications offers an accuracy of ±0.1ºC in a limited temperature range around the human body temperature.&lt;br /&gt;
Small size, no external component requirements and power saving mode allow us to obtain a perfect matching between required performances and space saving.&lt;br /&gt;
&lt;br /&gt;
[[Image:WADTemperatureComparison.jpg]]&lt;br /&gt;
&lt;br /&gt;
'''Accelerometer'''&lt;br /&gt;
&lt;br /&gt;
Head orientation and movements will be acquired by an accelerometer. First we think to utilize an ST Microelectronic LIS3L02AS4, due to the availability in the Lab of the evaluation board STEVAL-MKI001. It is a 3-axis ±2g/±6g linear accelerometer with 3 analog outputs, so it requires an external ADC to digitalize the three axis acceleration values. The conversion could be performed by a microcontroller with internal ADC.&lt;br /&gt;
A fast Internet research reveled this sensor is now obsolete and out of production. The choise had been to substitute the old chip with the new one: the LIS302DL (still produced by ST Microelectronic). It's a 3-axis, ± 2g/± 8g smart digital output accelerometer with I2C/SPI digital output interface and really small package. The device is capable of measuring accelerations with an output data rate of 100 Hz or 400 Hz and the self-test capability allows the user to check the functioning of the sensor in the final application.&lt;br /&gt;
In addition it may be configured to generate inertial wake-up/free-fall interrupt signals when a programmable acceleration threshold is crossed at least in one of the three axes. Thresholds and timing of interrupt generators are programmable by the end user on the fly.&lt;br /&gt;
This device, providing a digital output, doesn't need signals conversion, guaranteing better noise immunity; programmable interrupts and test interface allow greater fexibility in project. In addition wery small package, only one external resistor requirement (plus baypass capacitor) reduce significantly board space requirements.&lt;br /&gt;
&lt;br /&gt;
[[Image:WADAccelerometer.jpg]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
 NOTE:&lt;br /&gt;
 &lt;br /&gt;
 * In previous schematics, components phisical dimensions are not in scale.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== '''Microcontroller''' ===&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Foundamental requirements:&lt;br /&gt;
&lt;br /&gt;
- High speed to ensure high data output rate even in presence of a large number af sensing elemets;&lt;br /&gt;
&lt;br /&gt;
- Fast Internal ADC with multiple inputs;&lt;br /&gt;
&lt;br /&gt;
- (At Least) One I2C interface;&lt;br /&gt;
&lt;br /&gt;
- (At Least) One SPI interface;&lt;br /&gt;
&lt;br /&gt;
- (At Least) One UART interface;&lt;br /&gt;
&lt;br /&gt;
- Low-power consumption;&lt;br /&gt;
&lt;br /&gt;
- Power supply 3.3V;&lt;br /&gt;
&lt;br /&gt;
- Small package;&lt;br /&gt;
&lt;br /&gt;
In addition microcontroller was chosen between Microchip PIC family devices, due to positive previous experiences and availability of software and programmer in the Lab.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
PIC24HJ256GP206 is a 16 bit microcontroller capable of 40 MIPS speed. It provides 256KB of Flash memory, 16KB of Ram, a 10-bit 1.1Msps or 12-bit 500Ksps ADC, UART, SPI and I2C interface in a 64 pin TQFP package (10mmX10mm) powerd between 3.0V and 3.6V.&lt;br /&gt;
Power core is provided by an internal regulator reducing parts count on the board.&lt;br /&gt;
&lt;br /&gt;
The device is able to provide at the same time one I2C interface, two SPI interface and one UART interface: another UART port shares pins with an SPI port and a second I2C port shares pins with the second UART interface.&lt;br /&gt;
Findig a device that provides at the same time, on indipendent pins, an I2C, a SPI and an UART interface reduces considerably possible choises and suggests to chose a high performance microcontroller.&lt;br /&gt;
At the same time, high performance solutions have a larger pin counts than standard microcontroller, but this characteristic can be used to ensure further expansibility to the system. The second SPI interface can be used to connect another &amp;quot;intelligent&amp;quot; device or a mass storage device, for example a SD (Secure Digital) card to storage acquired data (see fig.).&lt;br /&gt;
&lt;br /&gt;
[[Image:WADSDCard.jpg]]&lt;br /&gt;
&lt;br /&gt;
Input pins connected to ADC and not used at the moment could be collected to a connector for further extension modules (for example an EMG or ECG peripheral or any other analog signal interesting in a particolar application).&lt;br /&gt;
For the same reason any other pin non used at the current stage is reported to an extension connector.&lt;br /&gt;
To guarante maximum flexibility an further update, board provides both ICD and JTAG connections (allowing on-board programming and debugging) through a couple of indipendent dedicated connectors fully compatibles with Microchip programmers and evaluation boards.&lt;br /&gt;
&lt;br /&gt;
[[Image:WADMicro.jpg]]&lt;br /&gt;
&lt;br /&gt;
=== '''Wireless Connection''' ===&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Wireless connection is based on BlueGiga WT12 module: it's a next-generation, class 2, Bluetooth 2.0+EDR (Enhanced Data Rates) module containing all the necessary elements from Bluetooth radio to antenna and a fully implemented protocol stack.&lt;br /&gt;
By default WT12 module is equipped with powerful and easy-to-use iWRAP firmware that enables users to access Bluetooth functionality with simple ASCII commands delivered to the module over serial interface like a Bluetooth modem.&lt;br /&gt;
The dedicated onboard microcontroller (MCU) acts as interrupt controller and event timer run the Bluetooth software stack and control the radio and host interfaces. A 16-bit reduced instruction set computer (RISC) microcontroller is used for low power consumption and efficient use of memory.&lt;br /&gt;
WT12 module support USB, SPI and UART interface and UART interface is used in this project to connect PIC microcontroller to wireless transmitter (see fig.).&lt;br /&gt;
&lt;br /&gt;
[[Image:WADWireless.jpg]]&lt;br /&gt;
&lt;br /&gt;
One of the most important WT12 characteristic is the high integration between all parts needed for efficent Bluetooth transmission: user interface, controller, radio circuits and antenna, all included in a low power, low size board (25.6mmx15mm) that requires a minimum number of external components.&lt;br /&gt;
Many other bluetooth components ara available, such as LMX9830, produced by National Semiconductor. It's an extremely small device (only 6.1mm×9.1 mm), but requires a number of external components (see fig.) like oscillators, resistors, capacitors, inductors and the antenna, in addition to an high competence in radio frequency layout circuits.&lt;br /&gt;
&lt;br /&gt;
[[Image:WADLMX9830.jpg]]&lt;br /&gt;
&lt;br /&gt;
Lack of experience in radio frequency circuit suggests to chose a ready-to-use module, factory optimized for best performance and easy to integrate in our board.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
This is the updated simplified schematic block diagram:&lt;br /&gt;
&lt;br /&gt;
[[Image:WADSchematicDiagram02.jpg]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== '''Prototype realization [WIP (Work in Progress)]''' ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Fist stage plans to realize a board using, where possible, through-hole (TH) compenents soldered on a prototyping board (100x160mm) powered from a laboratory power supply (instead of Li-on battery) and not implementing bluetooth wireless transmission. Parts not available on TH package are used with special SMD-&amp;gt;TH adapter boards or simply fixing and soldering them to the PCB by wires.&lt;br /&gt;
&lt;br /&gt;
Second stage plans to realize microcontoller firmware and test it acquiring biological signals from a patient. Firmware will be developed by subsequently steps, implementing and testing only a single peripheral at each time: only at the end single pheripheral softwares will be merged together.&lt;br /&gt;
&lt;br /&gt;
Third stage will be bluetooth interface (hardware and software) implementation and integration on the board with transmission test.&lt;br /&gt;
&lt;br /&gt;
Fourth stage will consider power supply optimization with battery management and recharge interface.&lt;br /&gt;
&lt;br /&gt;
Finally, only after a successful full board test, the last stage will be the circuit layout design with an electronic CAD, using where possible, Surface Mount Devices (SMD) to reduce board area.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== '''Main board''' ===&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Main board include power supply regulator with led power-on indicator, PIC microcontroller (mounted on a SMD-&amp;gt;TH adapeter board) with basic circuitry (decoupling capacitors, oscillator and programming-debugging ICD interface), a status led connected to PIC to verify basic microcontroller function, a series of connectors for add-on modules (BVP, GSR, temperature and accelerometer) and a USB PC interface not considered before.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== '''USB interface''' ===&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
USB interface, not projected before, replaces in developing stage Bluetooth interface, allowing a direct control/communication with a PC. In this prototype PIC UART, althought being connected to Bluettoth module, is connected to a FTDI FT232RL chip. The FT232RL is the latest device to be added to FTDI’s range of USB UART interface Integrated Circuit Devices. USB to serial designs using the FT232RL have been further simplified by fully integrating the external EEPROM, clock circuit and USB resistors onto the device.&lt;br /&gt;
The FT232RL is available in Pb-free (RoHS compliant) compact 28-Lead SSOP, so this require another SMD-&amp;gt;TH board adapter but the circuit design is very simple, including two status led for TX and RX operations. An USB B female connector was eputated the best choise for PC connection allowing to use a simple USB printer cable.&lt;br /&gt;
&lt;br /&gt;
[[Image:WADUSBInterface.jpg]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Note that USB and Bluetooth must not be connected to the board at the same time! USB port has only a developent function.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== '''BVP''' ===&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Circuit designed for BVP acquisition (refer to previous schematic) doesn't meet the expected results. Week signal hanged by noise suggested us to re-design the circuit simplifying it and reducing the number of components. For this design also sensing element has been substitute. Instead of an integrated reflective IR sensor (SFH9202), new project use a couple af discrete IR led and photothansistor matched: SFH487 and SFH309FA.&lt;br /&gt;
SFH487 is a very highly efficient GaAlAs infrared emitter (880 nm) and SFH309FA is a silicon NPN phototransistor especially suitable for applications of 880 nm with an high linearity. Both have a 3 mm led plastic package, are spectrum-matched and receiver is ambient-light shilded. After a series of positive test without the led driver (not used due to the really reduced mechanical dimensions), also led drive circuit was removed and replaced with a resistance connected directly to a PIC pin.&lt;br /&gt;
This choise reduces parts count and board space required without making worse sistem performance, allowing (like led driver) to turn off the sensor led when not used to reduce power consumption.&lt;br /&gt;
&lt;br /&gt;
[[Image:WADBVPNew.jpg]]&lt;br /&gt;
&lt;br /&gt;
Even if operation amplifier used are half of before, double second-order filter stage is manteined. In addition to filtering, these opamp privide a first gain (note that in previous design filtering stages works as a unitary buffer in pass-band) allowing a high signal at VGA (variable gain amplifier) input stage allowing a better SNR.&lt;br /&gt;
1N4148 diode provides a sort of ofsetted virtual ground, shifting up all signals but not being amplified through the amplification chain.&lt;br /&gt;
Figure show the signal measured directly on filtering stage output (TS952 pin 7) before the VGA with a Tektronix scopemeter TDS2014B. No particular triks had been used: signal has been recorded the first time circuit was assembled on a protoboard.&lt;br /&gt;
&lt;br /&gt;
[[Image:WADBVPScope03.jpg]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== '''GSR''' ===&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
First approach with AD5934 resulted really hard due to some errors occurred in control software in relation with internal chip complexity and I2C bus protocol. &lt;br /&gt;
After a sart session with the AD5934, GSR hardware acquisition interface was further simplified replacing it with AD5933 (refer to schematic). AD5933 has the same pinout and functions of AD5934 but provides also an internal oscillator at 16.776MHz allowing no external crystal connection. A temperature sensor that allow the user to measure chip temperature and 1 MSPS Converter (instad of a 250KSPS one) are the only other differences between the tho integrated semiconductor produced by Analog Devices.&lt;br /&gt;
On the other hand AD5934 has a larger impedance measurement range that goes from 100 Ohm to 10 MOhm in opposition to AD5933 that can only measure impedences between 1 Ohm and 10 MOhm. Because of the high skin impedence values (in the range of MOhm for dry fingers skin), this is not a problem in our application.&lt;br /&gt;
&lt;br /&gt;
[[Image:WADGSRNew.jpg]]&lt;br /&gt;
&lt;br /&gt;
First dataset acquired whith the correct control software and the correct data reading routine, has shown all the potentiality of this chip, providing data comparables with RAW data acquired with a bigger and very expensive professional equipement produced by ProComp.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== '''ACCELERATION''' ===&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Lis302DL datasheet gives a short definition of this chip as &amp;quot;MEMS motion sensor 3-axis - ± 2g/± 8g smart digital output “piccolo” accelerometer&amp;quot; and it is really very, very small for human-working. For this space saving quality this accelerometer is also use in third generation Apple i-phone.&lt;br /&gt;
The major problem with this sensor had been to solder it to a sort of adapter to connect it to the circuit, but after that it works fine, with a good sensitivity and accuracy. Because of free fall and double click recognition at not required (at the moment) in this application, software routines for setting configuration registers and reading data resulted simplified.&lt;br /&gt;
A usefull caracteristic of this sensor, not previously noticed, is the presence of internal pull-up resistors that allows no necessity of external I2C bus pull-up resistors, reducing space occupation and components count.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== '''TEMPERATURE''' ===&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The choice to use MLX90614 due to his characteristics (non contact measure, 0.02°C resolution with accuracy of ±0.1°C for medical applications version) creates a really serious supplies problem: Melexis (sensor manufacture) wasn't able to give us a sample and no one in Italy can sell us only a pair of theese sensors to try them. A single piece was bought from Future Electronics, ordering it via web and paying it via credit card. Fortunately the sensor, that cames directly from USA, arrived in Italy few days later the payment in excellent conditions.&lt;br /&gt;
&lt;br /&gt;
[[Image:WADMLX90614.jpg]]&lt;br /&gt;
&lt;br /&gt;
Problems occurred interfacing this sensor on I2C bus with other devices (AD5933 and LIS302) connected. MLX90614 has a 2 wire serial SMBus compatible protocol: I2C bus and  SMBus are popular 2-wire buses that are essentially compatible with each other, but are not the same.&lt;br /&gt;
The buses operate at the same speed, up to 100kHz, but the I2C bus has both 400kHz and 2MHz versions. Complete compatibility between both buses is ensured only below 100kHz.&lt;br /&gt;
Timeout and (as a consequence of timeout) minimum clock speed are the most important differences between the I2C bus and the SMBus:&lt;br /&gt;
&lt;br /&gt;
I2C Bus = DC (no timeout)&lt;br /&gt;
&lt;br /&gt;
SMBus = 10kHz (35mS timeout)&lt;br /&gt;
&lt;br /&gt;
Despite differences in logic-level specifications between the two buses, generally devices can be mixed and matched with abandon.&lt;br /&gt;
Level Specifications for the I2C Bus and the SMBus are shown below (VDD is typically expected to be between 3 volts and 5 volts):&lt;br /&gt;
&lt;br /&gt;
[[Image:WADTable1.jpg]]&lt;br /&gt;
&lt;br /&gt;
What wasn't readily evident in the discussion of voltage levels is that these levels are also specified with different currents between the buses. The SMBus specifies a minimum sink current of 100microA, and a maximum of 350microA, compared to 3mA for the I2C bus. This in turn would determine the lowest acceptable value of the pullup resistor, examples of which are shown in the table below.&lt;br /&gt;
&lt;br /&gt;
[[Image:WADTable2.jpg]]&lt;br /&gt;
&lt;br /&gt;
In reality, it is not unusual to encounter pullup resistor values in SMBus systems, which violate this specification by being lower than recommended. A very popular range for pullup resistor values, even in some SMBus systems, seems to be 2.4k to 3.9k.&lt;br /&gt;
&lt;br /&gt;
These reasons, in adition to clear ideas about close developments, suggest a general review of schematic to re-distribute microcontroller resources.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== '''Part 6: final review [WIP (Work in Progress)]''' ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== '''Microcontroller''' ===&lt;br /&gt;
&lt;br /&gt;
Referring to previous schematic, some chenges had been applied:&lt;br /&gt;
&lt;br /&gt;
- Programmer/Debugger interface is now PGD1/EMUD1 and PGC1/EMUC1 instead of PGD1/EMUD2 and PGC1/EMUC2;&lt;br /&gt;
&lt;br /&gt;
- JTAG interface had been removed;&lt;br /&gt;
&lt;br /&gt;
- UART2 is no more available so UART1 has replaced UART2 as communication port;&lt;br /&gt;
&lt;br /&gt;
- SPI2 is no more available so SPI1 is now used to control both LMP8100 VGA (Variable Gain Amplifier) and SD Storage Card;&lt;br /&gt;
&lt;br /&gt;
- RG12, RG13, RG14 pins had been connected to three status led for a machine visual state detection;&lt;br /&gt;
&lt;br /&gt;
- I2C1 interface is now connected to accelerometer (LIS302) and GSR (AD5933) only;&lt;br /&gt;
&lt;br /&gt;
- I2C2 interface is dedicated to temperature sensor (MLX90614), enabling I/O pin thresholds compliant with SMBus specification;&lt;br /&gt;
&lt;br /&gt;
- Connectors for I2C, SMBus and SPI expansion modules had been added to the board;&lt;br /&gt;
&lt;br /&gt;
- Test point pads had been added to the board to simplify debugging.&lt;br /&gt;
&lt;br /&gt;
That's the complete microcontroller schematic diagram:&lt;br /&gt;
&lt;br /&gt;
[[Image:WAD_Micro_Final.jpg]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== '''Data link''' ===&lt;br /&gt;
&lt;br /&gt;
During developing stages, an USB port had replaced Bluetooth wireless transmission, allowing a direct control/communication with a PC. This interfaced, based on a FT232RL, prove to be very usefull and simple to use.&lt;br /&gt;
The choice to use an usb port to charge internal battery, in addition to availability of a UART multiplexer inside the Bluetooth module BlueGiga WT12, suggest to implement both USB and Bluetooth interface.&lt;br /&gt;
&lt;br /&gt;
That's the BlueGiga WT12 internal UART multiplexer schematic:&lt;br /&gt;
&lt;br /&gt;
[[Image:WAD_UARTMux.jpg]]&lt;br /&gt;
&lt;br /&gt;
The complete data link schematic diagram:&lt;br /&gt;
&lt;br /&gt;
[[Image:WAD_USB+Bluetooth_Final.jpg]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== '''Battery Charge, Monitor &amp;amp; Power On''' ===&lt;br /&gt;
&lt;br /&gt;
Device is powered by a single cell Li-on battery (3.7V, 1080mAh): this is the same unit used in IPod(TM) from Apple.&lt;br /&gt;
&lt;br /&gt;
[[Image:WAD_Battery.jpg]]&lt;br /&gt;
&lt;br /&gt;
Battery charge is executed by Maxim's MAX1811: it is a really compact single-cell lithium-ion (Li+) battery charger that can be powered directly from a USB port or from an external supply up to 6.5V. It has a 0.5% overall battery regulation voltage accuracy to allow maximum utilization of the battery capacity.&lt;br /&gt;
The charger uses an internal FET to deliver up to 500mA charging current to the battery. The device can be configured for either a 4.1V or 4.2V battery, using the SELV input. The SELI input sets the charge current to either 100mA or 500mA. An open-drain output indicates charge status.&lt;br /&gt;
MAX1811 has preconditioning that soft-starts a near-dead battery cell before charging. Other safety features include continuous monitoring of voltage and current and initial checking for fault conditions before charging.&lt;br /&gt;
&lt;br /&gt;
[[Image:WAD_Battery_Charge&amp;amp;PowerOn_Final.jpg]]&lt;br /&gt;
&lt;br /&gt;
White battery wire (see photo) is connected to internal NTC thermistor (10KOhm@+25°C). In this way it's posible to implement an over/under charge temperature detector using a couple af operational amplifier as comparator.&lt;br /&gt;
With the resistence network in schematic it had been possible to set an upper temperature threshold of 47.5°C (corresponding to 3.97K NTC value) and a down thresold of 2.5°C (corresponding to &lt;br /&gt;
28.7K NTC value). Out of this range comparators output go low disabling battery charger.&lt;br /&gt;
This function allows to prevent battery demage or explosion during charge.&lt;br /&gt;
&lt;br /&gt;
Power-up and shut-down are implemented using a Maxim's MAX16054 connected with an ADG801 by Analog Device.&lt;br /&gt;
MAX16054 is a pushbutton on/off controller with a single switch debouncer and built-in latch. It accepts a noisy input from a mechanical switch and produces a clean latched digital output after a factory-fixed qualification delay.&lt;br /&gt;
The state of the output changes only when triggered by the falling edge of the debounced switch input; the output remains unchanged on the rising edge of the input.An asynchronous CLEAR input allows an external signal to force the output flip-flop low.&lt;br /&gt;
1 MOhm resistor and 10 uF capacitor connected to power-on pushbutton  (in addition to internal 63KOhm pullup resistor) allow to obtain a delay of about 3 seconds.&lt;br /&gt;
&lt;br /&gt;
ADG801 is a monolithic CMOS, single-pole, single throw (SPST), normally open (NO) switch with on resistance of less than 0.4Ohm. This switch conducts equally well in both directions when on.&lt;br /&gt;
&lt;br /&gt;
Battery voltage monitor is hardware implemented by another Maxim's device: MAX8212.&lt;br /&gt;
MAX8212 is a CMOS micropower voltage detector that warn microprocessors/microcontroller of power failures. It contains a comparator, a 1.5V bandgap reference, and an open-drain n-channel output driver. Two external resistors are used in conjunction with the internal reference to set the trip voltage to the desired level. A hysteresis output is also included, allowing the user to apply positive feedback for noise-free output switching.&lt;br /&gt;
Using a couple of these device is possible to set two treshold: one for low battery and another for end battery detection. Low battery detection allow communicate the user battery level; end battery detection allow microprocessor shut down the device before battery voltage fall down under 3.4V that is the minimun input voltage allowed by linear regulator MCP1700.&lt;br /&gt;
If battery level fall down under 3.4V, MCP1700 is not able to guarantee line regulation. &lt;br /&gt;
&lt;br /&gt;
[[Image:WAD_Battery_Monitor_Final.jpg]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Students that have worked on the project==&lt;br /&gt;
&lt;br /&gt;
* Mattia Colombo (Blood Volume Pressure sensor)&lt;br /&gt;
* Alessia Cornaggia (Galvanic skin response sensor)&lt;br /&gt;
* Sala Mirko (Galvanic skin response sensor)&lt;br /&gt;
&lt;br /&gt;
== Laboratory work and risk analysis ==&lt;br /&gt;
&lt;br /&gt;
Laboratory work for this project will be mainly performed at AIRLab/Lambrate. It will include electrical and electronic activity. Potentially risky activities are the following:&lt;br /&gt;
* Use of mechanical tools. Standard safety measures described in [http://airlab.elet.polimi.it/index.php/airlab/content/download/461/4110/file/documento_valutazione_rischi_AIRLab.pdf Safety norms] will be followed.&lt;br /&gt;
* Use of soldering iron. Standard safety measures described in [http://airlab.elet.polimi.it/index.php/airlab/content/download/461/4110/file/documento_valutazione_rischi_AIRLab.pdf Safety norms] will be followed.&lt;br /&gt;
* Use of high-voltage circuits. Special gloves and a current limiter will be used. Standard safety measures described in [http://airlab.elet.polimi.it/index.php/airlab/content/download/461/4110/file/documento_valutazione_rischi_AIRLab.pdf Safety norms] will be followed.&lt;/div&gt;</summary>
		<author><name>PaoloVilla</name></author>	</entry>

	<entry>
		<id>https://airwiki.deib.polimi.it/index.php?title=File:WAD_Battery_Monitor_Final.jpg&amp;diff=9469</id>
		<title>File:WAD Battery Monitor Final.jpg</title>
		<link rel="alternate" type="text/html" href="https://airwiki.deib.polimi.it/index.php?title=File:WAD_Battery_Monitor_Final.jpg&amp;diff=9469"/>
				<updated>2009-11-26T13:53:58Z</updated>
		
		<summary type="html">&lt;p&gt;PaoloVilla: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>PaoloVilla</name></author>	</entry>

	<entry>
		<id>https://airwiki.deib.polimi.it/index.php?title=File:WAD_Battery_Charge%26PowerOn_Final.jpg&amp;diff=9468</id>
		<title>File:WAD Battery Charge&amp;PowerOn Final.jpg</title>
		<link rel="alternate" type="text/html" href="https://airwiki.deib.polimi.it/index.php?title=File:WAD_Battery_Charge%26PowerOn_Final.jpg&amp;diff=9468"/>
				<updated>2009-11-26T13:53:36Z</updated>
		
		<summary type="html">&lt;p&gt;PaoloVilla: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>PaoloVilla</name></author>	</entry>

	<entry>
		<id>https://airwiki.deib.polimi.it/index.php?title=Wireless_Affective_Devices&amp;diff=9467</id>
		<title>Wireless Affective Devices</title>
		<link rel="alternate" type="text/html" href="https://airwiki.deib.polimi.it/index.php?title=Wireless_Affective_Devices&amp;diff=9467"/>
				<updated>2009-11-26T13:52:35Z</updated>
		
		<summary type="html">&lt;p&gt;PaoloVilla: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{Project&lt;br /&gt;
|title=Wireless Affective Devices&lt;br /&gt;
|tutor=SimoneTognetti;MatteoMatteucci&lt;br /&gt;
|students=PaoloVilla&lt;br /&gt;
|resarea=BioSignal Analysis&lt;br /&gt;
|restopic=Affective Computing&lt;br /&gt;
|start=2008/01/08&lt;br /&gt;
|end=2009/12/30&lt;br /&gt;
|status=Active&lt;br /&gt;
|level=Ms&lt;br /&gt;
|type=Thesis&lt;br /&gt;
}}&lt;br /&gt;
==Project aims ==&lt;br /&gt;
&lt;br /&gt;
 ”''Everyone knows what an emotion is, until asked to give a definition''”&lt;br /&gt;
                                         &lt;br /&gt;
                                                                 Beverly Fehr and James Russell&lt;br /&gt;
&lt;br /&gt;
Research on Human-Computer-Interfaces has recently begun to take into account the affective state of the user. By appropriately reacting to the affective user state, interfaces could not only become more pleasant or entertaining, but also more effective or safer.&lt;br /&gt;
It is known that affective states have bodily correlates, and thus physiological signals could provide the necessary information for acquiring the affective user state. In contrast to other sources of information about the affective user state such as speech or facial expression, most physiological signals are not under voluntary control, and thus cannot be masked up to the same extent. Furthermore, it can be presumed that the signs of affective states in physiological signals are less dependent on individual and contextual factors: this is because the signals correspond to internal physiology, largely related to the autonomous nervous and limbic systems, rather than to external expressions that can be manipulated easily.&lt;br /&gt;
Recently, the issue of emotion regulation drew interests from several fields including neuroscience, psychology, education, computer science, etc. Possible applications are e-learningin, human computer interaction, development of communicative technologies for use by people with autism, car infotainment system, lie detection tests, cognitive workload, multimodal user interfaces MMUI (allow users to control computers using speech and gesture), etc.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The project is aimed at developing a device, connected to a PC, to acquire biological signals (such as GSR, BVP, Temperature and Head orientation) in a way that is less invasive for the subject. The term invasive is related to how much the sensors we use compromise the normal interaction between subject and machine.&lt;br /&gt;
Through these biological signal the PC is able o understand emotion in people who wear the device.&lt;br /&gt;
&lt;br /&gt;
An affective device should be weared easily, should not have cables and should acquire as much sensors as possible. We relax some constraint on the quality of signal but we add constraint on way they are acquired(i.e. the subject can put it on easily, the usual movements are not influenced..). The aim of the resulting device is not to replace the standard medical devices usually used to acquire that signals, but is to be much more suitable for industrial application in which the medical requirement are replaced by invasivity requirement.&lt;br /&gt;
&lt;br /&gt;
It is composed by:&lt;br /&gt;
&lt;br /&gt;
* Low power, high efficiency, battery powered design&lt;br /&gt;
* Wireless comunication with a PC&lt;br /&gt;
* Blood Volume Pressure Sensor (Preliminary release by Mattia Colombo)&lt;br /&gt;
* Galvanic Skin Response Sensor (Preliminary release by Sala Mirko e Alessia Cornaggia)&lt;br /&gt;
* Temperature Sensor&lt;br /&gt;
* 3 Way Accelerometer&lt;br /&gt;
* Possibility of further extension&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''GSR (or EDR or EDA)'''&lt;br /&gt;
&lt;br /&gt;
An often misunderstood and difficult technique, GSR (also known as the electrodermal response EDR or electrodermal activity EDA) has gone through many phases of interest and rejection since the early 1900's and is very popular in psychophysiological studies since Carl Jung and his students (1907) described it as a mean to&lt;br /&gt;
enter the “sea of the unconscious” because “every stimulus accompanied by an emotion produced a deviation of the galvanometer” directly proportional to the strength of the emotion aroused. It has been used in important research on anxiety and stress levels (Fenz &amp;amp; Epstein, ' 67); and it has been a part of lie detection (Raskin, ' 73). Controversy has centered around the technique, underlying mechanisms, and the meaning of the responses obtained from the skin. &lt;br /&gt;
There has been a long history of electrodermal activity research, even if most investigators accept the phenomenon without understanding exactly what it means (Hume, ' 76).&lt;br /&gt;
The resistance of the skin is usually large, approximately 1M; however, momentary changes in the level of the sweat gland activity causes changes in resistance (up to approximately 950K).&lt;br /&gt;
Physiology, the GSR reflescts sweat gland activity and changes in the sympathetic nervous system and measurement variables. The activity of the sweat glands in response to sympathetic nervous stimulation ( Increased sympathetic activation ) results in an increase in the level of conductance. There ia a relationship between sympathetic activity and emotional arousal, although one cannot identify the specific emotion being elicited. &lt;br /&gt;
Basically there are two techniques in the history of Electrodermal measurement. In one a current is passed thru the skin and the the resistance to passage is measured; in the other no current is used externally and the skin itself is the source of electrical activity.&lt;br /&gt;
By applying a conventional 0.5 Volts across the skin and measuring changes in the&lt;br /&gt;
corresponding conductance, the emotional state of the subject can be inferred. In general, the electrodes used are of the Ag/AgCl type which are recessed from the skin and require the use of a suitable electrode paste.&lt;br /&gt;
It is important to note, however, that fluctuations in skin conductivity are resultant of many types of arousal.&lt;br /&gt;
By observing only these changes, it is impossible to deduce without prior knowledge whether&lt;br /&gt;
the subject has become happy, startled, physically active, etcetera.&lt;br /&gt;
EDA consists of two components: tonic and phasic. The tonic component is a low&lt;br /&gt;
frequency baseline conductivity level, which can oscillate over the course of days. The phasic&lt;br /&gt;
component rides on top of the tonic component, exhibits more rapid fluctuations, and&lt;br /&gt;
generally increases when a person is aroused. Problematically, each person has a different&lt;br /&gt;
tonic conductivity, so in order to infer the arousal level of the subject, the relative changes in&lt;br /&gt;
EDA must be analyzed over a period of time. Furthermore, skin conductance (measured in&lt;br /&gt;
units of siemens; formerly mhos) depends on the skin path length between the two electrodes&lt;br /&gt;
contacts, even for subjects with identical skin conductivity (measured in units of&lt;br /&gt;
siemens/meter). It is for these reasons that it is crucial to analyze the temporal variations of&lt;br /&gt;
the EDA signal.&lt;br /&gt;
&lt;br /&gt;
'''BVP'''&lt;br /&gt;
&lt;br /&gt;
The cardiovascular system is in charge to keep us alive by maintaining the vital blood flow throughout the body, providing nutrients and oxygen to our cells. The SNS controls this system&lt;br /&gt;
by shifting the flow in response to exercise, temperature,postural and emotional changes.&lt;br /&gt;
Blood Volume Pulse (BVP) is the most common measure of vasomotor activity because it reflects the phasic pumping of the heart, the vasodilation of vessels that changes in the amount of acral blood delivered.&lt;br /&gt;
The Blood Volume Pulse (BVP) waveform is an important indicator of circulatory function that can be obtained noninvasively through a photoplethysmographic transducer (a PPG is often obtained by using a pulse oximeter, Shelley and Shelley, 2001) applied to the finger or the earlobe of human subjects. In particular, this signal may be useful in determining the degree of cardiovascular change undergone by a subject through an exercise session. &lt;br /&gt;
&lt;br /&gt;
''Principles of photoplethysmographic Technology:''&lt;br /&gt;
&lt;br /&gt;
The principle of photoplethysmographic (That is the same of pulse oximetry) is based on the red and infrared light absorption characteristics of oxygenated and deoxygenated hemoglobin. Oxygenated hemoglobin absorbs more infrared light and allows more red light to pass through. Deoxygenated (or reduced) hemoglobin absorbs more red light and allows more infrared light to pass through. Red light is in the 600-750 nm wavelength light band.&lt;br /&gt;
Pulse oximetry uses a light emitter with red and infrared LEDs that shines through a reasonably translucent site with good blood flow. Opposite the emitter is a photodetector that receives the light that passes through the measuring site.&lt;br /&gt;
There are two methods of sending light through the measuring site: transmission and reflectance. In the transmission the emitter and photodetector are opposite of each other with the measuring site in-between. The light can then pass through the site. In the reflectance method, the emitter and photodetector are next to each other on top the measuring site. The light bounces from the emitter to the detector across the site. The transmission method is the most common type used.&lt;br /&gt;
While pulse oximeters are a commonly used medical device the PPG derived from them is rarely displayed, and is nominally only processed to determine heart rate. &lt;br /&gt;
&lt;br /&gt;
'''Temperature'''&lt;br /&gt;
&lt;br /&gt;
The temperatures of peripheral limbs vary as a consequence of changes in blood flow.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== '''Previous work''' ==&lt;br /&gt;
&lt;br /&gt;
Here is a preliminary release of the headset produced before 2008/08/08&lt;br /&gt;
&lt;br /&gt;
[[Image:Wd1.jpg]]&lt;br /&gt;
&lt;br /&gt;
If you are interested on the making of the headset please see [[making rubber models]]&lt;br /&gt;
&lt;br /&gt;
'''* Blood Volume pressure'''&lt;br /&gt;
First graph showing a signal acquired with the wireless sensor. &lt;br /&gt;
[[Image:Bvp.png]]&lt;br /&gt;
&lt;br /&gt;
'''* Skin galvanic response''' (Sala Mirko e Alessia Cornaggia[http://airwiki.elet.polimi.it/mediawiki/index.php/User:AlessiaCornaggia])&lt;br /&gt;
Galvanic skin response (GSR), also known as electrodermal response (EDR), psychogalvanic reflex (PGR), or skin conductance response (SCR), is a method of measuring the electrical resistance of the skin.  There is a relationship between sympathetic activity and emotional arousal, although one cannot identify the specific emotion being elicited. The GSR is highly sensitive to emotions in some people. Fear, anger, startle response, orienting response and sexual feelings are all among the emotions which may produce similar GSR responses.&lt;br /&gt;
Response of the skin to the passage of a small electric current. The ease with which the current flows between two points on the skin can be used to indicate stress. When a person is tense or emotional, the sweat glands become more active, increasing moisture on the skin; this allows the electric current to flow more readily. &lt;br /&gt;
The response may also be used in relaxation training: information about the galvanic skin response is fed back aurally or visually to the subject who can, with practice, learn to increase or decrease sweating on the skin by learning to relax or tense muscles.&lt;br /&gt;
We measure the galvanic skin response using two electrodes attached to the skin. The optimal placement is the palm of the hands, but we are experimenting other places like on the forehead.&lt;br /&gt;
The circuit we are creating is the one below.&lt;br /&gt;
&lt;br /&gt;
[[Image:circuito.jpg]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== '''Project the device''' ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== '''Re-definition of the complete work''' ===&lt;br /&gt;
&lt;br /&gt;
Sensors are an important part of an Affective Computing System because they provide information about the wearer's physical state or behavior. They can gather data in a continuous way without having to interrupt the user. &lt;br /&gt;
To define in detail electronic specifications and requirements it's necessary a preliminary research/study (in literature and web) about state of art of sensor type used to monitor each type of biological signals we are interested about.&lt;br /&gt;
In this way it's possible both understand problematics related to interaction between biological and electonical worlds and improve or re-desig existing prototype.&lt;br /&gt;
&lt;br /&gt;
About Sensors: &lt;br /&gt;
&lt;br /&gt;
BVP will be acquire by an IR transmitter-receiver measuring light reflected from skin (photoplethysmography). Particular attention will be put on position, geometry and power absorption of this stage. &lt;br /&gt;
&lt;br /&gt;
GSR will be acquiret by a couple of electrodes forcing a low current (or voltage) and reading voltage (or current) through electrodes. Particular attention will be put on electrodes position and material. In addition is possible to foresee some problems in amplifier stage due to large range of skin resistance. Problem consist in chosing a correct amplification to overwork ADC full scale with a signal affected by little variation but huge possible range. &lt;br /&gt;
&lt;br /&gt;
Temperature will be acquired by thermocouple or PTC/NTC. Slowly variable signal, possible problems with noise due to resolution required. &lt;br /&gt;
&lt;br /&gt;
Head orientation will be acquired by an accelerometer and a gyroscope, problably integrated in the same chip. Two possibilities: analog output (need to digitalize up to six line) or digital output (like displaied in schematic block diagram). &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
This was the preliminary simplified schematic block diagram of the complete instrumentation setup:&lt;br /&gt;
&lt;br /&gt;
[[Image:WADSchematicDiagram01.jpg]]&lt;br /&gt;
&lt;br /&gt;
 NOTE:&lt;br /&gt;
 &lt;br /&gt;
 * In schematic is not present Power Supply Module: it will be based on a rechargeable Li-ion&lt;br /&gt;
 battery. It must satisfy requirements of high efficiency, logn life and low weight.&lt;br /&gt;
 &lt;br /&gt;
 * ADC and Microcontroller could be unified using a microcontroller with internal ADC and&lt;br /&gt;
 internal or external multiplexer to select lines.&lt;br /&gt;
 &lt;br /&gt;
 * Wireless section could be implemeted in Bluetooth (instead of using a XBee module like in&lt;br /&gt;
 preliminary release) due to it's diffusion in cellular phones, notebooks, MP3 reader...&lt;br /&gt;
 without necessity of external modules.&lt;br /&gt;
&lt;br /&gt;
It was based on a theoretical approach to any single part. Any sensing device was designed in &amp;quot;conventional&amp;quot; way founded on analog electronic (a bridge with a NTC resisistance as sensing element, discrete IR led and some photodiode around to capture the most reflefted light as possible, GSR electrodes on the gain arm of a non-inverting amplifier...).&lt;br /&gt;
Unfortunatly a deep analysis on signal physiology, signal transduction, noise vs required accurancy, forced us to a completely different approach implementing everywhere possible a digital interface.&lt;br /&gt;
&lt;br /&gt;
=== '''Sensors Design''' ===&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''BVP'''&lt;br /&gt;
&lt;br /&gt;
Discrete IR leds and phototransistor, used in the first realize (see fig.), had been replaced first with a single led and one or more photodiodes to optimize power consumption in case of non-planar sensor positioning. Subsequently an integrated Reflective Object Sensor was introduced, with benefits about space saving, transmitter-receiver matching and power consumption.&lt;br /&gt;
To ensure light power stability, led is powered through a linear led drive LDO (Low Drop-Out). The choise of linear LDO is necessary to ensure no noise or spikes would be generated by charge pump systems or boost converters. In addition, the linear drive utilized requires only one external resitor to set led current and a decoupling capacitor, reducing part counts and board space occupation.&lt;br /&gt;
The couple factor of the reflex sensors is relatively small, even in the case of good reflecting surfaces. Therefore an additional amplifier is necessary at the sensor output: classic trans-impedance amplifier used with photo-diodes and photo-transistors was introduced. This circuit features an output voltage that is a linear function of the light level on the photo-transistor. The gain is set by the feedback resistor which could be in the millions of ohms. Linear operation is achieved by operating the photo device with a fixed voltage drop across it.&lt;br /&gt;
Trans-impedance amplifier is followed by an active fourth order band-pass filter (0.5Hz-5Hz): it's composed cascading two second order bandpass cells. In first project session only a single cell was used, but a deeper study combined with previous experiences suggests to use a 4th order filter to reduce 50Hz interference (50Hz interference produced by mains is placed only a decade after the filter pole).&lt;br /&gt;
Filter is followed by a VGA (Variable Gain Amplifier) digitally controlled through I2C Bus that allows to optimize dinamically ADC input signal amplitude directly during acquisition session, obtaining the best performance from ADC.&lt;br /&gt;
The resulting circuit is quite compact (led drive, reflective sensor, trans-impedence amplifier, active filter and variable-gain amplifier), doesn't require much power and represents a good mix between analog and digital approach: analog front-end with acquisition and first conditioning, and at the chain-end a digital controlled amplifier to ensure flexibility.&lt;br /&gt;
&lt;br /&gt;
[[Image:WADBVPComparison.jpg]]&lt;br /&gt;
&lt;br /&gt;
'''GSR'''&lt;br /&gt;
&lt;br /&gt;
GSR will be acquired by a couple of electrodes forcing a low voltage and reading current through electrodes. First designs and implementations were based on literature study: best solution appears to put GSR electrodes on the gain arm of a non-inverting amplifier (see fig.) rather than using a Wheatstone bridge due to week signal produced by this solution.&lt;br /&gt;
Putting GSR electrodes on the gain arm produces a sort of gain modulation of the constant voltage applied between electrodes but doesn't solve problems in amplifier stage due to large range of skin resistance.&lt;br /&gt;
Problems in chosing correct amplification to overwork ADC full scale with a signal affected by little variation but huge possible range could be reduced usign a variable resistor on gain arm (for example a digital potentiometer controlled by the microcontroller), but cannot be completely removed. In addition little signals are easily deteriorated by noise.&lt;br /&gt;
Solution is provided considering a new point of view: measure of unknown skin resistence is extremely similar to measure unknown electrical impedence with an auto-range multimeter!&lt;br /&gt;
Solution consist in a digital Impedance Converter: AD5934 is a high precision impedance converter system which combines an on-board frequency generator with a 12-bit, 250 kSPS, analog-to-digital converter (ADC). The frequency generator allows an external complex impedance to be excited with a known frequency; the response signal from the impedance is sampled by the on-board ADC and a discrete Fourier transform (DFT) is processed by an on-board DSP engine. The DFT algorithm returns a real (R) and imaginary (I) data-word at each output frequency. This solution not only allows to measure impedence range from 100 Ohm to 10 MOhm, but in adition allow to investigate it across a wide range of frequency, producing a noise-free digital output.&lt;br /&gt;
The resulting circuit is extremely compact (converter chip, one setting resistor and bypass capacitors), provides a system accuracy of 0.5% and connects to microcontroller using I2C interface, ensuring an high flexibility and the possibility to modify acquisition settings after board production (through microcontroller firmware).&lt;br /&gt;
&lt;br /&gt;
[[Image:WADGSRComparison.jpg]]&lt;br /&gt;
&lt;br /&gt;
'''Temperature'''&lt;br /&gt;
&lt;br /&gt;
First idea was to acquire temperature by a NTC connected in a Wheatstone bridge. Trying to reduce noise, bridge was powered by an oscillator circuit with a frequency of some KHerz, to translate signal out of 1/f noise region. Bridge outputs were connected to an INA amplifier wich also implements signal filtering (see fig.).&lt;br /&gt;
Weak signal, noise and resolution required (0.1°C) put in crisis the system. In addition other unsolved problems were the optimization of thermal and mechanical contact between sensor and body and the sensor large thermic constant. Unstable thermic contact produces unreliable measures, whereas high sensor thermic constant hampers a fast sensor response (needed to detect short peak due to emotional reactions).&lt;br /&gt;
Possible solutions to problems of weak signal and noise arrive from digital integrated temperature sensor (for example LM35 or LM74), but these don't solve the problem of thermal contact and thermal constant. In addition none of the sensors take in consideration provides the required resolution.&lt;br /&gt;
High resolution required, noise immunity, fast response and thermal contact immunity problems had been solved using a digital optical infra red thermometer. The MLX90614 is an infra red thermometer for non contact temperature measurements based on a thermopile detector chip including signal conditioning in the same TO-39 package. Thanks to its low noise amplifier, 17-bit ADC and powerful DSP unit, a high accuracy and resolution of the thermometer is achieved.&lt;br /&gt;
The calculated object and ambient temperatures are available in RAM of MLX90614 with 0.02°C resolution: they are accessible by 2 wire serial SMBus compatible protocol. A special version for medical applications offers an accuracy of ±0.1ºC in a limited temperature range around the human body temperature.&lt;br /&gt;
Small size, no external component requirements and power saving mode allow us to obtain a perfect matching between required performances and space saving.&lt;br /&gt;
&lt;br /&gt;
[[Image:WADTemperatureComparison.jpg]]&lt;br /&gt;
&lt;br /&gt;
'''Accelerometer'''&lt;br /&gt;
&lt;br /&gt;
Head orientation and movements will be acquired by an accelerometer. First we think to utilize an ST Microelectronic LIS3L02AS4, due to the availability in the Lab of the evaluation board STEVAL-MKI001. It is a 3-axis ±2g/±6g linear accelerometer with 3 analog outputs, so it requires an external ADC to digitalize the three axis acceleration values. The conversion could be performed by a microcontroller with internal ADC.&lt;br /&gt;
A fast Internet research reveled this sensor is now obsolete and out of production. The choise had been to substitute the old chip with the new one: the LIS302DL (still produced by ST Microelectronic). It's a 3-axis, ± 2g/± 8g smart digital output accelerometer with I2C/SPI digital output interface and really small package. The device is capable of measuring accelerations with an output data rate of 100 Hz or 400 Hz and the self-test capability allows the user to check the functioning of the sensor in the final application.&lt;br /&gt;
In addition it may be configured to generate inertial wake-up/free-fall interrupt signals when a programmable acceleration threshold is crossed at least in one of the three axes. Thresholds and timing of interrupt generators are programmable by the end user on the fly.&lt;br /&gt;
This device, providing a digital output, doesn't need signals conversion, guaranteing better noise immunity; programmable interrupts and test interface allow greater fexibility in project. In addition wery small package, only one external resistor requirement (plus baypass capacitor) reduce significantly board space requirements.&lt;br /&gt;
&lt;br /&gt;
[[Image:WADAccelerometer.jpg]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
 NOTE:&lt;br /&gt;
 &lt;br /&gt;
 * In previous schematics, components phisical dimensions are not in scale.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== '''Microcontroller''' ===&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Foundamental requirements:&lt;br /&gt;
&lt;br /&gt;
- High speed to ensure high data output rate even in presence of a large number af sensing elemets;&lt;br /&gt;
&lt;br /&gt;
- Fast Internal ADC with multiple inputs;&lt;br /&gt;
&lt;br /&gt;
- (At Least) One I2C interface;&lt;br /&gt;
&lt;br /&gt;
- (At Least) One SPI interface;&lt;br /&gt;
&lt;br /&gt;
- (At Least) One UART interface;&lt;br /&gt;
&lt;br /&gt;
- Low-power consumption;&lt;br /&gt;
&lt;br /&gt;
- Power supply 3.3V;&lt;br /&gt;
&lt;br /&gt;
- Small package;&lt;br /&gt;
&lt;br /&gt;
In addition microcontroller was chosen between Microchip PIC family devices, due to positive previous experiences and availability of software and programmer in the Lab.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
PIC24HJ256GP206 is a 16 bit microcontroller capable of 40 MIPS speed. It provides 256KB of Flash memory, 16KB of Ram, a 10-bit 1.1Msps or 12-bit 500Ksps ADC, UART, SPI and I2C interface in a 64 pin TQFP package (10mmX10mm) powerd between 3.0V and 3.6V.&lt;br /&gt;
Power core is provided by an internal regulator reducing parts count on the board.&lt;br /&gt;
&lt;br /&gt;
The device is able to provide at the same time one I2C interface, two SPI interface and one UART interface: another UART port shares pins with an SPI port and a second I2C port shares pins with the second UART interface.&lt;br /&gt;
Findig a device that provides at the same time, on indipendent pins, an I2C, a SPI and an UART interface reduces considerably possible choises and suggests to chose a high performance microcontroller.&lt;br /&gt;
At the same time, high performance solutions have a larger pin counts than standard microcontroller, but this characteristic can be used to ensure further expansibility to the system. The second SPI interface can be used to connect another &amp;quot;intelligent&amp;quot; device or a mass storage device, for example a SD (Secure Digital) card to storage acquired data (see fig.).&lt;br /&gt;
&lt;br /&gt;
[[Image:WADSDCard.jpg]]&lt;br /&gt;
&lt;br /&gt;
Input pins connected to ADC and not used at the moment could be collected to a connector for further extension modules (for example an EMG or ECG peripheral or any other analog signal interesting in a particolar application).&lt;br /&gt;
For the same reason any other pin non used at the current stage is reported to an extension connector.&lt;br /&gt;
To guarante maximum flexibility an further update, board provides both ICD and JTAG connections (allowing on-board programming and debugging) through a couple of indipendent dedicated connectors fully compatibles with Microchip programmers and evaluation boards.&lt;br /&gt;
&lt;br /&gt;
[[Image:WADMicro.jpg]]&lt;br /&gt;
&lt;br /&gt;
=== '''Wireless Connection''' ===&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Wireless connection is based on BlueGiga WT12 module: it's a next-generation, class 2, Bluetooth 2.0+EDR (Enhanced Data Rates) module containing all the necessary elements from Bluetooth radio to antenna and a fully implemented protocol stack.&lt;br /&gt;
By default WT12 module is equipped with powerful and easy-to-use iWRAP firmware that enables users to access Bluetooth functionality with simple ASCII commands delivered to the module over serial interface like a Bluetooth modem.&lt;br /&gt;
The dedicated onboard microcontroller (MCU) acts as interrupt controller and event timer run the Bluetooth software stack and control the radio and host interfaces. A 16-bit reduced instruction set computer (RISC) microcontroller is used for low power consumption and efficient use of memory.&lt;br /&gt;
WT12 module support USB, SPI and UART interface and UART interface is used in this project to connect PIC microcontroller to wireless transmitter (see fig.).&lt;br /&gt;
&lt;br /&gt;
[[Image:WADWireless.jpg]]&lt;br /&gt;
&lt;br /&gt;
One of the most important WT12 characteristic is the high integration between all parts needed for efficent Bluetooth transmission: user interface, controller, radio circuits and antenna, all included in a low power, low size board (25.6mmx15mm) that requires a minimum number of external components.&lt;br /&gt;
Many other bluetooth components ara available, such as LMX9830, produced by National Semiconductor. It's an extremely small device (only 6.1mm×9.1 mm), but requires a number of external components (see fig.) like oscillators, resistors, capacitors, inductors and the antenna, in addition to an high competence in radio frequency layout circuits.&lt;br /&gt;
&lt;br /&gt;
[[Image:WADLMX9830.jpg]]&lt;br /&gt;
&lt;br /&gt;
Lack of experience in radio frequency circuit suggests to chose a ready-to-use module, factory optimized for best performance and easy to integrate in our board.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
This is the updated simplified schematic block diagram:&lt;br /&gt;
&lt;br /&gt;
[[Image:WADSchematicDiagram02.jpg]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== '''Prototype realization [WIP (Work in Progress)]''' ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Fist stage plans to realize a board using, where possible, through-hole (TH) compenents soldered on a prototyping board (100x160mm) powered from a laboratory power supply (instead of Li-on battery) and not implementing bluetooth wireless transmission. Parts not available on TH package are used with special SMD-&amp;gt;TH adapter boards or simply fixing and soldering them to the PCB by wires.&lt;br /&gt;
&lt;br /&gt;
Second stage plans to realize microcontoller firmware and test it acquiring biological signals from a patient. Firmware will be developed by subsequently steps, implementing and testing only a single peripheral at each time: only at the end single pheripheral softwares will be merged together.&lt;br /&gt;
&lt;br /&gt;
Third stage will be bluetooth interface (hardware and software) implementation and integration on the board with transmission test.&lt;br /&gt;
&lt;br /&gt;
Fourth stage will consider power supply optimization with battery management and recharge interface.&lt;br /&gt;
&lt;br /&gt;
Finally, only after a successful full board test, the last stage will be the circuit layout design with an electronic CAD, using where possible, Surface Mount Devices (SMD) to reduce board area.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== '''Main board''' ===&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Main board include power supply regulator with led power-on indicator, PIC microcontroller (mounted on a SMD-&amp;gt;TH adapeter board) with basic circuitry (decoupling capacitors, oscillator and programming-debugging ICD interface), a status led connected to PIC to verify basic microcontroller function, a series of connectors for add-on modules (BVP, GSR, temperature and accelerometer) and a USB PC interface not considered before.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== '''USB interface''' ===&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
USB interface, not projected before, replaces in developing stage Bluetooth interface, allowing a direct control/communication with a PC. In this prototype PIC UART, althought being connected to Bluettoth module, is connected to a FTDI FT232RL chip. The FT232RL is the latest device to be added to FTDI’s range of USB UART interface Integrated Circuit Devices. USB to serial designs using the FT232RL have been further simplified by fully integrating the external EEPROM, clock circuit and USB resistors onto the device.&lt;br /&gt;
The FT232RL is available in Pb-free (RoHS compliant) compact 28-Lead SSOP, so this require another SMD-&amp;gt;TH board adapter but the circuit design is very simple, including two status led for TX and RX operations. An USB B female connector was eputated the best choise for PC connection allowing to use a simple USB printer cable.&lt;br /&gt;
&lt;br /&gt;
[[Image:WADUSBInterface.jpg]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Note that USB and Bluetooth must not be connected to the board at the same time! USB port has only a developent function.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== '''BVP''' ===&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Circuit designed for BVP acquisition (refer to previous schematic) doesn't meet the expected results. Week signal hanged by noise suggested us to re-design the circuit simplifying it and reducing the number of components. For this design also sensing element has been substitute. Instead of an integrated reflective IR sensor (SFH9202), new project use a couple af discrete IR led and photothansistor matched: SFH487 and SFH309FA.&lt;br /&gt;
SFH487 is a very highly efficient GaAlAs infrared emitter (880 nm) and SFH309FA is a silicon NPN phototransistor especially suitable for applications of 880 nm with an high linearity. Both have a 3 mm led plastic package, are spectrum-matched and receiver is ambient-light shilded. After a series of positive test without the led driver (not used due to the really reduced mechanical dimensions), also led drive circuit was removed and replaced with a resistance connected directly to a PIC pin.&lt;br /&gt;
This choise reduces parts count and board space required without making worse sistem performance, allowing (like led driver) to turn off the sensor led when not used to reduce power consumption.&lt;br /&gt;
&lt;br /&gt;
[[Image:WADBVPNew.jpg]]&lt;br /&gt;
&lt;br /&gt;
Even if operation amplifier used are half of before, double second-order filter stage is manteined. In addition to filtering, these opamp privide a first gain (note that in previous design filtering stages works as a unitary buffer in pass-band) allowing a high signal at VGA (variable gain amplifier) input stage allowing a better SNR.&lt;br /&gt;
1N4148 diode provides a sort of ofsetted virtual ground, shifting up all signals but not being amplified through the amplification chain.&lt;br /&gt;
Figure show the signal measured directly on filtering stage output (TS952 pin 7) before the VGA with a Tektronix scopemeter TDS2014B. No particular triks had been used: signal has been recorded the first time circuit was assembled on a protoboard.&lt;br /&gt;
&lt;br /&gt;
[[Image:WADBVPScope03.jpg]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== '''GSR''' ===&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
First approach with AD5934 resulted really hard due to some errors occurred in control software in relation with internal chip complexity and I2C bus protocol. &lt;br /&gt;
After a sart session with the AD5934, GSR hardware acquisition interface was further simplified replacing it with AD5933 (refer to schematic). AD5933 has the same pinout and functions of AD5934 but provides also an internal oscillator at 16.776MHz allowing no external crystal connection. A temperature sensor that allow the user to measure chip temperature and 1 MSPS Converter (instad of a 250KSPS one) are the only other differences between the tho integrated semiconductor produced by Analog Devices.&lt;br /&gt;
On the other hand AD5934 has a larger impedance measurement range that goes from 100 Ohm to 10 MOhm in opposition to AD5933 that can only measure impedences between 1 Ohm and 10 MOhm. Because of the high skin impedence values (in the range of MOhm for dry fingers skin), this is not a problem in our application.&lt;br /&gt;
&lt;br /&gt;
[[Image:WADGSRNew.jpg]]&lt;br /&gt;
&lt;br /&gt;
First dataset acquired whith the correct control software and the correct data reading routine, has shown all the potentiality of this chip, providing data comparables with RAW data acquired with a bigger and very expensive professional equipement produced by ProComp.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== '''ACCELERATION''' ===&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Lis302DL datasheet gives a short definition of this chip as &amp;quot;MEMS motion sensor 3-axis - ± 2g/± 8g smart digital output “piccolo” accelerometer&amp;quot; and it is really very, very small for human-working. For this space saving quality this accelerometer is also use in third generation Apple i-phone.&lt;br /&gt;
The major problem with this sensor had been to solder it to a sort of adapter to connect it to the circuit, but after that it works fine, with a good sensitivity and accuracy. Because of free fall and double click recognition at not required (at the moment) in this application, software routines for setting configuration registers and reading data resulted simplified.&lt;br /&gt;
A usefull caracteristic of this sensor, not previously noticed, is the presence of internal pull-up resistors that allows no necessity of external I2C bus pull-up resistors, reducing space occupation and components count.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== '''TEMPERATURE''' ===&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The choice to use MLX90614 due to his characteristics (non contact measure, 0.02°C resolution with accuracy of ±0.1°C for medical applications version) creates a really serious supplies problem: Melexis (sensor manufacture) wasn't able to give us a sample and no one in Italy can sell us only a pair of theese sensors to try them. A single piece was bought from Future Electronics, ordering it via web and paying it via credit card. Fortunately the sensor, that cames directly from USA, arrived in Italy few days later the payment in excellent conditions.&lt;br /&gt;
&lt;br /&gt;
[[Image:WADMLX90614.jpg]]&lt;br /&gt;
&lt;br /&gt;
Problems occurred interfacing this sensor on I2C bus with other devices (AD5933 and LIS302) connected. MLX90614 has a 2 wire serial SMBus compatible protocol: I2C bus and  SMBus are popular 2-wire buses that are essentially compatible with each other, but are not the same.&lt;br /&gt;
The buses operate at the same speed, up to 100kHz, but the I2C bus has both 400kHz and 2MHz versions. Complete compatibility between both buses is ensured only below 100kHz.&lt;br /&gt;
Timeout and (as a consequence of timeout) minimum clock speed are the most important differences between the I2C bus and the SMBus:&lt;br /&gt;
&lt;br /&gt;
I2C Bus = DC (no timeout)&lt;br /&gt;
&lt;br /&gt;
SMBus = 10kHz (35mS timeout)&lt;br /&gt;
&lt;br /&gt;
Despite differences in logic-level specifications between the two buses, generally devices can be mixed and matched with abandon.&lt;br /&gt;
Level Specifications for the I2C Bus and the SMBus are shown below (VDD is typically expected to be between 3 volts and 5 volts):&lt;br /&gt;
&lt;br /&gt;
[[Image:WADTable1.jpg]]&lt;br /&gt;
&lt;br /&gt;
What wasn't readily evident in the discussion of voltage levels is that these levels are also specified with different currents between the buses. The SMBus specifies a minimum sink current of 100microA, and a maximum of 350microA, compared to 3mA for the I2C bus. This in turn would determine the lowest acceptable value of the pullup resistor, examples of which are shown in the table below.&lt;br /&gt;
&lt;br /&gt;
[[Image:WADTable2.jpg]]&lt;br /&gt;
&lt;br /&gt;
In reality, it is not unusual to encounter pullup resistor values in SMBus systems, which violate this specification by being lower than recommended. A very popular range for pullup resistor values, even in some SMBus systems, seems to be 2.4k to 3.9k.&lt;br /&gt;
&lt;br /&gt;
These reasons, in adition to clear ideas about close developments, suggest a general review of schematic to re-distribute microcontroller resources.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== '''Part 6: final review [WIP (Work in Progress)]''' ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== '''Microcontroller''' ===&lt;br /&gt;
&lt;br /&gt;
Referring to previous schematic, some chenges had been applied:&lt;br /&gt;
&lt;br /&gt;
- Programmer/Debugger interface is now PGD1/EMUD1 and PGC1/EMUC1 instead of PGD1/EMUD2 and PGC1/EMUC2;&lt;br /&gt;
&lt;br /&gt;
- JTAG interface had been removed;&lt;br /&gt;
&lt;br /&gt;
- UART2 is no more available so UART1 has replaced UART2 as communication port;&lt;br /&gt;
&lt;br /&gt;
- SPI2 is no more available so SPI1 is now used to control both LMP8100 VGA (Variable Gain Amplifier) and SD Storage Card;&lt;br /&gt;
&lt;br /&gt;
- RG12, RG13, RG14 pins had been connected to three status led for a machine visual state detection;&lt;br /&gt;
&lt;br /&gt;
- I2C1 interface is now connected to accelerometer (LIS302) and GSR (AD5933) only;&lt;br /&gt;
&lt;br /&gt;
- I2C2 interface is dedicated to temperature sensor (MLX90614), enabling I/O pin thresholds compliant with SMBus specification;&lt;br /&gt;
&lt;br /&gt;
- Connectors for I2C, SMBus and SPI expansion modules had been added to the board;&lt;br /&gt;
&lt;br /&gt;
- Test point pads had been added to the board to simplify debugging.&lt;br /&gt;
&lt;br /&gt;
That's the complete microcontroller schematic diagram:&lt;br /&gt;
&lt;br /&gt;
[[Image:WAD_Micro_Final.jpg]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== '''Data link''' ===&lt;br /&gt;
&lt;br /&gt;
During developing stages, an USB port had replaced Bluetooth wireless transmission, allowing a direct control/communication with a PC. This interfaced, based on a FT232RL, prove to be very usefull and simple to use.&lt;br /&gt;
The choice to use an usb port to charge internal battery, in addition to availability of a UART multiplexer inside the Bluetooth module BlueGiga WT12, suggest to implement both USB and Bluetooth interface.&lt;br /&gt;
&lt;br /&gt;
That's the BlueGiga WT12 internal UART multiplexer schematic:&lt;br /&gt;
&lt;br /&gt;
[[Image:WAD_UARTMux.jpg]]&lt;br /&gt;
&lt;br /&gt;
The complete data link schematic diagram:&lt;br /&gt;
&lt;br /&gt;
[[Image:WAD_USB+Bluetooth_Final.jpg]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== '''Battery Charge, Monitor &amp;amp; Power On''' ===&lt;br /&gt;
&lt;br /&gt;
Device is powered by a single cell Li-on battery (3.7V, 1080mAh): this is the same unit used in IPod(TM) from Apple.&lt;br /&gt;
&lt;br /&gt;
[[Image:WAD_Battery.jpg]]&lt;br /&gt;
&lt;br /&gt;
Battery charge is executed by Maxim's MAX1811: it is a really compact single-cell lithium-ion (Li+) battery charger that can be powered directly from a USB port or from an external supply up to 6.5V. It has a 0.5% overall battery regulation voltage accuracy to allow maximum utilization of the battery capacity.&lt;br /&gt;
The charger uses an internal FET to deliver up to 500mA charging current to the battery. The device can be configured for either a 4.1V or 4.2V battery, using the SELV input. The SELI input sets the charge current to either 100mA or 500mA. An open-drain output indicates charge status.&lt;br /&gt;
MAX1811 has preconditioning that soft-starts a near-dead battery cell before charging. Other safety features include continuous monitoring of voltage and current and initial checking for fault conditions before charging.&lt;br /&gt;
&lt;br /&gt;
[[Image:WAD_Battery_Charge&amp;amp;PowerOn_Final.jpg]]&lt;br /&gt;
&lt;br /&gt;
White battery wire (see photo) is connected to internal NTC thermistor (10KOhm@+25°C). In this way it's posible to implement an over/under charge temperature detector using a couple af operational amplifier as comparator.&lt;br /&gt;
With the resistence network in schematic it had been possible to set an upper temperature threshold of 47.5°C (corresponding to 3.97K NTC value) and a down thresold of 2.5°C (corresponding to &lt;br /&gt;
28.7K NTC value). Out of this range comparators output go low disabling battery charger.&lt;br /&gt;
This function allows to prevent battery demage or explosion during charge.&lt;br /&gt;
&lt;br /&gt;
Power-up and shut-down are implemented using a Maxim's MAX16054 connected with an ADG801 by Analog Device.&lt;br /&gt;
MAX16054 is a pushbutton on/off controller with a single switch debouncer and built-in latch. It accepts a noisy input from a mechanical switch and produces a clean latched digital output after a factory-fixed qualification delay.&lt;br /&gt;
The state of the output changes only when triggered by the falling edge of the debounced switch input; the output remains unchanged on the rising edge of the input.An asynchronous CLEAR input allows an external signal to force the output flip-flop low.&lt;br /&gt;
1 MOhm resistor and 10 uF capacitor connected to power-on pushbutton  (in addition to internal 63KOhm pullup resistor) allow to obtain a delay of about 3 seconds.&lt;br /&gt;
&lt;br /&gt;
ADG801 is a monolithic CMOS, single-pole, single throw (SPST), normally open (NO) switch with on resistance of less than 0.4Ohm. This switch conducts equally well in both directions when on.&lt;br /&gt;
&lt;br /&gt;
Battery voltage monitor is hardware implemented by another Maxim's device: MAX8212.&lt;br /&gt;
MAX8212 is a CMOS micropower voltage detector that warn microprocessors/microcontroller of power failures. It contains a comparator, a 1.5V bandgap reference, and an open-drain n-channel output driver. Two external resistors are used in conjunction with the internal reference to set the trip voltage to the desired level. A hysteresis output is also included, allowing the user to apply positive feedback for noise-free output switching.&lt;br /&gt;
Using a couple of these device is possible to set two treshold: one for low battery and another for end battery detection. Low battery detection allow communicate the user battery level; end battery detection allow microprocessor shut down the device before battery voltage fall down under 3.4V that is the minimun input voltage allowed by linear regulator MCP1700.&lt;br /&gt;
If batterY level fall down under 3.4V, MCP1700 is not able to guarantee line regulation. &lt;br /&gt;
&lt;br /&gt;
[[Image:WAD_Battery_Monitor_Final.jpg]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Students that have worked on the project==&lt;br /&gt;
&lt;br /&gt;
* Mattia Colombo (Blood Volume Pressure sensor)&lt;br /&gt;
* Alessia Cornaggia (Galvanic skin response sensor)&lt;br /&gt;
* Sala Mirko (Galvanic skin response sensor)&lt;br /&gt;
&lt;br /&gt;
== Laboratory work and risk analysis ==&lt;br /&gt;
&lt;br /&gt;
Laboratory work for this project will be mainly performed at AIRLab/Lambrate. It will include electrical and electronic activity. Potentially risky activities are the following:&lt;br /&gt;
* Use of mechanical tools. Standard safety measures described in [http://airlab.elet.polimi.it/index.php/airlab/content/download/461/4110/file/documento_valutazione_rischi_AIRLab.pdf Safety norms] will be followed.&lt;br /&gt;
* Use of soldering iron. Standard safety measures described in [http://airlab.elet.polimi.it/index.php/airlab/content/download/461/4110/file/documento_valutazione_rischi_AIRLab.pdf Safety norms] will be followed.&lt;br /&gt;
* Use of high-voltage circuits. Special gloves and a current limiter will be used. Standard safety measures described in [http://airlab.elet.polimi.it/index.php/airlab/content/download/461/4110/file/documento_valutazione_rischi_AIRLab.pdf Safety norms] will be followed.&lt;/div&gt;</summary>
		<author><name>PaoloVilla</name></author>	</entry>

	<entry>
		<id>https://airwiki.deib.polimi.it/index.php?title=File:WAD_Micro_Final.jpg&amp;diff=9432</id>
		<title>File:WAD Micro Final.jpg</title>
		<link rel="alternate" type="text/html" href="https://airwiki.deib.polimi.it/index.php?title=File:WAD_Micro_Final.jpg&amp;diff=9432"/>
				<updated>2009-11-24T15:57:36Z</updated>
		
		<summary type="html">&lt;p&gt;PaoloVilla: uploaded a new version of &amp;quot;Image:WAD Micro Final.jpg&amp;quot;&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>PaoloVilla</name></author>	</entry>

	<entry>
		<id>https://airwiki.deib.polimi.it/index.php?title=File:WAD_Micro_Final.jpg&amp;diff=9431</id>
		<title>File:WAD Micro Final.jpg</title>
		<link rel="alternate" type="text/html" href="https://airwiki.deib.polimi.it/index.php?title=File:WAD_Micro_Final.jpg&amp;diff=9431"/>
				<updated>2009-11-23T14:34:11Z</updated>
		
		<summary type="html">&lt;p&gt;PaoloVilla: uploaded a new version of &amp;quot;Image:WAD Micro Final.jpg&amp;quot;&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>PaoloVilla</name></author>	</entry>

	<entry>
		<id>https://airwiki.deib.polimi.it/index.php?title=Wireless_Affective_Devices&amp;diff=9424</id>
		<title>Wireless Affective Devices</title>
		<link rel="alternate" type="text/html" href="https://airwiki.deib.polimi.it/index.php?title=Wireless_Affective_Devices&amp;diff=9424"/>
				<updated>2009-11-20T12:55:49Z</updated>
		
		<summary type="html">&lt;p&gt;PaoloVilla: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{Project&lt;br /&gt;
|title=Wireless Affective Devices&lt;br /&gt;
|tutor=SimoneTognetti;MatteoMatteucci&lt;br /&gt;
|students=PaoloVilla&lt;br /&gt;
|resarea=BioSignal Analysis&lt;br /&gt;
|restopic=Affective Computing&lt;br /&gt;
|start=2008/01/08&lt;br /&gt;
|end=2009/12/30&lt;br /&gt;
|status=Active&lt;br /&gt;
|level=Ms&lt;br /&gt;
|type=Thesis&lt;br /&gt;
}}&lt;br /&gt;
==Project aims ==&lt;br /&gt;
&lt;br /&gt;
 ”''Everyone knows what an emotion is, until asked to give a definition''”&lt;br /&gt;
                                         &lt;br /&gt;
                                                                 Beverly Fehr and James Russell&lt;br /&gt;
&lt;br /&gt;
Research on Human-Computer-Interfaces has recently begun to take into account the affective state of the user. By appropriately reacting to the affective user state, interfaces could not only become more pleasant or entertaining, but also more effective or safer.&lt;br /&gt;
It is known that affective states have bodily correlates, and thus physiological signals could provide the necessary information for acquiring the affective user state. In contrast to other sources of information about the affective user state such as speech or facial expression, most physiological signals are not under voluntary control, and thus cannot be masked up to the same extent. Furthermore, it can be presumed that the signs of affective states in physiological signals are less dependent on individual and contextual factors: this is because the signals correspond to internal physiology, largely related to the autonomous nervous and limbic systems, rather than to external expressions that can be manipulated easily.&lt;br /&gt;
Recently, the issue of emotion regulation drew interests from several fields including neuroscience, psychology, education, computer science, etc. Possible applications are e-learningin, human computer interaction, development of communicative technologies for use by people with autism, car infotainment system, lie detection tests, cognitive workload, multimodal user interfaces MMUI (allow users to control computers using speech and gesture), etc.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The project is aimed at developing a device, connected to a PC, to acquire biological signals (such as GSR, BVP, Temperature and Head orientation) in a way that is less invasive for the subject. The term invasive is related to how much the sensors we use compromise the normal interaction between subject and machine.&lt;br /&gt;
Through these biological signal the PC is able o understand emotion in people who wear the device.&lt;br /&gt;
&lt;br /&gt;
An affective device should be weared easily, should not have cables and should acquire as much sensors as possible. We relax some constraint on the quality of signal but we add constraint on way they are acquired(i.e. the subject can put it on easily, the usual movements are not influenced..). The aim of the resulting device is not to replace the standard medical devices usually used to acquire that signals, but is to be much more suitable for industrial application in which the medical requirement are replaced by invasivity requirement.&lt;br /&gt;
&lt;br /&gt;
It is composed by:&lt;br /&gt;
&lt;br /&gt;
* Low power, high efficiency, battery powered design&lt;br /&gt;
* Wireless comunication with a PC&lt;br /&gt;
* Blood Volume Pressure Sensor (Preliminary release by Mattia Colombo)&lt;br /&gt;
* Galvanic Skin Response Sensor (Preliminary release by Sala Mirko e Alessia Cornaggia)&lt;br /&gt;
* Temperature Sensor&lt;br /&gt;
* 3 Way Accelerometer&lt;br /&gt;
* Possibility of further extension&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''GSR (or EDR or EDA)'''&lt;br /&gt;
&lt;br /&gt;
An often misunderstood and difficult technique, GSR (also known as the electrodermal response EDR or electrodermal activity EDA) has gone through many phases of interest and rejection since the early 1900's and is very popular in psychophysiological studies since Carl Jung and his students (1907) described it as a mean to&lt;br /&gt;
enter the “sea of the unconscious” because “every stimulus accompanied by an emotion produced a deviation of the galvanometer” directly proportional to the strength of the emotion aroused. It has been used in important research on anxiety and stress levels (Fenz &amp;amp; Epstein, ' 67); and it has been a part of lie detection (Raskin, ' 73). Controversy has centered around the technique, underlying mechanisms, and the meaning of the responses obtained from the skin. &lt;br /&gt;
There has been a long history of electrodermal activity research, even if most investigators accept the phenomenon without understanding exactly what it means (Hume, ' 76).&lt;br /&gt;
The resistance of the skin is usually large, approximately 1M; however, momentary changes in the level of the sweat gland activity causes changes in resistance (up to approximately 950K).&lt;br /&gt;
Physiology, the GSR reflescts sweat gland activity and changes in the sympathetic nervous system and measurement variables. The activity of the sweat glands in response to sympathetic nervous stimulation ( Increased sympathetic activation ) results in an increase in the level of conductance. There ia a relationship between sympathetic activity and emotional arousal, although one cannot identify the specific emotion being elicited. &lt;br /&gt;
Basically there are two techniques in the history of Electrodermal measurement. In one a current is passed thru the skin and the the resistance to passage is measured; in the other no current is used externally and the skin itself is the source of electrical activity.&lt;br /&gt;
By applying a conventional 0.5 Volts across the skin and measuring changes in the&lt;br /&gt;
corresponding conductance, the emotional state of the subject can be inferred. In general, the electrodes used are of the Ag/AgCl type which are recessed from the skin and require the use of a suitable electrode paste.&lt;br /&gt;
It is important to note, however, that fluctuations in skin conductivity are resultant of many types of arousal.&lt;br /&gt;
By observing only these changes, it is impossible to deduce without prior knowledge whether&lt;br /&gt;
the subject has become happy, startled, physically active, etcetera.&lt;br /&gt;
EDA consists of two components: tonic and phasic. The tonic component is a low&lt;br /&gt;
frequency baseline conductivity level, which can oscillate over the course of days. The phasic&lt;br /&gt;
component rides on top of the tonic component, exhibits more rapid fluctuations, and&lt;br /&gt;
generally increases when a person is aroused. Problematically, each person has a different&lt;br /&gt;
tonic conductivity, so in order to infer the arousal level of the subject, the relative changes in&lt;br /&gt;
EDA must be analyzed over a period of time. Furthermore, skin conductance (measured in&lt;br /&gt;
units of siemens; formerly mhos) depends on the skin path length between the two electrodes&lt;br /&gt;
contacts, even for subjects with identical skin conductivity (measured in units of&lt;br /&gt;
siemens/meter). It is for these reasons that it is crucial to analyze the temporal variations of&lt;br /&gt;
the EDA signal.&lt;br /&gt;
&lt;br /&gt;
'''BVP'''&lt;br /&gt;
&lt;br /&gt;
The cardiovascular system is in charge to keep us alive by maintaining the vital blood flow throughout the body, providing nutrients and oxygen to our cells. The SNS controls this system&lt;br /&gt;
by shifting the flow in response to exercise, temperature,postural and emotional changes.&lt;br /&gt;
Blood Volume Pulse (BVP) is the most common measure of vasomotor activity because it reflects the phasic pumping of the heart, the vasodilation of vessels that changes in the amount of acral blood delivered.&lt;br /&gt;
The Blood Volume Pulse (BVP) waveform is an important indicator of circulatory function that can be obtained noninvasively through a photoplethysmographic transducer (a PPG is often obtained by using a pulse oximeter, Shelley and Shelley, 2001) applied to the finger or the earlobe of human subjects. In particular, this signal may be useful in determining the degree of cardiovascular change undergone by a subject through an exercise session. &lt;br /&gt;
&lt;br /&gt;
''Principles of photoplethysmographic Technology:''&lt;br /&gt;
&lt;br /&gt;
The principle of photoplethysmographic (That is the same of pulse oximetry) is based on the red and infrared light absorption characteristics of oxygenated and deoxygenated hemoglobin. Oxygenated hemoglobin absorbs more infrared light and allows more red light to pass through. Deoxygenated (or reduced) hemoglobin absorbs more red light and allows more infrared light to pass through. Red light is in the 600-750 nm wavelength light band.&lt;br /&gt;
Pulse oximetry uses a light emitter with red and infrared LEDs that shines through a reasonably translucent site with good blood flow. Opposite the emitter is a photodetector that receives the light that passes through the measuring site.&lt;br /&gt;
There are two methods of sending light through the measuring site: transmission and reflectance. In the transmission the emitter and photodetector are opposite of each other with the measuring site in-between. The light can then pass through the site. In the reflectance method, the emitter and photodetector are next to each other on top the measuring site. The light bounces from the emitter to the detector across the site. The transmission method is the most common type used.&lt;br /&gt;
While pulse oximeters are a commonly used medical device the PPG derived from them is rarely displayed, and is nominally only processed to determine heart rate. &lt;br /&gt;
&lt;br /&gt;
'''Temperature'''&lt;br /&gt;
&lt;br /&gt;
The temperatures of peripheral limbs vary as a consequence of changes in blood flow.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== '''Previous work''' ==&lt;br /&gt;
&lt;br /&gt;
Here is a preliminary release of the headset produced before 2008/08/08&lt;br /&gt;
&lt;br /&gt;
[[Image:Wd1.jpg]]&lt;br /&gt;
&lt;br /&gt;
If you are interested on the making of the headset please see [[making rubber models]]&lt;br /&gt;
&lt;br /&gt;
'''* Blood Volume pressure'''&lt;br /&gt;
First graph showing a signal acquired with the wireless sensor. &lt;br /&gt;
[[Image:Bvp.png]]&lt;br /&gt;
&lt;br /&gt;
'''* Skin galvanic response''' (Sala Mirko e Alessia Cornaggia[http://airwiki.elet.polimi.it/mediawiki/index.php/User:AlessiaCornaggia])&lt;br /&gt;
Galvanic skin response (GSR), also known as electrodermal response (EDR), psychogalvanic reflex (PGR), or skin conductance response (SCR), is a method of measuring the electrical resistance of the skin.  There is a relationship between sympathetic activity and emotional arousal, although one cannot identify the specific emotion being elicited. The GSR is highly sensitive to emotions in some people. Fear, anger, startle response, orienting response and sexual feelings are all among the emotions which may produce similar GSR responses.&lt;br /&gt;
Response of the skin to the passage of a small electric current. The ease with which the current flows between two points on the skin can be used to indicate stress. When a person is tense or emotional, the sweat glands become more active, increasing moisture on the skin; this allows the electric current to flow more readily. &lt;br /&gt;
The response may also be used in relaxation training: information about the galvanic skin response is fed back aurally or visually to the subject who can, with practice, learn to increase or decrease sweating on the skin by learning to relax or tense muscles.&lt;br /&gt;
We measure the galvanic skin response using two electrodes attached to the skin. The optimal placement is the palm of the hands, but we are experimenting other places like on the forehead.&lt;br /&gt;
The circuit we are creating is the one below.&lt;br /&gt;
&lt;br /&gt;
[[Image:circuito.jpg]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== '''Project the device''' ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== '''Re-definition of the complete work''' ===&lt;br /&gt;
&lt;br /&gt;
Sensors are an important part of an Affective Computing System because they provide information about the wearer's physical state or behavior. They can gather data in a continuous way without having to interrupt the user. &lt;br /&gt;
To define in detail electronic specifications and requirements it's necessary a preliminary research/study (in literature and web) about state of art of sensor type used to monitor each type of biological signals we are interested about.&lt;br /&gt;
In this way it's possible both understand problematics related to interaction between biological and electonical worlds and improve or re-desig existing prototype.&lt;br /&gt;
&lt;br /&gt;
About Sensors: &lt;br /&gt;
&lt;br /&gt;
BVP will be acquire by an IR transmitter-receiver measuring light reflected from skin (photoplethysmography). Particular attention will be put on position, geometry and power absorption of this stage. &lt;br /&gt;
&lt;br /&gt;
GSR will be acquiret by a couple of electrodes forcing a low current (or voltage) and reading voltage (or current) through electrodes. Particular attention will be put on electrodes position and material. In addition is possible to foresee some problems in amplifier stage due to large range of skin resistance. Problem consist in chosing a correct amplification to overwork ADC full scale with a signal affected by little variation but huge possible range. &lt;br /&gt;
&lt;br /&gt;
Temperature will be acquired by thermocouple or PTC/NTC. Slowly variable signal, possible problems with noise due to resolution required. &lt;br /&gt;
&lt;br /&gt;
Head orientation will be acquired by an accelerometer and a gyroscope, problably integrated in the same chip. Two possibilities: analog output (need to digitalize up to six line) or digital output (like displaied in schematic block diagram). &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
This was the preliminary simplified schematic block diagram of the complete instrumentation setup:&lt;br /&gt;
&lt;br /&gt;
[[Image:WADSchematicDiagram01.jpg]]&lt;br /&gt;
&lt;br /&gt;
 NOTE:&lt;br /&gt;
 &lt;br /&gt;
 * In schematic is not present Power Supply Module: it will be based on a rechargeable Li-ion&lt;br /&gt;
 battery. It must satisfy requirements of high efficiency, logn life and low weight.&lt;br /&gt;
 &lt;br /&gt;
 * ADC and Microcontroller could be unified using a microcontroller with internal ADC and&lt;br /&gt;
 internal or external multiplexer to select lines.&lt;br /&gt;
 &lt;br /&gt;
 * Wireless section could be implemeted in Bluetooth (instead of using a XBee module like in&lt;br /&gt;
 preliminary release) due to it's diffusion in cellular phones, notebooks, MP3 reader...&lt;br /&gt;
 without necessity of external modules.&lt;br /&gt;
&lt;br /&gt;
It was based on a theoretical approach to any single part. Any sensing device was designed in &amp;quot;conventional&amp;quot; way founded on analog electronic (a bridge with a NTC resisistance as sensing element, discrete IR led and some photodiode around to capture the most reflefted light as possible, GSR electrodes on the gain arm of a non-inverting amplifier...).&lt;br /&gt;
Unfortunatly a deep analysis on signal physiology, signal transduction, noise vs required accurancy, forced us to a completely different approach implementing everywhere possible a digital interface.&lt;br /&gt;
&lt;br /&gt;
=== '''Sensors Design''' ===&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''BVP'''&lt;br /&gt;
&lt;br /&gt;
Discrete IR leds and phototransistor, used in the first realize (see fig.), had been replaced first with a single led and one or more photodiodes to optimize power consumption in case of non-planar sensor positioning. Subsequently an integrated Reflective Object Sensor was introduced, with benefits about space saving, transmitter-receiver matching and power consumption.&lt;br /&gt;
To ensure light power stability, led is powered through a linear led drive LDO (Low Drop-Out). The choise of linear LDO is necessary to ensure no noise or spikes would be generated by charge pump systems or boost converters. In addition, the linear drive utilized requires only one external resitor to set led current and a decoupling capacitor, reducing part counts and board space occupation.&lt;br /&gt;
The couple factor of the reflex sensors is relatively small, even in the case of good reflecting surfaces. Therefore an additional amplifier is necessary at the sensor output: classic trans-impedance amplifier used with photo-diodes and photo-transistors was introduced. This circuit features an output voltage that is a linear function of the light level on the photo-transistor. The gain is set by the feedback resistor which could be in the millions of ohms. Linear operation is achieved by operating the photo device with a fixed voltage drop across it.&lt;br /&gt;
Trans-impedance amplifier is followed by an active fourth order band-pass filter (0.5Hz-5Hz): it's composed cascading two second order bandpass cells. In first project session only a single cell was used, but a deeper study combined with previous experiences suggests to use a 4th order filter to reduce 50Hz interference (50Hz interference produced by mains is placed only a decade after the filter pole).&lt;br /&gt;
Filter is followed by a VGA (Variable Gain Amplifier) digitally controlled through I2C Bus that allows to optimize dinamically ADC input signal amplitude directly during acquisition session, obtaining the best performance from ADC.&lt;br /&gt;
The resulting circuit is quite compact (led drive, reflective sensor, trans-impedence amplifier, active filter and variable-gain amplifier), doesn't require much power and represents a good mix between analog and digital approach: analog front-end with acquisition and first conditioning, and at the chain-end a digital controlled amplifier to ensure flexibility.&lt;br /&gt;
&lt;br /&gt;
[[Image:WADBVPComparison.jpg]]&lt;br /&gt;
&lt;br /&gt;
'''GSR'''&lt;br /&gt;
&lt;br /&gt;
GSR will be acquired by a couple of electrodes forcing a low voltage and reading current through electrodes. First designs and implementations were based on literature study: best solution appears to put GSR electrodes on the gain arm of a non-inverting amplifier (see fig.) rather than using a Wheatstone bridge due to week signal produced by this solution.&lt;br /&gt;
Putting GSR electrodes on the gain arm produces a sort of gain modulation of the constant voltage applied between electrodes but doesn't solve problems in amplifier stage due to large range of skin resistance.&lt;br /&gt;
Problems in chosing correct amplification to overwork ADC full scale with a signal affected by little variation but huge possible range could be reduced usign a variable resistor on gain arm (for example a digital potentiometer controlled by the microcontroller), but cannot be completely removed. In addition little signals are easily deteriorated by noise.&lt;br /&gt;
Solution is provided considering a new point of view: measure of unknown skin resistence is extremely similar to measure unknown electrical impedence with an auto-range multimeter!&lt;br /&gt;
Solution consist in a digital Impedance Converter: AD5934 is a high precision impedance converter system which combines an on-board frequency generator with a 12-bit, 250 kSPS, analog-to-digital converter (ADC). The frequency generator allows an external complex impedance to be excited with a known frequency; the response signal from the impedance is sampled by the on-board ADC and a discrete Fourier transform (DFT) is processed by an on-board DSP engine. The DFT algorithm returns a real (R) and imaginary (I) data-word at each output frequency. This solution not only allows to measure impedence range from 100 Ohm to 10 MOhm, but in adition allow to investigate it across a wide range of frequency, producing a noise-free digital output.&lt;br /&gt;
The resulting circuit is extremely compact (converter chip, one setting resistor and bypass capacitors), provides a system accuracy of 0.5% and connects to microcontroller using I2C interface, ensuring an high flexibility and the possibility to modify acquisition settings after board production (through microcontroller firmware).&lt;br /&gt;
&lt;br /&gt;
[[Image:WADGSRComparison.jpg]]&lt;br /&gt;
&lt;br /&gt;
'''Temperature'''&lt;br /&gt;
&lt;br /&gt;
First idea was to acquire temperature by a NTC connected in a Wheatstone bridge. Trying to reduce noise, bridge was powered by an oscillator circuit with a frequency of some KHerz, to translate signal out of 1/f noise region. Bridge outputs were connected to an INA amplifier wich also implements signal filtering (see fig.).&lt;br /&gt;
Weak signal, noise and resolution required (0.1°C) put in crisis the system. In addition other unsolved problems were the optimization of thermal and mechanical contact between sensor and body and the sensor large thermic constant. Unstable thermic contact produces unreliable measures, whereas high sensor thermic constant hampers a fast sensor response (needed to detect short peak due to emotional reactions).&lt;br /&gt;
Possible solutions to problems of weak signal and noise arrive from digital integrated temperature sensor (for example LM35 or LM74), but these don't solve the problem of thermal contact and thermal constant. In addition none of the sensors take in consideration provides the required resolution.&lt;br /&gt;
High resolution required, noise immunity, fast response and thermal contact immunity problems had been solved using a digital optical infra red thermometer. The MLX90614 is an infra red thermometer for non contact temperature measurements based on a thermopile detector chip including signal conditioning in the same TO-39 package. Thanks to its low noise amplifier, 17-bit ADC and powerful DSP unit, a high accuracy and resolution of the thermometer is achieved.&lt;br /&gt;
The calculated object and ambient temperatures are available in RAM of MLX90614 with 0.02°C resolution: they are accessible by 2 wire serial SMBus compatible protocol. A special version for medical applications offers an accuracy of ±0.1ºC in a limited temperature range around the human body temperature.&lt;br /&gt;
Small size, no external component requirements and power saving mode allow us to obtain a perfect matching between required performances and space saving.&lt;br /&gt;
&lt;br /&gt;
[[Image:WADTemperatureComparison.jpg]]&lt;br /&gt;
&lt;br /&gt;
'''Accelerometer'''&lt;br /&gt;
&lt;br /&gt;
Head orientation and movements will be acquired by an accelerometer. First we think to utilize an ST Microelectronic LIS3L02AS4, due to the availability in the Lab of the evaluation board STEVAL-MKI001. It is a 3-axis ±2g/±6g linear accelerometer with 3 analog outputs, so it requires an external ADC to digitalize the three axis acceleration values. The conversion could be performed by a microcontroller with internal ADC.&lt;br /&gt;
A fast Internet research reveled this sensor is now obsolete and out of production. The choise had been to substitute the old chip with the new one: the LIS302DL (still produced by ST Microelectronic). It's a 3-axis, ± 2g/± 8g smart digital output accelerometer with I2C/SPI digital output interface and really small package. The device is capable of measuring accelerations with an output data rate of 100 Hz or 400 Hz and the self-test capability allows the user to check the functioning of the sensor in the final application.&lt;br /&gt;
In addition it may be configured to generate inertial wake-up/free-fall interrupt signals when a programmable acceleration threshold is crossed at least in one of the three axes. Thresholds and timing of interrupt generators are programmable by the end user on the fly.&lt;br /&gt;
This device, providing a digital output, doesn't need signals conversion, guaranteing better noise immunity; programmable interrupts and test interface allow greater fexibility in project. In addition wery small package, only one external resistor requirement (plus baypass capacitor) reduce significantly board space requirements.&lt;br /&gt;
&lt;br /&gt;
[[Image:WADAccelerometer.jpg]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
 NOTE:&lt;br /&gt;
 &lt;br /&gt;
 * In previous schematics, components phisical dimensions are not in scale.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== '''Microcontroller''' ===&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Foundamental requirements:&lt;br /&gt;
&lt;br /&gt;
- High speed to ensure high data output rate even in presence of a large number af sensing elemets;&lt;br /&gt;
&lt;br /&gt;
- Fast Internal ADC with multiple inputs;&lt;br /&gt;
&lt;br /&gt;
- (At Least) One I2C interface;&lt;br /&gt;
&lt;br /&gt;
- (At Least) One SPI interface;&lt;br /&gt;
&lt;br /&gt;
- (At Least) One UART interface;&lt;br /&gt;
&lt;br /&gt;
- Low-power consumption;&lt;br /&gt;
&lt;br /&gt;
- Power supply 3.3V;&lt;br /&gt;
&lt;br /&gt;
- Small package;&lt;br /&gt;
&lt;br /&gt;
In addition microcontroller was chosen between Microchip PIC family devices, due to positive previous experiences and availability of software and programmer in the Lab.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
PIC24HJ256GP206 is a 16 bit microcontroller capable of 40 MIPS speed. It provides 256KB of Flash memory, 16KB of Ram, a 10-bit 1.1Msps or 12-bit 500Ksps ADC, UART, SPI and I2C interface in a 64 pin TQFP package (10mmX10mm) powerd between 3.0V and 3.6V.&lt;br /&gt;
Power core is provided by an internal regulator reducing parts count on the board.&lt;br /&gt;
&lt;br /&gt;
The device is able to provide at the same time one I2C interface, two SPI interface and one UART interface: another UART port shares pins with an SPI port and a second I2C port shares pins with the second UART interface.&lt;br /&gt;
Findig a device that provides at the same time, on indipendent pins, an I2C, a SPI and an UART interface reduces considerably possible choises and suggests to chose a high performance microcontroller.&lt;br /&gt;
At the same time, high performance solutions have a larger pin counts than standard microcontroller, but this characteristic can be used to ensure further expansibility to the system. The second SPI interface can be used to connect another &amp;quot;intelligent&amp;quot; device or a mass storage device, for example a SD (Secure Digital) card to storage acquired data (see fig.).&lt;br /&gt;
&lt;br /&gt;
[[Image:WADSDCard.jpg]]&lt;br /&gt;
&lt;br /&gt;
Input pins connected to ADC and not used at the moment could be collected to a connector for further extension modules (for example an EMG or ECG peripheral or any other analog signal interesting in a particolar application).&lt;br /&gt;
For the same reason any other pin non used at the current stage is reported to an extension connector.&lt;br /&gt;
To guarante maximum flexibility an further update, board provides both ICD and JTAG connections (allowing on-board programming and debugging) through a couple of indipendent dedicated connectors fully compatibles with Microchip programmers and evaluation boards.&lt;br /&gt;
&lt;br /&gt;
[[Image:WADMicro.jpg]]&lt;br /&gt;
&lt;br /&gt;
=== '''Wireless Connection''' ===&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Wireless connection is based on BlueGiga WT12 module: it's a next-generation, class 2, Bluetooth 2.0+EDR (Enhanced Data Rates) module containing all the necessary elements from Bluetooth radio to antenna and a fully implemented protocol stack.&lt;br /&gt;
By default WT12 module is equipped with powerful and easy-to-use iWRAP firmware that enables users to access Bluetooth functionality with simple ASCII commands delivered to the module over serial interface like a Bluetooth modem.&lt;br /&gt;
The dedicated onboard microcontroller (MCU) acts as interrupt controller and event timer run the Bluetooth software stack and control the radio and host interfaces. A 16-bit reduced instruction set computer (RISC) microcontroller is used for low power consumption and efficient use of memory.&lt;br /&gt;
WT12 module support USB, SPI and UART interface and UART interface is used in this project to connect PIC microcontroller to wireless transmitter (see fig.).&lt;br /&gt;
&lt;br /&gt;
[[Image:WADWireless.jpg]]&lt;br /&gt;
&lt;br /&gt;
One of the most important WT12 characteristic is the high integration between all parts needed for efficent Bluetooth transmission: user interface, controller, radio circuits and antenna, all included in a low power, low size board (25.6mmx15mm) that requires a minimum number of external components.&lt;br /&gt;
Many other bluetooth components ara available, such as LMX9830, produced by National Semiconductor. It's an extremely small device (only 6.1mm×9.1 mm), but requires a number of external components (see fig.) like oscillators, resistors, capacitors, inductors and the antenna, in addition to an high competence in radio frequency layout circuits.&lt;br /&gt;
&lt;br /&gt;
[[Image:WADLMX9830.jpg]]&lt;br /&gt;
&lt;br /&gt;
Lack of experience in radio frequency circuit suggests to chose a ready-to-use module, factory optimized for best performance and easy to integrate in our board.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
This is the updated simplified schematic block diagram:&lt;br /&gt;
&lt;br /&gt;
[[Image:WADSchematicDiagram02.jpg]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== '''Prototype realization [WIP (Work in Progress)]''' ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Fist stage plans to realize a board using, where possible, through-hole (TH) compenents soldered on a prototyping board (100x160mm) powered from a laboratory power supply (instead of Li-on battery) and not implementing bluetooth wireless transmission. Parts not available on TH package are used with special SMD-&amp;gt;TH adapter boards or simply fixing and soldering them to the PCB by wires.&lt;br /&gt;
&lt;br /&gt;
Second stage plans to realize microcontoller firmware and test it acquiring biological signals from a patient. Firmware will be developed by subsequently steps, implementing and testing only a single peripheral at each time: only at the end single pheripheral softwares will be merged together.&lt;br /&gt;
&lt;br /&gt;
Third stage will be bluetooth interface (hardware and software) implementation and integration on the board with transmission test.&lt;br /&gt;
&lt;br /&gt;
Fourth stage will consider power supply optimization with battery management and recharge interface.&lt;br /&gt;
&lt;br /&gt;
Finally, only after a successful full board test, the last stage will be the circuit layout design with an electronic CAD, using where possible, Surface Mount Devices (SMD) to reduce board area.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== '''Main board''' ===&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Main board include power supply regulator with led power-on indicator, PIC microcontroller (mounted on a SMD-&amp;gt;TH adapeter board) with basic circuitry (decoupling capacitors, oscillator and programming-debugging ICD interface), a status led connected to PIC to verify basic microcontroller function, a series of connectors for add-on modules (BVP, GSR, temperature and accelerometer) and a USB PC interface not considered before.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== '''USB interface''' ===&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
USB interface, not projected before, replaces in developing stage Bluetooth interface, allowing a direct control/communication with a PC. In this prototype PIC UART, althought being connected to Bluettoth module, is connected to a FTDI FT232RL chip. The FT232RL is the latest device to be added to FTDI’s range of USB UART interface Integrated Circuit Devices. USB to serial designs using the FT232RL have been further simplified by fully integrating the external EEPROM, clock circuit and USB resistors onto the device.&lt;br /&gt;
The FT232RL is available in Pb-free (RoHS compliant) compact 28-Lead SSOP, so this require another SMD-&amp;gt;TH board adapter but the circuit design is very simple, including two status led for TX and RX operations. An USB B female connector was eputated the best choise for PC connection allowing to use a simple USB printer cable.&lt;br /&gt;
&lt;br /&gt;
[[Image:WADUSBInterface.jpg]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Note that USB and Bluetooth must not be connected to the board at the same time! USB port has only a developent function.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== '''BVP''' ===&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Circuit designed for BVP acquisition (refer to previous schematic) doesn't meet the expected results. Week signal hanged by noise suggested us to re-design the circuit simplifying it and reducing the number of components. For this design also sensing element has been substitute. Instead of an integrated reflective IR sensor (SFH9202), new project use a couple af discrete IR led and photothansistor matched: SFH487 and SFH309FA.&lt;br /&gt;
SFH487 is a very highly efficient GaAlAs infrared emitter (880 nm) and SFH309FA is a silicon NPN phototransistor especially suitable for applications of 880 nm with an high linearity. Both have a 3 mm led plastic package, are spectrum-matched and receiver is ambient-light shilded. After a series of positive test without the led driver (not used due to the really reduced mechanical dimensions), also led drive circuit was removed and replaced with a resistance connected directly to a PIC pin.&lt;br /&gt;
This choise reduces parts count and board space required without making worse sistem performance, allowing (like led driver) to turn off the sensor led when not used to reduce power consumption.&lt;br /&gt;
&lt;br /&gt;
[[Image:WADBVPNew.jpg]]&lt;br /&gt;
&lt;br /&gt;
Even if operation amplifier used are half of before, double second-order filter stage is manteined. In addition to filtering, these opamp privide a first gain (note that in previous design filtering stages works as a unitary buffer in pass-band) allowing a high signal at VGA (variable gain amplifier) input stage allowing a better SNR.&lt;br /&gt;
1N4148 diode provides a sort of ofsetted virtual ground, shifting up all signals but not being amplified through the amplification chain.&lt;br /&gt;
Figure show the signal measured directly on filtering stage output (TS952 pin 7) before the VGA with a Tektronix scopemeter TDS2014B. No particular triks had been used: signal has been recorded the first time circuit was assembled on a protoboard.&lt;br /&gt;
&lt;br /&gt;
[[Image:WADBVPScope03.jpg]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== '''GSR''' ===&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
First approach with AD5934 resulted really hard due to some errors occurred in control software in relation with internal chip complexity and I2C bus protocol. &lt;br /&gt;
After a sart session with the AD5934, GSR hardware acquisition interface was further simplified replacing it with AD5933 (refer to schematic). AD5933 has the same pinout and functions of AD5934 but provides also an internal oscillator at 16.776MHz allowing no external crystal connection. A temperature sensor that allow the user to measure chip temperature and 1 MSPS Converter (instad of a 250KSPS one) are the only other differences between the tho integrated semiconductor produced by Analog Devices.&lt;br /&gt;
On the other hand AD5934 has a larger impedance measurement range that goes from 100 Ohm to 10 MOhm in opposition to AD5933 that can only measure impedences between 1 Ohm and 10 MOhm. Because of the high skin impedence values (in the range of MOhm for dry fingers skin), this is not a problem in our application.&lt;br /&gt;
&lt;br /&gt;
[[Image:WADGSRNew.jpg]]&lt;br /&gt;
&lt;br /&gt;
First dataset acquired whith the correct control software and the correct data reading routine, has shown all the potentiality of this chip, providing data comparables with RAW data acquired with a bigger and very expensive professional equipement produced by ProComp.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== '''ACCELERATION''' ===&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Lis302DL datasheet gives a short definition of this chip as &amp;quot;MEMS motion sensor 3-axis - ± 2g/± 8g smart digital output “piccolo” accelerometer&amp;quot; and it is really very, very small for human-working. For this space saving quality this accelerometer is also use in third generation Apple i-phone.&lt;br /&gt;
The major problem with this sensor had been to solder it to a sort of adapter to connect it to the circuit, but after that it works fine, with a good sensitivity and accuracy. Because of free fall and double click recognition at not required (at the moment) in this application, software routines for setting configuration registers and reading data resulted simplified.&lt;br /&gt;
A usefull caracteristic of this sensor, not previously noticed, is the presence of internal pull-up resistors that allows no necessity of external I2C bus pull-up resistors, reducing space occupation and components count.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== '''TEMPERATURE''' ===&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The choice to use MLX90614 due to his characteristics (non contact measure, 0.02°C resolution with accuracy of ±0.1°C for medical applications version) creates a really serious supplies problem: Melexis (sensor manufacture) wasn't able to give us a sample and no one in Italy can sell us only a pair of theese sensors to try them. A single piece was bought from Future Electronics, ordering it via web and paying it via credit card. Fortunately the sensor, that cames directly from USA, arrived in Italy few days later the payment in excellent conditions.&lt;br /&gt;
&lt;br /&gt;
[[Image:WADMLX90614.jpg]]&lt;br /&gt;
&lt;br /&gt;
Problems occurred interfacing this sensor on I2C bus with other devices (AD5933 and LIS302) connected. MLX90614 has a 2 wire serial SMBus compatible protocol: I2C bus and  SMBus are popular 2-wire buses that are essentially compatible with each other, but are not the same.&lt;br /&gt;
The buses operate at the same speed, up to 100kHz, but the I2C bus has both 400kHz and 2MHz versions. Complete compatibility between both buses is ensured only below 100kHz.&lt;br /&gt;
Timeout and (as a consequence of timeout) minimum clock speed are the most important differences between the I2C bus and the SMBus:&lt;br /&gt;
&lt;br /&gt;
I2C Bus = DC (no timeout)&lt;br /&gt;
&lt;br /&gt;
SMBus = 10kHz (35mS timeout)&lt;br /&gt;
&lt;br /&gt;
Despite differences in logic-level specifications between the two buses, generally devices can be mixed and matched with abandon.&lt;br /&gt;
Level Specifications for the I2C Bus and the SMBus are shown below (VDD is typically expected to be between 3 volts and 5 volts):&lt;br /&gt;
&lt;br /&gt;
[[Image:WADTable1.jpg]]&lt;br /&gt;
&lt;br /&gt;
What wasn't readily evident in the discussion of voltage levels is that these levels are also specified with different currents between the buses. The SMBus specifies a minimum sink current of 100microA, and a maximum of 350microA, compared to 3mA for the I2C bus. This in turn would determine the lowest acceptable value of the pullup resistor, examples of which are shown in the table below.&lt;br /&gt;
&lt;br /&gt;
[[Image:WADTable2.jpg]]&lt;br /&gt;
&lt;br /&gt;
In reality, it is not unusual to encounter pullup resistor values in SMBus systems, which violate this specification by being lower than recommended. A very popular range for pullup resistor values, even in some SMBus systems, seems to be 2.4k to 3.9k.&lt;br /&gt;
&lt;br /&gt;
These reasons, in adition to clear ideas about close developments, suggest a general review of schematic to re-distribute microcontroller resources.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== '''Part 6: final review [WIP (Work in Progress)]''' ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== '''Microcontroller''' ===&lt;br /&gt;
&lt;br /&gt;
Referring to previous schematic, some chenges had been applied:&lt;br /&gt;
&lt;br /&gt;
- Programmer/Debugger interface is now PGD1/EMUD1 and PGC1/EMUC1 instead of PGD1/EMUD2 and PGC1/EMUC2;&lt;br /&gt;
&lt;br /&gt;
- JTAG interface had been removed;&lt;br /&gt;
&lt;br /&gt;
- UART2 is no more available so UART1 has replaced UART2 as communication port;&lt;br /&gt;
&lt;br /&gt;
- SPI2 is no more available so SPI1 is now used to control both LMP8100 VGA (Variable Gain Amplifier) and SD Storage Card;&lt;br /&gt;
&lt;br /&gt;
- RG12, RG13, RG14 pins had been connected to three status led for a machine visual state detection;&lt;br /&gt;
&lt;br /&gt;
- I2C1 interface is now connected to accelerometer (LIS302) and GSR (AD5933) only;&lt;br /&gt;
&lt;br /&gt;
- I2C2 interface is dedicated to temperature sensor (MLX90614), enabling I/O pin thresholds compliant with SMBus specification;&lt;br /&gt;
&lt;br /&gt;
- Connectors for I2C, SMBus and SPI expansion modules had been added to the board;&lt;br /&gt;
&lt;br /&gt;
- Test point pads had been added to the board to simplify debugging.&lt;br /&gt;
&lt;br /&gt;
That's the complete microcontroller schematic diagram:&lt;br /&gt;
&lt;br /&gt;
[[Image:WAD_Micro_Final.jpg]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== '''Data link''' ===&lt;br /&gt;
&lt;br /&gt;
During developing stages, an USB port had replaced Bluetooth wireless transmission, allowing a direct control/communication with a PC. This interfaced, based on a FT232RL, prove to be very usefull and simple to use.&lt;br /&gt;
The choice to use an usb port to charge internal battery, in addition to availability of a UART multiplexer inside the Bluetooth module BlueGiga WT12, suggest to implement both USB and Bluetooth interface.&lt;br /&gt;
&lt;br /&gt;
That's the BlueGiga WT12 internal UART multiplexer schematic:&lt;br /&gt;
&lt;br /&gt;
[[Image:WAD_UARTMux.jpg]]&lt;br /&gt;
&lt;br /&gt;
The complete data link schematic diagram:&lt;br /&gt;
&lt;br /&gt;
[[Image:WAD_USB+Bluetooth_Final.jpg]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== '''Battery Charge &amp;amp; Monitor''' ===&lt;br /&gt;
&lt;br /&gt;
Device is powered by a single cell Li-on battery (3.7V, 1080mAh): this is the same unit used in IPod(TM) from Apple.&lt;br /&gt;
&lt;br /&gt;
[[Image:WAD_Battery.jpg]]&lt;br /&gt;
&lt;br /&gt;
Battery charge is executed by Maxim's MAX1811: it is a really compact single-cell lithium-ion (Li+) battery charger that can be powered directly from a USB port or from an external supply up to 6.5V. It has a 0.5% overall battery regulation voltage accuracy to allow maximum utilization of the battery capacity.&lt;br /&gt;
The charger uses an internal FET to deliver up to 500mA charging current to the battery. The device can be configured for either a 4.1V or 4.2V battery, using the SELV input. The SELI input sets the charge current to either 100mA or 500mA. An open-drain output indicates charge status.&lt;br /&gt;
MAX1811 has preconditioning that soft-starts a near-dead battery cell before charging. Other safety features include continuous monitoring of voltage and current and initial checking for fault conditions before charging.&lt;br /&gt;
&lt;br /&gt;
Battery voltage monitor is hardware implemented by another Maxim's device: MAX8212.&lt;br /&gt;
MAX8212 is a CMOS micropower voltage detector that warn microprocessors/microcontroller of power failures. It contains a comparator, a 1.5V bandgap reference, and an open-drain n-channel output driver. Two external resistors are used in conjunction with the internal reference to set the trip voltage to the desired level. A hysteresis output is also included, allowing the user to apply positive feedback for noise-free output switching.&lt;br /&gt;
Using a couple of these device is possible to set two treshold: one for low battery and another for end battery detection. Low battery detection allow communicate the user battery level; end battery detection allow microprocessor shut down the device before battery voltage fall down under 3.4V that is the minimun input voltage allowed by linear regulator MCP1700.&lt;br /&gt;
If batterY level fall down under 3.4V, MCP1700 is not able to guarantee line regulation. &lt;br /&gt;
&lt;br /&gt;
[[Image:WAD_BAttery_Charge&amp;amp;Monitor_Final.jpg]]&lt;br /&gt;
&lt;br /&gt;
Power-up and shut-down are implemented using a Maxim's MAX16054 connected with an ADG801 by Analog Device.&lt;br /&gt;
MAX16054 is a pushbutton on/off controller with a single switch debouncer and built-in latch. It accepts a noisy input from a mechanical switch and produces a clean latched digital output after a factory-fixed qualification delay.&lt;br /&gt;
The state of the output changes only when triggered by the falling edge of the debounced switch input; the output remains unchanged on the rising edge of the input.An asynchronous CLEAR input allows an external signal to force the output flip-flop low.&lt;br /&gt;
1 MOhm resistor and 10 uF capacitor connected to power-on pushbutton allow to obtain a delay of about 3 seconds (with an internal 63KOhm pullup resistor)&lt;br /&gt;
&lt;br /&gt;
ADG801 is a monolithic CMOS, single-pole, single throw (SPST), normally open (NO) switch with on resistance of less than 0.4Ohm. This switch conducts equally well in both directions when on.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Students that have worked on the project==&lt;br /&gt;
&lt;br /&gt;
* Mattia Colombo (Blood Volume Pressure sensor)&lt;br /&gt;
* Alessia Cornaggia (Galvanic skin response sensor)&lt;br /&gt;
* Sala Mirko (Galvanic skin response sensor)&lt;br /&gt;
&lt;br /&gt;
== Laboratory work and risk analysis ==&lt;br /&gt;
&lt;br /&gt;
Laboratory work for this project will be mainly performed at AIRLab/Lambrate. It will include electrical and electronic activity. Potentially risky activities are the following:&lt;br /&gt;
* Use of mechanical tools. Standard safety measures described in [http://airlab.elet.polimi.it/index.php/airlab/content/download/461/4110/file/documento_valutazione_rischi_AIRLab.pdf Safety norms] will be followed.&lt;br /&gt;
* Use of soldering iron. Standard safety measures described in [http://airlab.elet.polimi.it/index.php/airlab/content/download/461/4110/file/documento_valutazione_rischi_AIRLab.pdf Safety norms] will be followed.&lt;br /&gt;
* Use of high-voltage circuits. Special gloves and a current limiter will be used. Standard safety measures described in [http://airlab.elet.polimi.it/index.php/airlab/content/download/461/4110/file/documento_valutazione_rischi_AIRLab.pdf Safety norms] will be followed.&lt;/div&gt;</summary>
		<author><name>PaoloVilla</name></author>	</entry>

	<entry>
		<id>https://airwiki.deib.polimi.it/index.php?title=File:WAD_Battery.jpg&amp;diff=9423</id>
		<title>File:WAD Battery.jpg</title>
		<link rel="alternate" type="text/html" href="https://airwiki.deib.polimi.it/index.php?title=File:WAD_Battery.jpg&amp;diff=9423"/>
				<updated>2009-11-20T12:54:14Z</updated>
		
		<summary type="html">&lt;p&gt;PaoloVilla: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>PaoloVilla</name></author>	</entry>

	<entry>
		<id>https://airwiki.deib.polimi.it/index.php?title=File:WAD_BAttery_Charge%26Monitor_Final.jpg&amp;diff=9422</id>
		<title>File:WAD BAttery Charge&amp;Monitor Final.jpg</title>
		<link rel="alternate" type="text/html" href="https://airwiki.deib.polimi.it/index.php?title=File:WAD_BAttery_Charge%26Monitor_Final.jpg&amp;diff=9422"/>
				<updated>2009-11-20T10:30:14Z</updated>
		
		<summary type="html">&lt;p&gt;PaoloVilla: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>PaoloVilla</name></author>	</entry>

	<entry>
		<id>https://airwiki.deib.polimi.it/index.php?title=File:WAD_UARTMux.jpg&amp;diff=9421</id>
		<title>File:WAD UARTMux.jpg</title>
		<link rel="alternate" type="text/html" href="https://airwiki.deib.polimi.it/index.php?title=File:WAD_UARTMux.jpg&amp;diff=9421"/>
				<updated>2009-11-20T10:29:07Z</updated>
		
		<summary type="html">&lt;p&gt;PaoloVilla: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>PaoloVilla</name></author>	</entry>

	<entry>
		<id>https://airwiki.deib.polimi.it/index.php?title=File:WAD_Micro_Final.jpg&amp;diff=9420</id>
		<title>File:WAD Micro Final.jpg</title>
		<link rel="alternate" type="text/html" href="https://airwiki.deib.polimi.it/index.php?title=File:WAD_Micro_Final.jpg&amp;diff=9420"/>
				<updated>2009-11-20T10:28:19Z</updated>
		
		<summary type="html">&lt;p&gt;PaoloVilla: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>PaoloVilla</name></author>	</entry>

	<entry>
		<id>https://airwiki.deib.polimi.it/index.php?title=Wireless_Affective_Devices&amp;diff=9419</id>
		<title>Wireless Affective Devices</title>
		<link rel="alternate" type="text/html" href="https://airwiki.deib.polimi.it/index.php?title=Wireless_Affective_Devices&amp;diff=9419"/>
				<updated>2009-11-20T10:26:15Z</updated>
		
		<summary type="html">&lt;p&gt;PaoloVilla: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{Project&lt;br /&gt;
|title=Wireless Affective Devices&lt;br /&gt;
|tutor=SimoneTognetti;MatteoMatteucci&lt;br /&gt;
|students=PaoloVilla&lt;br /&gt;
|resarea=BioSignal Analysis&lt;br /&gt;
|restopic=Affective Computing&lt;br /&gt;
|start=2008/01/08&lt;br /&gt;
|end=2009/12/30&lt;br /&gt;
|status=Active&lt;br /&gt;
|level=Ms&lt;br /&gt;
|type=Thesis&lt;br /&gt;
}}&lt;br /&gt;
==Project aims ==&lt;br /&gt;
&lt;br /&gt;
 ”''Everyone knows what an emotion is, until asked to give a definition''”&lt;br /&gt;
                                         &lt;br /&gt;
                                                                 Beverly Fehr and James Russell&lt;br /&gt;
&lt;br /&gt;
Research on Human-Computer-Interfaces has recently begun to take into account the affective state of the user. By appropriately reacting to the affective user state, interfaces could not only become more pleasant or entertaining, but also more effective or safer.&lt;br /&gt;
It is known that affective states have bodily correlates, and thus physiological signals could provide the necessary information for acquiring the affective user state. In contrast to other sources of information about the affective user state such as speech or facial expression, most physiological signals are not under voluntary control, and thus cannot be masked up to the same extent. Furthermore, it can be presumed that the signs of affective states in physiological signals are less dependent on individual and contextual factors: this is because the signals correspond to internal physiology, largely related to the autonomous nervous and limbic systems, rather than to external expressions that can be manipulated easily.&lt;br /&gt;
Recently, the issue of emotion regulation drew interests from several fields including neuroscience, psychology, education, computer science, etc. Possible applications are e-learningin, human computer interaction, development of communicative technologies for use by people with autism, car infotainment system, lie detection tests, cognitive workload, multimodal user interfaces MMUI (allow users to control computers using speech and gesture), etc.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The project is aimed at developing a device, connected to a PC, to acquire biological signals (such as GSR, BVP, Temperature and Head orientation) in a way that is less invasive for the subject. The term invasive is related to how much the sensors we use compromise the normal interaction between subject and machine.&lt;br /&gt;
Through these biological signal the PC is able o understand emotion in people who wear the device.&lt;br /&gt;
&lt;br /&gt;
An affective device should be weared easily, should not have cables and should acquire as much sensors as possible. We relax some constraint on the quality of signal but we add constraint on way they are acquired(i.e. the subject can put it on easily, the usual movements are not influenced..). The aim of the resulting device is not to replace the standard medical devices usually used to acquire that signals, but is to be much more suitable for industrial application in which the medical requirement are replaced by invasivity requirement.&lt;br /&gt;
&lt;br /&gt;
It is composed by:&lt;br /&gt;
&lt;br /&gt;
* Low power, high efficiency, battery powered design&lt;br /&gt;
* Wireless comunication with a PC&lt;br /&gt;
* Blood Volume Pressure Sensor (Preliminary release by Mattia Colombo)&lt;br /&gt;
* Galvanic Skin Response Sensor (Preliminary release by Sala Mirko e Alessia Cornaggia)&lt;br /&gt;
* Temperature Sensor&lt;br /&gt;
* 3 Way Accelerometer&lt;br /&gt;
* Possibility of further extension&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''GSR (or EDR or EDA)'''&lt;br /&gt;
&lt;br /&gt;
An often misunderstood and difficult technique, GSR (also known as the electrodermal response EDR or electrodermal activity EDA) has gone through many phases of interest and rejection since the early 1900's and is very popular in psychophysiological studies since Carl Jung and his students (1907) described it as a mean to&lt;br /&gt;
enter the “sea of the unconscious” because “every stimulus accompanied by an emotion produced a deviation of the galvanometer” directly proportional to the strength of the emotion aroused. It has been used in important research on anxiety and stress levels (Fenz &amp;amp; Epstein, ' 67); and it has been a part of lie detection (Raskin, ' 73). Controversy has centered around the technique, underlying mechanisms, and the meaning of the responses obtained from the skin. &lt;br /&gt;
There has been a long history of electrodermal activity research, even if most investigators accept the phenomenon without understanding exactly what it means (Hume, ' 76).&lt;br /&gt;
The resistance of the skin is usually large, approximately 1M; however, momentary changes in the level of the sweat gland activity causes changes in resistance (up to approximately 950K).&lt;br /&gt;
Physiology, the GSR reflescts sweat gland activity and changes in the sympathetic nervous system and measurement variables. The activity of the sweat glands in response to sympathetic nervous stimulation ( Increased sympathetic activation ) results in an increase in the level of conductance. There ia a relationship between sympathetic activity and emotional arousal, although one cannot identify the specific emotion being elicited. &lt;br /&gt;
Basically there are two techniques in the history of Electrodermal measurement. In one a current is passed thru the skin and the the resistance to passage is measured; in the other no current is used externally and the skin itself is the source of electrical activity.&lt;br /&gt;
By applying a conventional 0.5 Volts across the skin and measuring changes in the&lt;br /&gt;
corresponding conductance, the emotional state of the subject can be inferred. In general, the electrodes used are of the Ag/AgCl type which are recessed from the skin and require the use of a suitable electrode paste.&lt;br /&gt;
It is important to note, however, that fluctuations in skin conductivity are resultant of many types of arousal.&lt;br /&gt;
By observing only these changes, it is impossible to deduce without prior knowledge whether&lt;br /&gt;
the subject has become happy, startled, physically active, etcetera.&lt;br /&gt;
EDA consists of two components: tonic and phasic. The tonic component is a low&lt;br /&gt;
frequency baseline conductivity level, which can oscillate over the course of days. The phasic&lt;br /&gt;
component rides on top of the tonic component, exhibits more rapid fluctuations, and&lt;br /&gt;
generally increases when a person is aroused. Problematically, each person has a different&lt;br /&gt;
tonic conductivity, so in order to infer the arousal level of the subject, the relative changes in&lt;br /&gt;
EDA must be analyzed over a period of time. Furthermore, skin conductance (measured in&lt;br /&gt;
units of siemens; formerly mhos) depends on the skin path length between the two electrodes&lt;br /&gt;
contacts, even for subjects with identical skin conductivity (measured in units of&lt;br /&gt;
siemens/meter). It is for these reasons that it is crucial to analyze the temporal variations of&lt;br /&gt;
the EDA signal.&lt;br /&gt;
&lt;br /&gt;
'''BVP'''&lt;br /&gt;
&lt;br /&gt;
The cardiovascular system is in charge to keep us alive by maintaining the vital blood flow throughout the body, providing nutrients and oxygen to our cells. The SNS controls this system&lt;br /&gt;
by shifting the flow in response to exercise, temperature,postural and emotional changes.&lt;br /&gt;
Blood Volume Pulse (BVP) is the most common measure of vasomotor activity because it reflects the phasic pumping of the heart, the vasodilation of vessels that changes in the amount of acral blood delivered.&lt;br /&gt;
The Blood Volume Pulse (BVP) waveform is an important indicator of circulatory function that can be obtained noninvasively through a photoplethysmographic transducer (a PPG is often obtained by using a pulse oximeter, Shelley and Shelley, 2001) applied to the finger or the earlobe of human subjects. In particular, this signal may be useful in determining the degree of cardiovascular change undergone by a subject through an exercise session. &lt;br /&gt;
&lt;br /&gt;
''Principles of photoplethysmographic Technology:''&lt;br /&gt;
&lt;br /&gt;
The principle of photoplethysmographic (That is the same of pulse oximetry) is based on the red and infrared light absorption characteristics of oxygenated and deoxygenated hemoglobin. Oxygenated hemoglobin absorbs more infrared light and allows more red light to pass through. Deoxygenated (or reduced) hemoglobin absorbs more red light and allows more infrared light to pass through. Red light is in the 600-750 nm wavelength light band.&lt;br /&gt;
Pulse oximetry uses a light emitter with red and infrared LEDs that shines through a reasonably translucent site with good blood flow. Opposite the emitter is a photodetector that receives the light that passes through the measuring site.&lt;br /&gt;
There are two methods of sending light through the measuring site: transmission and reflectance. In the transmission the emitter and photodetector are opposite of each other with the measuring site in-between. The light can then pass through the site. In the reflectance method, the emitter and photodetector are next to each other on top the measuring site. The light bounces from the emitter to the detector across the site. The transmission method is the most common type used.&lt;br /&gt;
While pulse oximeters are a commonly used medical device the PPG derived from them is rarely displayed, and is nominally only processed to determine heart rate. &lt;br /&gt;
&lt;br /&gt;
'''Temperature'''&lt;br /&gt;
&lt;br /&gt;
The temperatures of peripheral limbs vary as a consequence of changes in blood flow.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== '''Previous work''' ==&lt;br /&gt;
&lt;br /&gt;
Here is a preliminary release of the headset produced before 2008/08/08&lt;br /&gt;
&lt;br /&gt;
[[Image:Wd1.jpg]]&lt;br /&gt;
&lt;br /&gt;
If you are interested on the making of the headset please see [[making rubber models]]&lt;br /&gt;
&lt;br /&gt;
'''* Blood Volume pressure'''&lt;br /&gt;
First graph showing a signal acquired with the wireless sensor. &lt;br /&gt;
[[Image:Bvp.png]]&lt;br /&gt;
&lt;br /&gt;
'''* Skin galvanic response''' (Sala Mirko e Alessia Cornaggia[http://airwiki.elet.polimi.it/mediawiki/index.php/User:AlessiaCornaggia])&lt;br /&gt;
Galvanic skin response (GSR), also known as electrodermal response (EDR), psychogalvanic reflex (PGR), or skin conductance response (SCR), is a method of measuring the electrical resistance of the skin.  There is a relationship between sympathetic activity and emotional arousal, although one cannot identify the specific emotion being elicited. The GSR is highly sensitive to emotions in some people. Fear, anger, startle response, orienting response and sexual feelings are all among the emotions which may produce similar GSR responses.&lt;br /&gt;
Response of the skin to the passage of a small electric current. The ease with which the current flows between two points on the skin can be used to indicate stress. When a person is tense or emotional, the sweat glands become more active, increasing moisture on the skin; this allows the electric current to flow more readily. &lt;br /&gt;
The response may also be used in relaxation training: information about the galvanic skin response is fed back aurally or visually to the subject who can, with practice, learn to increase or decrease sweating on the skin by learning to relax or tense muscles.&lt;br /&gt;
We measure the galvanic skin response using two electrodes attached to the skin. The optimal placement is the palm of the hands, but we are experimenting other places like on the forehead.&lt;br /&gt;
The circuit we are creating is the one below.&lt;br /&gt;
&lt;br /&gt;
[[Image:circuito.jpg]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== '''Project the device''' ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== '''Re-definition of the complete work''' ===&lt;br /&gt;
&lt;br /&gt;
Sensors are an important part of an Affective Computing System because they provide information about the wearer's physical state or behavior. They can gather data in a continuous way without having to interrupt the user. &lt;br /&gt;
To define in detail electronic specifications and requirements it's necessary a preliminary research/study (in literature and web) about state of art of sensor type used to monitor each type of biological signals we are interested about.&lt;br /&gt;
In this way it's possible both understand problematics related to interaction between biological and electonical worlds and improve or re-desig existing prototype.&lt;br /&gt;
&lt;br /&gt;
About Sensors: &lt;br /&gt;
&lt;br /&gt;
BVP will be acquire by an IR transmitter-receiver measuring light reflected from skin (photoplethysmography). Particular attention will be put on position, geometry and power absorption of this stage. &lt;br /&gt;
&lt;br /&gt;
GSR will be acquiret by a couple of electrodes forcing a low current (or voltage) and reading voltage (or current) through electrodes. Particular attention will be put on electrodes position and material. In addition is possible to foresee some problems in amplifier stage due to large range of skin resistance. Problem consist in chosing a correct amplification to overwork ADC full scale with a signal affected by little variation but huge possible range. &lt;br /&gt;
&lt;br /&gt;
Temperature will be acquired by thermocouple or PTC/NTC. Slowly variable signal, possible problems with noise due to resolution required. &lt;br /&gt;
&lt;br /&gt;
Head orientation will be acquired by an accelerometer and a gyroscope, problably integrated in the same chip. Two possibilities: analog output (need to digitalize up to six line) or digital output (like displaied in schematic block diagram). &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
This was the preliminary simplified schematic block diagram of the complete instrumentation setup:&lt;br /&gt;
&lt;br /&gt;
[[Image:WADSchematicDiagram01.jpg]]&lt;br /&gt;
&lt;br /&gt;
 NOTE:&lt;br /&gt;
 &lt;br /&gt;
 * In schematic is not present Power Supply Module: it will be based on a rechargeable Li-ion&lt;br /&gt;
 battery. It must satisfy requirements of high efficiency, logn life and low weight.&lt;br /&gt;
 &lt;br /&gt;
 * ADC and Microcontroller could be unified using a microcontroller with internal ADC and&lt;br /&gt;
 internal or external multiplexer to select lines.&lt;br /&gt;
 &lt;br /&gt;
 * Wireless section could be implemeted in Bluetooth (instead of using a XBee module like in&lt;br /&gt;
 preliminary release) due to it's diffusion in cellular phones, notebooks, MP3 reader...&lt;br /&gt;
 without necessity of external modules.&lt;br /&gt;
&lt;br /&gt;
It was based on a theoretical approach to any single part. Any sensing device was designed in &amp;quot;conventional&amp;quot; way founded on analog electronic (a bridge with a NTC resisistance as sensing element, discrete IR led and some photodiode around to capture the most reflefted light as possible, GSR electrodes on the gain arm of a non-inverting amplifier...).&lt;br /&gt;
Unfortunatly a deep analysis on signal physiology, signal transduction, noise vs required accurancy, forced us to a completely different approach implementing everywhere possible a digital interface.&lt;br /&gt;
&lt;br /&gt;
=== '''Sensors Design''' ===&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''BVP'''&lt;br /&gt;
&lt;br /&gt;
Discrete IR leds and phototransistor, used in the first realize (see fig.), had been replaced first with a single led and one or more photodiodes to optimize power consumption in case of non-planar sensor positioning. Subsequently an integrated Reflective Object Sensor was introduced, with benefits about space saving, transmitter-receiver matching and power consumption.&lt;br /&gt;
To ensure light power stability, led is powered through a linear led drive LDO (Low Drop-Out). The choise of linear LDO is necessary to ensure no noise or spikes would be generated by charge pump systems or boost converters. In addition, the linear drive utilized requires only one external resitor to set led current and a decoupling capacitor, reducing part counts and board space occupation.&lt;br /&gt;
The couple factor of the reflex sensors is relatively small, even in the case of good reflecting surfaces. Therefore an additional amplifier is necessary at the sensor output: classic trans-impedance amplifier used with photo-diodes and photo-transistors was introduced. This circuit features an output voltage that is a linear function of the light level on the photo-transistor. The gain is set by the feedback resistor which could be in the millions of ohms. Linear operation is achieved by operating the photo device with a fixed voltage drop across it.&lt;br /&gt;
Trans-impedance amplifier is followed by an active fourth order band-pass filter (0.5Hz-5Hz): it's composed cascading two second order bandpass cells. In first project session only a single cell was used, but a deeper study combined with previous experiences suggests to use a 4th order filter to reduce 50Hz interference (50Hz interference produced by mains is placed only a decade after the filter pole).&lt;br /&gt;
Filter is followed by a VGA (Variable Gain Amplifier) digitally controlled through I2C Bus that allows to optimize dinamically ADC input signal amplitude directly during acquisition session, obtaining the best performance from ADC.&lt;br /&gt;
The resulting circuit is quite compact (led drive, reflective sensor, trans-impedence amplifier, active filter and variable-gain amplifier), doesn't require much power and represents a good mix between analog and digital approach: analog front-end with acquisition and first conditioning, and at the chain-end a digital controlled amplifier to ensure flexibility.&lt;br /&gt;
&lt;br /&gt;
[[Image:WADBVPComparison.jpg]]&lt;br /&gt;
&lt;br /&gt;
'''GSR'''&lt;br /&gt;
&lt;br /&gt;
GSR will be acquired by a couple of electrodes forcing a low voltage and reading current through electrodes. First designs and implementations were based on literature study: best solution appears to put GSR electrodes on the gain arm of a non-inverting amplifier (see fig.) rather than using a Wheatstone bridge due to week signal produced by this solution.&lt;br /&gt;
Putting GSR electrodes on the gain arm produces a sort of gain modulation of the constant voltage applied between electrodes but doesn't solve problems in amplifier stage due to large range of skin resistance.&lt;br /&gt;
Problems in chosing correct amplification to overwork ADC full scale with a signal affected by little variation but huge possible range could be reduced usign a variable resistor on gain arm (for example a digital potentiometer controlled by the microcontroller), but cannot be completely removed. In addition little signals are easily deteriorated by noise.&lt;br /&gt;
Solution is provided considering a new point of view: measure of unknown skin resistence is extremely similar to measure unknown electrical impedence with an auto-range multimeter!&lt;br /&gt;
Solution consist in a digital Impedance Converter: AD5934 is a high precision impedance converter system which combines an on-board frequency generator with a 12-bit, 250 kSPS, analog-to-digital converter (ADC). The frequency generator allows an external complex impedance to be excited with a known frequency; the response signal from the impedance is sampled by the on-board ADC and a discrete Fourier transform (DFT) is processed by an on-board DSP engine. The DFT algorithm returns a real (R) and imaginary (I) data-word at each output frequency. This solution not only allows to measure impedence range from 100 Ohm to 10 MOhm, but in adition allow to investigate it across a wide range of frequency, producing a noise-free digital output.&lt;br /&gt;
The resulting circuit is extremely compact (converter chip, one setting resistor and bypass capacitors), provides a system accuracy of 0.5% and connects to microcontroller using I2C interface, ensuring an high flexibility and the possibility to modify acquisition settings after board production (through microcontroller firmware).&lt;br /&gt;
&lt;br /&gt;
[[Image:WADGSRComparison.jpg]]&lt;br /&gt;
&lt;br /&gt;
'''Temperature'''&lt;br /&gt;
&lt;br /&gt;
First idea was to acquire temperature by a NTC connected in a Wheatstone bridge. Trying to reduce noise, bridge was powered by an oscillator circuit with a frequency of some KHerz, to translate signal out of 1/f noise region. Bridge outputs were connected to an INA amplifier wich also implements signal filtering (see fig.).&lt;br /&gt;
Weak signal, noise and resolution required (0.1°C) put in crisis the system. In addition other unsolved problems were the optimization of thermal and mechanical contact between sensor and body and the sensor large thermic constant. Unstable thermic contact produces unreliable measures, whereas high sensor thermic constant hampers a fast sensor response (needed to detect short peak due to emotional reactions).&lt;br /&gt;
Possible solutions to problems of weak signal and noise arrive from digital integrated temperature sensor (for example LM35 or LM74), but these don't solve the problem of thermal contact and thermal constant. In addition none of the sensors take in consideration provides the required resolution.&lt;br /&gt;
High resolution required, noise immunity, fast response and thermal contact immunity problems had been solved using a digital optical infra red thermometer. The MLX90614 is an infra red thermometer for non contact temperature measurements based on a thermopile detector chip including signal conditioning in the same TO-39 package. Thanks to its low noise amplifier, 17-bit ADC and powerful DSP unit, a high accuracy and resolution of the thermometer is achieved.&lt;br /&gt;
The calculated object and ambient temperatures are available in RAM of MLX90614 with 0.02°C resolution: they are accessible by 2 wire serial SMBus compatible protocol. A special version for medical applications offers an accuracy of ±0.1ºC in a limited temperature range around the human body temperature.&lt;br /&gt;
Small size, no external component requirements and power saving mode allow us to obtain a perfect matching between required performances and space saving.&lt;br /&gt;
&lt;br /&gt;
[[Image:WADTemperatureComparison.jpg]]&lt;br /&gt;
&lt;br /&gt;
'''Accelerometer'''&lt;br /&gt;
&lt;br /&gt;
Head orientation and movements will be acquired by an accelerometer. First we think to utilize an ST Microelectronic LIS3L02AS4, due to the availability in the Lab of the evaluation board STEVAL-MKI001. It is a 3-axis ±2g/±6g linear accelerometer with 3 analog outputs, so it requires an external ADC to digitalize the three axis acceleration values. The conversion could be performed by a microcontroller with internal ADC.&lt;br /&gt;
A fast Internet research reveled this sensor is now obsolete and out of production. The choise had been to substitute the old chip with the new one: the LIS302DL (still produced by ST Microelectronic). It's a 3-axis, ± 2g/± 8g smart digital output accelerometer with I2C/SPI digital output interface and really small package. The device is capable of measuring accelerations with an output data rate of 100 Hz or 400 Hz and the self-test capability allows the user to check the functioning of the sensor in the final application.&lt;br /&gt;
In addition it may be configured to generate inertial wake-up/free-fall interrupt signals when a programmable acceleration threshold is crossed at least in one of the three axes. Thresholds and timing of interrupt generators are programmable by the end user on the fly.&lt;br /&gt;
This device, providing a digital output, doesn't need signals conversion, guaranteing better noise immunity; programmable interrupts and test interface allow greater fexibility in project. In addition wery small package, only one external resistor requirement (plus baypass capacitor) reduce significantly board space requirements.&lt;br /&gt;
&lt;br /&gt;
[[Image:WADAccelerometer.jpg]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
 NOTE:&lt;br /&gt;
 &lt;br /&gt;
 * In previous schematics, components phisical dimensions are not in scale.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== '''Microcontroller''' ===&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Foundamental requirements:&lt;br /&gt;
&lt;br /&gt;
- High speed to ensure high data output rate even in presence of a large number af sensing elemets;&lt;br /&gt;
&lt;br /&gt;
- Fast Internal ADC with multiple inputs;&lt;br /&gt;
&lt;br /&gt;
- (At Least) One I2C interface;&lt;br /&gt;
&lt;br /&gt;
- (At Least) One SPI interface;&lt;br /&gt;
&lt;br /&gt;
- (At Least) One UART interface;&lt;br /&gt;
&lt;br /&gt;
- Low-power consumption;&lt;br /&gt;
&lt;br /&gt;
- Power supply 3.3V;&lt;br /&gt;
&lt;br /&gt;
- Small package;&lt;br /&gt;
&lt;br /&gt;
In addition microcontroller was chosen between Microchip PIC family devices, due to positive previous experiences and availability of software and programmer in the Lab.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
PIC24HJ256GP206 is a 16 bit microcontroller capable of 40 MIPS speed. It provides 256KB of Flash memory, 16KB of Ram, a 10-bit 1.1Msps or 12-bit 500Ksps ADC, UART, SPI and I2C interface in a 64 pin TQFP package (10mmX10mm) powerd between 3.0V and 3.6V.&lt;br /&gt;
Power core is provided by an internal regulator reducing parts count on the board.&lt;br /&gt;
&lt;br /&gt;
The device is able to provide at the same time one I2C interface, two SPI interface and one UART interface: another UART port shares pins with an SPI port and a second I2C port shares pins with the second UART interface.&lt;br /&gt;
Findig a device that provides at the same time, on indipendent pins, an I2C, a SPI and an UART interface reduces considerably possible choises and suggests to chose a high performance microcontroller.&lt;br /&gt;
At the same time, high performance solutions have a larger pin counts than standard microcontroller, but this characteristic can be used to ensure further expansibility to the system. The second SPI interface can be used to connect another &amp;quot;intelligent&amp;quot; device or a mass storage device, for example a SD (Secure Digital) card to storage acquired data (see fig.).&lt;br /&gt;
&lt;br /&gt;
[[Image:WADSDCard.jpg]]&lt;br /&gt;
&lt;br /&gt;
Input pins connected to ADC and not used at the moment could be collected to a connector for further extension modules (for example an EMG or ECG peripheral or any other analog signal interesting in a particolar application).&lt;br /&gt;
For the same reason any other pin non used at the current stage is reported to an extension connector.&lt;br /&gt;
To guarante maximum flexibility an further update, board provides both ICD and JTAG connections (allowing on-board programming and debugging) through a couple of indipendent dedicated connectors fully compatibles with Microchip programmers and evaluation boards.&lt;br /&gt;
&lt;br /&gt;
[[Image:WADMicro.jpg]]&lt;br /&gt;
&lt;br /&gt;
=== '''Wireless Connection''' ===&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Wireless connection is based on BlueGiga WT12 module: it's a next-generation, class 2, Bluetooth 2.0+EDR (Enhanced Data Rates) module containing all the necessary elements from Bluetooth radio to antenna and a fully implemented protocol stack.&lt;br /&gt;
By default WT12 module is equipped with powerful and easy-to-use iWRAP firmware that enables users to access Bluetooth functionality with simple ASCII commands delivered to the module over serial interface like a Bluetooth modem.&lt;br /&gt;
The dedicated onboard microcontroller (MCU) acts as interrupt controller and event timer run the Bluetooth software stack and control the radio and host interfaces. A 16-bit reduced instruction set computer (RISC) microcontroller is used for low power consumption and efficient use of memory.&lt;br /&gt;
WT12 module support USB, SPI and UART interface and UART interface is used in this project to connect PIC microcontroller to wireless transmitter (see fig.).&lt;br /&gt;
&lt;br /&gt;
[[Image:WADWireless.jpg]]&lt;br /&gt;
&lt;br /&gt;
One of the most important WT12 characteristic is the high integration between all parts needed for efficent Bluetooth transmission: user interface, controller, radio circuits and antenna, all included in a low power, low size board (25.6mmx15mm) that requires a minimum number of external components.&lt;br /&gt;
Many other bluetooth components ara available, such as LMX9830, produced by National Semiconductor. It's an extremely small device (only 6.1mm×9.1 mm), but requires a number of external components (see fig.) like oscillators, resistors, capacitors, inductors and the antenna, in addition to an high competence in radio frequency layout circuits.&lt;br /&gt;
&lt;br /&gt;
[[Image:WADLMX9830.jpg]]&lt;br /&gt;
&lt;br /&gt;
Lack of experience in radio frequency circuit suggests to chose a ready-to-use module, factory optimized for best performance and easy to integrate in our board.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
This is the updated simplified schematic block diagram:&lt;br /&gt;
&lt;br /&gt;
[[Image:WADSchematicDiagram02.jpg]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== '''Prototype realization [WIP (Work in Progress)]''' ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Fist stage plans to realize a board using, where possible, through-hole (TH) compenents soldered on a prototyping board (100x160mm) powered from a laboratory power supply (instead of Li-on battery) and not implementing bluetooth wireless transmission. Parts not available on TH package are used with special SMD-&amp;gt;TH adapter boards or simply fixing and soldering them to the PCB by wires.&lt;br /&gt;
&lt;br /&gt;
Second stage plans to realize microcontoller firmware and test it acquiring biological signals from a patient. Firmware will be developed by subsequently steps, implementing and testing only a single peripheral at each time: only at the end single pheripheral softwares will be merged together.&lt;br /&gt;
&lt;br /&gt;
Third stage will be bluetooth interface (hardware and software) implementation and integration on the board with transmission test.&lt;br /&gt;
&lt;br /&gt;
Fourth stage will consider power supply optimization with battery management and recharge interface.&lt;br /&gt;
&lt;br /&gt;
Finally, only after a successful full board test, the last stage will be the circuit layout design with an electronic CAD, using where possible, Surface Mount Devices (SMD) to reduce board area.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== '''Main board''' ===&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Main board include power supply regulator with led power-on indicator, PIC microcontroller (mounted on a SMD-&amp;gt;TH adapeter board) with basic circuitry (decoupling capacitors, oscillator and programming-debugging ICD interface), a status led connected to PIC to verify basic microcontroller function, a series of connectors for add-on modules (BVP, GSR, temperature and accelerometer) and a USB PC interface not considered before.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== '''USB interface''' ===&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
USB interface, not projected before, replaces in developing stage Bluetooth interface, allowing a direct control/communication with a PC. In this prototype PIC UART, althought being connected to Bluettoth module, is connected to a FTDI FT232RL chip. The FT232RL is the latest device to be added to FTDI’s range of USB UART interface Integrated Circuit Devices. USB to serial designs using the FT232RL have been further simplified by fully integrating the external EEPROM, clock circuit and USB resistors onto the device.&lt;br /&gt;
The FT232RL is available in Pb-free (RoHS compliant) compact 28-Lead SSOP, so this require another SMD-&amp;gt;TH board adapter but the circuit design is very simple, including two status led for TX and RX operations. An USB B female connector was eputated the best choise for PC connection allowing to use a simple USB printer cable.&lt;br /&gt;
&lt;br /&gt;
[[Image:WADUSBInterface.jpg]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Note that USB and Bluetooth must not be connected to the board at the same time! USB port has only a developent function.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== '''BVP''' ===&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Circuit designed for BVP acquisition (refer to previous schematic) doesn't meet the expected results. Week signal hanged by noise suggested us to re-design the circuit simplifying it and reducing the number of components. For this design also sensing element has been substitute. Instead of an integrated reflective IR sensor (SFH9202), new project use a couple af discrete IR led and photothansistor matched: SFH487 and SFH309FA.&lt;br /&gt;
SFH487 is a very highly efficient GaAlAs infrared emitter (880 nm) and SFH309FA is a silicon NPN phototransistor especially suitable for applications of 880 nm with an high linearity. Both have a 3 mm led plastic package, are spectrum-matched and receiver is ambient-light shilded. After a series of positive test without the led driver (not used due to the really reduced mechanical dimensions), also led drive circuit was removed and replaced with a resistance connected directly to a PIC pin.&lt;br /&gt;
This choise reduces parts count and board space required without making worse sistem performance, allowing (like led driver) to turn off the sensor led when not used to reduce power consumption.&lt;br /&gt;
&lt;br /&gt;
[[Image:WADBVPNew.jpg]]&lt;br /&gt;
&lt;br /&gt;
Even if operation amplifier used are half of before, double second-order filter stage is manteined. In addition to filtering, these opamp privide a first gain (note that in previous design filtering stages works as a unitary buffer in pass-band) allowing a high signal at VGA (variable gain amplifier) input stage allowing a better SNR.&lt;br /&gt;
1N4148 diode provides a sort of ofsetted virtual ground, shifting up all signals but not being amplified through the amplification chain.&lt;br /&gt;
Figure show the signal measured directly on filtering stage output (TS952 pin 7) before the VGA with a Tektronix scopemeter TDS2014B. No particular triks had been used: signal has been recorded the first time circuit was assembled on a protoboard.&lt;br /&gt;
&lt;br /&gt;
[[Image:WADBVPScope03.jpg]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== '''GSR''' ===&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
First approach with AD5934 resulted really hard due to some errors occurred in control software in relation with internal chip complexity and I2C bus protocol. &lt;br /&gt;
After a sart session with the AD5934, GSR hardware acquisition interface was further simplified replacing it with AD5933 (refer to schematic). AD5933 has the same pinout and functions of AD5934 but provides also an internal oscillator at 16.776MHz allowing no external crystal connection. A temperature sensor that allow the user to measure chip temperature and 1 MSPS Converter (instad of a 250KSPS one) are the only other differences between the tho integrated semiconductor produced by Analog Devices.&lt;br /&gt;
On the other hand AD5934 has a larger impedance measurement range that goes from 100 Ohm to 10 MOhm in opposition to AD5933 that can only measure impedences between 1 Ohm and 10 MOhm. Because of the high skin impedence values (in the range of MOhm for dry fingers skin), this is not a problem in our application.&lt;br /&gt;
&lt;br /&gt;
[[Image:WADGSRNew.jpg]]&lt;br /&gt;
&lt;br /&gt;
First dataset acquired whith the correct control software and the correct data reading routine, has shown all the potentiality of this chip, providing data comparables with RAW data acquired with a bigger and very expensive professional equipement produced by ProComp.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== '''ACCELERATION''' ===&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Lis302DL datasheet gives a short definition of this chip as &amp;quot;MEMS motion sensor 3-axis - ± 2g/± 8g smart digital output “piccolo” accelerometer&amp;quot; and it is really very, very small for human-working. For this space saving quality this accelerometer is also use in third generation Apple i-phone.&lt;br /&gt;
The major problem with this sensor had been to solder it to a sort of adapter to connect it to the circuit, but after that it works fine, with a good sensitivity and accuracy. Because of free fall and double click recognition at not required (at the moment) in this application, software routines for setting configuration registers and reading data resulted simplified.&lt;br /&gt;
A usefull caracteristic of this sensor, not previously noticed, is the presence of internal pull-up resistors that allows no necessity of external I2C bus pull-up resistors, reducing space occupation and components count.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== '''TEMPERATURE''' ===&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The choice to use MLX90614 due to his characteristics (non contact measure, 0.02°C resolution with accuracy of ±0.1°C for medical applications version) creates a really serious supplies problem: Melexis (sensor manufacture) wasn't able to give us a sample and no one in Italy can sell us only a pair of theese sensors to try them. A single piece was bought from Future Electronics, ordering it via web and paying it via credit card. Fortunately the sensor, that cames directly from USA, arrived in Italy few days later the payment in excellent conditions.&lt;br /&gt;
&lt;br /&gt;
[[Image:WADMLX90614.jpg]]&lt;br /&gt;
&lt;br /&gt;
Problems occurred interfacing this sensor on I2C bus with other devices (AD5933 and LIS302) connected. MLX90614 has a 2 wire serial SMBus compatible protocol: I2C bus and  SMBus are popular 2-wire buses that are essentially compatible with each other, but are not the same.&lt;br /&gt;
The buses operate at the same speed, up to 100kHz, but the I2C bus has both 400kHz and 2MHz versions. Complete compatibility between both buses is ensured only below 100kHz.&lt;br /&gt;
Timeout and (as a consequence of timeout) minimum clock speed are the most important differences between the I2C bus and the SMBus:&lt;br /&gt;
&lt;br /&gt;
I2C Bus = DC (no timeout)&lt;br /&gt;
&lt;br /&gt;
SMBus = 10kHz (35mS timeout)&lt;br /&gt;
&lt;br /&gt;
Despite differences in logic-level specifications between the two buses, generally devices can be mixed and matched with abandon.&lt;br /&gt;
Level Specifications for the I2C Bus and the SMBus are shown below (VDD is typically expected to be between 3 volts and 5 volts):&lt;br /&gt;
&lt;br /&gt;
[[Image:WADTable1.jpg]]&lt;br /&gt;
&lt;br /&gt;
What wasn't readily evident in the discussion of voltage levels is that these levels are also specified with different currents between the buses. The SMBus specifies a minimum sink current of 100microA, and a maximum of 350microA, compared to 3mA for the I2C bus. This in turn would determine the lowest acceptable value of the pullup resistor, examples of which are shown in the table below.&lt;br /&gt;
&lt;br /&gt;
[[Image:WADTable2.jpg]]&lt;br /&gt;
&lt;br /&gt;
In reality, it is not unusual to encounter pullup resistor values in SMBus systems, which violate this specification by being lower than recommended. A very popular range for pullup resistor values, even in some SMBus systems, seems to be 2.4k to 3.9k.&lt;br /&gt;
&lt;br /&gt;
These reasons, in adition to clear ideas about close developments, suggest a general review of schematic to re-distribute microcontroller resources.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== '''Part 6: final review [WIP (Work in Progress)]''' ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== '''Microcontroller''' ===&lt;br /&gt;
&lt;br /&gt;
Referring to previous schematic, some chenges had been applied:&lt;br /&gt;
&lt;br /&gt;
- Programmer/Debugger interface is now PGD1/EMUD1 and PGC1/EMUC1 instead of PGD1/EMUD2 and PGC1/EMUC2;&lt;br /&gt;
&lt;br /&gt;
- JTAG interface had been removed;&lt;br /&gt;
&lt;br /&gt;
- UART2 is no more available so UART1 has replaced UART2 as communication port;&lt;br /&gt;
&lt;br /&gt;
- SPI2 is no more available so SPI1 is now used to control both LMP8100 VGA (Variable Gain Amplifier) and SD Storage Card;&lt;br /&gt;
&lt;br /&gt;
- RG12, RG13, RG14 pins had been connected to three status led for a machine visual state detection;&lt;br /&gt;
&lt;br /&gt;
- I2C1 interface is now connected to accelerometer (LIS302) and GSR (AD5933) only;&lt;br /&gt;
&lt;br /&gt;
- I2C2 interface is dedicated to temperature sensor (MLX90614), enabling I/O pin thresholds compliant with SMBus specification;&lt;br /&gt;
&lt;br /&gt;
- Connectors for I2C, SMBus and SPI expansion modules had been added to the board;&lt;br /&gt;
&lt;br /&gt;
- Test point pads had been added to the board to simplify debugging.&lt;br /&gt;
&lt;br /&gt;
That's the complete microcontroller schematic diagram:&lt;br /&gt;
&lt;br /&gt;
[[Image:WAD_Micro_Final.jpg]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== '''Data link''' ===&lt;br /&gt;
&lt;br /&gt;
During developing stages, an USB port had replaced Bluetooth wireless transmission, allowing a direct control/communication with a PC. This interfaced, based on a FT232RL, prove to be very usefull and simple to use.&lt;br /&gt;
The choice to use an usb port to charge internal battery, in addition to availability of a UART multiplexer inside the Bluetooth module BlueGiga WT12, suggest to implement both USB and Bluetooth interface.&lt;br /&gt;
&lt;br /&gt;
That's the BlueGiga WT12 internal UART multiplexer schematic:&lt;br /&gt;
&lt;br /&gt;
[[Image:WAD_UARTMux.jpg]]&lt;br /&gt;
&lt;br /&gt;
The complete data link schematic diagram:&lt;br /&gt;
&lt;br /&gt;
[[Image:WAD_USB+Bluetooth_Final.jpg]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== '''Battery Charge &amp;amp; Monitor''' ===&lt;br /&gt;
&lt;br /&gt;
[[Image:WAD_BAttery_Charge&amp;amp;Monitor_Final.jpg]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Students that have worked on the project==&lt;br /&gt;
&lt;br /&gt;
* Mattia Colombo (Blood Volume Pressure sensor)&lt;br /&gt;
* Alessia Cornaggia (Galvanic skin response sensor)&lt;br /&gt;
* Sala Mirko (Galvanic skin response sensor)&lt;br /&gt;
&lt;br /&gt;
== Laboratory work and risk analysis ==&lt;br /&gt;
&lt;br /&gt;
Laboratory work for this project will be mainly performed at AIRLab/Lambrate. It will include electrical and electronic activity. Potentially risky activities are the following:&lt;br /&gt;
* Use of mechanical tools. Standard safety measures described in [http://airlab.elet.polimi.it/index.php/airlab/content/download/461/4110/file/documento_valutazione_rischi_AIRLab.pdf Safety norms] will be followed.&lt;br /&gt;
* Use of soldering iron. Standard safety measures described in [http://airlab.elet.polimi.it/index.php/airlab/content/download/461/4110/file/documento_valutazione_rischi_AIRLab.pdf Safety norms] will be followed.&lt;br /&gt;
* Use of high-voltage circuits. Special gloves and a current limiter will be used. Standard safety measures described in [http://airlab.elet.polimi.it/index.php/airlab/content/download/461/4110/file/documento_valutazione_rischi_AIRLab.pdf Safety norms] will be followed.&lt;/div&gt;</summary>
		<author><name>PaoloVilla</name></author>	</entry>

	<entry>
		<id>https://airwiki.deib.polimi.it/index.php?title=File:WAD_USB%2BBluetooth_Final.jpg&amp;diff=9418</id>
		<title>File:WAD USB+Bluetooth Final.jpg</title>
		<link rel="alternate" type="text/html" href="https://airwiki.deib.polimi.it/index.php?title=File:WAD_USB%2BBluetooth_Final.jpg&amp;diff=9418"/>
				<updated>2009-11-20T10:25:41Z</updated>
		
		<summary type="html">&lt;p&gt;PaoloVilla: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>PaoloVilla</name></author>	</entry>

	<entry>
		<id>https://airwiki.deib.polimi.it/index.php?title=Wireless_Affective_Devices&amp;diff=9417</id>
		<title>Wireless Affective Devices</title>
		<link rel="alternate" type="text/html" href="https://airwiki.deib.polimi.it/index.php?title=Wireless_Affective_Devices&amp;diff=9417"/>
				<updated>2009-11-20T10:24:02Z</updated>
		
		<summary type="html">&lt;p&gt;PaoloVilla: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{Project&lt;br /&gt;
|title=Wireless Affective Devices&lt;br /&gt;
|tutor=SimoneTognetti;MatteoMatteucci&lt;br /&gt;
|students=PaoloVilla&lt;br /&gt;
|resarea=BioSignal Analysis&lt;br /&gt;
|restopic=Affective Computing&lt;br /&gt;
|start=2008/01/08&lt;br /&gt;
|end=2009/12/30&lt;br /&gt;
|status=Active&lt;br /&gt;
|level=Ms&lt;br /&gt;
|type=Thesis&lt;br /&gt;
}}&lt;br /&gt;
==Project aims ==&lt;br /&gt;
&lt;br /&gt;
 ”''Everyone knows what an emotion is, until asked to give a definition''”&lt;br /&gt;
                                         &lt;br /&gt;
                                                                 Beverly Fehr and James Russell&lt;br /&gt;
&lt;br /&gt;
Research on Human-Computer-Interfaces has recently begun to take into account the affective state of the user. By appropriately reacting to the affective user state, interfaces could not only become more pleasant or entertaining, but also more effective or safer.&lt;br /&gt;
It is known that affective states have bodily correlates, and thus physiological signals could provide the necessary information for acquiring the affective user state. In contrast to other sources of information about the affective user state such as speech or facial expression, most physiological signals are not under voluntary control, and thus cannot be masked up to the same extent. Furthermore, it can be presumed that the signs of affective states in physiological signals are less dependent on individual and contextual factors: this is because the signals correspond to internal physiology, largely related to the autonomous nervous and limbic systems, rather than to external expressions that can be manipulated easily.&lt;br /&gt;
Recently, the issue of emotion regulation drew interests from several fields including neuroscience, psychology, education, computer science, etc. Possible applications are e-learningin, human computer interaction, development of communicative technologies for use by people with autism, car infotainment system, lie detection tests, cognitive workload, multimodal user interfaces MMUI (allow users to control computers using speech and gesture), etc.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The project is aimed at developing a device, connected to a PC, to acquire biological signals (such as GSR, BVP, Temperature and Head orientation) in a way that is less invasive for the subject. The term invasive is related to how much the sensors we use compromise the normal interaction between subject and machine.&lt;br /&gt;
Through these biological signal the PC is able o understand emotion in people who wear the device.&lt;br /&gt;
&lt;br /&gt;
An affective device should be weared easily, should not have cables and should acquire as much sensors as possible. We relax some constraint on the quality of signal but we add constraint on way they are acquired(i.e. the subject can put it on easily, the usual movements are not influenced..). The aim of the resulting device is not to replace the standard medical devices usually used to acquire that signals, but is to be much more suitable for industrial application in which the medical requirement are replaced by invasivity requirement.&lt;br /&gt;
&lt;br /&gt;
It is composed by:&lt;br /&gt;
&lt;br /&gt;
* Low power, high efficiency, battery powered design&lt;br /&gt;
* Wireless comunication with a PC&lt;br /&gt;
* Blood Volume Pressure Sensor (Preliminary release by Mattia Colombo)&lt;br /&gt;
* Galvanic Skin Response Sensor (Preliminary release by Sala Mirko e Alessia Cornaggia)&lt;br /&gt;
* Temperature Sensor&lt;br /&gt;
* 3 Way Accelerometer&lt;br /&gt;
* Possibility of further extension&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''GSR (or EDR or EDA)'''&lt;br /&gt;
&lt;br /&gt;
An often misunderstood and difficult technique, GSR (also known as the electrodermal response EDR or electrodermal activity EDA) has gone through many phases of interest and rejection since the early 1900's and is very popular in psychophysiological studies since Carl Jung and his students (1907) described it as a mean to&lt;br /&gt;
enter the “sea of the unconscious” because “every stimulus accompanied by an emotion produced a deviation of the galvanometer” directly proportional to the strength of the emotion aroused. It has been used in important research on anxiety and stress levels (Fenz &amp;amp; Epstein, ' 67); and it has been a part of lie detection (Raskin, ' 73). Controversy has centered around the technique, underlying mechanisms, and the meaning of the responses obtained from the skin. &lt;br /&gt;
There has been a long history of electrodermal activity research, even if most investigators accept the phenomenon without understanding exactly what it means (Hume, ' 76).&lt;br /&gt;
The resistance of the skin is usually large, approximately 1M; however, momentary changes in the level of the sweat gland activity causes changes in resistance (up to approximately 950K).&lt;br /&gt;
Physiology, the GSR reflescts sweat gland activity and changes in the sympathetic nervous system and measurement variables. The activity of the sweat glands in response to sympathetic nervous stimulation ( Increased sympathetic activation ) results in an increase in the level of conductance. There ia a relationship between sympathetic activity and emotional arousal, although one cannot identify the specific emotion being elicited. &lt;br /&gt;
Basically there are two techniques in the history of Electrodermal measurement. In one a current is passed thru the skin and the the resistance to passage is measured; in the other no current is used externally and the skin itself is the source of electrical activity.&lt;br /&gt;
By applying a conventional 0.5 Volts across the skin and measuring changes in the&lt;br /&gt;
corresponding conductance, the emotional state of the subject can be inferred. In general, the electrodes used are of the Ag/AgCl type which are recessed from the skin and require the use of a suitable electrode paste.&lt;br /&gt;
It is important to note, however, that fluctuations in skin conductivity are resultant of many types of arousal.&lt;br /&gt;
By observing only these changes, it is impossible to deduce without prior knowledge whether&lt;br /&gt;
the subject has become happy, startled, physically active, etcetera.&lt;br /&gt;
EDA consists of two components: tonic and phasic. The tonic component is a low&lt;br /&gt;
frequency baseline conductivity level, which can oscillate over the course of days. The phasic&lt;br /&gt;
component rides on top of the tonic component, exhibits more rapid fluctuations, and&lt;br /&gt;
generally increases when a person is aroused. Problematically, each person has a different&lt;br /&gt;
tonic conductivity, so in order to infer the arousal level of the subject, the relative changes in&lt;br /&gt;
EDA must be analyzed over a period of time. Furthermore, skin conductance (measured in&lt;br /&gt;
units of siemens; formerly mhos) depends on the skin path length between the two electrodes&lt;br /&gt;
contacts, even for subjects with identical skin conductivity (measured in units of&lt;br /&gt;
siemens/meter). It is for these reasons that it is crucial to analyze the temporal variations of&lt;br /&gt;
the EDA signal.&lt;br /&gt;
&lt;br /&gt;
'''BVP'''&lt;br /&gt;
&lt;br /&gt;
The cardiovascular system is in charge to keep us alive by maintaining the vital blood flow throughout the body, providing nutrients and oxygen to our cells. The SNS controls this system&lt;br /&gt;
by shifting the flow in response to exercise, temperature,postural and emotional changes.&lt;br /&gt;
Blood Volume Pulse (BVP) is the most common measure of vasomotor activity because it reflects the phasic pumping of the heart, the vasodilation of vessels that changes in the amount of acral blood delivered.&lt;br /&gt;
The Blood Volume Pulse (BVP) waveform is an important indicator of circulatory function that can be obtained noninvasively through a photoplethysmographic transducer (a PPG is often obtained by using a pulse oximeter, Shelley and Shelley, 2001) applied to the finger or the earlobe of human subjects. In particular, this signal may be useful in determining the degree of cardiovascular change undergone by a subject through an exercise session. &lt;br /&gt;
&lt;br /&gt;
''Principles of photoplethysmographic Technology:''&lt;br /&gt;
&lt;br /&gt;
The principle of photoplethysmographic (That is the same of pulse oximetry) is based on the red and infrared light absorption characteristics of oxygenated and deoxygenated hemoglobin. Oxygenated hemoglobin absorbs more infrared light and allows more red light to pass through. Deoxygenated (or reduced) hemoglobin absorbs more red light and allows more infrared light to pass through. Red light is in the 600-750 nm wavelength light band.&lt;br /&gt;
Pulse oximetry uses a light emitter with red and infrared LEDs that shines through a reasonably translucent site with good blood flow. Opposite the emitter is a photodetector that receives the light that passes through the measuring site.&lt;br /&gt;
There are two methods of sending light through the measuring site: transmission and reflectance. In the transmission the emitter and photodetector are opposite of each other with the measuring site in-between. The light can then pass through the site. In the reflectance method, the emitter and photodetector are next to each other on top the measuring site. The light bounces from the emitter to the detector across the site. The transmission method is the most common type used.&lt;br /&gt;
While pulse oximeters are a commonly used medical device the PPG derived from them is rarely displayed, and is nominally only processed to determine heart rate. &lt;br /&gt;
&lt;br /&gt;
'''Temperature'''&lt;br /&gt;
&lt;br /&gt;
The temperatures of peripheral limbs vary as a consequence of changes in blood flow.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== '''Previous work''' ==&lt;br /&gt;
&lt;br /&gt;
Here is a preliminary release of the headset produced before 2008/08/08&lt;br /&gt;
&lt;br /&gt;
[[Image:Wd1.jpg]]&lt;br /&gt;
&lt;br /&gt;
If you are interested on the making of the headset please see [[making rubber models]]&lt;br /&gt;
&lt;br /&gt;
'''* Blood Volume pressure'''&lt;br /&gt;
First graph showing a signal acquired with the wireless sensor. &lt;br /&gt;
[[Image:Bvp.png]]&lt;br /&gt;
&lt;br /&gt;
'''* Skin galvanic response''' (Sala Mirko e Alessia Cornaggia[http://airwiki.elet.polimi.it/mediawiki/index.php/User:AlessiaCornaggia])&lt;br /&gt;
Galvanic skin response (GSR), also known as electrodermal response (EDR), psychogalvanic reflex (PGR), or skin conductance response (SCR), is a method of measuring the electrical resistance of the skin.  There is a relationship between sympathetic activity and emotional arousal, although one cannot identify the specific emotion being elicited. The GSR is highly sensitive to emotions in some people. Fear, anger, startle response, orienting response and sexual feelings are all among the emotions which may produce similar GSR responses.&lt;br /&gt;
Response of the skin to the passage of a small electric current. The ease with which the current flows between two points on the skin can be used to indicate stress. When a person is tense or emotional, the sweat glands become more active, increasing moisture on the skin; this allows the electric current to flow more readily. &lt;br /&gt;
The response may also be used in relaxation training: information about the galvanic skin response is fed back aurally or visually to the subject who can, with practice, learn to increase or decrease sweating on the skin by learning to relax or tense muscles.&lt;br /&gt;
We measure the galvanic skin response using two electrodes attached to the skin. The optimal placement is the palm of the hands, but we are experimenting other places like on the forehead.&lt;br /&gt;
The circuit we are creating is the one below.&lt;br /&gt;
&lt;br /&gt;
[[Image:circuito.jpg]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== '''Project the device''' ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== '''Re-definition of the complete work''' ===&lt;br /&gt;
&lt;br /&gt;
Sensors are an important part of an Affective Computing System because they provide information about the wearer's physical state or behavior. They can gather data in a continuous way without having to interrupt the user. &lt;br /&gt;
To define in detail electronic specifications and requirements it's necessary a preliminary research/study (in literature and web) about state of art of sensor type used to monitor each type of biological signals we are interested about.&lt;br /&gt;
In this way it's possible both understand problematics related to interaction between biological and electonical worlds and improve or re-desig existing prototype.&lt;br /&gt;
&lt;br /&gt;
About Sensors: &lt;br /&gt;
&lt;br /&gt;
BVP will be acquire by an IR transmitter-receiver measuring light reflected from skin (photoplethysmography). Particular attention will be put on position, geometry and power absorption of this stage. &lt;br /&gt;
&lt;br /&gt;
GSR will be acquiret by a couple of electrodes forcing a low current (or voltage) and reading voltage (or current) through electrodes. Particular attention will be put on electrodes position and material. In addition is possible to foresee some problems in amplifier stage due to large range of skin resistance. Problem consist in chosing a correct amplification to overwork ADC full scale with a signal affected by little variation but huge possible range. &lt;br /&gt;
&lt;br /&gt;
Temperature will be acquired by thermocouple or PTC/NTC. Slowly variable signal, possible problems with noise due to resolution required. &lt;br /&gt;
&lt;br /&gt;
Head orientation will be acquired by an accelerometer and a gyroscope, problably integrated in the same chip. Two possibilities: analog output (need to digitalize up to six line) or digital output (like displaied in schematic block diagram). &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
This was the preliminary simplified schematic block diagram of the complete instrumentation setup:&lt;br /&gt;
&lt;br /&gt;
[[Image:WADSchematicDiagram01.jpg]]&lt;br /&gt;
&lt;br /&gt;
 NOTE:&lt;br /&gt;
 &lt;br /&gt;
 * In schematic is not present Power Supply Module: it will be based on a rechargeable Li-ion&lt;br /&gt;
 battery. It must satisfy requirements of high efficiency, logn life and low weight.&lt;br /&gt;
 &lt;br /&gt;
 * ADC and Microcontroller could be unified using a microcontroller with internal ADC and&lt;br /&gt;
 internal or external multiplexer to select lines.&lt;br /&gt;
 &lt;br /&gt;
 * Wireless section could be implemeted in Bluetooth (instead of using a XBee module like in&lt;br /&gt;
 preliminary release) due to it's diffusion in cellular phones, notebooks, MP3 reader...&lt;br /&gt;
 without necessity of external modules.&lt;br /&gt;
&lt;br /&gt;
It was based on a theoretical approach to any single part. Any sensing device was designed in &amp;quot;conventional&amp;quot; way founded on analog electronic (a bridge with a NTC resisistance as sensing element, discrete IR led and some photodiode around to capture the most reflefted light as possible, GSR electrodes on the gain arm of a non-inverting amplifier...).&lt;br /&gt;
Unfortunatly a deep analysis on signal physiology, signal transduction, noise vs required accurancy, forced us to a completely different approach implementing everywhere possible a digital interface.&lt;br /&gt;
&lt;br /&gt;
=== '''Sensors Design''' ===&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''BVP'''&lt;br /&gt;
&lt;br /&gt;
Discrete IR leds and phototransistor, used in the first realize (see fig.), had been replaced first with a single led and one or more photodiodes to optimize power consumption in case of non-planar sensor positioning. Subsequently an integrated Reflective Object Sensor was introduced, with benefits about space saving, transmitter-receiver matching and power consumption.&lt;br /&gt;
To ensure light power stability, led is powered through a linear led drive LDO (Low Drop-Out). The choise of linear LDO is necessary to ensure no noise or spikes would be generated by charge pump systems or boost converters. In addition, the linear drive utilized requires only one external resitor to set led current and a decoupling capacitor, reducing part counts and board space occupation.&lt;br /&gt;
The couple factor of the reflex sensors is relatively small, even in the case of good reflecting surfaces. Therefore an additional amplifier is necessary at the sensor output: classic trans-impedance amplifier used with photo-diodes and photo-transistors was introduced. This circuit features an output voltage that is a linear function of the light level on the photo-transistor. The gain is set by the feedback resistor which could be in the millions of ohms. Linear operation is achieved by operating the photo device with a fixed voltage drop across it.&lt;br /&gt;
Trans-impedance amplifier is followed by an active fourth order band-pass filter (0.5Hz-5Hz): it's composed cascading two second order bandpass cells. In first project session only a single cell was used, but a deeper study combined with previous experiences suggests to use a 4th order filter to reduce 50Hz interference (50Hz interference produced by mains is placed only a decade after the filter pole).&lt;br /&gt;
Filter is followed by a VGA (Variable Gain Amplifier) digitally controlled through I2C Bus that allows to optimize dinamically ADC input signal amplitude directly during acquisition session, obtaining the best performance from ADC.&lt;br /&gt;
The resulting circuit is quite compact (led drive, reflective sensor, trans-impedence amplifier, active filter and variable-gain amplifier), doesn't require much power and represents a good mix between analog and digital approach: analog front-end with acquisition and first conditioning, and at the chain-end a digital controlled amplifier to ensure flexibility.&lt;br /&gt;
&lt;br /&gt;
[[Image:WADBVPComparison.jpg]]&lt;br /&gt;
&lt;br /&gt;
'''GSR'''&lt;br /&gt;
&lt;br /&gt;
GSR will be acquired by a couple of electrodes forcing a low voltage and reading current through electrodes. First designs and implementations were based on literature study: best solution appears to put GSR electrodes on the gain arm of a non-inverting amplifier (see fig.) rather than using a Wheatstone bridge due to week signal produced by this solution.&lt;br /&gt;
Putting GSR electrodes on the gain arm produces a sort of gain modulation of the constant voltage applied between electrodes but doesn't solve problems in amplifier stage due to large range of skin resistance.&lt;br /&gt;
Problems in chosing correct amplification to overwork ADC full scale with a signal affected by little variation but huge possible range could be reduced usign a variable resistor on gain arm (for example a digital potentiometer controlled by the microcontroller), but cannot be completely removed. In addition little signals are easily deteriorated by noise.&lt;br /&gt;
Solution is provided considering a new point of view: measure of unknown skin resistence is extremely similar to measure unknown electrical impedence with an auto-range multimeter!&lt;br /&gt;
Solution consist in a digital Impedance Converter: AD5934 is a high precision impedance converter system which combines an on-board frequency generator with a 12-bit, 250 kSPS, analog-to-digital converter (ADC). The frequency generator allows an external complex impedance to be excited with a known frequency; the response signal from the impedance is sampled by the on-board ADC and a discrete Fourier transform (DFT) is processed by an on-board DSP engine. The DFT algorithm returns a real (R) and imaginary (I) data-word at each output frequency. This solution not only allows to measure impedence range from 100 Ohm to 10 MOhm, but in adition allow to investigate it across a wide range of frequency, producing a noise-free digital output.&lt;br /&gt;
The resulting circuit is extremely compact (converter chip, one setting resistor and bypass capacitors), provides a system accuracy of 0.5% and connects to microcontroller using I2C interface, ensuring an high flexibility and the possibility to modify acquisition settings after board production (through microcontroller firmware).&lt;br /&gt;
&lt;br /&gt;
[[Image:WADGSRComparison.jpg]]&lt;br /&gt;
&lt;br /&gt;
'''Temperature'''&lt;br /&gt;
&lt;br /&gt;
First idea was to acquire temperature by a NTC connected in a Wheatstone bridge. Trying to reduce noise, bridge was powered by an oscillator circuit with a frequency of some KHerz, to translate signal out of 1/f noise region. Bridge outputs were connected to an INA amplifier wich also implements signal filtering (see fig.).&lt;br /&gt;
Weak signal, noise and resolution required (0.1°C) put in crisis the system. In addition other unsolved problems were the optimization of thermal and mechanical contact between sensor and body and the sensor large thermic constant. Unstable thermic contact produces unreliable measures, whereas high sensor thermic constant hampers a fast sensor response (needed to detect short peak due to emotional reactions).&lt;br /&gt;
Possible solutions to problems of weak signal and noise arrive from digital integrated temperature sensor (for example LM35 or LM74), but these don't solve the problem of thermal contact and thermal constant. In addition none of the sensors take in consideration provides the required resolution.&lt;br /&gt;
High resolution required, noise immunity, fast response and thermal contact immunity problems had been solved using a digital optical infra red thermometer. The MLX90614 is an infra red thermometer for non contact temperature measurements based on a thermopile detector chip including signal conditioning in the same TO-39 package. Thanks to its low noise amplifier, 17-bit ADC and powerful DSP unit, a high accuracy and resolution of the thermometer is achieved.&lt;br /&gt;
The calculated object and ambient temperatures are available in RAM of MLX90614 with 0.02°C resolution: they are accessible by 2 wire serial SMBus compatible protocol. A special version for medical applications offers an accuracy of ±0.1ºC in a limited temperature range around the human body temperature.&lt;br /&gt;
Small size, no external component requirements and power saving mode allow us to obtain a perfect matching between required performances and space saving.&lt;br /&gt;
&lt;br /&gt;
[[Image:WADTemperatureComparison.jpg]]&lt;br /&gt;
&lt;br /&gt;
'''Accelerometer'''&lt;br /&gt;
&lt;br /&gt;
Head orientation and movements will be acquired by an accelerometer. First we think to utilize an ST Microelectronic LIS3L02AS4, due to the availability in the Lab of the evaluation board STEVAL-MKI001. It is a 3-axis ±2g/±6g linear accelerometer with 3 analog outputs, so it requires an external ADC to digitalize the three axis acceleration values. The conversion could be performed by a microcontroller with internal ADC.&lt;br /&gt;
A fast Internet research reveled this sensor is now obsolete and out of production. The choise had been to substitute the old chip with the new one: the LIS302DL (still produced by ST Microelectronic). It's a 3-axis, ± 2g/± 8g smart digital output accelerometer with I2C/SPI digital output interface and really small package. The device is capable of measuring accelerations with an output data rate of 100 Hz or 400 Hz and the self-test capability allows the user to check the functioning of the sensor in the final application.&lt;br /&gt;
In addition it may be configured to generate inertial wake-up/free-fall interrupt signals when a programmable acceleration threshold is crossed at least in one of the three axes. Thresholds and timing of interrupt generators are programmable by the end user on the fly.&lt;br /&gt;
This device, providing a digital output, doesn't need signals conversion, guaranteing better noise immunity; programmable interrupts and test interface allow greater fexibility in project. In addition wery small package, only one external resistor requirement (plus baypass capacitor) reduce significantly board space requirements.&lt;br /&gt;
&lt;br /&gt;
[[Image:WADAccelerometer.jpg]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
 NOTE:&lt;br /&gt;
 &lt;br /&gt;
 * In previous schematics, components phisical dimensions are not in scale.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== '''Microcontroller''' ===&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Foundamental requirements:&lt;br /&gt;
&lt;br /&gt;
- High speed to ensure high data output rate even in presence of a large number af sensing elemets;&lt;br /&gt;
&lt;br /&gt;
- Fast Internal ADC with multiple inputs;&lt;br /&gt;
&lt;br /&gt;
- (At Least) One I2C interface;&lt;br /&gt;
&lt;br /&gt;
- (At Least) One SPI interface;&lt;br /&gt;
&lt;br /&gt;
- (At Least) One UART interface;&lt;br /&gt;
&lt;br /&gt;
- Low-power consumption;&lt;br /&gt;
&lt;br /&gt;
- Power supply 3.3V;&lt;br /&gt;
&lt;br /&gt;
- Small package;&lt;br /&gt;
&lt;br /&gt;
In addition microcontroller was chosen between Microchip PIC family devices, due to positive previous experiences and availability of software and programmer in the Lab.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
PIC24HJ256GP206 is a 16 bit microcontroller capable of 40 MIPS speed. It provides 256KB of Flash memory, 16KB of Ram, a 10-bit 1.1Msps or 12-bit 500Ksps ADC, UART, SPI and I2C interface in a 64 pin TQFP package (10mmX10mm) powerd between 3.0V and 3.6V.&lt;br /&gt;
Power core is provided by an internal regulator reducing parts count on the board.&lt;br /&gt;
&lt;br /&gt;
The device is able to provide at the same time one I2C interface, two SPI interface and one UART interface: another UART port shares pins with an SPI port and a second I2C port shares pins with the second UART interface.&lt;br /&gt;
Findig a device that provides at the same time, on indipendent pins, an I2C, a SPI and an UART interface reduces considerably possible choises and suggests to chose a high performance microcontroller.&lt;br /&gt;
At the same time, high performance solutions have a larger pin counts than standard microcontroller, but this characteristic can be used to ensure further expansibility to the system. The second SPI interface can be used to connect another &amp;quot;intelligent&amp;quot; device or a mass storage device, for example a SD (Secure Digital) card to storage acquired data (see fig.).&lt;br /&gt;
&lt;br /&gt;
[[Image:WADSDCard.jpg]]&lt;br /&gt;
&lt;br /&gt;
Input pins connected to ADC and not used at the moment could be collected to a connector for further extension modules (for example an EMG or ECG peripheral or any other analog signal interesting in a particolar application).&lt;br /&gt;
For the same reason any other pin non used at the current stage is reported to an extension connector.&lt;br /&gt;
To guarante maximum flexibility an further update, board provides both ICD and JTAG connections (allowing on-board programming and debugging) through a couple of indipendent dedicated connectors fully compatibles with Microchip programmers and evaluation boards.&lt;br /&gt;
&lt;br /&gt;
[[Image:WADMicro.jpg]]&lt;br /&gt;
&lt;br /&gt;
=== '''Wireless Connection''' ===&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Wireless connection is based on BlueGiga WT12 module: it's a next-generation, class 2, Bluetooth 2.0+EDR (Enhanced Data Rates) module containing all the necessary elements from Bluetooth radio to antenna and a fully implemented protocol stack.&lt;br /&gt;
By default WT12 module is equipped with powerful and easy-to-use iWRAP firmware that enables users to access Bluetooth functionality with simple ASCII commands delivered to the module over serial interface like a Bluetooth modem.&lt;br /&gt;
The dedicated onboard microcontroller (MCU) acts as interrupt controller and event timer run the Bluetooth software stack and control the radio and host interfaces. A 16-bit reduced instruction set computer (RISC) microcontroller is used for low power consumption and efficient use of memory.&lt;br /&gt;
WT12 module support USB, SPI and UART interface and UART interface is used in this project to connect PIC microcontroller to wireless transmitter (see fig.).&lt;br /&gt;
&lt;br /&gt;
[[Image:WADWireless.jpg]]&lt;br /&gt;
&lt;br /&gt;
One of the most important WT12 characteristic is the high integration between all parts needed for efficent Bluetooth transmission: user interface, controller, radio circuits and antenna, all included in a low power, low size board (25.6mmx15mm) that requires a minimum number of external components.&lt;br /&gt;
Many other bluetooth components ara available, such as LMX9830, produced by National Semiconductor. It's an extremely small device (only 6.1mm×9.1 mm), but requires a number of external components (see fig.) like oscillators, resistors, capacitors, inductors and the antenna, in addition to an high competence in radio frequency layout circuits.&lt;br /&gt;
&lt;br /&gt;
[[Image:WADLMX9830.jpg]]&lt;br /&gt;
&lt;br /&gt;
Lack of experience in radio frequency circuit suggests to chose a ready-to-use module, factory optimized for best performance and easy to integrate in our board.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
This is the updated simplified schematic block diagram:&lt;br /&gt;
&lt;br /&gt;
[[Image:WADSchematicDiagram02.jpg]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== '''Prototype realization [WIP (Work in Progress)]''' ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Fist stage plans to realize a board using, where possible, through-hole (TH) compenents soldered on a prototyping board (100x160mm) powered from a laboratory power supply (instead of Li-on battery) and not implementing bluetooth wireless transmission. Parts not available on TH package are used with special SMD-&amp;gt;TH adapter boards or simply fixing and soldering them to the PCB by wires.&lt;br /&gt;
&lt;br /&gt;
Second stage plans to realize microcontoller firmware and test it acquiring biological signals from a patient. Firmware will be developed by subsequently steps, implementing and testing only a single peripheral at each time: only at the end single pheripheral softwares will be merged together.&lt;br /&gt;
&lt;br /&gt;
Third stage will be bluetooth interface (hardware and software) implementation and integration on the board with transmission test.&lt;br /&gt;
&lt;br /&gt;
Fourth stage will consider power supply optimization with battery management and recharge interface.&lt;br /&gt;
&lt;br /&gt;
Finally, only after a successful full board test, the last stage will be the circuit layout design with an electronic CAD, using where possible, Surface Mount Devices (SMD) to reduce board area.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== '''Main board''' ===&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Main board include power supply regulator with led power-on indicator, PIC microcontroller (mounted on a SMD-&amp;gt;TH adapeter board) with basic circuitry (decoupling capacitors, oscillator and programming-debugging ICD interface), a status led connected to PIC to verify basic microcontroller function, a series of connectors for add-on modules (BVP, GSR, temperature and accelerometer) and a USB PC interface not considered before.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== '''USB interface''' ===&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
USB interface, not projected before, replaces in developing stage Bluetooth interface, allowing a direct control/communication with a PC. In this prototype PIC UART, althought being connected to Bluettoth module, is connected to a FTDI FT232RL chip. The FT232RL is the latest device to be added to FTDI’s range of USB UART interface Integrated Circuit Devices. USB to serial designs using the FT232RL have been further simplified by fully integrating the external EEPROM, clock circuit and USB resistors onto the device.&lt;br /&gt;
The FT232RL is available in Pb-free (RoHS compliant) compact 28-Lead SSOP, so this require another SMD-&amp;gt;TH board adapter but the circuit design is very simple, including two status led for TX and RX operations. An USB B female connector was eputated the best choise for PC connection allowing to use a simple USB printer cable.&lt;br /&gt;
&lt;br /&gt;
[[Image:WADUSBInterface.jpg]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Note that USB and Bluetooth must not be connected to the board at the same time! USB port has only a developent function.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== '''BVP''' ===&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Circuit designed for BVP acquisition (refer to previous schematic) doesn't meet the expected results. Week signal hanged by noise suggested us to re-design the circuit simplifying it and reducing the number of components. For this design also sensing element has been substitute. Instead of an integrated reflective IR sensor (SFH9202), new project use a couple af discrete IR led and photothansistor matched: SFH487 and SFH309FA.&lt;br /&gt;
SFH487 is a very highly efficient GaAlAs infrared emitter (880 nm) and SFH309FA is a silicon NPN phototransistor especially suitable for applications of 880 nm with an high linearity. Both have a 3 mm led plastic package, are spectrum-matched and receiver is ambient-light shilded. After a series of positive test without the led driver (not used due to the really reduced mechanical dimensions), also led drive circuit was removed and replaced with a resistance connected directly to a PIC pin.&lt;br /&gt;
This choise reduces parts count and board space required without making worse sistem performance, allowing (like led driver) to turn off the sensor led when not used to reduce power consumption.&lt;br /&gt;
&lt;br /&gt;
[[Image:WADBVPNew.jpg]]&lt;br /&gt;
&lt;br /&gt;
Even if operation amplifier used are half of before, double second-order filter stage is manteined. In addition to filtering, these opamp privide a first gain (note that in previous design filtering stages works as a unitary buffer in pass-band) allowing a high signal at VGA (variable gain amplifier) input stage allowing a better SNR.&lt;br /&gt;
1N4148 diode provides a sort of ofsetted virtual ground, shifting up all signals but not being amplified through the amplification chain.&lt;br /&gt;
Figure show the signal measured directly on filtering stage output (TS952 pin 7) before the VGA with a Tektronix scopemeter TDS2014B. No particular triks had been used: signal has been recorded the first time circuit was assembled on a protoboard.&lt;br /&gt;
&lt;br /&gt;
[[Image:WADBVPScope03.jpg]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== '''GSR''' ===&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
First approach with AD5934 resulted really hard due to some errors occurred in control software in relation with internal chip complexity and I2C bus protocol. &lt;br /&gt;
After a sart session with the AD5934, GSR hardware acquisition interface was further simplified replacing it with AD5933 (refer to schematic). AD5933 has the same pinout and functions of AD5934 but provides also an internal oscillator at 16.776MHz allowing no external crystal connection. A temperature sensor that allow the user to measure chip temperature and 1 MSPS Converter (instad of a 250KSPS one) are the only other differences between the tho integrated semiconductor produced by Analog Devices.&lt;br /&gt;
On the other hand AD5934 has a larger impedance measurement range that goes from 100 Ohm to 10 MOhm in opposition to AD5933 that can only measure impedences between 1 Ohm and 10 MOhm. Because of the high skin impedence values (in the range of MOhm for dry fingers skin), this is not a problem in our application.&lt;br /&gt;
&lt;br /&gt;
[[Image:WADGSRNew.jpg]]&lt;br /&gt;
&lt;br /&gt;
First dataset acquired whith the correct control software and the correct data reading routine, has shown all the potentiality of this chip, providing data comparables with RAW data acquired with a bigger and very expensive professional equipement produced by ProComp.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== '''ACCELERATION''' ===&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Lis302DL datasheet gives a short definition of this chip as &amp;quot;MEMS motion sensor 3-axis - ± 2g/± 8g smart digital output “piccolo” accelerometer&amp;quot; and it is really very, very small for human-working. For this space saving quality this accelerometer is also use in third generation Apple i-phone.&lt;br /&gt;
The major problem with this sensor had been to solder it to a sort of adapter to connect it to the circuit, but after that it works fine, with a good sensitivity and accuracy. Because of free fall and double click recognition at not required (at the moment) in this application, software routines for setting configuration registers and reading data resulted simplified.&lt;br /&gt;
A usefull caracteristic of this sensor, not previously noticed, is the presence of internal pull-up resistors that allows no necessity of external I2C bus pull-up resistors, reducing space occupation and components count.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== '''TEMPERATURE''' ===&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The choice to use MLX90614 due to his characteristics (non contact measure, 0.02°C resolution with accuracy of ±0.1°C for medical applications version) creates a really serious supplies problem: Melexis (sensor manufacture) wasn't able to give us a sample and no one in Italy can sell us only a pair of theese sensors to try them. A single piece was bought from Future Electronics, ordering it via web and paying it via credit card. Fortunately the sensor, that cames directly from USA, arrived in Italy few days later the payment in excellent conditions.&lt;br /&gt;
&lt;br /&gt;
[[Image:WADMLX90614.jpg]]&lt;br /&gt;
&lt;br /&gt;
Problems occurred interfacing this sensor on I2C bus with other devices (AD5933 and LIS302) connected. MLX90614 has a 2 wire serial SMBus compatible protocol: I2C bus and  SMBus are popular 2-wire buses that are essentially compatible with each other, but are not the same.&lt;br /&gt;
The buses operate at the same speed, up to 100kHz, but the I2C bus has both 400kHz and 2MHz versions. Complete compatibility between both buses is ensured only below 100kHz.&lt;br /&gt;
Timeout and (as a consequence of timeout) minimum clock speed are the most important differences between the I2C bus and the SMBus:&lt;br /&gt;
&lt;br /&gt;
I2C Bus = DC (no timeout)&lt;br /&gt;
&lt;br /&gt;
SMBus = 10kHz (35mS timeout)&lt;br /&gt;
&lt;br /&gt;
Despite differences in logic-level specifications between the two buses, generally devices can be mixed and matched with abandon.&lt;br /&gt;
Level Specifications for the I2C Bus and the SMBus are shown below (VDD is typically expected to be between 3 volts and 5 volts):&lt;br /&gt;
&lt;br /&gt;
[[Image:WADTable1.jpg]]&lt;br /&gt;
&lt;br /&gt;
What wasn't readily evident in the discussion of voltage levels is that these levels are also specified with different currents between the buses. The SMBus specifies a minimum sink current of 100microA, and a maximum of 350microA, compared to 3mA for the I2C bus. This in turn would determine the lowest acceptable value of the pullup resistor, examples of which are shown in the table below.&lt;br /&gt;
&lt;br /&gt;
[[Image:WADTable2.jpg]]&lt;br /&gt;
&lt;br /&gt;
In reality, it is not unusual to encounter pullup resistor values in SMBus systems, which violate this specification by being lower than recommended. A very popular range for pullup resistor values, even in some SMBus systems, seems to be 2.4k to 3.9k.&lt;br /&gt;
&lt;br /&gt;
These reasons, in adition to clear ideas about close developments, suggest a general review of schematic to re-distribute microcontroller resources.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== '''Part 6: final review [WIP (Work in Progress)]''' ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== '''Microcontroller''' ===&lt;br /&gt;
&lt;br /&gt;
Referring to previous schematic, some chenges had been applied:&lt;br /&gt;
&lt;br /&gt;
- Programmer/Debugger interface is now PGD1/EMUD1 and PGC1/EMUC1 instead of PGD1/EMUD2 and PGC1/EMUC2;&lt;br /&gt;
&lt;br /&gt;
- JTAG interface had been removed;&lt;br /&gt;
&lt;br /&gt;
- UART2 is no more available so UART1 has replaced UART2 as communication port;&lt;br /&gt;
&lt;br /&gt;
- SPI2 is no more available so SPI1 is now used to control both LMP8100 VGA (Variable Gain Amplifier) and SD Storage Card;&lt;br /&gt;
&lt;br /&gt;
- RG12, RG13, RG14 pins had been connected to three status led for a machine visual state detection;&lt;br /&gt;
&lt;br /&gt;
- I2C1 interface is now connected to accelerometer (LIS302) and GSR (AD5933) only;&lt;br /&gt;
&lt;br /&gt;
- I2C2 interface is dedicated to temperature sensor (MLX90614), enabling I/O pin thresholds compliant with SMBus specification;&lt;br /&gt;
&lt;br /&gt;
- Connectors for I2C, SMBus and SPI expansion modules had been added to the board;&lt;br /&gt;
&lt;br /&gt;
- Test point pads had been added to the board to simplify debugging.&lt;br /&gt;
&lt;br /&gt;
That's the complete microcontroller schematic diagram:&lt;br /&gt;
&lt;br /&gt;
[[Image:WAD_Micro_Final.jpg]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== '''Data link''' ===&lt;br /&gt;
&lt;br /&gt;
During developing stages, an USB port had replaced Bluetooth wireless transmission, allowing a direct control/communication with a PC. This interfaced, based on a FT232RL, prove to be very usefull and simple to use.&lt;br /&gt;
The choice to use an usb port to charge internal battery, in addition to availability of a UART multiplexer inside the Bluetooth module BlueGiga WT12, suggest to implement both USB and Bluetooth interface.&lt;br /&gt;
&lt;br /&gt;
That's the BlueGiga WT12 internal UART multiplexer schematic:&lt;br /&gt;
&lt;br /&gt;
[[Image:WAD_UARTMux.jpg]]&lt;br /&gt;
&lt;br /&gt;
The complete data link schematic diagram:&lt;br /&gt;
&lt;br /&gt;
[[Image:WAD_USB+Bluetooth_Final.jpg]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== '''Battery Charge &amp;amp; Monitor''' ===&lt;br /&gt;
&lt;br /&gt;
[[Image:WAD_BAttery_Charge&amp;amp;Monitor_Final.jpg]]&lt;br /&gt;
==Students that have worked on the project==&lt;br /&gt;
&lt;br /&gt;
* Mattia Colombo (Blood Volume Pressure sensor)&lt;br /&gt;
* Alessia Cornaggia (Galvanic skin response sensor)&lt;br /&gt;
* Sala Mirko (Galvanic skin response sensor)&lt;br /&gt;
&lt;br /&gt;
== Laboratory work and risk analysis ==&lt;br /&gt;
&lt;br /&gt;
Laboratory work for this project will be mainly performed at AIRLab/Lambrate. It will include electrical and electronic activity. Potentially risky activities are the following:&lt;br /&gt;
* Use of mechanical tools. Standard safety measures described in [http://airlab.elet.polimi.it/index.php/airlab/content/download/461/4110/file/documento_valutazione_rischi_AIRLab.pdf Safety norms] will be followed.&lt;br /&gt;
* Use of soldering iron. Standard safety measures described in [http://airlab.elet.polimi.it/index.php/airlab/content/download/461/4110/file/documento_valutazione_rischi_AIRLab.pdf Safety norms] will be followed.&lt;br /&gt;
* Use of high-voltage circuits. Special gloves and a current limiter will be used. Standard safety measures described in [http://airlab.elet.polimi.it/index.php/airlab/content/download/461/4110/file/documento_valutazione_rischi_AIRLab.pdf Safety norms] will be followed.&lt;/div&gt;</summary>
		<author><name>PaoloVilla</name></author>	</entry>

	<entry>
		<id>https://airwiki.deib.polimi.it/index.php?title=Getting_Started_With_PIC(TM)_MCU&amp;diff=9298</id>
		<title>Getting Started With PIC(TM) MCU</title>
		<link rel="alternate" type="text/html" href="https://airwiki.deib.polimi.it/index.php?title=Getting_Started_With_PIC(TM)_MCU&amp;diff=9298"/>
				<updated>2009-11-10T08:54:16Z</updated>
		
		<summary type="html">&lt;p&gt;PaoloVilla: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;!!!___WORK_IN_PROGRESS___!!!&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
 NOTE:&lt;br /&gt;
 This is not a replacement for the microcontroller datasheet, reference manual and programmer’s manual published by Microchip&lt;br /&gt;
 Technology. It is also not a replacement for the MPLAB C30 compiler user’s guide, and all the libraries and related software&lt;br /&gt;
 tools offered by Microchip. Should you notice a conflict between this document and the official documentation, ALWAYS refer&lt;br /&gt;
 to the latter.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== '''Part 1: Introduction''' ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Chosing a PIC(TM) Microcontroller ===&lt;br /&gt;
&lt;br /&gt;
The first step to chose a microcontroller is to focus on hardware/software needs:&lt;br /&gt;
&lt;br /&gt;
* Board power supply is 3V or 5V (or other)?&lt;br /&gt;
* Power saving is crucial? You need a Ultra-Micro-Low-Nanowatt-Power microcontroller?&lt;br /&gt;
* Application need a little, low cost microcontroller (8bit MCU), a bigger, high performance 16bit MCU or an exagerated 32bit microcontroller?&lt;br /&gt;
* What kind and how many peripherics are needed in your application? ADC, UART, Timers, PWM Channels, stackable Interrupts, SPI, I2C, Can Bus, Ethernet, USB... Yes, it's not a joke! High Performance PIC Microcontroller can have one or more USB and/or Ethernet port, you can implement usb mass storage or TCP-IP functions.&lt;br /&gt;
* Available memory space: you need an extra large memory because you just know your firmare will be extra long?&lt;br /&gt;
&lt;br /&gt;
Once you have answered some of these questions you can use Microchip Advanced Parts Selector (MAPS(TM)) to find only microcontrollers that satisfy your requirements.&lt;br /&gt;
MAPS is available on-line or for download directly from Microchip web site (http://www.microchip.com).&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Software tools ===&lt;br /&gt;
&lt;br /&gt;
Let’s verify you have all the necessary equipments, ready and installed (latest version available for download from Microchip web site at&lt;br /&gt;
http://www.microchip.com):&lt;br /&gt;
&lt;br /&gt;
* PIC MCU Datasheet;&lt;br /&gt;
* MPLAB IDE(TM), free Integrated Development Environment;&lt;br /&gt;
* MPLAB C30(TM), C compiler (demo or free student version).&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== '''Part 2: Basic hardware''' ==&lt;br /&gt;
&lt;br /&gt;
Besides a PC, because of we intend &amp;quot;make&amp;quot; something and not only talk about it, we need some hardware tools:&lt;br /&gt;
&lt;br /&gt;
* PIC MCU programmer-debugger (in Ai&amp;amp;R Lab Lambrate you can find some Microchip ICD2(TM) programmer-debugger, some adapter boards with ZIF socket and some self-made programming cables);&lt;br /&gt;
* PIC MCU demoboard or your board with power supply, PIC Microconroller, oscillator, MCLR circuitry and some input-output hardware.&lt;br /&gt;
&lt;br /&gt;
[[Image:ICD2.jpg]]&lt;br /&gt;
&lt;br /&gt;
If you are watching to buy an own programmer/debugger, Microchip PIC-KIT could be the right choise due to it's little dimensions, low price and good&lt;br /&gt;
performances. For detailed information, including PIC microcontroller supported list, visit microchip web site.&lt;br /&gt;
&lt;br /&gt;
[[Image:PicKit.jpg]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Oscillator ===&lt;br /&gt;
&lt;br /&gt;
The system clock (FOSC) source can be provided by a different number of options, depending by microcontroller family (low power, low cost microcontroller&lt;br /&gt;
allow less options choise than high power, high cost MCU).Generally options can be divided in:&lt;br /&gt;
&lt;br /&gt;
* Internal Oscillator (in general an internal RC network);&lt;br /&gt;
* External Oscillator (external clock source, external crystal or ceramic resonator operation and external RC network).&lt;br /&gt;
&lt;br /&gt;
[[Image:MCUOscillator.jpg]]&lt;br /&gt;
&lt;br /&gt;
In addition, oscillator system can includes on-chip Phase-Locked Loop (PLL) to boost internal operating frequency, on-the-fly clock switching between&lt;br /&gt;
various clock sources and Fail-Safe Clock Monitor (FSCM) that detects clock failure and permits safe application recovery or shutdown.&lt;br /&gt;
This means, for example, that with a PIC24H series microcontoller, you can use a 10Mhz external crystal resonator for clock source, but configuring&lt;br /&gt;
internal PLL circuitry through dedicated registers, you can obtain a 80Mhz internal clock frequency, achieving 40MIPS core operation speed&lt;br /&gt;
(PIC24H need two clock cycles to execute a single instruction).&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== MCLR circuit ===&lt;br /&gt;
&lt;br /&gt;
PIC Microcontroller has a number of reset sources and controls (POR: Power-on Reset; BOR: Brown-out Reset; MCLR: Master Clear Pin Reset; WDTO: Watchdog&lt;br /&gt;
Timer Reset).The external reset is generated by driving the MCLR pin low. The MCLR pin is a Schmitt trigger input with an additional glitch filter.&lt;br /&gt;
Reset pulses that are longer than the minimum pulse width generates a Reset (see datasheet). The External Reset (MCLR) Pin (EXTR) bit in the Reset&lt;br /&gt;
Control (RCON) register is set to indicate the MCLR Reset.If your system has an external supervisory circuits that generate reset signals to Reset&lt;br /&gt;
multiple devices in the system, this external Reset signal can be directly connected to the MCLR pin to&lt;br /&gt;
reset the device when the rest of system is Reset.&lt;br /&gt;
When using the internal power supervisory circuit to Reset the device, the external reset pin (MCLR) should be tied directly or resistively to VDD.&lt;br /&gt;
In this case, the MCLR pin is not used to generate a Reset. The external reset pin (MCLR) does not have an internal pull-up and must not be left&lt;br /&gt;
unconnected. A typical power-on reset circuit is:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Image:MCUMCLR.jpg]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Programming/Debugging interface ===&lt;br /&gt;
&lt;br /&gt;
ICSP(TM) (In-Circuit Serial Programming(TM)) mode is a special programming protocol that allows you to read and write to PIC Microcontroller and is the&lt;br /&gt;
most direct method used to program the device.The ICSP capability is Microchip’s proprietary process for microcontroller programming in the target&lt;br /&gt;
application. The ICSP interface uses two pins as its core.&lt;br /&gt;
The programming data pin (PGD) functions as both an input and an output, allowing programming data to be read in and device information to be read out&lt;br /&gt;
on command. The programming clock pin (PGC) clocks in data and controls the overall process.&lt;br /&gt;
&lt;br /&gt;
Serial programming allows customers to manufacture boards with unprogrammed devices and then to program the digital signal controller just before shipping&lt;br /&gt;
the product. Serial programming also allows the most recent firmware or a custom firmware to be programmed.&lt;br /&gt;
&lt;br /&gt;
Depending from used Microcontroller it's possible to have one or more programming ports. PIC24HJ256JP206, for example, has three pairs of programming&lt;br /&gt;
clock/data pins:&lt;br /&gt;
&lt;br /&gt;
* PGC1/EMUC1 and PGD1/EMUD1&lt;br /&gt;
* PGC2/EMUC2 and PGD2/EMUD2&lt;br /&gt;
* PGC3/EMUC3 and PGD3/EMUD3&lt;br /&gt;
&lt;br /&gt;
Used programming port must be specified in MPLAB IDE selecting &amp;quot;Configuration Bits...&amp;quot; in &amp;quot;Configure&amp;quot; menu.&lt;br /&gt;
The High-Level ICSP Programming Flow is:&lt;br /&gt;
&lt;br /&gt;
[[Image:HL_ICSP_PROGRAMMING_FLOW.jpg]]&lt;br /&gt;
&lt;br /&gt;
When the MPLAB(TM) ICD 2 or another in-circuit emulator is selected as a debugger,the in-circuit debugging functionality is enabled.&lt;br /&gt;
This function allows simple debugging when used with MPLAB IDE. The debugging functionality is controlled through the EMUCx (emulation/debug clock) and&lt;br /&gt;
EMUDx (emulation/debug data) pin functions. To use the in-circuit debugger function of the device, the design must implement ICSP connections to MCLR,&lt;br /&gt;
VDD, VSS, PGCx/EMCx and PGDx/EMUDx pin pairs. In addition, when the feature is enabled, some of the resources are not available for general use.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Programmer Connection ===&lt;br /&gt;
&lt;br /&gt;
ICD 2 programmer/debugger has a RJ12 6 pin output connector while PIC-KIT has a more comfortable 6 pin female strip headers. &lt;br /&gt;
The simplest way to interface programmer/debugger with microcontroller is to solder a 6 pin male strip headers to your board connetting PGCX, PGDX, MCLR,&lt;br /&gt;
VDD and VSS pins, as in figure:&lt;br /&gt;
&lt;br /&gt;
[[Image:ICSP_Connector.jpg]]&lt;br /&gt;
&lt;br /&gt;
Connecting pins in the same order as in figure you can either connect directly PIC-KIT to your board, or use an RJ12-&amp;gt;female_strip_headers adapter cable to&lt;br /&gt;
connect ICD 2 to target device. You can find two of that selfmade cabe in AI&amp;amp;R Lab, or you can build your own one using an RJ12 connector, a piece of 6 core&lt;br /&gt;
cable (you can use also a piece of 8 core ethernet cable), a 6 pin female strip headers and a bit of talent!&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== '''Part 3: PIC MCU programming''' ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== MPLAB IDE settings ===&lt;br /&gt;
&lt;br /&gt;
Select in &amp;quot;Debugger&amp;quot; menu the programmer/debugger device you have to use (probably &amp;quot;1 MPLAB ICD 2&amp;quot;, if you are working on AI&amp;amp;R Lab...)&lt;br /&gt;
&lt;br /&gt;
[[Image:MPLAB_Debugger_Menu.jpg]]&lt;br /&gt;
&lt;br /&gt;
To verify if programmer/debugger is connected to your Pc, to PIC microcontroller and is ready to operate select &amp;quot;Settings&amp;quot; in &amp;quot;Debug&amp;quot; menu and than pres&lt;br /&gt;
&amp;quot;Run Self Test&amp;quot; in the just opened window:&lt;br /&gt;
&lt;br /&gt;
[[Image:MPLAB_ICD2_Settings.jpg]]&lt;br /&gt;
&lt;br /&gt;
In this window you can also check the correct target power supply (&amp;quot;Power&amp;quot; submenu) and change PC-Programmer/debugger communication port&lt;br /&gt;
(&amp;quot;Communications&amp;quot; submenu).&lt;br /&gt;
&lt;br /&gt;
Let's talk about usefull functions on tool bar:&lt;br /&gt;
&lt;br /&gt;
[[Image:MPLAB_Menu.jpg]]&lt;br /&gt;
&lt;br /&gt;
* &amp;quot;Save File&amp;quot;: save only the file you are working on.&lt;br /&gt;
* &amp;quot;Find in Files&amp;quot;: find a word in all files included in the project.&lt;br /&gt;
* &amp;quot;Build Configuration&amp;quot;: to set up language tools for debug, select &amp;quot;Debug&amp;quot;; when your code is debugged and you are ready to release it (program the finished&lt;br /&gt;
code into a device), select &amp;quot;Release&amp;quot;. &lt;br /&gt;
* &amp;quot;Open Project&amp;quot;: open a just created project.&lt;br /&gt;
* &amp;quot;Save Workspace&amp;quot;: save all files in your project and workspace (windows placement on the screen).&lt;br /&gt;
* &amp;quot;Build All&amp;quot;: assemble, link and compile your project; the Output window shows the result of the build process.&lt;br /&gt;
* &amp;quot;Program Target Device&amp;quot;: program the microcontroller with your code; the Output window shows the result of this operation.&lt;br /&gt;
&lt;br /&gt;
[[Image:Output Window.jpg]]&lt;br /&gt;
&lt;br /&gt;
* &amp;quot;Run&amp;quot;: after you had build your project and programmed the microcontrolle, now you can run your application on PIC Microcontroller!&lt;br /&gt;
* &amp;quot;Halt&amp;quot;: halt program execution: the line of code where the application halted will be indicated by the solid green arrow.&lt;br /&gt;
* &amp;quot;Reset&amp;quot;: reset microcontroller.&lt;br /&gt;
* &amp;quot;BreakPoints&amp;quot;: Open the Breakpoint dialog window allowing to set or remove multiple breakpoints. &lt;br /&gt;
&lt;br /&gt;
[[Image:Breakpoints Window.jpg]]&lt;br /&gt;
&lt;br /&gt;
Once you will have create your project, builded it and programmed the microcontroller, in order to see if the code is operating as intended it's possible&lt;br /&gt;
to watch the values being written to microcontroller registers. Select View&amp;gt;Watch to bring up an empty Watch window. There are two pull downs on the top of&lt;br /&gt;
the Watch window. The one on the left labeled &amp;quot;Add SFR&amp;quot; can be used to add a phisical microcontroller register into the watch. Select a register from the&lt;br /&gt;
list and then click Add SFR to add it to the window. The pull down on the right, allows symbols to be added from the program. Use this pull down to add your&lt;br /&gt;
software variable into the Watch window. Select a variable from the list and then click Add Symbol to add it to the window. &lt;br /&gt;
The Watch window should now show the address, name and value of the registers you have added.&lt;br /&gt;
&lt;br /&gt;
[[Image:Watch Window.jpg]]&lt;br /&gt;
&lt;br /&gt;
It's possible to control microcontroller memory usage through the &amp;quot;Memory Usage Gauge&amp;quot;. You can find it selecting “Memory Usage Gauge” in &amp;quot;View&amp;quot; menu.&lt;br /&gt;
Don’t be alarmed! Even though you wrote only few lines of code and the amount of program memory used appears to already be up to 300+ bytes, this is not&lt;br /&gt;
an indication of any inherent inefficiency of the C language. There is a minimum block of code that is always generated (for our convenience) by the&lt;br /&gt;
C30 compiler. This is the initialization code (c0).&lt;br /&gt;
&lt;br /&gt;
[[Image:Memory Usage Gauge.jpg]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Create a new project ===&lt;br /&gt;
&lt;br /&gt;
Then, let’s follow the “New Project Set-up” checklist to create a new project with the MPLAB IDE:&lt;br /&gt;
&lt;br /&gt;
* Select “Project-&amp;gt;Project Wizard” to activate the new project wizard, which will guide us automatically through the following steps…&lt;br /&gt;
* Select the correct PIC device, and click Next.&lt;br /&gt;
* Select the MPLAB C30 Compiler Suite and click Next.&lt;br /&gt;
* Create a new folder and name it “FolderName”; name the project “ProjectName” and click Next.&lt;br /&gt;
* Click Next to the following dialog (box—there is no need to copy any source files from any previous projects or directories.&lt;br /&gt;
* Click on Finish to complete the Wizard set-up.&lt;br /&gt;
&lt;br /&gt;
Open a new editor window.&lt;br /&gt;
&lt;br /&gt;
* Select “File-&amp;gt;Save As”, to save the file as: “FileName.c”.&lt;br /&gt;
* Select “Project-&amp;gt;Save” to save the project.&lt;br /&gt;
&lt;br /&gt;
You should have a screenshot similar to this one:&lt;br /&gt;
&lt;br /&gt;
[[Image:MPLAB1.jpg]]&lt;br /&gt;
&lt;br /&gt;
On the left you have the files list included in your project. Clicking on a folder you can add files (that you have just created with a simple text editor)&lt;br /&gt;
or folder to your project. In &amp;quot;Source Files&amp;quot; folder you must put all &amp;quot;.c&amp;quot; files, while &amp;quot;Header Files&amp;quot; folder is for &amp;quot;.h&amp;quot; files. In this folder you must add&lt;br /&gt;
the &amp;quot;.h&amp;quot; file corresponding to your microcontroller: for example, if you use a PIC24HJ256GP206 microcontroller, you will add the &amp;quot;p24hj256gp206.h&amp;quot;&lt;br /&gt;
file. These files are located in &amp;quot;C:\Program Files\Microchip\MPLAB C30\support\h\&amp;quot;. In &amp;quot;Library Files&amp;quot; folder you have to add the library file corresponding&lt;br /&gt;
to your device. As before, if your device is a PIC24HJ256GP206, you will add &amp;quot;libp24HJ256GP206-coff.a&amp;quot; and &amp;quot;libp24HJ256GP206-elf.a&amp;quot; files. These files are&lt;br /&gt;
located in &amp;quot;C:\Program Files\Microchip\MPLAB C30\lib\&amp;quot;. In the &amp;quot;Linker Script&amp;quot; folder you must add &amp;quot;.gld&amp;quot; file corresponding to your microcontroller.&lt;br /&gt;
For PIC24HJ256GP206 the file is &amp;quot;p24HJ256GP206.gld&amp;quot;, located in &amp;quot;C:\Program Files\Microchip\MPLAB C30\support\gld\&amp;quot;.&lt;br /&gt;
On the right top of the screen there is the editor window and on the bottom the output reports window, where you can see if there are some errors building&lt;br /&gt;
the code, errors in programmer/debugger connection and all other messages from MPLAB IDE.&lt;br /&gt;
&lt;br /&gt;
[[Image:MPLAB2.jpg]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Write the program ===&lt;br /&gt;
&lt;br /&gt;
Our first line of code is going to be:&lt;br /&gt;
&lt;br /&gt;
 #include &amp;lt;p24hj256gp206.h&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Note that 24hj256gp206 is the microcontroller used in this example. You must replace it with your own microcontroller model: files are located in&lt;br /&gt;
&amp;quot;C:\Program Files\Microchip\MPLAB C30\support\h\&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
This is a pseudo-instruction for the preprocessor telling the compiler to read the content of a device-specifi c file before proceeding any further.&lt;br /&gt;
The content of the device-specifi c “.h”&lt;br /&gt;
file chosen is a long list of the names (and sizes) of all the internal special-function registers (SFRs) of the chosen PIC model: those names reflect&lt;br /&gt;
exactly those being used in the device datasheet.&lt;br /&gt;
Let’s add a couple more lines that will introduce you to the main() function:&lt;br /&gt;
&lt;br /&gt;
 main()&lt;br /&gt;
 {&lt;br /&gt;
 &lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
This is a complete, although still empty and pretty useless, C-language program. In between those two curly brackets is where to put the instructions of&lt;br /&gt;
your embedded-control application.&lt;br /&gt;
&lt;br /&gt;
The main() function is the place where the microcontroller (program counter) will go first at power-up or after each subsequent reset.&lt;br /&gt;
Before entering the main() function, the microcontroller will execute a short initialization code segment automatically inserted by the linker.&lt;br /&gt;
This is known as the c0 code. The c0 code will perform basic housekeeping chores, including the initialization of the microcontroller stack, among other&lt;br /&gt;
things.&lt;br /&gt;
&lt;br /&gt;
 NOTES FOR C EXPERTS:&lt;br /&gt;
 Standard C library functions (like &amp;quot;printf&amp;quot;, for example) are readily available with the MPLAB C30 compiler. But we are&lt;br /&gt;
 targeting embedded-control applications and we are not writing code for multigigabyte workstations. Get used to&lt;br /&gt;
 manipulating low-level hardware peripherals inside the PIC24 microcontrollers. A single call to a library function, like&lt;br /&gt;
 printf, could have added several kilobytes of code to your executable. Don’t assume a serial port and a terminal or a&lt;br /&gt;
 text display will always be available to you. Instead, develop a sensibility for the “weight” of each  function and&lt;br /&gt;
 library you use in light of the limited resources available in the embedded-design world.&lt;/div&gt;</summary>
		<author><name>PaoloVilla</name></author>	</entry>

	<entry>
		<id>https://airwiki.deib.polimi.it/index.php?title=File:Memory_Usage_Gauge.jpg&amp;diff=9297</id>
		<title>File:Memory Usage Gauge.jpg</title>
		<link rel="alternate" type="text/html" href="https://airwiki.deib.polimi.it/index.php?title=File:Memory_Usage_Gauge.jpg&amp;diff=9297"/>
				<updated>2009-11-10T08:53:14Z</updated>
		
		<summary type="html">&lt;p&gt;PaoloVilla: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>PaoloVilla</name></author>	</entry>

	<entry>
		<id>https://airwiki.deib.polimi.it/index.php?title=File:MPLAB2.jpg&amp;diff=9242</id>
		<title>File:MPLAB2.jpg</title>
		<link rel="alternate" type="text/html" href="https://airwiki.deib.polimi.it/index.php?title=File:MPLAB2.jpg&amp;diff=9242"/>
				<updated>2009-11-09T12:17:24Z</updated>
		
		<summary type="html">&lt;p&gt;PaoloVilla: uploaded a new version of &amp;quot;Image:MPLAB2.jpg&amp;quot;&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>PaoloVilla</name></author>	</entry>

	<entry>
		<id>https://airwiki.deib.polimi.it/index.php?title=File:PicKit.jpg&amp;diff=9240</id>
		<title>File:PicKit.jpg</title>
		<link rel="alternate" type="text/html" href="https://airwiki.deib.polimi.it/index.php?title=File:PicKit.jpg&amp;diff=9240"/>
				<updated>2009-11-09T09:43:42Z</updated>
		
		<summary type="html">&lt;p&gt;PaoloVilla: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>PaoloVilla</name></author>	</entry>

	<entry>
		<id>https://airwiki.deib.polimi.it/index.php?title=File:ICD2.jpg&amp;diff=9239</id>
		<title>File:ICD2.jpg</title>
		<link rel="alternate" type="text/html" href="https://airwiki.deib.polimi.it/index.php?title=File:ICD2.jpg&amp;diff=9239"/>
				<updated>2009-11-09T09:43:16Z</updated>
		
		<summary type="html">&lt;p&gt;PaoloVilla: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>PaoloVilla</name></author>	</entry>

	<entry>
		<id>https://airwiki.deib.polimi.it/index.php?title=Getting_Started_With_PIC(TM)_MCU&amp;diff=9238</id>
		<title>Getting Started With PIC(TM) MCU</title>
		<link rel="alternate" type="text/html" href="https://airwiki.deib.polimi.it/index.php?title=Getting_Started_With_PIC(TM)_MCU&amp;diff=9238"/>
				<updated>2009-11-09T09:42:43Z</updated>
		
		<summary type="html">&lt;p&gt;PaoloVilla: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;!!!___WORK_IN_PROGRESS___!!!&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
 NOTE:&lt;br /&gt;
 This is not a replacement for the microcontroller datasheet, reference manual and programmer’s manual published by Microchip&lt;br /&gt;
 Technology. It is also not a replacement for the MPLAB C30 compiler user’s guide, and all the libraries and related software&lt;br /&gt;
 tools offered by Microchip. Should you notice a conflict between this document and the official documentation, ALWAYS refer&lt;br /&gt;
 to the latter.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== '''Part 1: Introduction''' ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Chosing a PIC(TM) Microcontroller ===&lt;br /&gt;
&lt;br /&gt;
The first step to chose a microcontroller is to focus on hardware/software needs:&lt;br /&gt;
&lt;br /&gt;
* Board power supply is 3V or 5V (or other)?&lt;br /&gt;
* Power saving is crucial? You need a Ultra-Micro-Low-Nanowatt-Power microcontroller?&lt;br /&gt;
* Application need a little, low cost microcontroller (8bit MCU), a bigger, high performance 16bit MCU or an exagerated 32bit microcontroller?&lt;br /&gt;
* What kind and how many peripherics are needed in your application? ADC, UART, Timers, PWM Channels, stackable Interrupts, SPI, I2C, Can Bus, Ethernet, USB... Yes, it's not a joke! High Performance PIC Microcontroller can have one or more USB and/or Ethernet port, you can implement usb mass storage or TCP-IP functions.&lt;br /&gt;
* Available memory space: you need an extra large memory because you just know your firmare will be extra long?&lt;br /&gt;
&lt;br /&gt;
Once you have answered some of these questions you can use Microchip Advanced Parts Selector (MAPS(TM)) to find only microcontrollers that satisfy your requirements.&lt;br /&gt;
MAPS is available on-line or for download directly from Microchip web site (http://www.microchip.com).&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Software tools ===&lt;br /&gt;
&lt;br /&gt;
Let’s verify you have all the necessary equipments, ready and installed (latest version available for download from Microchip web site at&lt;br /&gt;
http://www.microchip.com):&lt;br /&gt;
&lt;br /&gt;
* PIC MCU Datasheet;&lt;br /&gt;
* MPLAB IDE(TM), free Integrated Development Environment;&lt;br /&gt;
* MPLAB C30(TM), C compiler (demo or free student version).&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== '''Part 2: Basic hardware''' ==&lt;br /&gt;
&lt;br /&gt;
Besides a PC, because of we intend &amp;quot;make&amp;quot; something and not only talk about it, we need some hardware tools:&lt;br /&gt;
&lt;br /&gt;
* PIC MCU programmer-debugger (in Ai&amp;amp;R Lab Lambrate you can find some Microchip ICD2(TM) programmer-debugger, some adapter boards with ZIF socket and some self-made programming cables);&lt;br /&gt;
* PIC MCU demoboard or your board with power supply, PIC Microconroller, oscillator, MCLR circuitry and some input-output hardware.&lt;br /&gt;
&lt;br /&gt;
[[Image:ICD2.jpg]]&lt;br /&gt;
&lt;br /&gt;
If you are watching to buy an own programmer/debugger, Microchip PIC-KIT could be the right choise due to it's little dimensions, low price and good&lt;br /&gt;
performances. For detailed information, including PIC microcontroller supported list, visit microchip web site.&lt;br /&gt;
&lt;br /&gt;
[[Image:PicKit.jpg]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Oscillator ===&lt;br /&gt;
&lt;br /&gt;
The system clock (FOSC) source can be provided by a different number of options, depending by microcontroller family (low power, low cost microcontroller&lt;br /&gt;
allow less options choise than high power, high cost MCU).Generally options can be divided in:&lt;br /&gt;
&lt;br /&gt;
* Internal Oscillator (in general an internal RC network);&lt;br /&gt;
* External Oscillator (external clock source, external crystal or ceramic resonator operation and external RC network).&lt;br /&gt;
&lt;br /&gt;
[[Image:MCUOscillator.jpg]]&lt;br /&gt;
&lt;br /&gt;
In addition, oscillator system can includes on-chip Phase-Locked Loop (PLL) to boost internal operating frequency, on-the-fly clock switching between&lt;br /&gt;
various clock sources and Fail-Safe Clock Monitor (FSCM) that detects clock failure and permits safe application recovery or shutdown.&lt;br /&gt;
This means, for example, that with a PIC24H series microcontoller, you can use a 10Mhz external crystal resonator for clock source, but configuring&lt;br /&gt;
internal PLL circuitry through dedicated registers, you can obtain a 80Mhz internal clock frequency, achieving 40MIPS core operation speed&lt;br /&gt;
(PIC24H need two clock cycles to execute a single instruction).&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== MCLR circuit ===&lt;br /&gt;
&lt;br /&gt;
PIC Microcontroller has a number of reset sources and controls (POR: Power-on Reset; BOR: Brown-out Reset; MCLR: Master Clear Pin Reset; WDTO: Watchdog&lt;br /&gt;
Timer Reset).The external reset is generated by driving the MCLR pin low. The MCLR pin is a Schmitt trigger input with an additional glitch filter.&lt;br /&gt;
Reset pulses that are longer than the minimum pulse width generates a Reset (see datasheet). The External Reset (MCLR) Pin (EXTR) bit in the Reset&lt;br /&gt;
Control (RCON) register is set to indicate the MCLR Reset.If your system has an external supervisory circuits that generate reset signals to Reset&lt;br /&gt;
multiple devices in the system, this external Reset signal can be directly connected to the MCLR pin to&lt;br /&gt;
reset the device when the rest of system is Reset.&lt;br /&gt;
When using the internal power supervisory circuit to Reset the device, the external reset pin (MCLR) should be tied directly or resistively to VDD.&lt;br /&gt;
In this case, the MCLR pin is not used to generate a Reset. The external reset pin (MCLR) does not have an internal pull-up and must not be left&lt;br /&gt;
unconnected. A typical power-on reset circuit is:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Image:MCUMCLR.jpg]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Programming/Debugging interface ===&lt;br /&gt;
&lt;br /&gt;
ICSP(TM) (In-Circuit Serial Programming(TM)) mode is a special programming protocol that allows you to read and write to PIC Microcontroller and is the&lt;br /&gt;
most direct method used to program the device.The ICSP capability is Microchip’s proprietary process for microcontroller programming in the target&lt;br /&gt;
application. The ICSP interface uses two pins as its core.&lt;br /&gt;
The programming data pin (PGD) functions as both an input and an output, allowing programming data to be read in and device information to be read out&lt;br /&gt;
on command.The programming clock pin (PGC) clocks in data and controls the overall process.&lt;br /&gt;
&lt;br /&gt;
Serial programming allows customers to manufacture boards with unprogrammed devices and then to program the digital signal controller just before shipping&lt;br /&gt;
the product. Serial programming also allows the most recent firmware or a custom firmware to be programmed.&lt;br /&gt;
&lt;br /&gt;
Depending from used Microcontroller it's possible to have one or more programming ports. PIC24HJ256JP206, for example, has three pairs of programming&lt;br /&gt;
clock/data pins:&lt;br /&gt;
&lt;br /&gt;
* PGC1/EMUC1 and PGD1/EMUD1&lt;br /&gt;
* PGC2/EMUC2 and PGD2/EMUD2&lt;br /&gt;
* PGC3/EMUC3 and PGD3/EMUD3&lt;br /&gt;
&lt;br /&gt;
Used programming port must be specified in MPLAB IDE selecting &amp;quot;Configuration Bits...&amp;quot; in &amp;quot;Configure&amp;quot; menu.&lt;br /&gt;
The High-Level ICSP Programming Flow is:&lt;br /&gt;
&lt;br /&gt;
[[Image:HL_ICSP_PROGRAMMING_FLOW.jpg]]&lt;br /&gt;
&lt;br /&gt;
When the MPLAB(TM) ICD 2 or another in-circuit emulator is selected as a debugger,the in-circuit debugging functionality is enabled.&lt;br /&gt;
This function allows simple debugging when used with MPLAB IDE. The debugging functionality is controlled through the EMUCx (emulation/debug clock) and&lt;br /&gt;
EMUDx (emulation/debug data) pin functions. To use the in-circuit debugger function of the device, the design must implement ICSP connections to MCLR,&lt;br /&gt;
VDD, VSS, PGCx/EMCx and PGDx/EMUDx pin pairs. In addition, when the feature is enabled, some of the resources are not available for general use.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Programmer Connection ===&lt;br /&gt;
&lt;br /&gt;
ICD 2 programmer/debugger has a RJ12 6 pin output connector while PIC-KIT has a more comfortable 6 pin female strip headers. &lt;br /&gt;
The simplest way to interface programmer/debugger with microcontroller is to solder a 6 pin male strip headers to your board connetting PGCX, PGDX, MCLR,&lt;br /&gt;
VDD and VSS pins, as in figure:&lt;br /&gt;
&lt;br /&gt;
[[Image:ICSP_Connector.jpg]]&lt;br /&gt;
&lt;br /&gt;
Connecting pins in the same order as in figure you can either connect directly PIC-KIT to your board, or use an RJ12-&amp;gt;female_strip_headers adapter cable to&lt;br /&gt;
connect ICD 2 to target device. You can find two of that selfmade cabe in AI&amp;amp;R Lab, or you can build your own one using an RJ12 connector, a piece of 6 core&lt;br /&gt;
cable (you can use also a piece of 8 core ethernet cable), a 6 pin female strip headers and a bit of talent!&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== '''Part 3: PIC MCU programming''' ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== MPLAB IDE settings ===&lt;br /&gt;
&lt;br /&gt;
Select in &amp;quot;Debugger&amp;quot; menu the programmer/debugger device you have to use (probably &amp;quot;1 MPLAB ICD 2&amp;quot;, if you are working on AI&amp;amp;R Lab...)&lt;br /&gt;
&lt;br /&gt;
[[Image:MPLAB_Debugger_Menu.jpg]]&lt;br /&gt;
&lt;br /&gt;
To verify if programmer/debugger is connected to your Pc, to PIC microcontroller and is ready to operate select &amp;quot;Settings&amp;quot; in &amp;quot;Debug&amp;quot; menu and than pres&lt;br /&gt;
&amp;quot;Run Self Test&amp;quot; in the just opened window:&lt;br /&gt;
&lt;br /&gt;
[[Image:MPLAB_ICD2_Settings.jpg]]&lt;br /&gt;
&lt;br /&gt;
In this window you can also check the correct target power supply (&amp;quot;Power&amp;quot; submenu) and change PC-Programmer/debugger communication port&lt;br /&gt;
(&amp;quot;Communications&amp;quot; submenu).&lt;br /&gt;
&lt;br /&gt;
Let's talk about usefull functions on tool bar:&lt;br /&gt;
&lt;br /&gt;
[[Image:MPLAB_Menu.jpg]]&lt;br /&gt;
&lt;br /&gt;
* &amp;quot;Save File&amp;quot;: save only the file you are working on.&lt;br /&gt;
* &amp;quot;Find in Files&amp;quot;: find a word in all files included in the project.&lt;br /&gt;
* &amp;quot;Build Configuration&amp;quot;: to set up language tools for debug, select &amp;quot;Debug&amp;quot;; when your code is debugged and you are ready to release it (program the finished&lt;br /&gt;
code into a device), select &amp;quot;Release&amp;quot;. &lt;br /&gt;
* &amp;quot;Open Project&amp;quot;: open a just created project.&lt;br /&gt;
* &amp;quot;Save Workspace&amp;quot;: save all files in your project and workspace (windows placement on the screen).&lt;br /&gt;
* &amp;quot;Build All&amp;quot;: assemble, link and compile your project; the Output window shows the result of the build process.&lt;br /&gt;
* &amp;quot;Program Target Device&amp;quot;: program the microcontroller with your code; the Output window shows the result of this operation.&lt;br /&gt;
&lt;br /&gt;
[[Image:Output Window.jpg]]&lt;br /&gt;
&lt;br /&gt;
* &amp;quot;Run&amp;quot;: after you had build your project and programmed the microcontrolle, now you can run your application on PIC Microcontroller!&lt;br /&gt;
* &amp;quot;Halt&amp;quot;: halt program execution: the line of code where the application halted will be indicated by the solid green arrow.&lt;br /&gt;
* &amp;quot;Reset&amp;quot;: reset microcontroller.&lt;br /&gt;
* &amp;quot;BreakPoints&amp;quot;: Open the Breakpoint dialog window allowing to set or remove multiple breakpoints. &lt;br /&gt;
&lt;br /&gt;
[[Image:Breakpoints Window.jpg]]&lt;br /&gt;
&lt;br /&gt;
Once you will have create your project, builded it and programmed the microcontroller, in order to see if the code is operating as intended it's possible&lt;br /&gt;
to watch the values being written to microcontroller registers. Select View&amp;gt;Watch to bring up an empty Watch window. There are two pull downs on the top of&lt;br /&gt;
the Watch window. The one on the left labeled &amp;quot;Add SFR&amp;quot; can be used to add a phisical microcontroller register into the watch. Select a register from the&lt;br /&gt;
list and then click Add SFR to add it to the window. The pull down on the right, allows symbols to be added from the program. Use this pull down to add your&lt;br /&gt;
software variable into the Watch window. Select a variable from the list and then click Add Symbol to add it to the window. &lt;br /&gt;
The Watch window should now show the address, name and value of the registers you have added.&lt;br /&gt;
&lt;br /&gt;
[[Image:Watch Window.jpg]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Create a new project ===&lt;br /&gt;
&lt;br /&gt;
Then, let’s follow the “New Project Set-up” checklist to create a new project with the MPLAB IDE:&lt;br /&gt;
&lt;br /&gt;
* Select “Project-&amp;gt;Project Wizard” to activate the new project wizard, which will guide us automatically through the following steps…&lt;br /&gt;
* Select the correct PIC device, and click Next.&lt;br /&gt;
* Select the MPLAB C30 Compiler Suite and click Next.&lt;br /&gt;
* Create a new folder and name it “FolderName”; name the project “ProjectName” and click Next.&lt;br /&gt;
* Click Next to the following dialog (box—there is no need to copy any source files from any previous projects or directories.&lt;br /&gt;
* Click on Finish to complete the Wizard set-up.&lt;br /&gt;
&lt;br /&gt;
Open a new editor window.&lt;br /&gt;
&lt;br /&gt;
* Select “File-&amp;gt;Save As”, to save the file as: “FileName.c”.&lt;br /&gt;
* Select “Project-&amp;gt;Save” to save the project.&lt;br /&gt;
&lt;br /&gt;
You should have a screenshot similar to this one:&lt;br /&gt;
&lt;br /&gt;
[[Image:MPLAB1.jpg]]&lt;br /&gt;
&lt;br /&gt;
On the left you have the files list included in your project. Clicking on a folder you can add files (that you have just created with a simple text editor)&lt;br /&gt;
or folder to your project. In &amp;quot;Source Files&amp;quot; folder you must put all &amp;quot;.c&amp;quot; files, while &amp;quot;Header Files&amp;quot; folder is for &amp;quot;.h&amp;quot; files. In this folder you must add&lt;br /&gt;
the &amp;quot;.h&amp;quot; file corresponding to your microcontroller: for example, if you use a PIC24HJ256GP206 microcontroller, you will add the &amp;quot;p24hj256gp206.h&amp;quot;&lt;br /&gt;
file. These files are located in &amp;quot;C:\Program Files\Microchip\MPLAB C30\support\h\&amp;quot;. In &amp;quot;Library Files&amp;quot; folder you have to add the library file corresponding&lt;br /&gt;
to your device. As before, if your device is a PIC24HJ256GP206, you will add &amp;quot;libp24HJ256GP206-coff.a&amp;quot; and &amp;quot;libp24HJ256GP206-elf.a&amp;quot; files. These files are&lt;br /&gt;
located in &amp;quot;C:\Program Files\Microchip\MPLAB C30\lib\&amp;quot;. In the &amp;quot;Linker Script&amp;quot; folder you must add &amp;quot;.gld&amp;quot; file corresponding to your microcontroller.&lt;br /&gt;
For PIC24HJ256GP206 the file is &amp;quot;p24HJ256GP206.gld&amp;quot;, located in &amp;quot;C:\Program Files\Microchip\MPLAB C30\support\gld\&amp;quot;.&lt;br /&gt;
On the right top of the screen there is the editor window and on the bottom the output reports window, where you can see if there are some errors building&lt;br /&gt;
the code, errors in programmer/debugger connection and all other messages from MPLAB IDE.&lt;br /&gt;
&lt;br /&gt;
[[Image:MPLAB2.jpg]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Write the program ===&lt;br /&gt;
&lt;br /&gt;
Our first line of code is going to be:&lt;br /&gt;
&lt;br /&gt;
 #include &amp;lt;p24hj256gp206.h&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Note that 24hj256gp206 is the microcontroller used in this example. You must replace it with your own microcontroller model: files are located in&lt;br /&gt;
&amp;quot;C:\Program Files\Microchip\MPLAB C30\support\h\&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
This is a pseudo-instruction for the preprocessor telling the compiler to read the content of a device-specifi c file before proceeding any further.&lt;br /&gt;
The content of the device-specifi c “.h”&lt;br /&gt;
file chosen is a long list of the names (and sizes) of all the internal special-function registers (SFRs) of the chosen PIC model: those names reflect&lt;br /&gt;
exactly those being used in the device datasheet.&lt;br /&gt;
Let’s add a couple more lines that will introduce you to the main() function:&lt;br /&gt;
&lt;br /&gt;
 main()&lt;br /&gt;
 {&lt;br /&gt;
 &lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
The main() function is the place where the microcontroller (program counter) will go first at power-up or after each subsequent reset.&lt;br /&gt;
Before entering the main() function, the microcontroller will execute a short initialization code segment automatically inserted by the linker.&lt;br /&gt;
This is known as the c0 code. The c0 code will perform basic housekeeping chores, including the initialization of the microcontroller stack, among other&lt;br /&gt;
things.&lt;/div&gt;</summary>
		<author><name>PaoloVilla</name></author>	</entry>

	<entry>
		<id>https://airwiki.deib.polimi.it/index.php?title=Getting_Started_With_PIC(TM)_MCU&amp;diff=9237</id>
		<title>Getting Started With PIC(TM) MCU</title>
		<link rel="alternate" type="text/html" href="https://airwiki.deib.polimi.it/index.php?title=Getting_Started_With_PIC(TM)_MCU&amp;diff=9237"/>
				<updated>2009-11-09T09:14:41Z</updated>
		
		<summary type="html">&lt;p&gt;PaoloVilla: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;!!!___WORK_IN_PROGRESS___!!!&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
 NOTE:&lt;br /&gt;
 This is not a replacement for the microcontroller datasheet, reference manual and programmer’s manual published by Microchip&lt;br /&gt;
 Technology. It is also not a replacement for the MPLAB C30 compiler user’s guide, and all the libraries and related software&lt;br /&gt;
 tools offered by Microchip. Should you notice a conflict between this document and the official documentation, ALWAYS refer&lt;br /&gt;
 to the latter.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== '''Part 1: Introduction''' ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Chosing a PIC(TM) Microcontroller ===&lt;br /&gt;
&lt;br /&gt;
The first step to chose a microcontroller is to focus on hardware/software needs:&lt;br /&gt;
&lt;br /&gt;
* Board power supply is 3V or 5V (or other)?&lt;br /&gt;
* Power saving is crucial? You need a Ultra-Micro-Low-Nanowatt-Power microcontroller?&lt;br /&gt;
* Application need a little, low cost microcontroller (8bit MCU), a bigger, high performance 16bit MCU or an exagerated 32bit microcontroller?&lt;br /&gt;
* What kind and how many peripherics are needed in your application? ADC, UART, Timers, PWM Channels, stackable Interrupts, SPI, I2C, Can Bus, Ethernet, USB... Yes, it's not a joke! High Performance PIC Microcontroller can have one or more USB and/or Ethernet port, you can implement usb mass storage or TCP-IP functions.&lt;br /&gt;
* Available memory space: you need an extra large memory because you just know your firmare will be extra long?&lt;br /&gt;
&lt;br /&gt;
Once you have answered some of these questions you can use Microchip Advanced Parts Selector (MAPS(TM)) to find only microcontrollers that satisfy your requirements.&lt;br /&gt;
MAPS is available on-line or for download directly from Microchip web site (http://www.microchip.com).&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Software tools ===&lt;br /&gt;
&lt;br /&gt;
Let’s verify you have all the necessary equipments, ready and installed (latest version available for download from Microchip web site at&lt;br /&gt;
http://www.microchip.com):&lt;br /&gt;
&lt;br /&gt;
* PIC MCU Datasheet;&lt;br /&gt;
* MPLAB IDE(TM), free Integrated Development Environment;&lt;br /&gt;
* MPLAB C30(TM), C compiler (demo or free student version).&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== '''Part 2: Basic hardware''' ==&lt;br /&gt;
&lt;br /&gt;
Besides a PC, because of we intend &amp;quot;make&amp;quot; something and not only talk about it, we need some hardware tools:&lt;br /&gt;
&lt;br /&gt;
* PIC MCU programmer-debugger (in Ai&amp;amp;R Lab Lambrate you can find some Microchip ICD2(TM) programmer-debugger, some adapter boards with ZIF socket and some self-made programming cables);&lt;br /&gt;
* PIC MCU demoboard or your board with power supply, PIC Microconroller, oscillator, MCLR circuitry and some input-output hardware.&lt;br /&gt;
&lt;br /&gt;
If you are watching to buy an own programmer/debugger, Microchip PIC-KIT could be the right choise due to it's little dimensions, low price and good&lt;br /&gt;
performances. For detailed information, including PIC microcontroller supported list, visit microchip web site.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Oscillator ===&lt;br /&gt;
&lt;br /&gt;
The system clock (FOSC) source can be provided by a different number of options, depending by microcontroller family (low power, low cost microcontroller&lt;br /&gt;
allow less options choise than high power, high cost MCU).Generally options can be divided in:&lt;br /&gt;
&lt;br /&gt;
* Internal Oscillator (in general an internal RC network);&lt;br /&gt;
* External Oscillator (external clock source, external crystal or ceramic resonator operation and external RC network).&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Image:MCUOscillator.jpg]]&lt;br /&gt;
&lt;br /&gt;
In addition, oscillator system can includes on-chip Phase-Locked Loop (PLL) to boost internal operating frequency, on-the-fly clock switching between&lt;br /&gt;
various clock sources and Fail-Safe Clock Monitor (FSCM) that detects clock failure and permits safe application recovery or shutdown.&lt;br /&gt;
This means, for example, that with a PIC24H series microcontoller, you can use a 10Mhz external crystal resonator for clock source, but configuring&lt;br /&gt;
internal PLL circuitry through dedicated registers, you can obtain a 80Mhz internal clock frequency, achieving 40MIPS core operation speed&lt;br /&gt;
(PIC24H need two clock cycles to execute a single instruction).&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== MCLR circuit ===&lt;br /&gt;
&lt;br /&gt;
PIC Microcontroller has a number of reset sources and controls (POR: Power-on Reset; BOR: Brown-out Reset; MCLR: Master Clear Pin Reset; WDTO: Watchdog&lt;br /&gt;
Timer Reset).The external reset is generated by driving the MCLR pin low. The MCLR pin is a Schmitt trigger input with an additional glitch filter.&lt;br /&gt;
Reset pulses that are longer than the minimum pulse width generates a Reset (see datasheet). The External Reset (MCLR) Pin (EXTR) bit in the Reset&lt;br /&gt;
Control (RCON) register is set to indicate the MCLR Reset.If your system has an external supervisory circuits that generate reset signals to Reset&lt;br /&gt;
multiple devices in the system, this external Reset signal can be directly connected to the MCLR pin to&lt;br /&gt;
reset the device when the rest of system is Reset.&lt;br /&gt;
When using the internal power supervisory circuit to Reset the device, the external reset pin (MCLR) should be tied directly or resistively to VDD.&lt;br /&gt;
In this case, the MCLR pin is not used to generate a Reset. The external reset pin (MCLR) does not have an internal pull-up and must not be left&lt;br /&gt;
unconnected. A typical power-on reset circuit is:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Image:MCUMCLR.jpg]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Programming/Debugging interface ===&lt;br /&gt;
&lt;br /&gt;
ICSP(TM) (In-Circuit Serial Programming(TM)) mode is a special programming protocol that allows you to read and write to PIC Microcontroller and is the&lt;br /&gt;
most direct method used to program the device.The ICSP capability is Microchip’s proprietary process for microcontroller programming in the target&lt;br /&gt;
application. The ICSP interface uses two pins as its core.&lt;br /&gt;
The programming data pin (PGD) functions as both an input and an output, allowing programming data to be read in and device information to be read out&lt;br /&gt;
on command.The programming clock pin (PGC) clocks in data and controls the overall process.&lt;br /&gt;
&lt;br /&gt;
Serial programming allows customers to manufacture boards with unprogrammed devices and then to program the digital signal controller just before shipping&lt;br /&gt;
the product. Serial programming also allows the most recent firmware or a custom firmware to be programmed.&lt;br /&gt;
&lt;br /&gt;
Depending from used Microcontroller it's possible to have one or more programming ports. PIC24HJ256JP206, for example, has three pairs of programming&lt;br /&gt;
clock/data pins:&lt;br /&gt;
&lt;br /&gt;
* PGC1/EMUC1 and PGD1/EMUD1&lt;br /&gt;
* PGC2/EMUC2 and PGD2/EMUD2&lt;br /&gt;
* PGC3/EMUC3 and PGD3/EMUD3&lt;br /&gt;
&lt;br /&gt;
Used programming port must be specified in MPLAB IDE selecting &amp;quot;Configuration Bits...&amp;quot; in &amp;quot;Configure&amp;quot; menu.&lt;br /&gt;
The High-Level ICSP Programming Flow is:&lt;br /&gt;
&lt;br /&gt;
[[Image:HL_ICSP_PROGRAMMING_FLOW.jpg]]&lt;br /&gt;
&lt;br /&gt;
When the MPLAB(TM) ICD 2 or another in-circuit emulator is selected as a debugger,the in-circuit debugging functionality is enabled.&lt;br /&gt;
This function allows simple debugging when used with MPLAB IDE. The debugging functionality is controlled through the EMUCx (emulation/debug clock) and&lt;br /&gt;
EMUDx (emulation/debug data) pin functions. To use the in-circuit debugger function of the device, the design must implement ICSP connections to MCLR,&lt;br /&gt;
VDD, VSS, PGCx/EMCx and PGDx/EMUDx pin pairs. In addition, when the feature is enabled, some of the resources are not available for general use.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Programmer Connection ===&lt;br /&gt;
&lt;br /&gt;
ICD 2 programmer/debugger has a RJ12 6 pin output connector while PIC-KIT has a more comfortable 6 pin female strip headers. &lt;br /&gt;
The simplest way to interface programmer/debugger with microcontroller is to solder a 6 pin male strip headers to your board connetting PGCX, PGDX, MCLR,&lt;br /&gt;
VDD and VSS pins, as in figure:&lt;br /&gt;
&lt;br /&gt;
[[Image:ICSP_Connector.jpg]]&lt;br /&gt;
&lt;br /&gt;
Connecting pins in the same order as in figure you can either connect directly PIC-KIT to your board, or use an RJ12-&amp;gt;female_strip_headers adapter cable to&lt;br /&gt;
connect ICD 2 to target device. You can find two of that selfmade cabe in AI&amp;amp;R Lab, or you can build your own one using an RJ12 connector, a piece of 6 core&lt;br /&gt;
cable (you can use also a piece of 8 core ethernet cable), a 6 pin female strip headers and a bit of talent!&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== '''Part 3: PIC MCU programming''' ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== MPLAB IDE settings ===&lt;br /&gt;
&lt;br /&gt;
Select in &amp;quot;Debugger&amp;quot; menu the programmer/debugger device you have to use (probably &amp;quot;1 MPLAB ICD 2&amp;quot;, if you are working on AI&amp;amp;R Lab...)&lt;br /&gt;
&lt;br /&gt;
[[Image:MPLAB_Debugger_Menu.jpg]]&lt;br /&gt;
&lt;br /&gt;
To verify if programmer/debugger is connected to your Pc, to PIC microcontroller and is ready to operate select &amp;quot;Settings&amp;quot; in &amp;quot;Debug&amp;quot; menu and than pres&lt;br /&gt;
&amp;quot;Run Self Test&amp;quot; in the just opened window:&lt;br /&gt;
&lt;br /&gt;
[[Image:MPLAB_ICD2_Settings.jpg]]&lt;br /&gt;
&lt;br /&gt;
In this window you can also check the correct target power supply (&amp;quot;Power&amp;quot; submenu) and change PC-Programmer/debugger communication port&lt;br /&gt;
(&amp;quot;Communications&amp;quot; submenu).&lt;br /&gt;
&lt;br /&gt;
Let's talk about usefull functions on tool bar:&lt;br /&gt;
&lt;br /&gt;
[[Image:MPLAB_Menu.jpg]]&lt;br /&gt;
&lt;br /&gt;
* &amp;quot;Save File&amp;quot;: save only the file you are working on.&lt;br /&gt;
* &amp;quot;Find in Files&amp;quot;: find a word in all files included in the project.&lt;br /&gt;
* &amp;quot;Build Configuration&amp;quot;: to set up language tools for debug, select &amp;quot;Debug&amp;quot;; when your code is debugged and you are ready to release it (program the finished&lt;br /&gt;
code into a device), select &amp;quot;Release&amp;quot;. &lt;br /&gt;
* &amp;quot;Open Project&amp;quot;: open a just created project.&lt;br /&gt;
* &amp;quot;Save Workspace&amp;quot;: save all files in your project and workspace (windows placement on the screen).&lt;br /&gt;
* &amp;quot;Build All&amp;quot;: assemble, link and compile your project; the Output window shows the result of the build process.&lt;br /&gt;
* &amp;quot;Program Target Device&amp;quot;: program the microcontroller with your code; the Output window shows the result of this operation.&lt;br /&gt;
&lt;br /&gt;
[[Image:Output Window.jpg]]&lt;br /&gt;
&lt;br /&gt;
* &amp;quot;Run&amp;quot;: after you had build your project and programmed the microcontrolle, now you can run your application on PIC Microcontroller!&lt;br /&gt;
* &amp;quot;Halt&amp;quot;: halt program execution: the line of code where the application halted will be indicated by the solid green arrow.&lt;br /&gt;
* &amp;quot;Reset&amp;quot;: reset microcontroller.&lt;br /&gt;
* &amp;quot;BreakPoints&amp;quot;: Open the Breakpoint dialog window allowing to set or remove multiple breakpoints. &lt;br /&gt;
&lt;br /&gt;
[[Image:Breakpoints Window.jpg]]&lt;br /&gt;
&lt;br /&gt;
Once you will have create your project, builded it and programmed the microcontroller, in order to see if the code is operating as intended it's possible&lt;br /&gt;
to watch the values being written to microcontroller registers. Select View&amp;gt;Watch to bring up an empty Watch window. There are two pull downs on the top of&lt;br /&gt;
the Watch window. The one on the left labeled &amp;quot;Add SFR&amp;quot; can be used to add a phisical microcontroller register into the watch. Select a register from the&lt;br /&gt;
list and then click Add SFR to add it to the window. The pull down on the right, allows symbols to be added from the program. Use this pull down to add your&lt;br /&gt;
software variable into the Watch window. Select a variable from the list and then click Add Symbol to add it to the window. &lt;br /&gt;
The Watch window should now show the address, name and value of the registers you have added.&lt;br /&gt;
&lt;br /&gt;
[[Image:Watch Window.jpg]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Create a new project ===&lt;br /&gt;
&lt;br /&gt;
Then, let’s follow the “New Project Set-up” checklist to create a new project with the MPLAB IDE:&lt;br /&gt;
&lt;br /&gt;
* Select “Project-&amp;gt;Project Wizard” to activate the new project wizard, which will guide us automatically through the following steps…&lt;br /&gt;
* Select the correct PIC device, and click Next.&lt;br /&gt;
* Select the MPLAB C30 Compiler Suite and click Next.&lt;br /&gt;
* Create a new folder and name it “FolderName”; name the project “ProjectName” and click Next.&lt;br /&gt;
* Click Next to the following dialog (box—there is no need to copy any source files from any previous projects or directories.&lt;br /&gt;
* Click on Finish to complete the Wizard set-up.&lt;br /&gt;
&lt;br /&gt;
Open a new editor window.&lt;br /&gt;
&lt;br /&gt;
* Select “File-&amp;gt;Save As”, to save the file as: “FileName.c”.&lt;br /&gt;
* Select “Project-&amp;gt;Save” to save the project.&lt;br /&gt;
&lt;br /&gt;
You should have a screenshot similar to this one:&lt;br /&gt;
&lt;br /&gt;
[[Image:MPLAB1.jpg]]&lt;br /&gt;
&lt;br /&gt;
On the left you have the files list included in your project. Clicking on a folder you can add files (that you have just created with a simple text editor)&lt;br /&gt;
or folder to your project. In &amp;quot;Source Files&amp;quot; folder you must put all &amp;quot;.c&amp;quot; files, while &amp;quot;Header Files&amp;quot; folder is for &amp;quot;.h&amp;quot; files. In this folder you must add&lt;br /&gt;
the &amp;quot;.h&amp;quot; file corresponding to your microcontroller: for example, if you use a PIC24HJ256GP206 microcontroller, you will add the &amp;quot;p24hj256gp206.h&amp;quot;&lt;br /&gt;
file. These files are located in &amp;quot;C:\Program Files\Microchip\MPLAB C30\support\h\&amp;quot;. In &amp;quot;Library Files&amp;quot; folder you have to add the library file corresponding&lt;br /&gt;
to your device. As before, if your device is a PIC24HJ256GP206, you will add &amp;quot;libp24HJ256GP206-coff.a&amp;quot; and &amp;quot;libp24HJ256GP206-elf.a&amp;quot; files. These files are&lt;br /&gt;
located in &amp;quot;C:\Program Files\Microchip\MPLAB C30\lib\&amp;quot;. In the &amp;quot;Linker Script&amp;quot; folder you must add &amp;quot;.gld&amp;quot; file corresponding to your microcontroller.&lt;br /&gt;
For PIC24HJ256GP206 the file is &amp;quot;p24HJ256GP206.gld&amp;quot;, located in &amp;quot;C:\Program Files\Microchip\MPLAB C30\support\gld\&amp;quot;.&lt;br /&gt;
On the right top of the screen there is the editor window and on the bottom the output reports window, where you can see if there are some errors building&lt;br /&gt;
the code, errors in programmer/debugger connection and all other messages from MPLAB IDE.&lt;br /&gt;
&lt;br /&gt;
[[Image:MPLAB2.jpg]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Write the program ===&lt;br /&gt;
&lt;br /&gt;
Our first line of code is going to be:&lt;br /&gt;
&lt;br /&gt;
 #include &amp;lt;p24hj256gp206.h&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Note that 24hj256gp206 is the microcontroller used in this example. You must replace it with your own microcontroller model: files are located in&lt;br /&gt;
&amp;quot;C:\Program Files\Microchip\MPLAB C30\support\h\&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
This is a pseudo-instruction for the preprocessor telling the compiler to read the content of a device-specifi c file before proceeding any further.&lt;br /&gt;
The content of the device-specifi c “.h”&lt;br /&gt;
file chosen is a long list of the names (and sizes) of all the internal special-function registers (SFRs) of the chosen PIC model: those names reflect&lt;br /&gt;
exactly those being used in the device datasheet.&lt;br /&gt;
Let’s add a couple more lines that will introduce you to the main() function:&lt;br /&gt;
&lt;br /&gt;
 main()&lt;br /&gt;
 {&lt;br /&gt;
 &lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
The main() function is the place where the microcontroller (program counter) will go first at power-up or after each subsequent reset.&lt;br /&gt;
Before entering the main() function, the microcontroller will execute a short initialization code segment automatically inserted by the linker.&lt;br /&gt;
This is known as the c0 code. The c0 code will perform basic housekeeping chores, including the initialization of the microcontroller stack, among other&lt;br /&gt;
things.&lt;/div&gt;</summary>
		<author><name>PaoloVilla</name></author>	</entry>

	<entry>
		<id>https://airwiki.deib.polimi.it/index.php?title=Getting_Started_With_PIC(TM)_MCU&amp;diff=9236</id>
		<title>Getting Started With PIC(TM) MCU</title>
		<link rel="alternate" type="text/html" href="https://airwiki.deib.polimi.it/index.php?title=Getting_Started_With_PIC(TM)_MCU&amp;diff=9236"/>
				<updated>2009-11-09T09:14:04Z</updated>
		
		<summary type="html">&lt;p&gt;PaoloVilla: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;!!!___WORK_IN_PROGRESS___!!!&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
 NOTE:&lt;br /&gt;
 This is not a replacement for the microcontroller datasheet, reference manual and programmer’s manual published by Microchip&lt;br /&gt;
 Technology. It is also not a replacement for the MPLAB C30 compiler user’s guide, and all the libraries and related software&lt;br /&gt;
 tools offered by Microchip. Should you notice a conflict between this document and the official documentation, ALWAYS refer&lt;br /&gt;
 to the latter.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== '''Part 1: Introduction''' ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Chosing a PIC(TM) Microcontroller ===&lt;br /&gt;
&lt;br /&gt;
The first step to chose a microcontroller is to focus on hardware/software needs:&lt;br /&gt;
&lt;br /&gt;
* Board power supply is 3V or 5V (or other)?&lt;br /&gt;
* Power saving is crucial? You need a Ultra-Micro-Low-Nanowatt-Power microcontroller?&lt;br /&gt;
* Application need a little, low cost microcontroller (8bit MCU), a bigger, high performance 16bit MCU or an exagerated 32bit microcontroller?&lt;br /&gt;
* What kind and how many peripherics are needed in your application? ADC, UART, Timers, PWM Channels, stackable Interrupts, SPI, I2C, Can Bus, Ethernet, USB... Yes, it's not a joke! High Performance PIC Microcontroller can have one or more USB and/or Ethernet port, you can implement usb mass storage or TCP-IP functions.&lt;br /&gt;
* Available memory space: you need an extra large memory because you just know your firmare will be extra long?&lt;br /&gt;
&lt;br /&gt;
Once you have answered some of these questions you can use Microchip Advanced Parts Selector (MAPS(TM)) to find only microcontrollers that satisfy your&lt;br /&gt;
requirements.&lt;br /&gt;
MAPS is available on-line or for download directly from Microchip web site (http://www.microchip.com).&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Software tools ===&lt;br /&gt;
&lt;br /&gt;
Let’s verify you have all the necessary equipments, ready and installed (latest version available for download from Microchip web site at&lt;br /&gt;
http://www.microchip.com):&lt;br /&gt;
&lt;br /&gt;
* PIC MCU Datasheet;&lt;br /&gt;
* MPLAB IDE(TM), free Integrated Development Environment;&lt;br /&gt;
* MPLAB C30(TM), C compiler (demo or free student version).&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== '''Part 2: Basic hardware''' ==&lt;br /&gt;
&lt;br /&gt;
Besides a PC, because of we intend &amp;quot;make&amp;quot; something and not only talk about it, we need some hardware tools:&lt;br /&gt;
&lt;br /&gt;
* PIC MCU programmer-debugger (in Ai&amp;amp;R Lab Lambrate you can find some Microchip ICD2(TM) programmer-debugger, some adapter boards with ZIF socket and some&lt;br /&gt;
self-made programming cables);&lt;br /&gt;
* PIC MCU demoboard or your board with power supply, PIC Microconroller, oscillator, MCLR circuitry and some input-output hardware.&lt;br /&gt;
&lt;br /&gt;
If you are watching to buy an own programmer/debugger, Microchip PIC-KIT could be the right choise due to it's little dimensions, low price and good&lt;br /&gt;
performances. For detailed information, including PIC microcontroller supported list, visit microchip web site.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Oscillator ===&lt;br /&gt;
&lt;br /&gt;
The system clock (FOSC) source can be provided by a different number of options, depending by microcontroller family (low power, low cost microcontroller&lt;br /&gt;
allow less options choise than high power, high cost MCU).Generally options can be divided in:&lt;br /&gt;
&lt;br /&gt;
* Internal Oscillator (in general an internal RC network);&lt;br /&gt;
* External Oscillator (external clock source, external crystal or ceramic resonator operation and external RC network).&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Image:MCUOscillator.jpg]]&lt;br /&gt;
&lt;br /&gt;
In addition, oscillator system can includes on-chip Phase-Locked Loop (PLL) to boost internal operating frequency, on-the-fly clock switching between&lt;br /&gt;
various clock sources and Fail-Safe Clock Monitor (FSCM) that detects clock failure and permits safe application recovery or shutdown.&lt;br /&gt;
This means, for example, that with a PIC24H series microcontoller, you can use a 10Mhz external crystal resonator for clock source, but configuring&lt;br /&gt;
internal PLL circuitry through dedicated registers, you can obtain a 80Mhz internal clock frequency, achieving 40MIPS core operation speed&lt;br /&gt;
(PIC24H need two clock cycles to execute a single instruction).&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== MCLR circuit ===&lt;br /&gt;
&lt;br /&gt;
PIC Microcontroller has a number of reset sources and controls (POR: Power-on Reset; BOR: Brown-out Reset; MCLR: Master Clear Pin Reset; WDTO: Watchdog&lt;br /&gt;
Timer Reset).The external reset is generated by driving the MCLR pin low. The MCLR pin is a Schmitt trigger input with an additional glitch filter.&lt;br /&gt;
Reset pulses that are longer than the minimum pulse width generates a Reset (see datasheet). The External Reset (MCLR) Pin (EXTR) bit in the Reset&lt;br /&gt;
Control (RCON) register is set to indicate the MCLR Reset.If your system has an external supervisory circuits that generate reset signals to Reset&lt;br /&gt;
multiple devices in the system, this external Reset signal can be directly connected to the MCLR pin to&lt;br /&gt;
reset the device when the rest of system is Reset.&lt;br /&gt;
When using the internal power supervisory circuit to Reset the device, the external reset pin (MCLR) should be tied directly or resistively to VDD.&lt;br /&gt;
In this case, the MCLR pin is not used to generate a Reset. The external reset pin (MCLR) does not have an internal pull-up and must not be left&lt;br /&gt;
unconnected. A typical power-on reset circuit is:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Image:MCUMCLR.jpg]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Programming/Debugging interface ===&lt;br /&gt;
&lt;br /&gt;
ICSP(TM) (In-Circuit Serial Programming(TM)) mode is a special programming protocol that allows you to read and write to PIC Microcontroller and is the&lt;br /&gt;
most direct method used to program the device.The ICSP capability is Microchip’s proprietary process for microcontroller programming in the target&lt;br /&gt;
application. The ICSP interface uses two pins as its core.&lt;br /&gt;
The programming data pin (PGD) functions as both an input and an output, allowing programming data to be read in and device information to be read out&lt;br /&gt;
on command.The programming clock pin (PGC) clocks in data and controls the overall process.&lt;br /&gt;
&lt;br /&gt;
Serial programming allows customers to manufacture boards with unprogrammed devices and then to program the digital signal controller just before shipping&lt;br /&gt;
the product. Serial programming also allows the most recent firmware or a custom firmware to be programmed.&lt;br /&gt;
&lt;br /&gt;
Depending from used Microcontroller it's possible to have one or more programming ports. PIC24HJ256JP206, for example, has three pairs of programming&lt;br /&gt;
clock/data pins:&lt;br /&gt;
&lt;br /&gt;
* PGC1/EMUC1 and PGD1/EMUD1&lt;br /&gt;
* PGC2/EMUC2 and PGD2/EMUD2&lt;br /&gt;
* PGC3/EMUC3 and PGD3/EMUD3&lt;br /&gt;
&lt;br /&gt;
Used programming port must be specified in MPLAB IDE selecting &amp;quot;Configuration Bits...&amp;quot; in &amp;quot;Configure&amp;quot; menu.&lt;br /&gt;
The High-Level ICSP Programming Flow is:&lt;br /&gt;
&lt;br /&gt;
[[Image:HL_ICSP_PROGRAMMING_FLOW.jpg]]&lt;br /&gt;
&lt;br /&gt;
When the MPLAB(TM) ICD 2 or another in-circuit emulator is selected as a debugger,the in-circuit debugging functionality is enabled.&lt;br /&gt;
This function allows simple debugging when used with MPLAB IDE. The debugging functionality is controlled through the EMUCx (emulation/debug clock) and&lt;br /&gt;
EMUDx (emulation/debug data) pin functions. To use the in-circuit debugger function of the device, the design must implement ICSP connections to MCLR,&lt;br /&gt;
VDD, VSS, PGCx/EMCx and PGDx/EMUDx pin pairs. In addition, when the feature is enabled, some of the resources are not available for general use.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Programmer Connection ===&lt;br /&gt;
&lt;br /&gt;
ICD 2 programmer/debugger has a RJ12 6 pin output connector while PIC-KIT has a more comfortable 6 pin female strip headers. &lt;br /&gt;
The simplest way to interface programmer/debugger with microcontroller is to solder a 6 pin male strip headers to your board connetting PGCX, PGDX, MCLR,&lt;br /&gt;
VDD and VSS pins, as in figure:&lt;br /&gt;
&lt;br /&gt;
[[Image:ICSP_Connector.jpg]]&lt;br /&gt;
&lt;br /&gt;
Connecting pins in the same order as in figure you can either connect directly PIC-KIT to your board, or use an RJ12-&amp;gt;female_strip_headers adapter cable to&lt;br /&gt;
connect ICD 2 to target device. You can find two of that selfmade cabe in AI&amp;amp;R Lab, or you can build your own one using an RJ12 connector, a piece of 6 core&lt;br /&gt;
cable (you can use also a piece of 8 core ethernet cable), a 6 pin female strip headers and a bit of talent!&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== '''Part 3: PIC MCU programming''' ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== MPLAB IDE settings ===&lt;br /&gt;
&lt;br /&gt;
Select in &amp;quot;Debugger&amp;quot; menu the programmer/debugger device you have to use (probably &amp;quot;1 MPLAB ICD 2&amp;quot;, if you are working on AI&amp;amp;R Lab...)&lt;br /&gt;
&lt;br /&gt;
[[Image:MPLAB_Debugger_Menu.jpg]]&lt;br /&gt;
&lt;br /&gt;
To verify if programmer/debugger is connected to your Pc, to PIC microcontroller and is ready to operate select &amp;quot;Settings&amp;quot; in &amp;quot;Debug&amp;quot; menu and than pres&lt;br /&gt;
&amp;quot;Run Self Test&amp;quot; in the just opened window:&lt;br /&gt;
&lt;br /&gt;
[[Image:MPLAB_ICD2_Settings.jpg]]&lt;br /&gt;
&lt;br /&gt;
In this window you can also check the correct target power supply (&amp;quot;Power&amp;quot; submenu) and change PC-Programmer/debugger communication port&lt;br /&gt;
(&amp;quot;Communications&amp;quot; submenu).&lt;br /&gt;
&lt;br /&gt;
Let's talk about usefull functions on tool bar:&lt;br /&gt;
&lt;br /&gt;
[[Image:MPLAB_Menu.jpg]]&lt;br /&gt;
&lt;br /&gt;
* &amp;quot;Save File&amp;quot;: save only the file you are working on.&lt;br /&gt;
* &amp;quot;Find in Files&amp;quot;: find a word in all files included in the project.&lt;br /&gt;
* &amp;quot;Build Configuration&amp;quot;: to set up language tools for debug, select &amp;quot;Debug&amp;quot;; when your code is debugged and you are ready to release it (program the finished&lt;br /&gt;
code into a device), select &amp;quot;Release&amp;quot;. &lt;br /&gt;
* &amp;quot;Open Project&amp;quot;: open a just created project.&lt;br /&gt;
* &amp;quot;Save Workspace&amp;quot;: save all files in your project and workspace (windows placement on the screen).&lt;br /&gt;
* &amp;quot;Build All&amp;quot;: assemble, link and compile your project; the Output window shows the result of the build process.&lt;br /&gt;
* &amp;quot;Program Target Device&amp;quot;: program the microcontroller with your code; the Output window shows the result of this operation.&lt;br /&gt;
&lt;br /&gt;
[[Image:Output Window.jpg]]&lt;br /&gt;
&lt;br /&gt;
* &amp;quot;Run&amp;quot;: after you had build your project and programmed the microcontrolle, now you can run your application on PIC Microcontroller!&lt;br /&gt;
* &amp;quot;Halt&amp;quot;: halt program execution: the line of code where the application halted will be indicated by the solid green arrow.&lt;br /&gt;
* &amp;quot;Reset&amp;quot;: reset microcontroller.&lt;br /&gt;
* &amp;quot;BreakPoints&amp;quot;: Open the Breakpoint dialog window allowing to set or remove multiple breakpoints. &lt;br /&gt;
&lt;br /&gt;
[[Image:Breakpoints Window.jpg]]&lt;br /&gt;
&lt;br /&gt;
Once you will have create your project, builded it and programmed the microcontroller, in order to see if the code is operating as intended it's possible&lt;br /&gt;
to watch the values being written to microcontroller registers. Select View&amp;gt;Watch to bring up an empty Watch window. There are two pull downs on the top of&lt;br /&gt;
the Watch window. The one on the left labeled &amp;quot;Add SFR&amp;quot; can be used to add a phisical microcontroller register into the watch. Select a register from the&lt;br /&gt;
list and then click Add SFR to add it to the window. The pull down on the right, allows symbols to be added from the program. Use this pull down to add your&lt;br /&gt;
software variable into the Watch window. Select a variable from the list and then click Add Symbol to add it to the window. &lt;br /&gt;
The Watch window should now show the address, name and value of the registers you have added.&lt;br /&gt;
&lt;br /&gt;
[[Image:Watch Window.jpg]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Create a new project ===&lt;br /&gt;
&lt;br /&gt;
Then, let’s follow the “New Project Set-up” checklist to create a new project with the MPLAB IDE:&lt;br /&gt;
&lt;br /&gt;
* Select “Project-&amp;gt;Project Wizard” to activate the new project wizard, which will guide us automatically through the following steps…&lt;br /&gt;
* Select the correct PIC device, and click Next.&lt;br /&gt;
* Select the MPLAB C30 Compiler Suite and click Next.&lt;br /&gt;
* Create a new folder and name it “FolderName”; name the project “ProjectName” and click Next.&lt;br /&gt;
* Click Next to the following dialog (box—there is no need to copy any source files from any previous projects or directories.&lt;br /&gt;
* Click on Finish to complete the Wizard set-up.&lt;br /&gt;
&lt;br /&gt;
Open a new editor window.&lt;br /&gt;
&lt;br /&gt;
* Select “File-&amp;gt;Save As”, to save the file as: “FileName.c”.&lt;br /&gt;
* Select “Project-&amp;gt;Save” to save the project.&lt;br /&gt;
&lt;br /&gt;
You should have a screenshot similar to this one:&lt;br /&gt;
&lt;br /&gt;
[[Image:MPLAB1.jpg]]&lt;br /&gt;
&lt;br /&gt;
On the left you have the files list included in your project. Clicking on a folder you can add files (that you have just created with a simple text editor)&lt;br /&gt;
or folder to your project. In &amp;quot;Source Files&amp;quot; folder you must put all &amp;quot;.c&amp;quot; files, while &amp;quot;Header Files&amp;quot; folder is for &amp;quot;.h&amp;quot; files. In this folder you must add&lt;br /&gt;
the &amp;quot;.h&amp;quot; file corresponding to your microcontroller: for example, if you use a PIC24HJ256GP206 microcontroller, you will add the &amp;quot;p24hj256gp206.h&amp;quot;&lt;br /&gt;
file. These files are located in &amp;quot;C:\Program Files\Microchip\MPLAB C30\support\h\&amp;quot;. In &amp;quot;Library Files&amp;quot; folder you have to add the library file corresponding&lt;br /&gt;
to your device. As before, if your device is a PIC24HJ256GP206, you will add &amp;quot;libp24HJ256GP206-coff.a&amp;quot; and &amp;quot;libp24HJ256GP206-elf.a&amp;quot; files. These files are&lt;br /&gt;
located in &amp;quot;C:\Program Files\Microchip\MPLAB C30\lib\&amp;quot;. In the &amp;quot;Linker Script&amp;quot; folder you must add &amp;quot;.gld&amp;quot; file corresponding to your microcontroller.&lt;br /&gt;
For PIC24HJ256GP206 the file is &amp;quot;p24HJ256GP206.gld&amp;quot;, located in &amp;quot;C:\Program Files\Microchip\MPLAB C30\support\gld\&amp;quot;.&lt;br /&gt;
On the right top of the screen there is the editor window and on the bottom the output reports window, where you can see if there are some errors building&lt;br /&gt;
the code, errors in programmer/debugger connection and all other messages from MPLAB IDE.&lt;br /&gt;
&lt;br /&gt;
[[Image:MPLAB2.jpg]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Write the program ===&lt;br /&gt;
&lt;br /&gt;
Our first line of code is going to be:&lt;br /&gt;
&lt;br /&gt;
 #include &amp;lt;p24hj256gp206.h&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Note that 24hj256gp206 is the microcontroller used in this example. You must replace it with your own microcontroller model: files are located in&lt;br /&gt;
&amp;quot;C:\Program Files\Microchip\MPLAB C30\support\h\&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
This is a pseudo-instruction for the preprocessor telling the compiler to read the content of a device-specifi c file before proceeding any further.&lt;br /&gt;
The content of the device-specifi c “.h”&lt;br /&gt;
file chosen is a long list of the names (and sizes) of all the internal special-function registers (SFRs) of the chosen PIC model: those names reflect&lt;br /&gt;
exactly those being used in the device datasheet.&lt;br /&gt;
Let’s add a couple more lines that will introduce you to the main() function:&lt;br /&gt;
&lt;br /&gt;
 main()&lt;br /&gt;
 {&lt;br /&gt;
 &lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
The main() function is the place where the microcontroller (program counter) will go first at power-up or after each subsequent reset.&lt;br /&gt;
Before entering the main() function, the microcontroller will execute a short initialization code segment automatically inserted by the linker.&lt;br /&gt;
This is known as the c0 code. The c0 code will perform basic housekeeping chores, including the initialization of the microcontroller stack, among other&lt;br /&gt;
things.&lt;/div&gt;</summary>
		<author><name>PaoloVilla</name></author>	</entry>

	<entry>
		<id>https://airwiki.deib.polimi.it/index.php?title=Getting_Started_With_PIC(TM)_MCU&amp;diff=9235</id>
		<title>Getting Started With PIC(TM) MCU</title>
		<link rel="alternate" type="text/html" href="https://airwiki.deib.polimi.it/index.php?title=Getting_Started_With_PIC(TM)_MCU&amp;diff=9235"/>
				<updated>2009-11-09T09:13:43Z</updated>
		
		<summary type="html">&lt;p&gt;PaoloVilla: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;!!!___WORK_IN_PROGRESS___!!!&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
 NOTE:&lt;br /&gt;
 This is not a replacement for the microcontroller datasheet, reference manual and programmer’s manual published by Microchip&lt;br /&gt;
 Technology. It is also not a replacement for the MPLAB C30 compiler user’s guide, and all the libraries and related software&lt;br /&gt;
 tools offered by Microchip. Should you notice a conflict between this document and the official documentation, ALWAYS refer&lt;br /&gt;
 to the latter.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== '''Part 1: Introduction''' ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Chosing a PIC(TM) Microcontroller ===&lt;br /&gt;
&lt;br /&gt;
The first step to chose a microcontroller is to focus on hardware/software needs:&lt;br /&gt;
&lt;br /&gt;
* Board power supply is 3V or 5V (or other)?&lt;br /&gt;
* Power saving is crucial? You need a Ultra-Micro-Low-Nanowatt-Power microcontroller?&lt;br /&gt;
* Application need a little, low cost microcontroller (8bit MCU), a bigger, high performance 16bit MCU or an exagerated 32bit microcontroller?&lt;br /&gt;
* What kind and how many peripherics are needed in your application? ADC, UART, Timers, PWM Channels, stackable Interrupts, SPI, I2C, Can Bus, Ethernet, USB... Yes, it's not a joke! High Performance PIC Microcontroller can have one or more USB and/or Ethernet port, you can implement usb mass storage or&lt;br /&gt;
TCP-IP functions.&lt;br /&gt;
* Available memory space: you need an extra large memory because you just know your firmare will be extra long?&lt;br /&gt;
&lt;br /&gt;
Once you have answered some of these questions you can use Microchip Advanced Parts Selector (MAPS(TM)) to find only microcontrollers that satisfy your&lt;br /&gt;
requirements.&lt;br /&gt;
MAPS is available on-line or for download directly from Microchip web site (http://www.microchip.com).&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Software tools ===&lt;br /&gt;
&lt;br /&gt;
Let’s verify you have all the necessary equipments, ready and installed (latest version available for download from Microchip web site at&lt;br /&gt;
http://www.microchip.com):&lt;br /&gt;
&lt;br /&gt;
* PIC MCU Datasheet;&lt;br /&gt;
* MPLAB IDE(TM), free Integrated Development Environment;&lt;br /&gt;
* MPLAB C30(TM), C compiler (demo or free student version).&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== '''Part 2: Basic hardware''' ==&lt;br /&gt;
&lt;br /&gt;
Besides a PC, because of we intend &amp;quot;make&amp;quot; something and not only talk about it, we need some hardware tools:&lt;br /&gt;
&lt;br /&gt;
* PIC MCU programmer-debugger (in Ai&amp;amp;R Lab Lambrate you can find some Microchip ICD2(TM) programmer-debugger, some adapter boards with ZIF socket and some&lt;br /&gt;
self-made programming cables);&lt;br /&gt;
* PIC MCU demoboard or your board with power supply, PIC Microconroller, oscillator, MCLR circuitry and some input-output hardware.&lt;br /&gt;
&lt;br /&gt;
If you are watching to buy an own programmer/debugger, Microchip PIC-KIT could be the right choise due to it's little dimensions, low price and good&lt;br /&gt;
performances. For detailed information, including PIC microcontroller supported list, visit microchip web site.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Oscillator ===&lt;br /&gt;
&lt;br /&gt;
The system clock (FOSC) source can be provided by a different number of options, depending by microcontroller family (low power, low cost microcontroller&lt;br /&gt;
allow less options choise than high power, high cost MCU).Generally options can be divided in:&lt;br /&gt;
&lt;br /&gt;
* Internal Oscillator (in general an internal RC network);&lt;br /&gt;
* External Oscillator (external clock source, external crystal or ceramic resonator operation and external RC network).&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Image:MCUOscillator.jpg]]&lt;br /&gt;
&lt;br /&gt;
In addition, oscillator system can includes on-chip Phase-Locked Loop (PLL) to boost internal operating frequency, on-the-fly clock switching between&lt;br /&gt;
various clock sources and Fail-Safe Clock Monitor (FSCM) that detects clock failure and permits safe application recovery or shutdown.&lt;br /&gt;
This means, for example, that with a PIC24H series microcontoller, you can use a 10Mhz external crystal resonator for clock source, but configuring&lt;br /&gt;
internal PLL circuitry through dedicated registers, you can obtain a 80Mhz internal clock frequency, achieving 40MIPS core operation speed&lt;br /&gt;
(PIC24H need two clock cycles to execute a single instruction).&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== MCLR circuit ===&lt;br /&gt;
&lt;br /&gt;
PIC Microcontroller has a number of reset sources and controls (POR: Power-on Reset; BOR: Brown-out Reset; MCLR: Master Clear Pin Reset; WDTO: Watchdog&lt;br /&gt;
Timer Reset).The external reset is generated by driving the MCLR pin low. The MCLR pin is a Schmitt trigger input with an additional glitch filter.&lt;br /&gt;
Reset pulses that are longer than the minimum pulse width generates a Reset (see datasheet). The External Reset (MCLR) Pin (EXTR) bit in the Reset&lt;br /&gt;
Control (RCON) register is set to indicate the MCLR Reset.If your system has an external supervisory circuits that generate reset signals to Reset&lt;br /&gt;
multiple devices in the system, this external Reset signal can be directly connected to the MCLR pin to&lt;br /&gt;
reset the device when the rest of system is Reset.&lt;br /&gt;
When using the internal power supervisory circuit to Reset the device, the external reset pin (MCLR) should be tied directly or resistively to VDD.&lt;br /&gt;
In this case, the MCLR pin is not used to generate a Reset. The external reset pin (MCLR) does not have an internal pull-up and must not be left&lt;br /&gt;
unconnected. A typical power-on reset circuit is:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Image:MCUMCLR.jpg]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Programming/Debugging interface ===&lt;br /&gt;
&lt;br /&gt;
ICSP(TM) (In-Circuit Serial Programming(TM)) mode is a special programming protocol that allows you to read and write to PIC Microcontroller and is the&lt;br /&gt;
most direct method used to program the device.The ICSP capability is Microchip’s proprietary process for microcontroller programming in the target&lt;br /&gt;
application. The ICSP interface uses two pins as its core.&lt;br /&gt;
The programming data pin (PGD) functions as both an input and an output, allowing programming data to be read in and device information to be read out&lt;br /&gt;
on command.The programming clock pin (PGC) clocks in data and controls the overall process.&lt;br /&gt;
&lt;br /&gt;
Serial programming allows customers to manufacture boards with unprogrammed devices and then to program the digital signal controller just before shipping&lt;br /&gt;
the product. Serial programming also allows the most recent firmware or a custom firmware to be programmed.&lt;br /&gt;
&lt;br /&gt;
Depending from used Microcontroller it's possible to have one or more programming ports. PIC24HJ256JP206, for example, has three pairs of programming&lt;br /&gt;
clock/data pins:&lt;br /&gt;
&lt;br /&gt;
* PGC1/EMUC1 and PGD1/EMUD1&lt;br /&gt;
* PGC2/EMUC2 and PGD2/EMUD2&lt;br /&gt;
* PGC3/EMUC3 and PGD3/EMUD3&lt;br /&gt;
&lt;br /&gt;
Used programming port must be specified in MPLAB IDE selecting &amp;quot;Configuration Bits...&amp;quot; in &amp;quot;Configure&amp;quot; menu.&lt;br /&gt;
The High-Level ICSP Programming Flow is:&lt;br /&gt;
&lt;br /&gt;
[[Image:HL_ICSP_PROGRAMMING_FLOW.jpg]]&lt;br /&gt;
&lt;br /&gt;
When the MPLAB(TM) ICD 2 or another in-circuit emulator is selected as a debugger,the in-circuit debugging functionality is enabled.&lt;br /&gt;
This function allows simple debugging when used with MPLAB IDE. The debugging functionality is controlled through the EMUCx (emulation/debug clock) and&lt;br /&gt;
EMUDx (emulation/debug data) pin functions. To use the in-circuit debugger function of the device, the design must implement ICSP connections to MCLR,&lt;br /&gt;
VDD, VSS, PGCx/EMCx and PGDx/EMUDx pin pairs. In addition, when the feature is enabled, some of the resources are not available for general use.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Programmer Connection ===&lt;br /&gt;
&lt;br /&gt;
ICD 2 programmer/debugger has a RJ12 6 pin output connector while PIC-KIT has a more comfortable 6 pin female strip headers. &lt;br /&gt;
The simplest way to interface programmer/debugger with microcontroller is to solder a 6 pin male strip headers to your board connetting PGCX, PGDX, MCLR,&lt;br /&gt;
VDD and VSS pins, as in figure:&lt;br /&gt;
&lt;br /&gt;
[[Image:ICSP_Connector.jpg]]&lt;br /&gt;
&lt;br /&gt;
Connecting pins in the same order as in figure you can either connect directly PIC-KIT to your board, or use an RJ12-&amp;gt;female_strip_headers adapter cable to&lt;br /&gt;
connect ICD 2 to target device. You can find two of that selfmade cabe in AI&amp;amp;R Lab, or you can build your own one using an RJ12 connector, a piece of 6 core&lt;br /&gt;
cable (you can use also a piece of 8 core ethernet cable), a 6 pin female strip headers and a bit of talent!&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== '''Part 3: PIC MCU programming''' ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== MPLAB IDE settings ===&lt;br /&gt;
&lt;br /&gt;
Select in &amp;quot;Debugger&amp;quot; menu the programmer/debugger device you have to use (probably &amp;quot;1 MPLAB ICD 2&amp;quot;, if you are working on AI&amp;amp;R Lab...)&lt;br /&gt;
&lt;br /&gt;
[[Image:MPLAB_Debugger_Menu.jpg]]&lt;br /&gt;
&lt;br /&gt;
To verify if programmer/debugger is connected to your Pc, to PIC microcontroller and is ready to operate select &amp;quot;Settings&amp;quot; in &amp;quot;Debug&amp;quot; menu and than pres&lt;br /&gt;
&amp;quot;Run Self Test&amp;quot; in the just opened window:&lt;br /&gt;
&lt;br /&gt;
[[Image:MPLAB_ICD2_Settings.jpg]]&lt;br /&gt;
&lt;br /&gt;
In this window you can also check the correct target power supply (&amp;quot;Power&amp;quot; submenu) and change PC-Programmer/debugger communication port&lt;br /&gt;
(&amp;quot;Communications&amp;quot; submenu).&lt;br /&gt;
&lt;br /&gt;
Let's talk about usefull functions on tool bar:&lt;br /&gt;
&lt;br /&gt;
[[Image:MPLAB_Menu.jpg]]&lt;br /&gt;
&lt;br /&gt;
* &amp;quot;Save File&amp;quot;: save only the file you are working on.&lt;br /&gt;
* &amp;quot;Find in Files&amp;quot;: find a word in all files included in the project.&lt;br /&gt;
* &amp;quot;Build Configuration&amp;quot;: to set up language tools for debug, select &amp;quot;Debug&amp;quot;; when your code is debugged and you are ready to release it (program the finished&lt;br /&gt;
code into a device), select &amp;quot;Release&amp;quot;. &lt;br /&gt;
* &amp;quot;Open Project&amp;quot;: open a just created project.&lt;br /&gt;
* &amp;quot;Save Workspace&amp;quot;: save all files in your project and workspace (windows placement on the screen).&lt;br /&gt;
* &amp;quot;Build All&amp;quot;: assemble, link and compile your project; the Output window shows the result of the build process.&lt;br /&gt;
* &amp;quot;Program Target Device&amp;quot;: program the microcontroller with your code; the Output window shows the result of this operation.&lt;br /&gt;
&lt;br /&gt;
[[Image:Output Window.jpg]]&lt;br /&gt;
&lt;br /&gt;
* &amp;quot;Run&amp;quot;: after you had build your project and programmed the microcontrolle, now you can run your application on PIC Microcontroller!&lt;br /&gt;
* &amp;quot;Halt&amp;quot;: halt program execution: the line of code where the application halted will be indicated by the solid green arrow.&lt;br /&gt;
* &amp;quot;Reset&amp;quot;: reset microcontroller.&lt;br /&gt;
* &amp;quot;BreakPoints&amp;quot;: Open the Breakpoint dialog window allowing to set or remove multiple breakpoints. &lt;br /&gt;
&lt;br /&gt;
[[Image:Breakpoints Window.jpg]]&lt;br /&gt;
&lt;br /&gt;
Once you will have create your project, builded it and programmed the microcontroller, in order to see if the code is operating as intended it's possible&lt;br /&gt;
to watch the values being written to microcontroller registers. Select View&amp;gt;Watch to bring up an empty Watch window. There are two pull downs on the top of&lt;br /&gt;
the Watch window. The one on the left labeled &amp;quot;Add SFR&amp;quot; can be used to add a phisical microcontroller register into the watch. Select a register from the&lt;br /&gt;
list and then click Add SFR to add it to the window. The pull down on the right, allows symbols to be added from the program. Use this pull down to add your&lt;br /&gt;
software variable into the Watch window. Select a variable from the list and then click Add Symbol to add it to the window. &lt;br /&gt;
The Watch window should now show the address, name and value of the registers you have added.&lt;br /&gt;
&lt;br /&gt;
[[Image:Watch Window.jpg]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Create a new project ===&lt;br /&gt;
&lt;br /&gt;
Then, let’s follow the “New Project Set-up” checklist to create a new project with the MPLAB IDE:&lt;br /&gt;
&lt;br /&gt;
* Select “Project-&amp;gt;Project Wizard” to activate the new project wizard, which will guide us automatically through the following steps…&lt;br /&gt;
* Select the correct PIC device, and click Next.&lt;br /&gt;
* Select the MPLAB C30 Compiler Suite and click Next.&lt;br /&gt;
* Create a new folder and name it “FolderName”; name the project “ProjectName” and click Next.&lt;br /&gt;
* Click Next to the following dialog (box—there is no need to copy any source files from any previous projects or directories.&lt;br /&gt;
* Click on Finish to complete the Wizard set-up.&lt;br /&gt;
&lt;br /&gt;
Open a new editor window.&lt;br /&gt;
&lt;br /&gt;
* Select “File-&amp;gt;Save As”, to save the file as: “FileName.c”.&lt;br /&gt;
* Select “Project-&amp;gt;Save” to save the project.&lt;br /&gt;
&lt;br /&gt;
You should have a screenshot similar to this one:&lt;br /&gt;
&lt;br /&gt;
[[Image:MPLAB1.jpg]]&lt;br /&gt;
&lt;br /&gt;
On the left you have the files list included in your project. Clicking on a folder you can add files (that you have just created with a simple text editor)&lt;br /&gt;
or folder to your project. In &amp;quot;Source Files&amp;quot; folder you must put all &amp;quot;.c&amp;quot; files, while &amp;quot;Header Files&amp;quot; folder is for &amp;quot;.h&amp;quot; files. In this folder you must add&lt;br /&gt;
the &amp;quot;.h&amp;quot; file corresponding to your microcontroller: for example, if you use a PIC24HJ256GP206 microcontroller, you will add the &amp;quot;p24hj256gp206.h&amp;quot;&lt;br /&gt;
file. These files are located in &amp;quot;C:\Program Files\Microchip\MPLAB C30\support\h\&amp;quot;. In &amp;quot;Library Files&amp;quot; folder you have to add the library file corresponding&lt;br /&gt;
to your device. As before, if your device is a PIC24HJ256GP206, you will add &amp;quot;libp24HJ256GP206-coff.a&amp;quot; and &amp;quot;libp24HJ256GP206-elf.a&amp;quot; files. These files are&lt;br /&gt;
located in &amp;quot;C:\Program Files\Microchip\MPLAB C30\lib\&amp;quot;. In the &amp;quot;Linker Script&amp;quot; folder you must add &amp;quot;.gld&amp;quot; file corresponding to your microcontroller.&lt;br /&gt;
For PIC24HJ256GP206 the file is &amp;quot;p24HJ256GP206.gld&amp;quot;, located in &amp;quot;C:\Program Files\Microchip\MPLAB C30\support\gld\&amp;quot;.&lt;br /&gt;
On the right top of the screen there is the editor window and on the bottom the output reports window, where you can see if there are some errors building&lt;br /&gt;
the code, errors in programmer/debugger connection and all other messages from MPLAB IDE.&lt;br /&gt;
&lt;br /&gt;
[[Image:MPLAB2.jpg]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Write the program ===&lt;br /&gt;
&lt;br /&gt;
Our first line of code is going to be:&lt;br /&gt;
&lt;br /&gt;
 #include &amp;lt;p24hj256gp206.h&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Note that 24hj256gp206 is the microcontroller used in this example. You must replace it with your own microcontroller model: files are located in&lt;br /&gt;
&amp;quot;C:\Program Files\Microchip\MPLAB C30\support\h\&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
This is a pseudo-instruction for the preprocessor telling the compiler to read the content of a device-specifi c file before proceeding any further.&lt;br /&gt;
The content of the device-specifi c “.h”&lt;br /&gt;
file chosen is a long list of the names (and sizes) of all the internal special-function registers (SFRs) of the chosen PIC model: those names reflect&lt;br /&gt;
exactly those being used in the device datasheet.&lt;br /&gt;
Let’s add a couple more lines that will introduce you to the main() function:&lt;br /&gt;
&lt;br /&gt;
 main()&lt;br /&gt;
 {&lt;br /&gt;
 &lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
The main() function is the place where the microcontroller (program counter) will go first at power-up or after each subsequent reset.&lt;br /&gt;
Before entering the main() function, the microcontroller will execute a short initialization code segment automatically inserted by the linker.&lt;br /&gt;
This is known as the c0 code. The c0 code will perform basic housekeeping chores, including the initialization of the microcontroller stack, among other&lt;br /&gt;
things.&lt;/div&gt;</summary>
		<author><name>PaoloVilla</name></author>	</entry>

	<entry>
		<id>https://airwiki.deib.polimi.it/index.php?title=File:Watch_Window.jpg&amp;diff=9234</id>
		<title>File:Watch Window.jpg</title>
		<link rel="alternate" type="text/html" href="https://airwiki.deib.polimi.it/index.php?title=File:Watch_Window.jpg&amp;diff=9234"/>
				<updated>2009-11-09T09:12:40Z</updated>
		
		<summary type="html">&lt;p&gt;PaoloVilla: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>PaoloVilla</name></author>	</entry>

	<entry>
		<id>https://airwiki.deib.polimi.it/index.php?title=File:Output_Window.jpg&amp;diff=9233</id>
		<title>File:Output Window.jpg</title>
		<link rel="alternate" type="text/html" href="https://airwiki.deib.polimi.it/index.php?title=File:Output_Window.jpg&amp;diff=9233"/>
				<updated>2009-11-09T09:12:04Z</updated>
		
		<summary type="html">&lt;p&gt;PaoloVilla: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>PaoloVilla</name></author>	</entry>

	<entry>
		<id>https://airwiki.deib.polimi.it/index.php?title=File:MPLAB_Menu.jpg&amp;diff=9232</id>
		<title>File:MPLAB Menu.jpg</title>
		<link rel="alternate" type="text/html" href="https://airwiki.deib.polimi.it/index.php?title=File:MPLAB_Menu.jpg&amp;diff=9232"/>
				<updated>2009-11-09T09:11:15Z</updated>
		
		<summary type="html">&lt;p&gt;PaoloVilla: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>PaoloVilla</name></author>	</entry>

	<entry>
		<id>https://airwiki.deib.polimi.it/index.php?title=File:Breakpoints_Window.jpg&amp;diff=9231</id>
		<title>File:Breakpoints Window.jpg</title>
		<link rel="alternate" type="text/html" href="https://airwiki.deib.polimi.it/index.php?title=File:Breakpoints_Window.jpg&amp;diff=9231"/>
				<updated>2009-11-09T09:10:27Z</updated>
		
		<summary type="html">&lt;p&gt;PaoloVilla: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>PaoloVilla</name></author>	</entry>

	<entry>
		<id>https://airwiki.deib.polimi.it/index.php?title=Getting_Started_With_PIC(TM)_MCU&amp;diff=9230</id>
		<title>Getting Started With PIC(TM) MCU</title>
		<link rel="alternate" type="text/html" href="https://airwiki.deib.polimi.it/index.php?title=Getting_Started_With_PIC(TM)_MCU&amp;diff=9230"/>
				<updated>2009-11-09T09:09:49Z</updated>
		
		<summary type="html">&lt;p&gt;PaoloVilla: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;!!!___WORK_IN_PROGRESS___!!!&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
 NOTE:&lt;br /&gt;
 This is not a replacement for the microcontroller datasheet, reference manual and programmer’s manual published by Microchip&lt;br /&gt;
 Technology. It is also not a replacement for the MPLAB C30 compiler user’s guide, and all the libraries and related software&lt;br /&gt;
 tools offered by Microchip. Should you notice a conflict between this document and the official documentation, ALWAYS refer&lt;br /&gt;
 to the latter.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== '''Part 1: Introduction''' ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Chosing a PIC(TM) Microcontroller ===&lt;br /&gt;
&lt;br /&gt;
The first step to chose a microcontroller is to focus on hardware/software needs:&lt;br /&gt;
&lt;br /&gt;
* Board power supply is 3V or 5V (or other)?&lt;br /&gt;
* Power saving is crucial? You need a Ultra-Micro-Low-Nanowatt-Power microcontroller?&lt;br /&gt;
* Application need a little, low cost microcontroller (8bit MCU), a bigger, high performance 16bit MCU or an exagerated 32bit microcontroller?&lt;br /&gt;
* What kind and how many peripherics are needed in your application? ADC, UART, Timers, PWM Channels, stackable Interrupts, SPI, I2C, Can Bus, Ethernet,&lt;br /&gt;
USB... Yes, it's not a joke! High Performance PIC Microcontroller can have one or more USB and/or Ethernet port, you can implement usb mass storage or&lt;br /&gt;
TCP-IP functions.&lt;br /&gt;
* Available memory space: you need an extra large memory because you just know your firmare will be extra long?&lt;br /&gt;
&lt;br /&gt;
Once you have answered some of these questions you can use Microchip Advanced Parts Selector (MAPS(TM)) to find only microcontrollers that satisfy your&lt;br /&gt;
requirements.&lt;br /&gt;
MAPS is available on-line or for download directly from Microchip web site (http://www.microchip.com).&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Software tools ===&lt;br /&gt;
&lt;br /&gt;
Let’s verify you have all the necessary equipments, ready and installed (latest version available for download from Microchip web site at&lt;br /&gt;
http://www.microchip.com):&lt;br /&gt;
&lt;br /&gt;
* PIC MCU Datasheet;&lt;br /&gt;
* MPLAB IDE(TM), free Integrated Development Environment;&lt;br /&gt;
* MPLAB C30(TM), C compiler (demo or free student version).&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== '''Part 2: Basic hardware''' ==&lt;br /&gt;
&lt;br /&gt;
Besides a PC, because of we intend &amp;quot;make&amp;quot; something and not only talk about it, we need some hardware tools:&lt;br /&gt;
&lt;br /&gt;
* PIC MCU programmer-debugger (in Ai&amp;amp;R Lab Lambrate you can find some Microchip ICD2(TM) programmer-debugger, some adapter boards with ZIF socket and some&lt;br /&gt;
self-made programming cables);&lt;br /&gt;
* PIC MCU demoboard or your board with power supply, PIC Microconroller, oscillator, MCLR circuitry and some input-output hardware.&lt;br /&gt;
&lt;br /&gt;
If you are watching to buy an own programmer/debugger, Microchip PIC-KIT could be the right choise due to it's little dimensions, low price and good&lt;br /&gt;
performances. For detailed information, including PIC microcontroller supported list, visit microchip web site.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Oscillator ===&lt;br /&gt;
&lt;br /&gt;
The system clock (FOSC) source can be provided by a different number of options, depending by microcontroller family (low power, low cost microcontroller&lt;br /&gt;
allow less options choise than high power, high cost MCU).Generally options can be divided in:&lt;br /&gt;
&lt;br /&gt;
* Internal Oscillator (in general an internal RC network);&lt;br /&gt;
* External Oscillator (external clock source, external crystal or ceramic resonator operation and external RC network).&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Image:MCUOscillator.jpg]]&lt;br /&gt;
&lt;br /&gt;
In addition, oscillator system can includes on-chip Phase-Locked Loop (PLL) to boost internal operating frequency, on-the-fly clock switching between&lt;br /&gt;
various clock sources and Fail-Safe Clock Monitor (FSCM) that detects clock failure and permits safe application recovery or shutdown.&lt;br /&gt;
This means, for example, that with a PIC24H series microcontoller, you can use a 10Mhz external crystal resonator for clock source, but configuring&lt;br /&gt;
internal PLL circuitry through dedicated registers, you can obtain a 80Mhz internal clock frequency, achieving 40MIPS core operation speed&lt;br /&gt;
(PIC24H need two clock cycles to execute a single instruction).&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== MCLR circuit ===&lt;br /&gt;
&lt;br /&gt;
PIC Microcontroller has a number of reset sources and controls (POR: Power-on Reset; BOR: Brown-out Reset; MCLR: Master Clear Pin Reset; WDTO: Watchdog&lt;br /&gt;
Timer Reset).The external reset is generated by driving the MCLR pin low. The MCLR pin is a Schmitt trigger input with an additional glitch filter.&lt;br /&gt;
Reset pulses that are longer than the minimum pulse width generates a Reset (see datasheet). The External Reset (MCLR) Pin (EXTR) bit in the Reset&lt;br /&gt;
Control (RCON) register is set to indicate the MCLR Reset.If your system has an external supervisory circuits that generate reset signals to Reset&lt;br /&gt;
multiple devices in the system, this external Reset signal can be directly connected to the MCLR pin to&lt;br /&gt;
reset the device when the rest of system is Reset.&lt;br /&gt;
When using the internal power supervisory circuit to Reset the device, the external reset pin (MCLR) should be tied directly or resistively to VDD.&lt;br /&gt;
In this case, the MCLR pin is not used to generate a Reset. The external reset pin (MCLR) does not have an internal pull-up and must not be left&lt;br /&gt;
unconnected. A typical power-on reset circuit is:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Image:MCUMCLR.jpg]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Programming/Debugging interface ===&lt;br /&gt;
&lt;br /&gt;
ICSP(TM) (In-Circuit Serial Programming(TM)) mode is a special programming protocol that allows you to read and write to PIC Microcontroller and is the&lt;br /&gt;
most direct method used to program the device.The ICSP capability is Microchip’s proprietary process for microcontroller programming in the target&lt;br /&gt;
application. The ICSP interface uses two pins as its core.&lt;br /&gt;
The programming data pin (PGD) functions as both an input and an output, allowing programming data to be read in and device information to be read out&lt;br /&gt;
on command.The programming clock pin (PGC) clocks in data and controls the overall process.&lt;br /&gt;
&lt;br /&gt;
Serial programming allows customers to manufacture boards with unprogrammed devices and then to program the digital signal controller just before shipping&lt;br /&gt;
the product. Serial programming also allows the most recent firmware or a custom firmware to be programmed.&lt;br /&gt;
&lt;br /&gt;
Depending from used Microcontroller it's possible to have one or more programming ports. PIC24HJ256JP206, for example, has three pairs of programming&lt;br /&gt;
clock/data pins:&lt;br /&gt;
&lt;br /&gt;
* PGC1/EMUC1 and PGD1/EMUD1&lt;br /&gt;
* PGC2/EMUC2 and PGD2/EMUD2&lt;br /&gt;
* PGC3/EMUC3 and PGD3/EMUD3&lt;br /&gt;
&lt;br /&gt;
Used programming port must be specified in MPLAB IDE selecting &amp;quot;Configuration Bits...&amp;quot; in &amp;quot;Configure&amp;quot; menu.&lt;br /&gt;
The High-Level ICSP Programming Flow is:&lt;br /&gt;
&lt;br /&gt;
[[Image:HL_ICSP_PROGRAMMING_FLOW.jpg]]&lt;br /&gt;
&lt;br /&gt;
When the MPLAB(TM) ICD 2 or another in-circuit emulator is selected as a debugger,the in-circuit debugging functionality is enabled.&lt;br /&gt;
This function allows simple debugging when used with MPLAB IDE. The debugging functionality is controlled through the EMUCx (emulation/debug clock) and&lt;br /&gt;
EMUDx (emulation/debug data) pin functions. To use the in-circuit debugger function of the device, the design must implement ICSP connections to MCLR,&lt;br /&gt;
VDD, VSS, PGCx/EMCx and PGDx/EMUDx pin pairs. In addition, when the feature is enabled, some of the resources are not available for general use.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Programmer Connection ===&lt;br /&gt;
&lt;br /&gt;
ICD 2 programmer/debugger has a RJ12 6 pin output connector while PIC-KIT has a more comfortable 6 pin female strip headers. &lt;br /&gt;
The simplest way to interface programmer/debugger with microcontroller is to solder a 6 pin male strip headers to your board connetting PGCX, PGDX, MCLR,&lt;br /&gt;
VDD and VSS pins, as in figure:&lt;br /&gt;
&lt;br /&gt;
[[Image:ICSP_Connector.jpg]]&lt;br /&gt;
&lt;br /&gt;
Connecting pins in the same order as in figure you can either connect directly PIC-KIT to your board, or use an RJ12-&amp;gt;female_strip_headers adapter cable to&lt;br /&gt;
connect ICD 2 to target device. You can find two of that selfmade cabe in AI&amp;amp;R Lab, or you can build your own one using an RJ12 connector, a piece of 6 core&lt;br /&gt;
cable (you can use also a piece of 8 core ethernet cable), a 6 pin female strip headers and a bit of talent!&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== '''Part 3: PIC MCU programming''' ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== MPLAB IDE settings ===&lt;br /&gt;
&lt;br /&gt;
Select in &amp;quot;Debugger&amp;quot; menu the programmer/debugger device you have to use (probably &amp;quot;1 MPLAB ICD 2&amp;quot;, if you are working on AI&amp;amp;R Lab...)&lt;br /&gt;
&lt;br /&gt;
[[Image:MPLAB_Debugger_Menu.jpg]]&lt;br /&gt;
&lt;br /&gt;
To verify if programmer/debugger is connected to your Pc, to PIC microcontroller and is ready to operate select &amp;quot;Settings&amp;quot; in &amp;quot;Debug&amp;quot; menu and than pres&lt;br /&gt;
&amp;quot;Run Self Test&amp;quot; in the just opened window:&lt;br /&gt;
&lt;br /&gt;
[[Image:MPLAB_ICD2_Settings.jpg]]&lt;br /&gt;
&lt;br /&gt;
In this window you can also check the correct target power supply (&amp;quot;Power&amp;quot; submenu) and change PC-Programmer/debugger communication port&lt;br /&gt;
(&amp;quot;Communications&amp;quot; submenu).&lt;br /&gt;
&lt;br /&gt;
Let's talk about usefull functions on tool bar:&lt;br /&gt;
&lt;br /&gt;
[[Image:MPLAB_Menu.jpg]]&lt;br /&gt;
&lt;br /&gt;
* &amp;quot;Save File&amp;quot;: save only the file you are working on.&lt;br /&gt;
* &amp;quot;Find in Files&amp;quot;: find a word in all files included in the project.&lt;br /&gt;
* &amp;quot;Build Configuration&amp;quot;: to set up language tools for debug, select &amp;quot;Debug&amp;quot;; when your code is debugged and you are ready to release it (program the finished&lt;br /&gt;
code into a device), select &amp;quot;Release&amp;quot;. &lt;br /&gt;
* &amp;quot;Open Project&amp;quot;: open a just created project.&lt;br /&gt;
* &amp;quot;Save Workspace&amp;quot;: save all files in your project and workspace (windows placement on the screen).&lt;br /&gt;
* &amp;quot;Build All&amp;quot;: assemble, link and compile your project; the Output window shows the result of the build process.&lt;br /&gt;
* &amp;quot;Program Target Device&amp;quot;: program the microcontroller with your code; the Output window shows the result of this operation.&lt;br /&gt;
&lt;br /&gt;
[[Image:Output Window.jpg]]&lt;br /&gt;
&lt;br /&gt;
* &amp;quot;Run&amp;quot;: after you had build your project and programmed the microcontrolle, now you can run your application on PIC Microcontroller!&lt;br /&gt;
* &amp;quot;Halt&amp;quot;: halt program execution: the line of code where the application halted will be indicated by the solid green arrow.&lt;br /&gt;
* &amp;quot;Reset&amp;quot;: reset microcontroller.&lt;br /&gt;
* &amp;quot;BreakPoints&amp;quot;: Open the Breakpoint dialog window allowing to set or remove multiple breakpoints. &lt;br /&gt;
&lt;br /&gt;
[[Image:Breakpoints Window.jpg]]&lt;br /&gt;
&lt;br /&gt;
Once you will have create your project, builded it and programmed the microcontroller, in order to see if the code is operating as intended it's possible&lt;br /&gt;
to watch the values being written to microcontroller registers. Select View&amp;gt;Watch to bring up an empty Watch window. There are two pull downs on the top of&lt;br /&gt;
the Watch window. The one on the left labeled &amp;quot;Add SFR&amp;quot; can be used to add a phisical microcontroller register into the watch. Select a register from the&lt;br /&gt;
list and then click Add SFR to add it to the window. The pull down on the right, allows symbols to be added from the program. Use this pull down to add your&lt;br /&gt;
software variable into the Watch window. Select a variable from the list and then click Add Symbol to add it to the window. &lt;br /&gt;
The Watch window should now show the address, name and value of the registers you have added.&lt;br /&gt;
&lt;br /&gt;
[[Image:Watch Window.jpg]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Create a new project ===&lt;br /&gt;
&lt;br /&gt;
Then, let’s follow the “New Project Set-up” checklist to create a new project with the MPLAB IDE:&lt;br /&gt;
&lt;br /&gt;
* Select “Project-&amp;gt;Project Wizard” to activate the new project wizard, which will guide us automatically through the following steps…&lt;br /&gt;
* Select the correct PIC device, and click Next.&lt;br /&gt;
* Select the MPLAB C30 Compiler Suite and click Next.&lt;br /&gt;
* Create a new folder and name it “FolderName”; name the project “ProjectName” and click Next.&lt;br /&gt;
* Click Next to the following dialog (box—there is no need to copy any source files from any previous projects or directories.&lt;br /&gt;
* Click on Finish to complete the Wizard set-up.&lt;br /&gt;
&lt;br /&gt;
Open a new editor window.&lt;br /&gt;
&lt;br /&gt;
* Select “File-&amp;gt;Save As”, to save the file as: “FileName.c”.&lt;br /&gt;
* Select “Project-&amp;gt;Save” to save the project.&lt;br /&gt;
&lt;br /&gt;
You should have a screenshot similar to this one:&lt;br /&gt;
&lt;br /&gt;
[[Image:MPLAB1.jpg]]&lt;br /&gt;
&lt;br /&gt;
On the left you have the files list included in your project. Clicking on a folder you can add files (that you have just created with a simple text editor)&lt;br /&gt;
or folder to your project. In &amp;quot;Source Files&amp;quot; folder you must put all &amp;quot;.c&amp;quot; files, while &amp;quot;Header Files&amp;quot; folder is for &amp;quot;.h&amp;quot; files. In this folder you must add&lt;br /&gt;
the &amp;quot;.h&amp;quot; file corresponding to your microcontroller: for example, if you use a PIC24HJ256GP206 microcontroller, you will add the &amp;quot;p24hj256gp206.h&amp;quot;&lt;br /&gt;
file. These files are located in &amp;quot;C:\Program Files\Microchip\MPLAB C30\support\h\&amp;quot;. In &amp;quot;Library Files&amp;quot; folder you have to add the library file corresponding&lt;br /&gt;
to your device. As before, if your device is a PIC24HJ256GP206, you will add &amp;quot;libp24HJ256GP206-coff.a&amp;quot; and &amp;quot;libp24HJ256GP206-elf.a&amp;quot; files. These files are&lt;br /&gt;
located in &amp;quot;C:\Program Files\Microchip\MPLAB C30\lib\&amp;quot;. In the &amp;quot;Linker Script&amp;quot; folder you must add &amp;quot;.gld&amp;quot; file corresponding to your microcontroller.&lt;br /&gt;
For PIC24HJ256GP206 the file is &amp;quot;p24HJ256GP206.gld&amp;quot;, located in &amp;quot;C:\Program Files\Microchip\MPLAB C30\support\gld\&amp;quot;.&lt;br /&gt;
On the right top of the screen there is the editor window and on the bottom the output reports window, where you can see if there are some errors building&lt;br /&gt;
the code, errors in programmer/debugger connection and all other messages from MPLAB IDE.&lt;br /&gt;
&lt;br /&gt;
[[Image:MPLAB2.jpg]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Write the program ===&lt;br /&gt;
&lt;br /&gt;
Our first line of code is going to be:&lt;br /&gt;
&lt;br /&gt;
 #include &amp;lt;p24hj256gp206.h&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Note that 24hj256gp206 is the microcontroller used in this example. You must replace it with your own microcontroller model: files are located in&lt;br /&gt;
&amp;quot;C:\Program Files\Microchip\MPLAB C30\support\h\&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
This is a pseudo-instruction for the preprocessor telling the compiler to read the content of a device-specifi c file before proceeding any further.&lt;br /&gt;
The content of the device-specifi c “.h”&lt;br /&gt;
file chosen is a long list of the names (and sizes) of all the internal special-function registers (SFRs) of the chosen PIC model: those names reflect&lt;br /&gt;
exactly those being used in the device datasheet.&lt;br /&gt;
Let’s add a couple more lines that will introduce you to the main() function:&lt;br /&gt;
&lt;br /&gt;
 main()&lt;br /&gt;
 {&lt;br /&gt;
 &lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
The main() function is the place where the microcontroller (program counter) will go first at power-up or after each subsequent reset.&lt;br /&gt;
Before entering the main() function, the microcontroller will execute a short initialization code segment automatically inserted by the linker.&lt;br /&gt;
This is known as the c0 code. The c0 code will perform basic housekeeping chores, including the initialization of the microcontroller stack, among other&lt;br /&gt;
things.&lt;/div&gt;</summary>
		<author><name>PaoloVilla</name></author>	</entry>

	<entry>
		<id>https://airwiki.deib.polimi.it/index.php?title=File:MPLAB_ICD2_Settings.jpg&amp;diff=9229</id>
		<title>File:MPLAB ICD2 Settings.jpg</title>
		<link rel="alternate" type="text/html" href="https://airwiki.deib.polimi.it/index.php?title=File:MPLAB_ICD2_Settings.jpg&amp;diff=9229"/>
				<updated>2009-11-09T07:39:01Z</updated>
		
		<summary type="html">&lt;p&gt;PaoloVilla: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>PaoloVilla</name></author>	</entry>

	<entry>
		<id>https://airwiki.deib.polimi.it/index.php?title=File:MPLAB2.jpg&amp;diff=9228</id>
		<title>File:MPLAB2.jpg</title>
		<link rel="alternate" type="text/html" href="https://airwiki.deib.polimi.it/index.php?title=File:MPLAB2.jpg&amp;diff=9228"/>
				<updated>2009-11-09T07:36:53Z</updated>
		
		<summary type="html">&lt;p&gt;PaoloVilla: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>PaoloVilla</name></author>	</entry>

	<entry>
		<id>https://airwiki.deib.polimi.it/index.php?title=File:MPLAB1.jpg&amp;diff=9227</id>
		<title>File:MPLAB1.jpg</title>
		<link rel="alternate" type="text/html" href="https://airwiki.deib.polimi.it/index.php?title=File:MPLAB1.jpg&amp;diff=9227"/>
				<updated>2009-11-09T07:35:50Z</updated>
		
		<summary type="html">&lt;p&gt;PaoloVilla: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>PaoloVilla</name></author>	</entry>

	<entry>
		<id>https://airwiki.deib.polimi.it/index.php?title=Getting_Started_With_PIC(TM)_MCU&amp;diff=9226</id>
		<title>Getting Started With PIC(TM) MCU</title>
		<link rel="alternate" type="text/html" href="https://airwiki.deib.polimi.it/index.php?title=Getting_Started_With_PIC(TM)_MCU&amp;diff=9226"/>
				<updated>2009-11-09T07:34:56Z</updated>
		
		<summary type="html">&lt;p&gt;PaoloVilla: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;!!!___WORK_IN_PROGRESS___!!!&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== '''Part 1: Introduction''' ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Chosing a PIC(TM) Microcontroller ===&lt;br /&gt;
&lt;br /&gt;
The first step to chese a microcontroller is to focus on hardware/software needs:&lt;br /&gt;
&lt;br /&gt;
* Board power supply is 3V or 5V (or other)?&lt;br /&gt;
* Power saving is crucial? You need a Ultra-Micro-Low-Nanowatt-Power microcontroller?&lt;br /&gt;
* Application need a little, low cost microcontroller (8bit MCU), a bigger, high performance 16bit MCU or an exagerated 32bit microcontroller?&lt;br /&gt;
* What kind and how many peripherics are needed in your application? ADC, UART, Timers, PWM Channels, Interrupt stackable, SPI, I2C, Can Bus, Ethernet,&lt;br /&gt;
USB... Yes, it's not a joke! High Performance PIC Microcontroller can have one or more USB and/or Ethernet port, you can implement usb mass storage or&lt;br /&gt;
TCP-IP functions.&lt;br /&gt;
* Available memory space: you need an extra large memory because you just know your firmare will be extra long?&lt;br /&gt;
&lt;br /&gt;
Once you have answered some of these questions you can use Microchip Advanced Parts Selector (MAPS(TM)) to find only microcontrollers that satisfy your&lt;br /&gt;
requests.&lt;br /&gt;
MAPS is available on-line or for download directly from Microchip web site (http://www.microchip.com).&lt;br /&gt;
&lt;br /&gt;
 NOTE:&lt;br /&gt;
 This is not a replacement for the microcontroller datasheet, reference manual and programmer’s manual published by Microchip Technology.&lt;br /&gt;
 It is also not a replacement for the MPLAB C30 compiler user’s guide, and all the libraries and related software tools offered by Microchip.&lt;br /&gt;
 Should you notice a conflict between this document and the official documentation, ALWAYS refer to the latter.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Software tools ===&lt;br /&gt;
&lt;br /&gt;
Let’s verify you have all the necessary equipments, ready and installed (latest version available for download from Microchip web site at&lt;br /&gt;
http://www.microchip.com):&lt;br /&gt;
&lt;br /&gt;
* PIC MCU Datasheet;&lt;br /&gt;
* MPLAB IDE(TM), free Integrated Development Environment;&lt;br /&gt;
* MPLAB C30(TM), C compiler (demo or free student version).&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== '''Part 2: Basic hardware''' ==&lt;br /&gt;
&lt;br /&gt;
Besides a PC, because of we intend &amp;quot;make&amp;quot; something and not only talk about it, we need some hardware tools:&lt;br /&gt;
&lt;br /&gt;
* PIC MCU programmer-debugger (in Ai&amp;amp;R Lab Lambrate you can find some Microchip ICD2(TM) programmer-debugger, some adapter boards with ZIF socket and some&lt;br /&gt;
self-made programming cables);&lt;br /&gt;
* PIC MCU demoboard or your board with power supply, PIC Microconroller, oscillator, MCLR circuitry and some input-output hardware.&lt;br /&gt;
&lt;br /&gt;
If you are watching to buy an own programmer/debugger, Microchip PIC-KIT could be the right choise due to it's little dimensions, low price and good&lt;br /&gt;
performances. For detailed information, including PIC microcontroller supported list, visit microchip web site.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Oscillator ===&lt;br /&gt;
&lt;br /&gt;
The system clock (FOSC) source can be provided by a different number of options, depending by microcontroller family (low power, low cost microcontroller&lt;br /&gt;
allow less options choise than high power, high cost MCU).Generally options can be divided in:&lt;br /&gt;
&lt;br /&gt;
* Internal Oscillator (in general an internal RC network);&lt;br /&gt;
* External Oscillator (external clock source, external crystal or ceramic resonator operation and external RC network).&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Image:MCUOscillator.jpg]]&lt;br /&gt;
&lt;br /&gt;
In addition, oscillator system can includes on-chip Phase-Locked Loop (PLL) to boost internal operating frequency, on-the-fly clock switching between&lt;br /&gt;
various clock sources and Fail-Safe Clock Monitor (FSCM) that detects clock failure and permits safe application recovery or shutdown.&lt;br /&gt;
This means, for example, that with a PIC24H series microcontoller, you can use a 10Mhz external crystal resonator for clock source, but configuring&lt;br /&gt;
internal PLL circuitry through dedicated registers, you can obtain a 80Mhz internal clock frequency, achieving 40MIPS core operation speed&lt;br /&gt;
(PIC24H need two clock cycles to execute a single instruction).&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== MCLR circuit ===&lt;br /&gt;
&lt;br /&gt;
PIC Microcontroller has a number of reset sources and controls (POR: Power-on Reset; BOR: Brown-out Reset; MCLR: Master Clear Pin Reset; WDTO: Watchdog&lt;br /&gt;
Timer Reset).The external reset is generated by driving the MCLR pin low. The MCLR pin is a Schmitt trigger input with an additional glitch filter.&lt;br /&gt;
Reset pulses that are longer than the minimum pulse width generates a Reset (see datasheet). The External Reset (MCLR) Pin (EXTR) bit in the Reset&lt;br /&gt;
Control (RCON) register is set to indicate the MCLR Reset.If your system has an external supervisory circuits that generate reset signals to Reset&lt;br /&gt;
multiple devices in the system, this external Reset signal can be directly connected to the MCLR pin to&lt;br /&gt;
reset the device when the rest of system is Reset.&lt;br /&gt;
When using the internal power supervisory circuit to Reset the device, the external reset pin (MCLR) should be tied directly or resistively to VDD.&lt;br /&gt;
In this case, the MCLR pin is not used to generate a Reset. The external reset pin (MCLR) does not have an internal pull-up and must not be left&lt;br /&gt;
unconnected. A typical power-on reset circuit is:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Image:MCUMCLR.jpg]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Programming/Debugging interface ===&lt;br /&gt;
&lt;br /&gt;
ICSP(TM) (In-Circuit Serial Programming(TM)) mode is a special programming protocol that allows you to read and write to PIC Microcontroller and is the&lt;br /&gt;
most direct method used to program the device.The ICSP capability is Microchip’s proprietary process for microcontroller programming in the target&lt;br /&gt;
application. The ICSP interface uses two pins as its core.&lt;br /&gt;
The programming data pin (PGD) functions as both an input and an output, allowing programming data to be read in and device information to be read out&lt;br /&gt;
on command.The programming clock pin (PGC) clocks in data and controls the overall process.&lt;br /&gt;
&lt;br /&gt;
Serial programming allows customers to manufacture boards with unprogrammed devices and then to program the digital signal controller just before shipping&lt;br /&gt;
the product. Serial programming also allows the most recent firmware or a custom firmware to be programmed.&lt;br /&gt;
&lt;br /&gt;
Depending from used Microcontroller it's possible to have one or more programming ports. PIC24HJ256JP206, for example, has three pairs of programming&lt;br /&gt;
clock/data pins:&lt;br /&gt;
&lt;br /&gt;
* PGC1/EMUC1 and PGD1/EMUD1&lt;br /&gt;
* PGC2/EMUC2 and PGD2/EMUD2&lt;br /&gt;
* PGC3/EMUC3 and PGD3/EMUD3&lt;br /&gt;
&lt;br /&gt;
Used programming port must be specified in MPLAB IDE selecting &amp;quot;Configuration Bits...&amp;quot; in &amp;quot;Configure&amp;quot; menu.&lt;br /&gt;
The High-Level ICSP Programming Flow is:&lt;br /&gt;
&lt;br /&gt;
[[Image:HL_ICSP_PROGRAMMING_FLOW.jpg]]&lt;br /&gt;
&lt;br /&gt;
When the MPLAB(TM) ICD 2 or another in-circuit emulator is selected as a debugger,the in-circuit debugging functionality is enabled.&lt;br /&gt;
This function allows simple debugging when used with MPLAB IDE. The debugging functionality is controlled through the EMUCx (emulation/debug clock) and&lt;br /&gt;
EMUDx (emulation/debug data) pin functions. To use the in-circuit debugger function of the device, the design must implement ICSP connections to MCLR,&lt;br /&gt;
VDD, VSS, PGCx/EMCx and PGDx/EMUDx pin pairs. In addition, when the feature is enabled, some of the resources are not available for general use.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Programmer Connection ===&lt;br /&gt;
&lt;br /&gt;
ICD 2 programmer/debugger has a RJ12 6 pin output connector while PIC-KIT has a more comfortable 6 pin female strip headers. &lt;br /&gt;
The simplest way to interface programmer/debugger with microcontroller is to solder a 6 pin male strip headers to your board connetting PGCX, PGDX, MCLR,&lt;br /&gt;
VDD and VSS pins, as in figure:&lt;br /&gt;
&lt;br /&gt;
[[Image:ICSP_Connector.jpg]]&lt;br /&gt;
&lt;br /&gt;
Connecting pins in the same order as in figure you can either connect directly PIC-KIT to your board, or use an RJ12-&amp;gt;female_strip_headers adapter cable to&lt;br /&gt;
connect ICD 2 to target device. You can find two of that selfmade cabe in AI&amp;amp;R Lab, or you can build your own one using an RJ12 connector, a piece of 6 core&lt;br /&gt;
cable (you can use also a piece of 8 core ethernet cable), a 6 pin female strip headers and a bit of talent!&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== '''Part 3: PIC MCU programming''' ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== MPLAB IDE settings ===&lt;br /&gt;
&lt;br /&gt;
Install MPLAB IDE and MPLAB C30 on your PC. Now let's talk about common functions on menu.&lt;br /&gt;
&lt;br /&gt;
Select in &amp;quot;Debugger&amp;quot; menu the right programmer/debugger device you have to use (probably &amp;quot;1 MPLAB ICD 2&amp;quot;, if you are working on AI&amp;amp;R Lab...)&lt;br /&gt;
&lt;br /&gt;
[[Image:MPLAB_Debugger_Menu.jpg]]&lt;br /&gt;
&lt;br /&gt;
To verify if programmer/debugger is connected to your Pc, to PIC microcontroller and is ready to operate select &amp;quot;Settings&amp;quot; in &amp;quot;Debug&amp;quot; menu and than pres&lt;br /&gt;
&amp;quot;Run Self Test&amp;quot; in the just opened window:&lt;br /&gt;
&lt;br /&gt;
[[Image:MPLAB_ICD2_Settings.jpg]]&lt;br /&gt;
&lt;br /&gt;
In this window you can also check the correct target power supply (&amp;quot;Power&amp;quot; submenu) and change PC-Programmer/debugger communication port&lt;br /&gt;
(&amp;quot;Communications&amp;quot; submenu).&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Start a new project ===&lt;br /&gt;
&lt;br /&gt;
Then, let’s follow the “New Project Set-up” checklist to create a new project with the MPLAB IDE:&lt;br /&gt;
&lt;br /&gt;
* Select “Project-&amp;gt;Project Wizard” to activate the new project wizard, which will guide us automatically through the following steps…&lt;br /&gt;
* Select the correct PIC device, and click Next.&lt;br /&gt;
* Select the MPLAB C30 Compiler Suite and click Next.&lt;br /&gt;
* Create a new folder and name it “FolderName”; name the project “ProjectName” and click Next.&lt;br /&gt;
* Click Next to the following dialog (box—there is no need to copy any source files from any previous projects or directories.&lt;br /&gt;
* Click on Finish to complete the Wizard set-up.&lt;br /&gt;
&lt;br /&gt;
Open a new editor window.&lt;br /&gt;
&lt;br /&gt;
* Select “File-&amp;gt;Save As”, to save the file as: “FileName.c”.&lt;br /&gt;
* Select “Project-&amp;gt;Save” to save the project.&lt;br /&gt;
&lt;br /&gt;
You should have a screenshot similar to this one:&lt;br /&gt;
&lt;br /&gt;
[[Image:MPLAB1.jpg]]&lt;br /&gt;
&lt;br /&gt;
On the left you have the files list included in your project. Clicking on a folder you can add files (that you have just created with a simple text editor)&lt;br /&gt;
or folder to your project. In &amp;quot;Source Files&amp;quot; folder you must put all &amp;quot;.c&amp;quot; files, while &amp;quot;Header Files&amp;quot; folder is for &amp;quot;.h&amp;quot; files. In this folder you must add&lt;br /&gt;
the &amp;quot;.h&amp;quot; file corresponding to your microcontroller: for example, if you use a PIC24HJ256GP206 microcontroller, you will add the &amp;quot;p24hj256gp206.h&amp;quot;&lt;br /&gt;
file. These files are located in &amp;quot;C:\Program Files\Microchip\MPLAB C30\support\h\&amp;quot;. In &amp;quot;Library Files&amp;quot; folder you have to add the library file corresponding&lt;br /&gt;
to your device. As before, if your device is a PIC24HJ256GP206, you will add &amp;quot;libp24HJ256GP206-coff.a&amp;quot; and &amp;quot;libp24HJ256GP206-elf.a&amp;quot; files. These files are&lt;br /&gt;
located in &amp;quot;C:\Program Files\Microchip\MPLAB C30\lib\&amp;quot;. In the &amp;quot;Linker Script&amp;quot; folder you must add &amp;quot;.gld&amp;quot; file corresponding to your microcontroller.&lt;br /&gt;
For PIC24HJ256GP206 the file is &amp;quot;p24HJ256GP206.gld&amp;quot;, located in &amp;quot;C:\Program Files\Microchip\MPLAB C30\support\gld\&amp;quot;.&lt;br /&gt;
On the right top of the screen there is the editor window and on the bottom the output reports window, where you can see if there are some errors building&lt;br /&gt;
the code, errors in programmer/debugger connection and all other messages from MPLAB IDE.&lt;br /&gt;
&lt;br /&gt;
[[Image:MPLAB2.jpg]]&lt;br /&gt;
&lt;br /&gt;
Our first line of code is going to be:&lt;br /&gt;
&lt;br /&gt;
 #include &amp;lt;p24hj256gp206.h&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Note that 24hj256gp206 is the microcontroller used in this example. You must replace it with your own microcontroller model: files are located in&lt;br /&gt;
&amp;quot;C:\Program Files\Microchip\MPLAB C30\support\h\&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
This is a pseudo-instruction for the preprocessor telling the compiler to read the content of a device-specifi c file before proceeding any further.&lt;br /&gt;
The content of the device-specifi c “.h”&lt;br /&gt;
file chosen is a long list of the names (and sizes) of all the internal special-function registers (SFRs) of the chosen PIC model: those names reflect&lt;br /&gt;
exactly those being used in the device datasheet.&lt;br /&gt;
Let’s add a couple more lines that will introduce you to the main() function:&lt;br /&gt;
&lt;br /&gt;
 main()&lt;br /&gt;
 {&lt;br /&gt;
 &lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
The main() function is the place where the microcontroller (program counter) will go first at power-up or after each subsequent reset.&lt;br /&gt;
Before entering the main() function, the microcontroller will execute a short initialization code segment automatically inserted by the linker.&lt;br /&gt;
This is known as the c0 code. The c0 code will perform basic housekeeping chores, including the initialization of the microcontroller stack, among other&lt;br /&gt;
things.&lt;/div&gt;</summary>
		<author><name>PaoloVilla</name></author>	</entry>

	<entry>
		<id>https://airwiki.deib.polimi.it/index.php?title=File:MPLAB_Debugger_Menu.jpg&amp;diff=9225</id>
		<title>File:MPLAB Debugger Menu.jpg</title>
		<link rel="alternate" type="text/html" href="https://airwiki.deib.polimi.it/index.php?title=File:MPLAB_Debugger_Menu.jpg&amp;diff=9225"/>
				<updated>2009-11-09T07:33:14Z</updated>
		
		<summary type="html">&lt;p&gt;PaoloVilla: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>PaoloVilla</name></author>	</entry>

	<entry>
		<id>https://airwiki.deib.polimi.it/index.php?title=File:ICSP_Connector.jpg&amp;diff=9224</id>
		<title>File:ICSP Connector.jpg</title>
		<link rel="alternate" type="text/html" href="https://airwiki.deib.polimi.it/index.php?title=File:ICSP_Connector.jpg&amp;diff=9224"/>
				<updated>2009-11-08T09:18:54Z</updated>
		
		<summary type="html">&lt;p&gt;PaoloVilla: uploaded a new version of &amp;quot;Image:ICSP Connector.jpg&amp;quot;&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>PaoloVilla</name></author>	</entry>

	<entry>
		<id>https://airwiki.deib.polimi.it/index.php?title=Getting_Started_With_PIC(TM)_MCU&amp;diff=9223</id>
		<title>Getting Started With PIC(TM) MCU</title>
		<link rel="alternate" type="text/html" href="https://airwiki.deib.polimi.it/index.php?title=Getting_Started_With_PIC(TM)_MCU&amp;diff=9223"/>
				<updated>2009-11-08T08:52:47Z</updated>
		
		<summary type="html">&lt;p&gt;PaoloVilla: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;!!!___WORK_IN_PROGRESS___!!!&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== '''Part 1: Introduction''' ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Chosing a PIC(TM) Microcontroller ===&lt;br /&gt;
&lt;br /&gt;
The first step to chese a microcontroller is to focus on hardware/software needs:&lt;br /&gt;
&lt;br /&gt;
* Board power supply is 3V or 5V (or other)?&lt;br /&gt;
* Power saving is crucial? You need a Ultra-Micro-Low-Nanowatt-Power microcontroller?&lt;br /&gt;
* Application need a little, low cost microcontroller (8bit MCU), a bigger, high performance 16bit MCU or an exagerated 32bit microcontroller?&lt;br /&gt;
* What kind and how many peripherics are needed in your application? ADC, UART, Timers, PWM Channels, Interrupt stackable, SPI, I2C, Can Bus, Ethernet, USB... Yes, it's not a joke! High Performance PIC Microcontroller can have one or more USB and/or Ethernet port, you can implement usb mass storage or TCP-IP functions.&lt;br /&gt;
* Available memory space: you need an extra large memory because you just know your firmare will be extra long?&lt;br /&gt;
&lt;br /&gt;
Once you have answered some of these questions you can use Microchip Advanced Parts Selector (MAPS(TM)) to find only microcontrollers that satisfy your&lt;br /&gt;
requests.&lt;br /&gt;
MAPS is available on-line or for download directly from Microchip web site (http://www.microchip.com).&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Software tools ===&lt;br /&gt;
&lt;br /&gt;
Let’s verify you have all the necessary equipments, ready and installed (latest version available for download from Microchip web site at http://www.microchip.com):&lt;br /&gt;
&lt;br /&gt;
* PIC MCU Datasheet;&lt;br /&gt;
* MPLAB IDE(TM), free Integrated Development Environment;&lt;br /&gt;
* MPLAB C30(TM), C compiler (demo or free student version).&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== '''Part 2: Basic hardware''' ==&lt;br /&gt;
&lt;br /&gt;
Besides a PC, because of we intend &amp;quot;make&amp;quot; something and not only talk about it, we need some hardware tools:&lt;br /&gt;
&lt;br /&gt;
* PIC MCU programmer-debugger (in Ai&amp;amp;R Lab Lambrate you can find some Microchip ICD2(TM) programmer-debugger, some adapter boards with ZIF socket and some self-made programming cables);&lt;br /&gt;
* PIC MCU demoboard or your board with power supply, PIC Microconroller, oscillator, MCLR circuitry and some input-output hardware.&lt;br /&gt;
&lt;br /&gt;
If you are watching to buy an own programmer/debugger, Microchip PIC-KIT could be the right choise due to it's little dimensions, low price and good&lt;br /&gt;
performances. For detailed information, including PIC microcontroller supported list, visit microchip web site.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Oscillator ===&lt;br /&gt;
&lt;br /&gt;
The system clock (FOSC) source can be provided by a different number of options, depending by microcontroller family (low power, low cost microcontroller&lt;br /&gt;
allow less options choise than high power, high cost MCU).Generally options can be divided in:&lt;br /&gt;
&lt;br /&gt;
* Internal Oscillator (in general an internal RC network);&lt;br /&gt;
* External Oscillator (external clock source, external crystal or ceramic resonator operation and external RC network).&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Image:MCUOscillator.jpg]]&lt;br /&gt;
&lt;br /&gt;
In addition, oscillator system can includes on-chip Phase-Locked Loop (PLL) to boost internal operating frequency, on-the-fly clock switching between&lt;br /&gt;
various clock sources and Fail-Safe Clock Monitor (FSCM) that detects clock failure and permits safe application recovery or shutdown.&lt;br /&gt;
This means, for example, that with a PIC24H series microcontoller, you can use a 10Mhz external crystal resonator for clock source, but configuring&lt;br /&gt;
internal PLL circuitry through dedicated registers, you can obtain a 80Mhz internal clock frequency, achieving 40MIPS core operation speed&lt;br /&gt;
(PIC24H need two clock cycles to execute a single instruction).&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== MCLR circuit ===&lt;br /&gt;
&lt;br /&gt;
PIC Microcontroller has a number of reset sources and controls (POR: Power-on Reset; BOR: Brown-out Reset; MCLR: Master Clear Pin Reset; WDTO: Watchdog&lt;br /&gt;
Timer Reset).The external reset is generated by driving the MCLR pin low. The MCLR pin is a Schmitt trigger input with an additional glitch filter.&lt;br /&gt;
Reset pulses that are longer than the minimum pulse width generates a Reset (see datasheet). The External Reset (MCLR) Pin (EXTR) bit in the Reset&lt;br /&gt;
Control (RCON) register is set to indicate the MCLR Reset.If your system has an external supervisory circuits that generate reset signals to Reset&lt;br /&gt;
multiple devices in the system, this external Reset signal can be directly connected to the MCLR pin to&lt;br /&gt;
reset the device when the rest of system is Reset.&lt;br /&gt;
When using the internal power supervisory circuit to Reset the device, the external reset pin (MCLR) should be tied directly or resistively to VDD.&lt;br /&gt;
In this case, the MCLR pin is not used to generate a Reset. The external reset pin (MCLR) does not have an internal pull-up and must not be left&lt;br /&gt;
unconnected. A typical power-on reset circuit is:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Image:MCUMCLR.jpg]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Programming/Debugging interface ===&lt;br /&gt;
&lt;br /&gt;
ICSP(TM) (In-Circuit Serial Programming(TM)) mode is a special programming protocol that allows you to read and write to PIC Microcontroller and is the&lt;br /&gt;
most direct method used to program the device.The ICSP capability is Microchip’s proprietary process for microcontroller programming in the target&lt;br /&gt;
application. The ICSP interface uses two pins as its core.&lt;br /&gt;
The programming data pin (PGD) functions as both an input and an output, allowing programming data to be read in and device information to be read out&lt;br /&gt;
on command.The programming clock pin (PGC) clocks in data and controls the overall process.&lt;br /&gt;
&lt;br /&gt;
Serial programming allows customers to manufacture boards with unprogrammed devices and then to program the digital signal controller just before shipping&lt;br /&gt;
the product. Serial programming also allows the most recent firmware or a custom firmware to be programmed.&lt;br /&gt;
&lt;br /&gt;
Depending from used Microcontroller it's possible to have one or more programming ports. PIC24HJ256JP206, for example, has three pairs of programming&lt;br /&gt;
clock/data pins:&lt;br /&gt;
&lt;br /&gt;
* PGC1/EMUC1 and PGD1/EMUD1&lt;br /&gt;
* PGC2/EMUC2 and PGD2/EMUD2&lt;br /&gt;
* PGC3/EMUC3 and PGD3/EMUD3&lt;br /&gt;
&lt;br /&gt;
Used programming port must be specified in MPLAB IDE selecting &amp;quot;Configuration Bits...&amp;quot; in &amp;quot;Configure&amp;quot; menu.&lt;br /&gt;
The High-Level ICSP Programming Flow is:&lt;br /&gt;
&lt;br /&gt;
[[Image:HL_ICSP_PROGRAMMING_FLOW.jpg]]&lt;br /&gt;
&lt;br /&gt;
When the MPLAB(TM) ICD 2 or another in-circuit emulator is selected as a debugger,the in-circuit debugging functionality is enabled.&lt;br /&gt;
This function allows simple debugging when used with MPLAB IDE. The debugging functionality is controlled through the EMUCx (emulation/debug clock) and&lt;br /&gt;
EMUDx (emulation/debug data) pin functions. To use the in-circuit debugger function of the device, the design must implement ICSP connections to MCLR,&lt;br /&gt;
VDD, VSS, PGCx/EMCx and PGDx/EMUDx pin pairs. In addition, when the feature is enabled, some of the resources are not available for general use.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Programmer Connection ===&lt;br /&gt;
&lt;br /&gt;
ICD 2 programmer/debugger has a RJ12 6 pin output connector while PIC-KIT has a more comfortable 6 pin female strip headers. &lt;br /&gt;
The simplest way to interface programmer/debugger with microcontroller is to solder a 6 pin male strip headers to your board connetting PGCX, PGDX, MCLR,&lt;br /&gt;
VDD and VSS pins, as in figure:&lt;br /&gt;
&lt;br /&gt;
[[Image:ICSP_Connector.jpg]]&lt;br /&gt;
&lt;br /&gt;
Connecting pins in the same order as in figure you can either connect directly PIC-KIT to your board, or use an RJ12-&amp;gt;female_strip_headers adapter cable to&lt;br /&gt;
connect ICD 2 to target device. You can find two of that selfmade cabe in AI&amp;amp;R Lab, or you can build your own one using an RJ12 connector, a piece of 6 core&lt;br /&gt;
cable (you can use also a piece of 8 core ethernet cable), a 6 pin female strip headers and a bit of talent!&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== '''Part 3: PIC MCU programming''' ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== MPLAB IDE settings ===&lt;br /&gt;
&lt;br /&gt;
Install MPLAB IDE and MPLAB C30(TM)on your PC.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Start a new project ===&lt;br /&gt;
&lt;br /&gt;
Then, let’s follow the “New Project Set-up” checklist to create a new project with the MPLAB IDE:&lt;br /&gt;
&lt;br /&gt;
* Select “Project-&amp;gt;Project Wizard” to activate the new project wizard, which will guide us automatically through the following steps…&lt;br /&gt;
* Select the correct PIC device, and click Next.&lt;br /&gt;
* Select the MPLAB C30 Compiler Suite and click Next.&lt;br /&gt;
* Create a new folder and name it “FolderName”; name the project “ProjectName” and click Next.&lt;br /&gt;
* Click Next to the following dialog (box—there is no need to copy any source files from any previous projects or directories.&lt;br /&gt;
* Click on Finish to complete the Wizard set-up.&lt;br /&gt;
&lt;br /&gt;
Open a new editor window.&lt;br /&gt;
&lt;br /&gt;
* Select “File-&amp;gt;Save As”, to save the file as: “FileName.c”.&lt;br /&gt;
* Select “Project-&amp;gt;Save” to save the project.&lt;br /&gt;
&lt;br /&gt;
Our first line of code is going to be:&lt;br /&gt;
&lt;br /&gt;
 #include &amp;lt;p24hj256gp206.h&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
NOTE: 24hj256gp206 is the microcontroller used in this example. You must replace it with your own microcontroller model: files are located in &amp;quot;C:\Program Files\Microchip\MPLAB C30\support\h\&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
This is a pseudo-instruction for the preprocessor telling the compiler to read the content of a device-specifi c file before proceeding any further.&lt;br /&gt;
The content of the device-specifi c “.h”&lt;br /&gt;
file chosen is a long list of the names (and sizes) of all the internal special-function registers (SFRs) of the chosen PIC model: those names reflect&lt;br /&gt;
exactly those being used in the device datasheet.&lt;br /&gt;
Let’s add a couple more lines that will introduce you to the main() function:&lt;br /&gt;
&lt;br /&gt;
 main()&lt;br /&gt;
 {&lt;br /&gt;
 &lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
The main() function is the place where the microcontroller (program counter) will go first at power-up or after each subsequent reset.&lt;br /&gt;
Before entering the main() function, the microcontroller will execute a short initialization code segment automatically inserted by the linker.&lt;br /&gt;
This is known as the c0 code. The c0 code will perform basic housekeeping chores, including the initialization of the microcontroller stack, among other&lt;br /&gt;
things.&lt;/div&gt;</summary>
		<author><name>PaoloVilla</name></author>	</entry>

	<entry>
		<id>https://airwiki.deib.polimi.it/index.php?title=Getting_Started_With_PIC(TM)_MCU&amp;diff=9222</id>
		<title>Getting Started With PIC(TM) MCU</title>
		<link rel="alternate" type="text/html" href="https://airwiki.deib.polimi.it/index.php?title=Getting_Started_With_PIC(TM)_MCU&amp;diff=9222"/>
				<updated>2009-11-08T08:51:06Z</updated>
		
		<summary type="html">&lt;p&gt;PaoloVilla: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;!!!___WORK_IN_PROGRESS___!!!&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== '''Part 1: Introduction''' ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Chosing a PIC(TM) Microcontroller ===&lt;br /&gt;
&lt;br /&gt;
The first step to chese a microcontroller is to focus on hardware/software needs:&lt;br /&gt;
&lt;br /&gt;
* Board power supply is 3V or 5V (or other)?&lt;br /&gt;
* Power saving is crucial? You need a Ultra-Micro-Low-Nanowatt-Power microcontroller?&lt;br /&gt;
* Application need a little, low cost microcontroller (8bit MCU), a bigger, high performance 16bit MCU or an exagerated 32bit microcontroller?&lt;br /&gt;
* What kind and how many peripherics are needed in your application? ADC, UART, Timers, PWM Channels, Interrupt stackable, SPI, I2C, Can Bus, Ethernet, USB... Yes, it's not a joke! High Performance PIC Microcontroller can have one or more USB and/or Ethernet port, you can implement usb mass storage or TCP-IP functions.&lt;br /&gt;
* Available memory space: you need an extra large memory because you just know your firmare will be extra long?&lt;br /&gt;
&lt;br /&gt;
Once you have answered some of these questions you can use Microchip Advanced Parts Selector (MAPS(TM)) to find only microcontrollers that satisfy your&lt;br /&gt;
requests.&lt;br /&gt;
MAPS is available on-line or for download directly from Microchip web site (http://www.microchip.com).&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Software tools ===&lt;br /&gt;
&lt;br /&gt;
Let’s verify you have all the necessary equipments, ready and installed (latest version available for download from Microchip web site at&lt;br /&gt;
http://www.microchip.com):&lt;br /&gt;
&lt;br /&gt;
* PIC MCU Datasheet;&lt;br /&gt;
* MPLAB IDE(TM), free Integrated Development Environment;&lt;br /&gt;
* MPLAB C30(TM), C compiler (demo or free student version).&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== '''Part 2: Basic hardware''' ==&lt;br /&gt;
&lt;br /&gt;
Besides a PC, because of we intend &amp;quot;make&amp;quot; something and not only talk about it, we need some hardware tools:&lt;br /&gt;
&lt;br /&gt;
* PIC MCU programmer-debugger (in Ai&amp;amp;R Lab Lambrate you can find some Microchip ICD2(TM) programmer-debugger, some adapter boards with ZIF socket and some self-made programming cables);&lt;br /&gt;
* PIC MCU demoboard or your board with power supply, PIC Microconroller, oscillator, MCLR circuitry and some input-output hardware.&lt;br /&gt;
&lt;br /&gt;
If you are watching to buy an own programmer/debugger, Microchip PIC-KIT could be the right choise due to it's little dimensions, low price and good&lt;br /&gt;
performances. For detailed information, including PIC microcontroller supported list, visit microchip web site.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Oscillator ===&lt;br /&gt;
&lt;br /&gt;
The system clock (FOSC) source can be provided by a different number of options, depending by microcontroller family (low power, low cost microcontroller&lt;br /&gt;
allow less options choise than high power, high cost MCU).Generally options can be divided in:&lt;br /&gt;
&lt;br /&gt;
* Internal Oscillator (in general an internal RC network);&lt;br /&gt;
* External Oscillator (external clock source, external crystal or ceramic resonator operation and external RC network).&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Image:MCUOscillator.jpg]]&lt;br /&gt;
&lt;br /&gt;
In addition, oscillator system can includes on-chip Phase-Locked Loop (PLL) to boost internal operating frequency, on-the-fly clock switching between&lt;br /&gt;
various clock sources and Fail-Safe Clock Monitor (FSCM) that detects clock failure and permits safe application recovery or shutdown.&lt;br /&gt;
This means, for example, that with a PIC24H series microcontoller, you can use a 10Mhz external crystal resonator for clock source, but configuring&lt;br /&gt;
internal PLL circuitry through dedicated registers, you can obtain a 80Mhz internal clock frequency, achieving 40MIPS core operation speed&lt;br /&gt;
(PIC24H need two clock cycles to execute a single instruction).&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== MCLR circuit ===&lt;br /&gt;
&lt;br /&gt;
PIC Microcontroller has a number of reset sources and controls (POR: Power-on Reset; BOR: Brown-out Reset; MCLR: Master Clear Pin Reset; WDTO: Watchdog&lt;br /&gt;
Timer Reset).The external reset is generated by driving the MCLR pin low. The MCLR pin is a Schmitt trigger input with an additional glitch filter.&lt;br /&gt;
Reset pulses that are longer than the minimum pulse width generates a Reset (see datasheet). The External Reset (MCLR) Pin (EXTR) bit in the Reset&lt;br /&gt;
Control (RCON) register is set to indicate the MCLR Reset.If your system has an external supervisory circuits that generate reset signals to Reset&lt;br /&gt;
multiple devices in the system, this external Reset signal can be directly connected to the MCLR pin to&lt;br /&gt;
reset the device when the rest of system is Reset.&lt;br /&gt;
When using the internal power supervisory circuit to Reset the device, the external reset pin (MCLR) should be tied directly or resistively to VDD.&lt;br /&gt;
In this case, the MCLR pin is not used to generate a Reset. The external reset pin (MCLR) does not have an internal pull-up and must not be left&lt;br /&gt;
unconnected. A typical power-on reset circuit is:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Image:MCUMCLR.jpg]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Programming/Debugging interface ===&lt;br /&gt;
&lt;br /&gt;
ICSP(TM) (In-Circuit Serial Programming(TM)) mode is a special programming protocol that allows you to read and write to PIC Microcontroller and is the&lt;br /&gt;
most direct method used to program the device.The ICSP capability is Microchip’s proprietary process for microcontroller programming in the target&lt;br /&gt;
application. The ICSP interface uses two pins as its core.&lt;br /&gt;
The programming data pin (PGD) functions as both an input and an output, allowing programming data to be read in and device information to be read out&lt;br /&gt;
on command.The programming clock pin (PGC) clocks in data and controls the overall process.&lt;br /&gt;
&lt;br /&gt;
Serial programming allows customers to manufacture boards with unprogrammed devices and then to program the digital signal controller just before shipping&lt;br /&gt;
the product. Serial programming also allows the most recent firmware or a custom firmware to be programmed.&lt;br /&gt;
&lt;br /&gt;
Depending from used Microcontroller it's possible to have one or more programming ports. PIC24HJ256JP206, for example, has three pairs of programming&lt;br /&gt;
clock/data pins:&lt;br /&gt;
&lt;br /&gt;
* PGC1/EMUC1 and PGD1/EMUD1&lt;br /&gt;
* PGC2/EMUC2 and PGD2/EMUD2&lt;br /&gt;
* PGC3/EMUC3 and PGD3/EMUD3&lt;br /&gt;
&lt;br /&gt;
Used programming port must be specified in MPLAB IDE selecting &amp;quot;Configuration Bits...&amp;quot; in &amp;quot;Configure&amp;quot; menu.&lt;br /&gt;
The High-Level ICSP Programming Flow is:&lt;br /&gt;
&lt;br /&gt;
[[Image:HL_ICSP_PROGRAMMING_FLOW.jpg]]&lt;br /&gt;
&lt;br /&gt;
When the MPLAB(TM) ICD 2 or another in-circuit emulator is selected as a debugger,the in-circuit debugging functionality is enabled.&lt;br /&gt;
This function allows simple debugging when used with MPLAB IDE. The debugging functionality is controlled through the EMUCx (emulation/debug clock) and&lt;br /&gt;
EMUDx (emulation/debug data) pin functions. To use the in-circuit debugger function of the device, the design must implement ICSP connections to MCLR,&lt;br /&gt;
VDD, VSS, PGCx/EMCx and PGDx/EMUDx pin pairs. In addition, when the feature is enabled, some of the resources are not available for general use.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Programmer Connection ===&lt;br /&gt;
&lt;br /&gt;
ICD 2 programmer/debugger has a RJ12 6 pin output connector while PIC-KIT has a more comfortable 6 pin female strip headers. &lt;br /&gt;
The simplest way to interface programmer/debugger with microcontroller is to solder a 6 pin male strip headers to your board connetting PGCX, PGDX, MCLR,&lt;br /&gt;
VDD and VSS pins, as in figure:&lt;br /&gt;
&lt;br /&gt;
[[Image:ICSP_Connector.jpg]]&lt;br /&gt;
&lt;br /&gt;
Connecting pins in the same order as in figure you can either connect directly PIC-KIT to your board, or use an RJ12-&amp;gt;female_strip_headers adapter cable to&lt;br /&gt;
connect ICD 2 to target device. You can find two of that selfmade cabe in AI&amp;amp;R Lab, or you can build your own one using an RJ12 connector, a piece of 6 core&lt;br /&gt;
cable (you can use also a piece of 8 core ethernet cable), a 6 pin female strip headers and a bit of talent!&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== '''Part 3: PIC MCU programming''' ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== MPLAB IDE settings ===&lt;br /&gt;
&lt;br /&gt;
Install MPLAB IDE and MPLAB C30(TM)on your PC.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Start a new project ===&lt;br /&gt;
&lt;br /&gt;
Then, let’s follow the “New Project Set-up” checklist to create a new project with the MPLAB IDE:&lt;br /&gt;
&lt;br /&gt;
* Select “Project-&amp;gt;Project Wizard” to activate the new project wizard, which will guide us automatically through the following steps…&lt;br /&gt;
* Select the correct PIC device, and click Next.&lt;br /&gt;
* Select the MPLAB C30 Compiler Suite and click Next.&lt;br /&gt;
* Create a new folder and name it “FolderName”; name the project “ProjectName” and click Next.&lt;br /&gt;
* Click Next to the following dialog (box—there is no need to copy any source files from any previous projects or directories.&lt;br /&gt;
* Click on Finish to complete the Wizard set-up.&lt;br /&gt;
&lt;br /&gt;
Open a new editor window.&lt;br /&gt;
&lt;br /&gt;
* Select “File-&amp;gt;Save As”, to save the file as: “FileName.c”.&lt;br /&gt;
* Select “Project-&amp;gt;Save” to save the project.&lt;br /&gt;
&lt;br /&gt;
Our first line of code is going to be:&lt;br /&gt;
&lt;br /&gt;
 #include &amp;lt;p24hj256gp206.h&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
NOTE: 24hj256gp206 is the microcontroller used in this example. You must replace it with your own microcontroller model: files are located in &amp;quot;C:\Program Files\Microchip\MPLAB C30\support\h\&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
This is a pseudo-instruction for the preprocessor telling the compiler to read the content of a device-specifi c file before proceeding any further.&lt;br /&gt;
The content of the device-specifi c “.h”&lt;br /&gt;
file chosen is a long list of the names (and sizes) of all the internal special-function registers (SFRs) of the chosen PIC model: those names reflect&lt;br /&gt;
exactly those being used in the device datasheet.&lt;br /&gt;
Let’s add a couple more lines that will introduce you to the main() function:&lt;br /&gt;
&lt;br /&gt;
 main()&lt;br /&gt;
 {&lt;br /&gt;
 &lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
The main() function is the place where the microcontroller (program counter) will go first at power-up or after each subsequent reset.&lt;br /&gt;
Before entering the main() function, the microcontroller will execute a short initialization code segment automatically inserted by the linker.&lt;br /&gt;
This is known as the c0 code. The c0 code will perform basic housekeeping chores, including the initialization of the microcontroller stack, among other&lt;br /&gt;
things.&lt;/div&gt;</summary>
		<author><name>PaoloVilla</name></author>	</entry>

	<entry>
		<id>https://airwiki.deib.polimi.it/index.php?title=Getting_Started_With_PIC(TM)_MCU&amp;diff=9221</id>
		<title>Getting Started With PIC(TM) MCU</title>
		<link rel="alternate" type="text/html" href="https://airwiki.deib.polimi.it/index.php?title=Getting_Started_With_PIC(TM)_MCU&amp;diff=9221"/>
				<updated>2009-11-08T08:50:27Z</updated>
		
		<summary type="html">&lt;p&gt;PaoloVilla: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;!!!___WORK_IN_PROGRESS___!!!&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== '''Part 1: Introduction''' ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Chosing a PIC(TM) Microcontroller ===&lt;br /&gt;
&lt;br /&gt;
The first step to chese a microcontroller is to focus on hardware/software needs:&lt;br /&gt;
&lt;br /&gt;
* Board power supply is 3V or 5V (or other)?&lt;br /&gt;
* Power saving is crucial? You need a Ultra-Micro-Low-Nanowatt-Power microcontroller?&lt;br /&gt;
* Application need a little, low cost microcontroller (8bit MCU), a bigger, high performance 16bit MCU or an exagerated 32bit microcontroller?&lt;br /&gt;
* What kind and how many peripherics are needed in your application? ADC, UART, Timers, PWM Channels, Interrupt stackable, SPI, I2C, Can Bus, Ethernet, USB... Yes, it's not a joke! High Performance PIC Microcontroller can have one or more USB and/or Ethernet port, you can implement usb mass storage or TCP-IP functions.&lt;br /&gt;
* Available memory space: you need an extra large memory because you just know your firmare will be extra long?&lt;br /&gt;
&lt;br /&gt;
Once you have answered some of these questions you can use Microchip Advanced Parts Selector (MAPS(TM)) to find only microcontrollers that satisfy your&lt;br /&gt;
requests.&lt;br /&gt;
MAPS is available on-line or for download directly from Microchip web site (http://www.microchip.com).&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Software tools ===&lt;br /&gt;
&lt;br /&gt;
Let’s verify you have all the necessary equipments, ready and installed (latest version available for download from Microchip web site at&lt;br /&gt;
http://www.microchip.com):&lt;br /&gt;
&lt;br /&gt;
* PIC MCU Datasheet;&lt;br /&gt;
* MPLAB IDE(TM), free Integrated Development Environment;&lt;br /&gt;
* MPLAB C30(TM), C compiler (demo or free student version).&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== '''Part 2: Basic hardware''' ==&lt;br /&gt;
&lt;br /&gt;
Besides a PC, because of we intend &amp;quot;make&amp;quot; something and not only talk about it, we need some hardware tools:&lt;br /&gt;
&lt;br /&gt;
* PIC MCU programmer-debugger (in Ai&amp;amp;R Lab Lambrate you can find some Microchip ICD2(TM) programmer-debugger, some adapter boards with ZIF socket and some&lt;br /&gt;
self-made programming cables);&lt;br /&gt;
* PIC MCU demoboard or your board with power supply, PIC Microconroller, oscillator, MCLR circuitry and some input-output hardware.&lt;br /&gt;
&lt;br /&gt;
If you are watching to buy an own programmer/debugger, Microchip PIC-KIT could be the right choise due to it's little dimensions, low price and good&lt;br /&gt;
performances. For detailed information, including PIC microcontroller supported list, visit microchip web site.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Oscillator ===&lt;br /&gt;
&lt;br /&gt;
The system clock (FOSC) source can be provided by a different number of options, depending by microcontroller family (low power, low cost microcontroller&lt;br /&gt;
allow less options choise than high power, high cost MCU).Generally options can be divided in:&lt;br /&gt;
&lt;br /&gt;
* Internal Oscillator (in general an internal RC network);&lt;br /&gt;
* External Oscillator (external clock source, external crystal or ceramic resonator operation and external RC network).&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Image:MCUOscillator.jpg]]&lt;br /&gt;
&lt;br /&gt;
In addition, oscillator system can includes on-chip Phase-Locked Loop (PLL) to boost internal operating frequency, on-the-fly clock switching between&lt;br /&gt;
various clock sources and Fail-Safe Clock Monitor (FSCM) that detects clock failure and permits safe application recovery or shutdown.&lt;br /&gt;
This means, for example, that with a PIC24H series microcontoller, you can use a 10Mhz external crystal resonator for clock source, but configuring&lt;br /&gt;
internal PLL circuitry through dedicated registers, you can obtain a 80Mhz internal clock frequency, achieving 40MIPS core operation speed&lt;br /&gt;
(PIC24H need two clock cycles to execute a single instruction).&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== MCLR circuit ===&lt;br /&gt;
&lt;br /&gt;
PIC Microcontroller has a number of reset sources and controls (POR: Power-on Reset; BOR: Brown-out Reset; MCLR: Master Clear Pin Reset; WDTO: Watchdog&lt;br /&gt;
Timer Reset).The external reset is generated by driving the MCLR pin low. The MCLR pin is a Schmitt trigger input with an additional glitch filter.&lt;br /&gt;
Reset pulses that are longer than the minimum pulse width generates a Reset (see datasheet). The External Reset (MCLR) Pin (EXTR) bit in the Reset&lt;br /&gt;
Control (RCON) register is set to indicate the MCLR Reset.If your system has an external supervisory circuits that generate reset signals to Reset&lt;br /&gt;
multiple devices in the system, this external Reset signal can be directly connected to the MCLR pin to&lt;br /&gt;
reset the device when the rest of system is Reset.&lt;br /&gt;
When using the internal power supervisory circuit to Reset the device, the external reset pin (MCLR) should be tied directly or resistively to VDD.&lt;br /&gt;
In this case, the MCLR pin is not used to generate a Reset. The external reset pin (MCLR) does not have an internal pull-up and must not be left&lt;br /&gt;
unconnected. A typical power-on reset circuit is:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Image:MCUMCLR.jpg]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Programming/Debugging interface ===&lt;br /&gt;
&lt;br /&gt;
ICSP(TM) (In-Circuit Serial Programming(TM)) mode is a special programming protocol that allows you to read and write to PIC Microcontroller and is the&lt;br /&gt;
most direct method used to program the device.The ICSP capability is Microchip’s proprietary process for microcontroller programming in the target&lt;br /&gt;
application. The ICSP interface uses two pins as its core.&lt;br /&gt;
The programming data pin (PGD) functions as both an input and an output, allowing programming data to be read in and device information to be read out&lt;br /&gt;
on command.The programming clock pin (PGC) clocks in data and controls the overall process.&lt;br /&gt;
&lt;br /&gt;
Serial programming allows customers to manufacture boards with unprogrammed devices and then to program the digital signal controller just before shipping&lt;br /&gt;
the product. Serial programming also allows the most recent firmware or a custom firmware to be programmed.&lt;br /&gt;
&lt;br /&gt;
Depending from used Microcontroller it's possible to have one or more programming ports. PIC24HJ256JP206, for example, has three pairs of programming&lt;br /&gt;
clock/data pins:&lt;br /&gt;
&lt;br /&gt;
* PGC1/EMUC1 and PGD1/EMUD1&lt;br /&gt;
* PGC2/EMUC2 and PGD2/EMUD2&lt;br /&gt;
* PGC3/EMUC3 and PGD3/EMUD3&lt;br /&gt;
&lt;br /&gt;
Used programming port must be specified in MPLAB IDE selecting &amp;quot;Configuration Bits...&amp;quot; in &amp;quot;Configure&amp;quot; menu.&lt;br /&gt;
The High-Level ICSP Programming Flow is:&lt;br /&gt;
&lt;br /&gt;
[[Image:HL_ICSP_PROGRAMMING_FLOW.jpg]]&lt;br /&gt;
&lt;br /&gt;
When the MPLAB(TM) ICD 2 or another in-circuit emulator is selected as a debugger,the in-circuit debugging functionality is enabled.&lt;br /&gt;
This function allows simple debugging when used with MPLAB IDE. The debugging functionality is controlled through the EMUCx (emulation/debug clock) and&lt;br /&gt;
EMUDx (emulation/debug data) pin functions. To use the in-circuit debugger function of the device, the design must implement ICSP connections to MCLR,&lt;br /&gt;
VDD, VSS, PGCx/EMCx and PGDx/EMUDx pin pairs. In addition, when the feature is enabled, some of the resources are not available for general use.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Programmer Connection ===&lt;br /&gt;
&lt;br /&gt;
ICD 2 programmer/debugger has a RJ12 6 pin output connector while PIC-KIT has a more comfortable 6 pin female strip headers. &lt;br /&gt;
The simplest way to interface programmer/debugger with microcontroller is to solder a 6 pin male strip headers to your board connetting PGCX, PGDX, MCLR,&lt;br /&gt;
VDD and VSS pins, as in figure:&lt;br /&gt;
&lt;br /&gt;
[[Image:ICSP_Connector.jpg]]&lt;br /&gt;
&lt;br /&gt;
Connecting pins in the same order as in figure you can either connect directly PIC-KIT to your board, or use an RJ12-&amp;gt;female_strip_headers adapter cable to&lt;br /&gt;
connect ICD 2 to target device. You can find two of that selfmade cabe in AI&amp;amp;R Lab, or you can build your own one using an RJ12 connector, a piece of 6 core&lt;br /&gt;
cable (you can use also a piece of 8 core ethernet cable), a 6 pin female strip headers and a bit of talent!&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== '''Part 3: PIC MCU programming''' ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== MPLAB IDE settings ===&lt;br /&gt;
&lt;br /&gt;
Install MPLAB IDE and MPLAB C30(TM)on your PC.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Start a new project ===&lt;br /&gt;
&lt;br /&gt;
Then, let’s follow the “New Project Set-up” checklist to create a new project with the MPLAB IDE:&lt;br /&gt;
&lt;br /&gt;
* Select “Project-&amp;gt;Project Wizard” to activate the new project wizard, which will guide us automatically through the following steps…&lt;br /&gt;
* Select the correct PIC device, and click Next.&lt;br /&gt;
* Select the MPLAB C30 Compiler Suite and click Next.&lt;br /&gt;
* Create a new folder and name it “FolderName”; name the project “ProjectName” and click Next.&lt;br /&gt;
* Click Next to the following dialog (box—there is no need to copy any source files from any previous projects or directories.&lt;br /&gt;
* Click on Finish to complete the Wizard set-up.&lt;br /&gt;
&lt;br /&gt;
Open a new editor window.&lt;br /&gt;
&lt;br /&gt;
* Select “File-&amp;gt;Save As”, to save the file as: “FileName.c”.&lt;br /&gt;
* Select “Project-&amp;gt;Save” to save the project.&lt;br /&gt;
&lt;br /&gt;
Our first line of code is going to be:&lt;br /&gt;
&lt;br /&gt;
 #include &amp;lt;p24hj256gp206.h&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
NOTE: 24hj256gp206 is the microcontroller used in this example. You must replace it with your own microcontroller model: files are located in &amp;quot;C:\Program Files\Microchip\MPLAB C30\support\h\&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
This is a pseudo-instruction for the preprocessor telling the compiler to read the content of a device-specifi c file before proceeding any further.&lt;br /&gt;
The content of the device-specifi c “.h”&lt;br /&gt;
file chosen is a long list of the names (and sizes) of all the internal special-function registers (SFRs) of the chosen PIC model: those names reflect&lt;br /&gt;
exactly those being used in the device datasheet.&lt;br /&gt;
Let’s add a couple more lines that will introduce you to the main() function:&lt;br /&gt;
&lt;br /&gt;
 main()&lt;br /&gt;
 {&lt;br /&gt;
 &lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
The main() function is the place where the microcontroller (program counter) will go first at power-up or after each subsequent reset.&lt;br /&gt;
Before entering the main() function, the microcontroller will execute a short initialization code segment automatically inserted by the linker.&lt;br /&gt;
This is known as the c0 code. The c0 code will perform basic housekeeping chores, including the initialization of the microcontroller stack, among other&lt;br /&gt;
things.&lt;/div&gt;</summary>
		<author><name>PaoloVilla</name></author>	</entry>

	<entry>
		<id>https://airwiki.deib.polimi.it/index.php?title=Getting_Started_With_PIC(TM)_MCU&amp;diff=9220</id>
		<title>Getting Started With PIC(TM) MCU</title>
		<link rel="alternate" type="text/html" href="https://airwiki.deib.polimi.it/index.php?title=Getting_Started_With_PIC(TM)_MCU&amp;diff=9220"/>
				<updated>2009-11-08T08:50:00Z</updated>
		
		<summary type="html">&lt;p&gt;PaoloVilla: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;!!!___WORK_IN_PROGRESS___!!!&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== '''Part 1: Introduction''' ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Chosing a PIC(TM) Microcontroller ===&lt;br /&gt;
&lt;br /&gt;
The first step to chese a microcontroller is to focus on hardware/software needs:&lt;br /&gt;
&lt;br /&gt;
* Board power supply is 3V or 5V (or other)?&lt;br /&gt;
* Power saving is crucial? You need a Ultra-Micro-Low-Nanowatt-Power microcontroller?&lt;br /&gt;
* Application need a little, low cost microcontroller (8bit MCU), a bigger, high performance 16bit MCU or an exagerated 32bit microcontroller?&lt;br /&gt;
* What kind and how many peripherics are needed in your application? ADC, UART, Timers, PWM Channels, Interrupt stackable, SPI, I2C, Can Bus, Ethernet, USB... Yes, it's not a joke! High Performance PIC Microcontroller can have one or more USB and/or Ethernet port, you can implement usb mass storage or&lt;br /&gt;
TCP-IP functions.&lt;br /&gt;
* Available memory space: you need an extra large memory because you just know your firmare will be extra long?&lt;br /&gt;
&lt;br /&gt;
Once you have answered some of these questions you can use Microchip Advanced Parts Selector (MAPS(TM)) to find only microcontrollers that satisfy your&lt;br /&gt;
requests.&lt;br /&gt;
MAPS is available on-line or for download directly from Microchip web site (http://www.microchip.com).&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Software tools ===&lt;br /&gt;
&lt;br /&gt;
Let’s verify you have all the necessary equipments, ready and installed (latest version available for download from Microchip web site at&lt;br /&gt;
http://www.microchip.com):&lt;br /&gt;
&lt;br /&gt;
* PIC MCU Datasheet;&lt;br /&gt;
* MPLAB IDE(TM), free Integrated Development Environment;&lt;br /&gt;
* MPLAB C30(TM), C compiler (demo or free student version).&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== '''Part 2: Basic hardware''' ==&lt;br /&gt;
&lt;br /&gt;
Besides a PC, because of we intend &amp;quot;make&amp;quot; something and not only talk about it, we need some hardware tools:&lt;br /&gt;
&lt;br /&gt;
* PIC MCU programmer-debugger (in Ai&amp;amp;R Lab Lambrate you can find some Microchip ICD2(TM) programmer-debugger, some adapter boards with ZIF socket and some&lt;br /&gt;
self-made programming cables);&lt;br /&gt;
* PIC MCU demoboard or your board with power supply, PIC Microconroller, oscillator, MCLR circuitry and some input-output hardware.&lt;br /&gt;
&lt;br /&gt;
If you are watching to buy an own programmer/debugger, Microchip PIC-KIT could be the right choise due to it's little dimensions, low price and good&lt;br /&gt;
performances. For detailed information, including PIC microcontroller supported list, visit microchip web site.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Oscillator ===&lt;br /&gt;
&lt;br /&gt;
The system clock (FOSC) source can be provided by a different number of options, depending by microcontroller family (low power, low cost microcontroller&lt;br /&gt;
allow less options choise than high power, high cost MCU).Generally options can be divided in:&lt;br /&gt;
&lt;br /&gt;
* Internal Oscillator (in general an internal RC network);&lt;br /&gt;
* External Oscillator (external clock source, external crystal or ceramic resonator operation and external RC network).&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Image:MCUOscillator.jpg]]&lt;br /&gt;
&lt;br /&gt;
In addition, oscillator system can includes on-chip Phase-Locked Loop (PLL) to boost internal operating frequency, on-the-fly clock switching between&lt;br /&gt;
various clock sources and Fail-Safe Clock Monitor (FSCM) that detects clock failure and permits safe application recovery or shutdown.&lt;br /&gt;
This means, for example, that with a PIC24H series microcontoller, you can use a 10Mhz external crystal resonator for clock source, but configuring&lt;br /&gt;
internal PLL circuitry through dedicated registers, you can obtain a 80Mhz internal clock frequency, achieving 40MIPS core operation speed&lt;br /&gt;
(PIC24H need two clock cycles to execute a single instruction).&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== MCLR circuit ===&lt;br /&gt;
&lt;br /&gt;
PIC Microcontroller has a number of reset sources and controls (POR: Power-on Reset; BOR: Brown-out Reset; MCLR: Master Clear Pin Reset; WDTO: Watchdog&lt;br /&gt;
Timer Reset).The external reset is generated by driving the MCLR pin low. The MCLR pin is a Schmitt trigger input with an additional glitch filter.&lt;br /&gt;
Reset pulses that are longer than the minimum pulse width generates a Reset (see datasheet). The External Reset (MCLR) Pin (EXTR) bit in the Reset&lt;br /&gt;
Control (RCON) register is set to indicate the MCLR Reset.If your system has an external supervisory circuits that generate reset signals to Reset&lt;br /&gt;
multiple devices in the system, this external Reset signal can be directly connected to the MCLR pin to&lt;br /&gt;
reset the device when the rest of system is Reset.&lt;br /&gt;
When using the internal power supervisory circuit to Reset the device, the external reset pin (MCLR) should be tied directly or resistively to VDD.&lt;br /&gt;
In this case, the MCLR pin is not used to generate a Reset. The external reset pin (MCLR) does not have an internal pull-up and must not be left&lt;br /&gt;
unconnected. A typical power-on reset circuit is:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Image:MCUMCLR.jpg]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Programming/Debugging interface ===&lt;br /&gt;
&lt;br /&gt;
ICSP(TM) (In-Circuit Serial Programming(TM)) mode is a special programming protocol that allows you to read and write to PIC Microcontroller and is the&lt;br /&gt;
most direct method used to program the device.The ICSP capability is Microchip’s proprietary process for microcontroller programming in the target&lt;br /&gt;
application. The ICSP interface uses two pins as its core.&lt;br /&gt;
The programming data pin (PGD) functions as both an input and an output, allowing programming data to be read in and device information to be read out&lt;br /&gt;
on command.The programming clock pin (PGC) clocks in data and controls the overall process.&lt;br /&gt;
&lt;br /&gt;
Serial programming allows customers to manufacture boards with unprogrammed devices and then to program the digital signal controller just before shipping&lt;br /&gt;
the product. Serial programming also allows the most recent firmware or a custom firmware to be programmed.&lt;br /&gt;
&lt;br /&gt;
Depending from used Microcontroller it's possible to have one or more programming ports. PIC24HJ256JP206, for example, has three pairs of programming&lt;br /&gt;
clock/data pins:&lt;br /&gt;
&lt;br /&gt;
* PGC1/EMUC1 and PGD1/EMUD1&lt;br /&gt;
* PGC2/EMUC2 and PGD2/EMUD2&lt;br /&gt;
* PGC3/EMUC3 and PGD3/EMUD3&lt;br /&gt;
&lt;br /&gt;
Used programming port must be specified in MPLAB IDE selecting &amp;quot;Configuration Bits...&amp;quot; in &amp;quot;Configure&amp;quot; menu.&lt;br /&gt;
The High-Level ICSP Programming Flow is:&lt;br /&gt;
&lt;br /&gt;
[[Image:HL_ICSP_PROGRAMMING_FLOW.jpg]]&lt;br /&gt;
&lt;br /&gt;
When the MPLAB(TM) ICD 2 or another in-circuit emulator is selected as a debugger,the in-circuit debugging functionality is enabled.&lt;br /&gt;
This function allows simple debugging when used with MPLAB IDE. The debugging functionality is controlled through the EMUCx (emulation/debug clock) and&lt;br /&gt;
EMUDx (emulation/debug data) pin functions. To use the in-circuit debugger function of the device, the design must implement ICSP connections to MCLR,&lt;br /&gt;
VDD, VSS, PGCx/EMCx and PGDx/EMUDx pin pairs. In addition, when the feature is enabled, some of the resources are not available for general use.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Programmer Connection ===&lt;br /&gt;
&lt;br /&gt;
ICD 2 programmer/debugger has a RJ12 6 pin output connector while PIC-KIT has a more comfortable 6 pin female strip headers. &lt;br /&gt;
The simplest way to interface programmer/debugger with microcontroller is to solder a 6 pin male strip headers to your board connetting PGCX, PGDX, MCLR,&lt;br /&gt;
VDD and VSS pins, as in figure:&lt;br /&gt;
&lt;br /&gt;
[[Image:ICSP_Connector.jpg]]&lt;br /&gt;
&lt;br /&gt;
Connecting pins in the same order as in figure you can either connect directly PIC-KIT to your board, or use an RJ12-&amp;gt;female_strip_headers adapter cable to&lt;br /&gt;
connect ICD 2 to target device. You can find two of that selfmade cabe in AI&amp;amp;R Lab, or you can build your own one using an RJ12 connector, a piece of 6 core&lt;br /&gt;
cable (you can use also a piece of 8 core ethernet cable), a 6 pin female strip headers and a bit of talent!&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== '''Part 3: PIC MCU programming''' ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== MPLAB IDE settings ===&lt;br /&gt;
&lt;br /&gt;
Install MPLAB IDE and MPLAB C30(TM)on your PC.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Start a new project ===&lt;br /&gt;
&lt;br /&gt;
Then, let’s follow the “New Project Set-up” checklist to create a new project with the MPLAB IDE:&lt;br /&gt;
&lt;br /&gt;
* Select “Project-&amp;gt;Project Wizard” to activate the new project wizard, which will guide us automatically through the following steps…&lt;br /&gt;
* Select the correct PIC device, and click Next.&lt;br /&gt;
* Select the MPLAB C30 Compiler Suite and click Next.&lt;br /&gt;
* Create a new folder and name it “FolderName”; name the project “ProjectName” and click Next.&lt;br /&gt;
* Click Next to the following dialog (box—there is no need to copy any source files from any previous projects or directories.&lt;br /&gt;
* Click on Finish to complete the Wizard set-up.&lt;br /&gt;
&lt;br /&gt;
Open a new editor window.&lt;br /&gt;
&lt;br /&gt;
* Select “File-&amp;gt;Save As”, to save the file as: “FileName.c”.&lt;br /&gt;
* Select “Project-&amp;gt;Save” to save the project.&lt;br /&gt;
&lt;br /&gt;
Our first line of code is going to be:&lt;br /&gt;
&lt;br /&gt;
 #include &amp;lt;p24hj256gp206.h&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
NOTE: 24hj256gp206 is the microcontroller used in this example. You must replace it with your own microcontroller model: files are located in &amp;quot;C:\Program Files\Microchip\MPLAB C30\support\h\&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
This is a pseudo-instruction for the preprocessor telling the compiler to read the content of a device-specifi c file before proceeding any further.&lt;br /&gt;
The content of the device-specifi c “.h”&lt;br /&gt;
file chosen is a long list of the names (and sizes) of all the internal special-function registers (SFRs) of the chosen PIC model: those names reflect&lt;br /&gt;
exactly those being used in the device datasheet.&lt;br /&gt;
Let’s add a couple more lines that will introduce you to the main() function:&lt;br /&gt;
&lt;br /&gt;
 main()&lt;br /&gt;
 {&lt;br /&gt;
 &lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
The main() function is the place where the microcontroller (program counter) will go first at power-up or after each subsequent reset.&lt;br /&gt;
Before entering the main() function, the microcontroller will execute a short initialization code segment automatically inserted by the linker.&lt;br /&gt;
This is known as the c0 code. The c0 code will perform basic housekeeping chores, including the initialization of the microcontroller stack, among other&lt;br /&gt;
things.&lt;/div&gt;</summary>
		<author><name>PaoloVilla</name></author>	</entry>

	<entry>
		<id>https://airwiki.deib.polimi.it/index.php?title=File:MCUOscillator.jpg&amp;diff=9219</id>
		<title>File:MCUOscillator.jpg</title>
		<link rel="alternate" type="text/html" href="https://airwiki.deib.polimi.it/index.php?title=File:MCUOscillator.jpg&amp;diff=9219"/>
				<updated>2009-11-08T08:49:12Z</updated>
		
		<summary type="html">&lt;p&gt;PaoloVilla: uploaded a new version of &amp;quot;Image:MCUOscillator.jpg&amp;quot;&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Example of Crystal or Ceramic Resonator Operation&lt;/div&gt;</summary>
		<author><name>PaoloVilla</name></author>	</entry>

	</feed>