<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://hades.mech.northwestern.edu//api.php?action=feedcontributions&amp;feedformat=atom&amp;user=DanJohnson</id>
	<title>Mech - User contributions [en]</title>
	<link rel="self" type="application/atom+xml" href="https://hades.mech.northwestern.edu//api.php?action=feedcontributions&amp;feedformat=atom&amp;user=DanJohnson"/>
	<link rel="alternate" type="text/html" href="https://hades.mech.northwestern.edu//index.php/Special:Contributions/DanJohnson"/>
	<updated>2026-05-15T15:03:07Z</updated>
	<subtitle>User contributions</subtitle>
	<generator>MediaWiki 1.43.8</generator>
	<entry>
		<id>https://hades.mech.northwestern.edu//index.php?title=Waveform_Generation_with_AD9833&amp;diff=9558</id>
		<title>Waveform Generation with AD9833</title>
		<link rel="alternate" type="text/html" href="https://hades.mech.northwestern.edu//index.php?title=Waveform_Generation_with_AD9833&amp;diff=9558"/>
		<updated>2008-12-18T02:12:15Z</updated>

		<summary type="html">&lt;p&gt;DanJohnson: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Image:AD9833Connsmall.jpg | right | thumb | Connection diagram for the AD9833 function generator.]]&lt;br /&gt;
&lt;br /&gt;
=Overview=&lt;br /&gt;
The AD9833 is a programmable waveform generator capable of creating sine, triangular, or square wave outputs in a frequency range of 0 to 12.5 MHz.  It has two 28-bit frequency registers and two 12-bit phase registers whose values can be used to calculate the frequency and phase of an output waveform.  This chip is perfectly suited for use with the PIC 18F4520, as it uses SPI communication for its setup and control.  A connection diagram for the AD9833 is given to the right.  The MCLK pin is tied directly to the oscillator of the PIC, and the three SPI communication lines are connected to three I/O pins on the PIC (in this case pins A1, A2, and A3).&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=Setup=&lt;br /&gt;
&lt;br /&gt;
In order to establish communication between the PIC and the AD9833, we need to set up the SPI for the pins we wish to use. Here, we use the software support included with the CCS compiler (the PIC also offers hardware support, which we did not use. It should, however, be very similar). The following should be added to the header of your program.&lt;br /&gt;
&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 #use spi(DO = PIN_A3, CLK = PIN_A2, ENABLE = PIN_A1, BITS = 16, MASTER, ENABLE_ACTIVE = 0, MSB_FIRST, IDLE = 1)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
The first three arguments determine which three pins we will be using: DO is the &amp;quot;SDATA&amp;quot; pin of the AD9833, CLK is the &amp;quot;SCLK&amp;quot; pin, and ENABLE is the &amp;quot;FSYNC&amp;quot; pin.  The next argument states that the max number of bits in one transfer is 16.  The next argument specifies that the PIC is the master and the AD9833 is the slave.  The AD9833&#039;s FSYNC pin is active low, and it accepts the most significant bit (MSB) of each transfer first.  The SCLK pin is also specified to be kept high when not in use.  After this initial setup, the SPI communication is quite straightforward.  We simply use the function &#039;&#039;&#039;spi_xfer()&#039;&#039;&#039; whenever we want to send information via SPI to the AD9833.&lt;br /&gt;
&lt;br /&gt;
=AD9833 Control Register=&lt;br /&gt;
In order to program the frequency generator, we need to write to its internal control register. This control register is used for resetting the chip, setting the mode of operation and selecting the frequency and phase registers on which the output is to be based. &lt;br /&gt;
&lt;br /&gt;
Each of the 16 bits transferred has a meaning, and these meanings are described in the table below.  Note that the if a frequency register is being written to (first two bits = 01 or 10), the last 14 bits are the value of the write, and do not have the same meaning as specified in the table.  Similarly, if a phase register is being written to (first two bits = 11), the last 12 bits are the value of the write.  Only if the control register is being written to (first two bits = 00) are most of the meanings specified in the table applicable.&lt;br /&gt;
&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{| border=&amp;quot;1&amp;quot; cellspacing=&amp;quot;0&amp;quot; cellpadding=&amp;quot;3&amp;quot; &lt;br /&gt;
|-&lt;br /&gt;
!Bit!! Significance&lt;br /&gt;
|-&lt;br /&gt;
|D15,D14(MSB) || 10 = FREQ1 write, 01 = FREQ0 write, 11 = PHASE write, 00 = control write&lt;br /&gt;
|-&lt;br /&gt;
|D13 ||If D15,D14 = 00, 0 = individual LSB and MSB FREQ write, 1 = both LSB and MSB FREQ writes consecutively&lt;br /&gt;
|-&lt;br /&gt;
| ||If D15,D14 = 11, 0 = PHASE0 write, 1 = PHASE1 write&lt;br /&gt;
|-&lt;br /&gt;
|D12||0 = writing LSB independently, 1 = writing MSB independently&lt;br /&gt;
|-&lt;br /&gt;
|D11||0 = output FREQ0, 1 = output FREQ1&lt;br /&gt;
|-&lt;br /&gt;
|D10||0 = output PHASE0, 1 = output PHASE1&lt;br /&gt;
|-&lt;br /&gt;
|D9||Reserved.  Must be 0.&lt;br /&gt;
|-&lt;br /&gt;
|D8||0 = RESET disabled, 1 = RESET enabled&lt;br /&gt;
|-&lt;br /&gt;
|D7||0 = internal clock is enabled, 1 = internal clock is disabled&lt;br /&gt;
|-&lt;br /&gt;
|D6||0 = onboard DAC is active for sine and triangle wave output, 1 = put DAC to sleep for square wave output&lt;br /&gt;
|-&lt;br /&gt;
|D5||0 = output depends on D1, 1 = output is a square wave&lt;br /&gt;
|-&lt;br /&gt;
|D4||Reserved.  Must be 0.&lt;br /&gt;
|-&lt;br /&gt;
|D3||0 = square wave of half frequency output, 1 = square wave output&lt;br /&gt;
|-&lt;br /&gt;
|D2||Reserved.  Must be 0.&lt;br /&gt;
|-&lt;br /&gt;
|D1||If D5 = 1, D1 = 0. Otherwise 0 = sine output, 1 = triangle output&lt;br /&gt;
|-&lt;br /&gt;
|D0||Reserved.  Must be 0.&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=Frequency and Phase Registers=&lt;br /&gt;
In order for the chip to output at a frequency &amp;lt;math&amp;gt;f_{out}&amp;lt;/math&amp;gt; and phase shift &amp;lt;math&amp;gt;\Phi_{shift}&amp;lt;/math&amp;gt; we need to have:&lt;br /&gt;
&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;math&amp;gt;f_{out}=\frac{f_{MCLK}}{2^{28}}\times FREQREG&amp;lt;/math&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;math&amp;gt;\Phi_{shift} = \frac{2\pi}{4096}\times PHASEREG&amp;lt;/math&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
In other words, the output frequency and phase shift are not the values of the frequency or phase registers.  They are related by the above equations, so the values you send to the registers need to be modified from the actual frequency and phase shift.  For instance, if we sent 200 to the FREQ register and 100 to the PHASE register, and we were using a 20 MHz MCLK, we would output a 14.9 Hz wave with a phase shift of 0.15 radians.&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
The chip has two frequency registers (FREQ0 and FREQ1) and two phase registers (PHASE0 and PHASE1). By setting or resetting bits 11 (FSELECT) and 10 (PSELECT) of the control word we select which frequency register and which phase register to combine in order to produce the output waveform.&lt;br /&gt;
&lt;br /&gt;
=Writing to the Registers=&lt;br /&gt;
The first two bits (most significant) of the SPI message select which of the registers is being written. The next bit is used in order to distinguish between the two phase registers, in case one of them is being written to. &lt;br /&gt;
&lt;br /&gt;
==Phase Registers==&lt;br /&gt;
In order to write to a phase register, the most significant two bits of the serially transmitted word have to be 11. The next bit is the number of the phase register that is being written, following is a &amp;quot;don&#039;t care&amp;quot; bit and the rest represent the value to be written.&lt;br /&gt;
&lt;br /&gt;
==Control Register==&lt;br /&gt;
Writing to the control register is done by setting the first two bits to 00. The other bits should be set according to the desired values found from the above table.&lt;br /&gt;
&lt;br /&gt;
==Frequency Registers==&lt;br /&gt;
Writing to the frequency registers can be done in two ways:&lt;br /&gt;
1. Both the 14 MSB (most significant bits) and 14 LSB (least significant bits) of a frequency register will be altered - coarse tuning&lt;br /&gt;
2. Only the MSB or the LSB will be written - fine tuning&lt;br /&gt;
In order to specify which kind of write is being performed we need to set bit 12(HLB) and 13(B28) of the control register accordingly.&lt;br /&gt;
To specify which of the two frequency registers is being written, we have to set the first two bits preceding the data to either 01 for FREQ0 or 10 for FREQ1. &lt;br /&gt;
&lt;br /&gt;
=Example=&lt;br /&gt;
In order to setup or update the AD9833 you first need to reset it, then transfer the frequency and phase information, then &amp;quot;unreset&amp;quot; it.  For example, if we wanted to output a 20 kHz square wave with no phase shift, we would send the following:&lt;br /&gt;
&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
 spi_xfer(0b0010000101101000);&lt;br /&gt;
&lt;br /&gt;
This resets the AD9833 (D8), tells it that we will be using the next two transfers to input both LSB and MSB (D13) of the FREQ0 register (D11), the internal clock is enabled (D7), the DAC has been put to sleep (D6), the output is to be a square wave (D5), and the square wave frequency is not to be divided by two (D3).&lt;br /&gt;
&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
 spi_xfer(0b0101100010010011);&lt;br /&gt;
 spi_xfer(0b0100000000010000);&lt;br /&gt;
&lt;br /&gt;
These transfers are writing to the value of the FREQ0 register (D15-D14), with the last 14 bits of each transfer representing first the LSB, then the MSB of the value.  This writes a value of 0000000001000001100010010011 (268435 decimal) to the FREQ0 register.  If we use the formula above, we see this corresponds to an output frequency of 20 kHz.&lt;br /&gt;
&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
 spi_xfer(0b1100000000000000);&lt;br /&gt;
&lt;br /&gt;
This transfer is writing to the PHASE0 register (D15,D14,D13) and is writing a twelve bit value of zero (D11-D0).&lt;br /&gt;
&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
 spi_xfer(0b0000000001101000);&lt;br /&gt;
&lt;br /&gt;
This transfer &amp;quot;unresets&amp;quot; the AD9833 (D8).&lt;br /&gt;
&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
With a small variation in the values of the five transfers, all of the frequency and phase registers can be written to and output from the VOUT pin of the AD9833.&lt;br /&gt;
==References==&lt;br /&gt;
*[http://www.analog.com/static/imported-files/Data_Sheets/AD9833.pdf AD9833 Datasheet, Analog Devices]&lt;/div&gt;</summary>
		<author><name>DanJohnson</name></author>
	</entry>
	<entry>
		<id>https://hades.mech.northwestern.edu//index.php?title=Waveform_Generation_with_AD9833,_and_SPI&amp;diff=9191</id>
		<title>Waveform Generation with AD9833, and SPI</title>
		<link rel="alternate" type="text/html" href="https://hades.mech.northwestern.edu//index.php?title=Waveform_Generation_with_AD9833,_and_SPI&amp;diff=9191"/>
		<updated>2008-12-10T01:13:51Z</updated>

		<summary type="html">&lt;p&gt;DanJohnson: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Image:AD9833Connsmall.jpg|right]]The AD9833 is a programmable waveform generator capable of creating sine, triangular, or square wave outputs in a frequency range of 0 to 12.5 MHz.  It has two 28-bit frequency registers and two 12-bit phase registers that can be written to and output from the VOUT pin.  This chip is perfectly suited for use with the PIC 18F4520, as it uses SPI communication for its setup and control.  A connection diagram for the AD9833 is given to the right.  The MCLK pin is tied directly to the oscillator of the PIC, and the three SPI communication lines are connected to three I/O pins on the PIC (in this case pins A1, A2, and A3).&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
In order to establish communication between the PIC and the AD9833, we need to set up the SPI for the pins we wish to use.  The following code should be included in your program.&lt;br /&gt;
&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 #use spi(DO = PIN_A3, CLK = PIN_A2, ENABLE = PIN_A1, BITS = 16, MASTER, ENABLE_ACTIVE = 0, MSB_FIRST, IDLE = 1)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
The first three arguments determine which three pins we will be using: DO is the &amp;quot;SDATA&amp;quot; pin of the AD9833, CLK is the &amp;quot;SCLK&amp;quot; pin, and ENABLE is the &amp;quot;FSYNC&amp;quot; pin.  The next argument states that the max number of bits in one transfer is 16.  The next argument specifies that the PIC is the master and the AD9833 is the slave.  The AD9833&#039;s FSYNC pin is active low, and it accepts the most significant bit (MSB) of each transfer first.  The SCLK pin is also specified to be kept high when not in use.  After this initial setup, the SPI communication is quite straightforward.  We simply use the function &#039;&#039;&#039;spi_xfer()&#039;&#039;&#039; whenever we want to send information via SPI to the AD9833.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
Now that we can talk to the waveform generator, we need to know what it needs to be told to produce what we want.  Each of the 16 bits transferred has a meaning, and these meanings are described in the Table below.  Note that the if a frequency register is being written to (first two bits = 01 or 10), the last 14 bits are the value of the write, and do not have the same meaning as specified in the table.  Similarly, if a phase register is being written to (first two bits = 11), the last 12 bits are the value of the write.  Only if the control register is being written to (first two bits = 00) are most of the meanings specified in the table applicable.&lt;br /&gt;
&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{| border=&amp;quot;1&amp;quot; cellspacing=&amp;quot;0&amp;quot; cellpadding=&amp;quot;3&amp;quot; &lt;br /&gt;
|-&lt;br /&gt;
!Bit!! Significance&lt;br /&gt;
|-&lt;br /&gt;
|D15,D14(MSB) || 10 = FREQ1 write, 01 = FREQ0 write, 11 = PHASE write, 00 = control write&lt;br /&gt;
|-&lt;br /&gt;
|D13 ||If D15,D14 = 00, 0 = individual LSB and MSB FREQ write, 1 = both LSB and MSB FREQ writes consecutively&lt;br /&gt;
|-&lt;br /&gt;
| ||If D15,D14 = 11, 0 = PHASE0 write, 1 = PHASE1 write&lt;br /&gt;
|-&lt;br /&gt;
|D12||0 = writing LSB independently, 1 = writing MSB independently&lt;br /&gt;
|-&lt;br /&gt;
|D11||0 = output FREQ0, 1 = output FREQ1&lt;br /&gt;
|-&lt;br /&gt;
|D10||0 = output PHASE0, 1 = output PHASE1&lt;br /&gt;
|-&lt;br /&gt;
|D9||Reserved.  Must be 0.&lt;br /&gt;
|-&lt;br /&gt;
|D8||0 = RESET disabled, 1 = RESET enabled&lt;br /&gt;
|-&lt;br /&gt;
|D7||0 = internal clock is enabled, 1 = internal clock is disabled&lt;br /&gt;
|-&lt;br /&gt;
|D6||0 = onboard DAC is active for sine and triangle wave output, 1 = put DAC to sleep for square wave output&lt;br /&gt;
|-&lt;br /&gt;
|D5||0 = output depends on D1, 1 = output is a square wave&lt;br /&gt;
|-&lt;br /&gt;
|D4||Reserved.  Must be 0.&lt;br /&gt;
|-&lt;br /&gt;
|D3||0 = square wave of half frequency output, 1 = square wave output&lt;br /&gt;
|-&lt;br /&gt;
|D2||Reserved.  Must be 0.&lt;br /&gt;
|-&lt;br /&gt;
|D1||If D5 = 1, D1 = 0. Otherwise 0 = sine output, 1 = triangle output&lt;br /&gt;
|-&lt;br /&gt;
|D0||Reserved.  Must be 0.&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Obviously this is a lot of information to pass to the waveform generator, but this setup can be performed with only a few SPI transfers.  This is nearly all you need to know to set the AD9833, but there are two more critical relationships:&lt;br /&gt;
&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;math&amp;gt;f_{out}=\frac{f_{MCLK}}{2^{28}}\times FREQREG&amp;lt;/math&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;math&amp;gt;\Phi_{shift} = \frac{2\pi}{4096}\times PHASEREG&amp;lt;/math&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
In other words, the output frequency and phase shift are not the values of the frequency or phase registers.  They are related by the above equations, so the values you send to the registers need to be modified from the actual frequency and phase shift.  For instance, if we sent 200 to the FREQ register and 100 to the PHASE register, and we were using a 20 MHz MCLK, we would output a 14.9 Hz wave with a phase shift of 0.15 radians.&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
In order to setup or update the AD9833 you first need to reset it, then transfer the frequency and phase information, then &amp;quot;unreset&amp;quot; it.  For example, if we wanted to output a 20 kHz square wave with no phase shift, we would send the following:&lt;br /&gt;
&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
 spi_xfer(0b0010000101101000);&lt;br /&gt;
&lt;br /&gt;
This resets the AD9833 (D8), tells it that we will be using the next two transfers to input both LSB and MSB (D13) of the FREQ0 register (D11), the internal clock is enabled (D7), the DAC has been put to sleep (D6), the output is to be a square wave (D5), and the square wave frequency is not to be divided by two (D3).&lt;br /&gt;
&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
 spi_xfer(0b0101100010010011);&lt;br /&gt;
 spi_xfer(0b0100000000010000);&lt;br /&gt;
&lt;br /&gt;
These transfers are writing to the value of the FREQ0 register (D15-D14), with the last 14 bits of each transfer representing first the LSB, then the MSB of the value.  This writes a value of 0000000001000001100010010011 (268435 decimal) to the FREQ0 register.  If we use the formula above, we see this corresponds to an output frequency of 20 kHz.&lt;br /&gt;
&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
 spi_xfer(0b1100000000000000);&lt;br /&gt;
&lt;br /&gt;
This transfer is writing to the PHASE0 register (D15,D14,D13) and is writing a twelve bit value of zero (D11-D0).&lt;br /&gt;
&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
 spi_xfer(0b0000000001101000);&lt;br /&gt;
&lt;br /&gt;
This transfer &amp;quot;unresets&amp;quot; the AD9833 (D8).&lt;br /&gt;
&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
With a small variation in the values of the five transfers, all of the frequency and phase registers can be written to and output from the VOUT pin of the AD9833.&lt;br /&gt;
==References==&lt;br /&gt;
*[http://www.analog.com/static/imported-files/Data_Sheets/AD9833.pdf AD9833 Datasheet, Analog Devices]&lt;/div&gt;</summary>
		<author><name>DanJohnson</name></author>
	</entry>
	<entry>
		<id>https://hades.mech.northwestern.edu//index.php?title=Filtering_with_the_LMF100&amp;diff=9190</id>
		<title>Filtering with the LMF100</title>
		<link rel="alternate" type="text/html" href="https://hades.mech.northwestern.edu//index.php?title=Filtering_with_the_LMF100&amp;diff=9190"/>
		<updated>2008-12-10T00:59:27Z</updated>

		<summary type="html">&lt;p&gt;DanJohnson: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Image:bpgain.jpg|right]]The LMF100 is a chip that contains two independent switched capacitor filters.  With just a few added external resistors, it can be used to create 1st-4th order lowpass, highpass, notch, and bandpass filters.  Independently each filter is either first or second order (depending on the external resistor configuration), but they can be cascaded to create up to a fourth order filter.  This page will focus primarily on what the device&#039;s datasheet calls &amp;quot;Mode 1&amp;quot; (a bandpass filter), although the other modes described in the datasheet are quite similar.  The bandpass gain plot is shown to the right. &amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In general, the second order bandpass response is given by:&lt;br /&gt;
&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;center&amp;gt;&amp;lt;math&amp;gt;H_{BP}(s)=\frac{H_{OBP}\cdot\frac{\omega_{0}}{Q}\cdot s}{s^2+\frac{s\omega_0}{Q}+\omega^2_0}&amp;lt;/math&amp;gt;&amp;lt;/center&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
where &amp;lt;math&amp;gt;H_{OBP}&amp;lt;/math&amp;gt; is the gain of the filter at the center frequency &amp;lt;math&amp;gt;f_0&amp;lt;/math&amp;gt;, &amp;lt;math&amp;gt;Q&amp;lt;/math&amp;gt; is the quality factor of the complex pole pair, and &amp;lt;math&amp;gt;\omega_0&amp;lt;/math&amp;gt; is the center frequency in rad/sec.&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&amp;lt;math&amp;gt;Q=\frac{f_0}{f_H-f_L}&amp;lt;/math&amp;gt;  &amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;math&amp;gt;\omega_0=2\pi f_0&amp;lt;/math&amp;gt;&amp;lt;/center&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For each mode described in the datasheet this simplifies down to a couple of governing equations relating external resistances to the properties of the bandpass filter.  If the chip is wired for Mode 1 operation, then the important equations are:&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&amp;lt;math&amp;gt;f_0 = \frac{f_{CLK}}{100}&amp;lt;/math&amp;gt;  &amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;math&amp;gt;H_{OBP} = -\frac{R3}{R1}&amp;lt;/math&amp;gt;&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;math&amp;gt;Q = \frac{f_0}{BW} = \frac{R3}{R2}&amp;lt;/math&amp;gt;&amp;lt;/center&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
From these equations you can determine the frequency of the incoming clock signal needed for a desired center frequency, and the values of resistors needed to set a desired center freqency gain and bandwidth (or alternately, Q).  If the chip is wired as two cascaded, Mode 1, second order, bandpass filters, as shown in below, and each filter is constructed with the same external resistors, the fourth order filter response is:&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&amp;lt;math&amp;gt;H_{BP}(s)=\left[\frac{H_{OBP}\cdot\frac{\omega_{0}}{Q}\cdot s}{s^2+\frac{s\omega_0}{Q}+\omega^2_0}\right]^2&amp;lt;/math&amp;gt;&amp;lt;/center&amp;gt;&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
[[Image:LMFwire.jpg|center]]&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The primary advantage to using the LMF100 with the PIC or a waveform generator like the [[Waveform Generation with AD9833, and SPI | AD9833]] is that it allows the filter to be tuned directly by the PIC, by varying the input clock frequency.  Beware when doing this, however, because by changing the center frequency of the filter you will also change your bandwidth in order to keep the constant Q value that is set by the external resistors.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
*[http://www.national.com/ds/LM/LMF100.pdf LMF100 Datasheet, National Semiconductor]&lt;/div&gt;</summary>
		<author><name>DanJohnson</name></author>
	</entry>
	<entry>
		<id>https://hades.mech.northwestern.edu//index.php?title=Filtering_with_the_LMF100&amp;diff=9189</id>
		<title>Filtering with the LMF100</title>
		<link rel="alternate" type="text/html" href="https://hades.mech.northwestern.edu//index.php?title=Filtering_with_the_LMF100&amp;diff=9189"/>
		<updated>2008-12-10T00:53:59Z</updated>

		<summary type="html">&lt;p&gt;DanJohnson: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Image:bpgain.jpg|right]]The LMF100 is a chip that contains two independent switched capacitor filters.  With just a few added external resistors, it can be used to create 1st-4th order lowpass, highpass, notch, and bandpass filters.  Independently each filter is either first or second order (depending on the external resistor configuration), but they can be cascaded to create up to a fourth order filter.  This page will focus primarily on what the device&#039;s datasheet calls &amp;quot;Mode 1&amp;quot; (a bandpass filter), although the other modes described in the datasheet are quite similar.  The bandpass gain plot is shown to the right. &amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In general, the second order bandpass response is given by:&lt;br /&gt;
&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;center&amp;gt;&amp;lt;math&amp;gt;H_{BP}(s)=\frac{H_{OBP}\cdot\frac{\omega_{0}}{Q}\cdot s}{s^2+\frac{s\omega_0}{Q}+\omega^2_0}&amp;lt;/math&amp;gt;&amp;lt;/center&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
where &amp;lt;math&amp;gt;H_{OBP}&amp;lt;/math&amp;gt; is the gain of the filter at the center frequency &amp;lt;math&amp;gt;f_0&amp;lt;/math&amp;gt;, &amp;lt;math&amp;gt;Q&amp;lt;/math&amp;gt; is the quality factor of the complex pole pair, and &amp;lt;math&amp;gt;\omega_0&amp;lt;/math&amp;gt; is the center frequency in rad/sec.&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&amp;lt;math&amp;gt;Q=\frac{f_0}{f_H-f_L}&amp;lt;/math&amp;gt;  &amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;math&amp;gt;\omega_0=2\pi f_0&amp;lt;/math&amp;gt;&amp;lt;/center&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For each mode described in the datasheet this simplifies down to a couple of governing equations relating external resistances to the properties of the bandpass filter.  If the chip is wired for Mode 1 operation, then the important equations are:&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&amp;lt;math&amp;gt;f_0 = \frac{f_{CLK}}{100}&amp;lt;/math&amp;gt;  &amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;math&amp;gt;H_{OBP} = -\frac{R3}{R1}&amp;lt;/math&amp;gt;&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;math&amp;gt;Q = \frac{f_0}{BW} = \frac{R3}{R2}&amp;lt;/math&amp;gt;&amp;lt;/center&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
From these equations you can determine the frequency of the incoming clock signal needed for a desired center frequency, and the values of resistors needed to set a desired center freqency gain and bandwidth (or alternately, Q).  If the chip is wired as two cascaded, Mode 1, second order, bandpass filters, as shown in below, and each filter is constructed with the same external resistors, the fourth order filter response is:&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&amp;lt;math&amp;gt;H_{BP}(s)=\left[\frac{H_{OBP}\cdot\frac{\omega_{0}}{Q}\cdot s}{s^2+\frac{s\omega_0}{Q}+\omega^2_0}\right]^2&amp;lt;/math&amp;gt;&amp;lt;/center&amp;gt;&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
[[Image:LMFwire.jpg|center]]&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The primary advantage to using the LMF100 with the PIC or a waveform generator like the AD9833 is that it allows the filter to be tuned directly by the PIC, by varying the input clock frequency.  Beware when doing this, however, because by changing the center frequency of the filter you will also change your bandwidth in order to keep the constant Q value that is set by the external resistors.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
*[http://www.national.com/ds/LM/LMF100.pdf LMF100 Datasheet, National Semiconductor]&lt;/div&gt;</summary>
		<author><name>DanJohnson</name></author>
	</entry>
	<entry>
		<id>https://hades.mech.northwestern.edu//index.php?title=File:LMFwire.jpg&amp;diff=9188</id>
		<title>File:LMFwire.jpg</title>
		<link rel="alternate" type="text/html" href="https://hades.mech.northwestern.edu//index.php?title=File:LMFwire.jpg&amp;diff=9188"/>
		<updated>2008-12-10T00:50:34Z</updated>

		<summary type="html">&lt;p&gt;DanJohnson: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>DanJohnson</name></author>
	</entry>
	<entry>
		<id>https://hades.mech.northwestern.edu//index.php?title=Filtering_with_the_LMF100&amp;diff=9187</id>
		<title>Filtering with the LMF100</title>
		<link rel="alternate" type="text/html" href="https://hades.mech.northwestern.edu//index.php?title=Filtering_with_the_LMF100&amp;diff=9187"/>
		<updated>2008-12-10T00:48:43Z</updated>

		<summary type="html">&lt;p&gt;DanJohnson: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Image:bpgain.jpg|right]]The LMF100 is a chip that contains two independent switched capacitor filters.  With just a few added external resistors, it can be used to create 1st-4th order lowpass, highpass, notch, and bandpass filters.  Independently each filter is either first or second order (depending on the external resistor configuration), but they can be cascaded to create up to a fourth order filter.  This page will focus primarily on what the device&#039;s datasheet calls &amp;quot;Mode 1&amp;quot; (a bandpass filter), although the other modes described in the datasheet are quite similar.  The bandpass gain plot is shown to the right. &amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In general, the second order bandpass response is given by:&lt;br /&gt;
&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;center&amp;gt;&amp;lt;math&amp;gt;H_{BP}(s)=\frac{H_{OBP}\cdot\frac{\omega_{0}}{Q}\cdot s}{s^2+\frac{s\omega_0}{Q}+\omega^2_0}&amp;lt;/math&amp;gt;&amp;lt;/center&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
where &amp;lt;math&amp;gt;H_{OBP}&amp;lt;/math&amp;gt; is the gain of the filter at the center frequency &amp;lt;math&amp;gt;f_0&amp;lt;/math&amp;gt;, &amp;lt;math&amp;gt;Q&amp;lt;/math&amp;gt; is the quality factor of the complex pole pair, and &amp;lt;math&amp;gt;\omega_0&amp;lt;/math&amp;gt; is the center frequency in rad/sec.&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&amp;lt;math&amp;gt;Q=\frac{f_0}{f_H-f_L}&amp;lt;/math&amp;gt;  &amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;math&amp;gt;\omega_0=2\pi f_0&amp;lt;/math&amp;gt;&amp;lt;/center&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For each mode described in the datasheet this simplifies down to a couple of governing equations relating external resistances to the properties of the bandpass filter.  If the chip is wired for Mode 1 operation, then the important equations are:&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&amp;lt;math&amp;gt;f_0 = \frac{f_{CLK}}{100}&amp;lt;/math&amp;gt;  &amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;math&amp;gt;H_{OBP} = -\frac{R3}{R1}&amp;lt;/math&amp;gt;&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;math&amp;gt;Q = \frac{f_0}{BW} = \frac{R3}{R2}&amp;lt;/math&amp;gt;&amp;lt;/center&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
From these equations you can determine the frequency of the incoming clock signal needed for a desired center frequency, and the values of resistors needed to set a desired center freqency gain and bandwidth (or alternately, Q).  If the chip is wired as two cascaded, Mode 1, second order, bandpass filters, as shown in below, and each filter is constructed with the same external resistors, the fourth order filter response is:&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&amp;lt;math&amp;gt;H_{BP}(s)=\left[\frac{H_{OBP}\cdot\frac{\omega_{0}}{Q}\cdot s}{s^2+\frac{s\omega_0}{Q}+\omega^2_0}\right]^2&amp;lt;/math&amp;gt;&amp;lt;/center&amp;gt;&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
[[Image:LMFwire.jpg|center]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
*[http://www.national.com/ds/LM/LMF100.pdf LMF100 Datasheet, National Semiconductor]&lt;/div&gt;</summary>
		<author><name>DanJohnson</name></author>
	</entry>
	<entry>
		<id>https://hades.mech.northwestern.edu//index.php?title=Filtering_with_the_LMF100&amp;diff=9183</id>
		<title>Filtering with the LMF100</title>
		<link rel="alternate" type="text/html" href="https://hades.mech.northwestern.edu//index.php?title=Filtering_with_the_LMF100&amp;diff=9183"/>
		<updated>2008-12-10T00:32:48Z</updated>

		<summary type="html">&lt;p&gt;DanJohnson: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Image:bpgain.jpg ]]The LMF100 is a chip that contains two independent switched capacitor filters.  With just a few added external resistors, it can be used to create 1st-4th order lowpass, highpass, notch, and bandpass filters.  Independently each filter is either first or second order (depending on the external resistor configuration), but they can be cascaded to create up to a fourth order filter.  This page will focus primarily on what the device&#039;s datasheet calls &amp;quot;Mode 1&amp;quot; (a bandpass filter), although the other modes described in the datasheet are quite similar.  The bandpass gain plot is shown to the right. &lt;br /&gt;
&lt;br /&gt;
In general, the second order bandpass response is given by:&lt;br /&gt;
&amp;lt;math&amp;gt;H_{BP}(s)=\frac{H_{OBP}\cdot\frac{\omega_{0}}{Q}\cdot s}{s^2+\frac{s\omega_0}{Q}+\omega^2_0}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
*[http://www.national.com/ds/LM/LMF100.pdf LMF100 Datasheet, National Semiconductor]&lt;/div&gt;</summary>
		<author><name>DanJohnson</name></author>
	</entry>
	<entry>
		<id>https://hades.mech.northwestern.edu//index.php?title=File:Bpgain.jpg&amp;diff=9180</id>
		<title>File:Bpgain.jpg</title>
		<link rel="alternate" type="text/html" href="https://hades.mech.northwestern.edu//index.php?title=File:Bpgain.jpg&amp;diff=9180"/>
		<updated>2008-12-10T00:30:21Z</updated>

		<summary type="html">&lt;p&gt;DanJohnson: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>DanJohnson</name></author>
	</entry>
	<entry>
		<id>https://hades.mech.northwestern.edu//index.php?title=Filtering_with_the_LMF100&amp;diff=9179</id>
		<title>Filtering with the LMF100</title>
		<link rel="alternate" type="text/html" href="https://hades.mech.northwestern.edu//index.php?title=Filtering_with_the_LMF100&amp;diff=9179"/>
		<updated>2008-12-10T00:28:55Z</updated>

		<summary type="html">&lt;p&gt;DanJohnson: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;The LMF100 is a chip that contains two independent switched capacitor filters.  With just a few added external resistors, it can be used to create 1st-4th order lowpass, highpass, notch, and bandpass filters.  Independently each filter is either first or second order (depending on the external resistor configuration), but they can be cascaded to create up to a fourth order filter.  This page will focus primarily on what the device&#039;s datasheet calls &amp;quot;Mode 1&amp;quot; (a bandpass filter), although the other modes described in the datasheet are quite similar.  The bandpass gain plot is shown to the right. [[Image:bpgain.jpg]]&lt;br /&gt;
&lt;br /&gt;
In general, the second order bandpass response is given by:&lt;br /&gt;
&amp;lt;math&amp;gt;H_{BP}(s)=\frac{H_{OBP}\cdot\frac{\omega_{0}}{Q}\cdot s}{s^2+\frac{s\omega_0}{Q}+\omega^2_0}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
*[http://www.national.com/ds/LM/LMF100.pdf LMF100 Datasheet, National Semiconductor]&lt;/div&gt;</summary>
		<author><name>DanJohnson</name></author>
	</entry>
	<entry>
		<id>https://hades.mech.northwestern.edu//index.php?title=Main_Page&amp;diff=9177</id>
		<title>Main Page</title>
		<link rel="alternate" type="text/html" href="https://hades.mech.northwestern.edu//index.php?title=Main_Page&amp;diff=9177"/>
		<updated>2008-12-10T00:19:51Z</updated>

		<summary type="html">&lt;p&gt;DanJohnson: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;The Northwestern University mechatronics design wiki provides reference material on the theory and applications of electronics, sensors, actuators, etc., for use in mechatronics-related research and projects.  Practical applications often refer to equipment and supplies available in the [http://mechatronics.mech.northwestern.edu/ Northwestern Mechatronics Design Lab].&lt;br /&gt;
&lt;br /&gt;
Important:  Please be sure to read the [http://mechatronics.mech.northwestern.edu/mech-rules.pdf Rules for Using the Mechatronics Design Lab].&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;h3&amp;gt;Design Competition 2008&amp;lt;/h3&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Wiki pages on sensors, actuators, programming, and microcontrollers: use pages below&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
* [http://www.mech.northwestern.edu/courses/433/Writeups/QuickStart/ Parts in the DC2008 quick start pack]&lt;br /&gt;
* [http://peshkin.mech.northwestern.edu/pic/info/piccintro_2008-01-24.pdf PIC C intro slides, as presented 2008/01/24 (pdf)]&lt;br /&gt;
* [http://peshkin.mech.northwestern.edu/pic/info/picinterfacing_2008-01-28.pdf PIC interfacing slides, as presented 2008/01/28 (pdf)]&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;h3&amp;gt;Sensors and actuators for DC&amp;lt;/h3&amp;gt;&lt;br /&gt;
* [[Using Solderless Breadboard|Solderless Breadboard &amp;amp; wiring that works]]&lt;br /&gt;
* [[Using LEDs &amp;amp; IREDs]]&lt;br /&gt;
* [[Using a laser]]&lt;br /&gt;
* [[Sensing optical tape|Infrared reflectivity]]&lt;br /&gt;
** Using phototransistors&lt;br /&gt;
** Sensing optical tape&lt;br /&gt;
* [[Comparators | Comparators : the analog digital interface]]&lt;br /&gt;
* [[Driving a DC Motor using PWM]]&lt;br /&gt;
* [http://www.robotroom.com/FaulhaberGearmotor.html Faulhaber MiniMotor SA gearmotor with encoder], as well as [[Actuators_Available_in_the_Mechatronics_Lab#Faulhaber_1524E006S_motor_with_141:1_gearhead_and_HES164A_magnetic_quadrature_encoder|the local wiki page]]&lt;br /&gt;
* [[Adding a magnetic encoder to a GM3 Gearmotor]]&lt;br /&gt;
** Using magnetic switches (Hall Effect)&lt;br /&gt;
* [[Driving using a single MOSFET | Driving a DC motor using a single MOSFET]]&lt;br /&gt;
* [[High-current devices|Driving high-current devices: several options]]&lt;br /&gt;
* [[Driving a Stepper Motor]]&lt;br /&gt;
* [[Driving an RC Servo]]&lt;br /&gt;
* [[Accelerometers]]&lt;br /&gt;
* [[Strain gauges]]&lt;br /&gt;
* [[Using the Basic Stamp Microcontroller|Basic Stamp Microcontroller]] &amp;lt;b&amp;gt;Not recommended for DC2008&amp;lt;/b&amp;gt;&lt;br /&gt;
* [http://www.mech.northwestern.edu/courses/433/Writeups/Battery_NiMH/ NiMH rechargable batteries and chargers]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;h3&amp;gt; [http://peshkin.mech.northwestern.edu/datasheets Prof. Peshkin&#039;s favorite datasheets]&amp;lt;/h3&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;h3&amp;gt;PIC 18F4520 prototyping board &amp;lt;/h3&amp;gt;&lt;br /&gt;
*[[4520 Board intro|Prototyping board intro]]&lt;br /&gt;
*[[4520 Board construction|Assembling the 18F4520 prototyping board, circuit, parts]]&lt;br /&gt;
*[[4520 Board use|Using the 18F4520 prototyping board]]&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;h3&amp;gt;Programming with CCS C &amp;lt;/h3&amp;gt;&lt;br /&gt;
*[[C language|The C language]]&lt;br /&gt;
*[[CCS C|CCS C, specifically for the 18F4520]]&lt;br /&gt;
*[[Embedded Programming Tips for CCS C]]&lt;br /&gt;
*[[CCS IDE|Using the CCS development environment]]&lt;br /&gt;
*[[Debugging C on a PIC]]&lt;br /&gt;
*[[More debugging tips]]&lt;br /&gt;
*[http://www.ccsinfo.com/forum/ CCS user forum]&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;h3&amp;gt;Interfacing and skeleton code for the PIC 18F4520&amp;lt;/h3&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;b&amp;gt;These topics have wiki pages &amp;lt;i&amp;gt;and&amp;lt;/i&amp;gt; sample code available&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;b&amp;gt;[http://peshkin.mech.northwestern.edu/pic/code Link to all sample code here.]&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
* [[Digital inputs &amp;amp; outputs]] (filename: DigitalIO)&lt;br /&gt;
* [[Analog Input]] (filename: AnalogInput)&lt;br /&gt;
** reading a trimpot&lt;br /&gt;
** reading a phototransistor&lt;br /&gt;
** amplified phototransistor, and IRED strobing&lt;br /&gt;
** using an instrumentation amp (example: for a strain gauge)&lt;br /&gt;
* [[Analog Output|Analog Output, and the I2C bus]] (filename: AnalogOutput)&lt;br /&gt;
* [[Waveform Generation with AD9833, and SPI]] (filename: AD9833)&lt;br /&gt;
*[[Pulse width modulation|Pulse width modulation (PWM) for driving motors or other high current devices]] (filename: MotorPWM)&lt;br /&gt;
** using H-bridges&lt;br /&gt;
* [[Interrupts]]&lt;br /&gt;
* [[Quadrature decoding in software]] (filename: QuadratureSoft)&lt;br /&gt;
* [[Quadrature decoding in hardware, or just counters]] (filename: QuadratureHard)&lt;br /&gt;
* [[Running RC servos]] (filename: RCservoSoft &amp;amp; RCservoHard)&lt;br /&gt;
* [[Watchdog timer]] (filename: Watchdog)&lt;br /&gt;
* [[PIC RS232|RS-232 serial communication between a PC and a PIC]] (filename: RS232)&lt;br /&gt;
* [[C Example: Serial LCD|Text output to a serial LCD display]]&lt;br /&gt;
* [[C Example: Parallel Interfacing with LCDs|Text output to a parallel LCD display]]&lt;br /&gt;
* [[Servo skeleton with fast &amp;amp; slow interrupts]]&lt;br /&gt;
* [[XBee radio communication between PICs]] (and between a PC and a PIC)&lt;br /&gt;
* [[I2C communication between PICs]]&lt;br /&gt;
* [[Serial communication with Matlab]]&lt;br /&gt;
* [[SPI communication between PICs]] &amp;lt;b&amp;gt; (Note:  this function has not been successfully tested)&amp;lt;/b&amp;gt;&lt;br /&gt;
* [[Microphones]]&lt;br /&gt;
* [[Ambient light color sensing]]&lt;br /&gt;
* [[Controlling a seven segment display]]&lt;br /&gt;
* [[Storing constant data in program memory]]&lt;br /&gt;
* [[PIC computation time benchmarks]]&lt;br /&gt;
* [[Stepper motor control with the PIC]]&lt;br /&gt;
* [[Global Positioning System]]&lt;br /&gt;
* [[IR communication between PICs]] &amp;lt;b&amp;gt; (Note:  this function has not been successfully tested) &amp;lt;/b&amp;gt;&lt;br /&gt;
* [[Interfacing to External EEPROM]]&lt;br /&gt;
* [[I2C Motor Controller]]&lt;br /&gt;
* [[Interfacing with a Photodiode Array]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;b&amp;gt;These topics have sample code available, but no wiki pages yet&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;b&amp;gt;[http://peshkin.mech.northwestern.edu/pic/code Link to all sample code here.]&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Counter0 - Counting pulses with Timer0]&lt;br /&gt;
* Counter1 - Counting pulses with Timer1]&lt;br /&gt;
* Interrupt0 - Periodic servo cycles using interrupt routines, 10mS &amp;amp; slower; Timer 0]&lt;br /&gt;
* Interrupt2 - Periodic servo cycles using interrupt routines; 10mS &amp;amp; faster; Timer 2]&lt;br /&gt;
* InterruptExternal - Interrupts generated by an external pulse]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;b&amp;gt;These topics need more development&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;b&amp;gt;[http://peshkin.mech.northwestern.edu/pic/code Link to all sample code here.]&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
* AnalogOutputParallel - Analog output using 8 digital lines]&lt;br /&gt;
* PIC-to-PIC communication &lt;br /&gt;
* Zigbee radio communication&lt;br /&gt;
* Modulated IR communication&lt;br /&gt;
* Strobing LEDs or IREDs for better range and immunity to background light&lt;br /&gt;
* I2C communication &lt;br /&gt;
* CAN bus&lt;br /&gt;
* Capturing data to Matlab&lt;br /&gt;
* Running stepper motors&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;h3&amp;gt;PIC Microcontrollers&amp;lt;/h3&amp;gt;&lt;br /&gt;
* [[PIC Microcontrollers with CCS Compiler]], for DC, 333, etc, using the CCS ICD-U40 device &amp;lt;b&amp;gt;[this section has been replaced by the material above]&amp;lt;/b&amp;gt;&lt;br /&gt;
* [[PIC Microcontrollers with C18 Compiler]], for e-puck, or using the Microchip ICD device or&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;h3&amp;gt;e-puck Mobile Robot&amp;lt;/h3&amp;gt;&lt;br /&gt;
* [[e-puck Mobile Robot]]&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;h3&amp;gt;[[Printing Circuit Boards]]&amp;lt;/h3&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;h3&amp;gt; Basic Electronics &amp;lt;/h3&amp;gt;&lt;br /&gt;
* [http://hades.mech.northwestern.edu/wiki/index.php/Category:Electronics Electronics]&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;h3&amp;gt;Analog and Digital chips&amp;lt;/h3&amp;gt;&lt;br /&gt;
* [[Comparators | Comparators: the analog to digital interface]]&lt;br /&gt;
* [[Filtering with the LMF100 | Filtering with the LMF100]]&lt;br /&gt;
* [http://en.wikipedia.org/wiki/Operational_amplifier_applications Opamps : building blocks of analog computation]&lt;br /&gt;
* [http://www.mech.northwestern.edu/courses/433/Writeups/InstAmp/instamp.htm Instrumentation amps, and NU circuit board for them]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=all/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;h3&amp;gt;[[:Category:Sensors|Sensors]]&amp;lt;/h3&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* [[Potentiometers|Angle, Linear Position: Potentiometers]]&lt;br /&gt;
* [[Optointerrupter|Beam Breaker: Optointerrupter]]&lt;br /&gt;
* [[Optoreflector|Proximity: Optoreflector]]&lt;br /&gt;
* [[Sensing optical tape|Infrared reflectivity : Sensing optical tape]]&lt;br /&gt;
* [[Reed Switch|Proximity: Reed Switch]]&lt;br /&gt;
* [[Hall Effect Sensor|Proximity, Angle: Hall Effect Sensor]]&lt;br /&gt;
* [[Rotary Encoder|Angle: Rotary Encoder]]&lt;br /&gt;
* Angular Velocity: Tachometer&lt;br /&gt;
* [[Photodiodes and Phototransistors|Light: Photodiodes and Phototransistors]]&lt;br /&gt;
* [[Photocell|Ambient Light: Photocell]]&lt;br /&gt;
* [[Thermistor|Temperature: Thermistor]]&lt;br /&gt;
* Temperature: Thermotransistor IC&lt;br /&gt;
* Audio: [[Microphones]]&lt;br /&gt;
* [[Accelerometers|Tilt, Acceleration: Accelerometers]]&lt;br /&gt;
* [[Strain Gauge|Force: Strain Gauge]]&lt;br /&gt;
* Current: Current Sense Resistor&lt;br /&gt;
* [[Limit Switch|Contact: Microswitch (Limit Switch)]]&lt;br /&gt;
* [[Ambient light color sensing]]&lt;br /&gt;
* [[Global Positioning System]]&lt;br /&gt;
* [[Optics]]&lt;br /&gt;
* [[Optical Locating]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=all/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;h3&amp;gt;[[:Category:Actuators|Actuators]]&amp;lt;/h3&amp;gt;&lt;br /&gt;
[[image:All-actuators-captions-small.jpg|thumb|300px|[[Actuators Available in the Mechatronics Lab|Available Actuators]]|right]]&lt;br /&gt;
&lt;br /&gt;
* [[Brushed DC Motor Theory|Brushed DC Motors]]&lt;br /&gt;
** [[Choosing a Motor and Gearing Combination|Choosing a Motor and Gearing Combination]]&lt;br /&gt;
** [[Linear Amplifier Motor Driver|Driving Using a Linear Amplifier]]&lt;br /&gt;
** [[Driving using a single MOSFET|Driving using a single MOSFET]]&lt;br /&gt;
** [[Pulse Width Modulation|Driving Using Pulse Width Modulation]]&lt;br /&gt;
** [[PIC PWM Motor Driver]]&lt;br /&gt;
** [[Gear Motor]]&lt;br /&gt;
*** [http://www.mech.northwestern.edu/courses/433/Writeups/AddEncoderHobbyEngGearMotor Adding a rotation encoder to a gearmotor]&lt;br /&gt;
* [[Brushless DC Motors]]&lt;br /&gt;
** [[Driving Brushless DC Motors]]&lt;br /&gt;
* [[Stepper Motor Theory|Stepper Motors]]&lt;br /&gt;
** [[Stepper Motor Circuits|Driving Stepper Motors]]&lt;br /&gt;
** [[Unipolar Stepper Motor Driver Circuit]]&lt;br /&gt;
** [[Bipolar Stepper Motor Driver Circuit]]&lt;br /&gt;
* [[RC Servo Theory|RC Servos]]&lt;br /&gt;
** [[555 Servo Circuit|Driving Your Servo Using a 555 Timer]]&lt;br /&gt;
* [[Solenoid Theory|Solenoids]]&lt;br /&gt;
** Practice: Driving Your Solenoid&lt;br /&gt;
* AC Motors&lt;br /&gt;
** [[Using the Yaskawa Motors]]&lt;br /&gt;
* [[Actuators Available in the Mechatronics Lab]]&lt;br /&gt;
&amp;lt;br clear=all/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;h3&amp;gt;Mechanical Design&amp;lt;/h3&amp;gt;&lt;br /&gt;
*Mechanics of Materials&lt;br /&gt;
**Beam Mechanics&lt;br /&gt;
**[[Mohr&#039;s Circle]]&lt;br /&gt;
*Failure Theories&lt;br /&gt;
**Static Loading&lt;br /&gt;
**Variable Loading and Fatigue&lt;br /&gt;
*Fastening&lt;br /&gt;
**Nuts and Bolts&lt;br /&gt;
**Keys and Keyways&lt;br /&gt;
**Press-fits&lt;br /&gt;
**Set Screws&lt;br /&gt;
*Support&lt;br /&gt;
**Housings&lt;br /&gt;
**Shafts&lt;br /&gt;
**[[Bearings]]&lt;br /&gt;
*Transmission&lt;br /&gt;
**Rigid: [[Gears]]&lt;br /&gt;
**Flexible: Belts, Chains&lt;br /&gt;
**Motion Connection/Separation: Clutches, Brakes, Couplings&lt;br /&gt;
*Linkages&lt;br /&gt;
**Serial Chains&lt;br /&gt;
**Parallel and Closed-Loop Chains&lt;br /&gt;
*Other: springs/dampers, cams, etc.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=all/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;h3&amp;gt;The PC/104 Stack&amp;lt;/h3&amp;gt;&lt;br /&gt;
[[Image:Img0174.jpg|thumb|300px|[[PC104 Overview|The PC104 Stack]]|right]]&lt;br /&gt;
* [[PC104 Overview|Overview]]&lt;br /&gt;
* [[The PC/104 Lab Kit]]&lt;br /&gt;
* Hardware:&lt;br /&gt;
** [[Advantech CPU Card]]&lt;br /&gt;
** [[Sensoray 526 Data Aquisition Card]]&lt;br /&gt;
&lt;br /&gt;
** [http://www.mech.northwestern.edu/courses/433/Writeups/PC104BoB/stack.htm#power[Power Components]]&lt;br /&gt;
** [http://www.mech.northwestern.edu/courses/433/Writeups/PC104BoB/stack.htm#electrical[I/O Electronics: Analog I/O, Digital I/O, Encoder Connections]]&lt;br /&gt;
* Advanced: Creating a Working Stack from Parts&lt;br /&gt;
** [http://www.mech.northwestern.edu/courses/433/Writeups/PC104BoB/stack.htm [Building the Breakout Board]]&lt;br /&gt;
** [http://www.mech.northwestern.edu/courses/433/Writeups/PC104BoB/stack.htm#ribboncables[Breakout Board Ribbon Cables]]&lt;br /&gt;
** [http://www.mech.northwestern.edu/courses/433/Writeups/PC104BoB/stack.htm#mechanical[Assembling the PC104 Stack]]&lt;br /&gt;
** &#039;&#039;&#039;[[Creating an xPC Flash Boot Disk]]&#039;&#039;&#039; &amp;lt;- when new version of MATLAB&lt;br /&gt;
* Custom Boards&lt;br /&gt;
** Dual PWM Motor Controller&lt;br /&gt;
** Dual Linear Amplifier Motor Controller&lt;br /&gt;
&amp;lt;br clear=all/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;h3&amp;gt;xPC Target Real-Time Operating System&amp;lt;/h3&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* [[xPC Overview|Overview of Real-Time Programming with Simulink and xPC Target]]&lt;br /&gt;
* [[Configuring xPC Target PC|Configuring xPC Host/Target PC]]&lt;br /&gt;
* [[Creating a Simple xPC Program|&#039;&#039;&#039;Quickstart&#039;&#039;&#039;:Creating a simple xPC Program]]&lt;br /&gt;
* [[Common xPC Blocks|Commonly Used Blocks]]&lt;br /&gt;
* [[Using the Host Scope]]&lt;br /&gt;
*Advanced&lt;br /&gt;
** Model Properties&lt;br /&gt;
** [[XPC M-file Communication|M-file communication]]&lt;br /&gt;
** Using outside of the lab&lt;br /&gt;
** [[media:standalone.pdf|Standalone Mode]]&lt;br /&gt;
** Stateflow&lt;br /&gt;
* Code Examples&lt;br /&gt;
** [[Controlling a DC Motor with an Encoder]]&lt;br /&gt;
** Something With State Machine&lt;br /&gt;
** [[Using RS-232 and Printing to LCD]]&lt;br /&gt;
**[[UDP Communications between Target and Host PC]]&lt;br /&gt;
** M-functions and S-functions&lt;br /&gt;
** [[xPC Code From Student Projects]]&lt;br /&gt;
&amp;lt;br clear=all/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;h3&amp;gt;QNX Real-Time Operating System&amp;lt;/h3&amp;gt;&lt;br /&gt;
*[[media:qnxtemplate.zip|QNX Control Program with Interrupts]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=all/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;h3&amp;gt;Lab Supplies and Data Sheets&amp;lt;/h3&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* [http://spreadsheets.google.com/pub?key=pa_bNAhFF-OvvxpSje1KDYg&amp;amp;output=html&amp;amp;gid=0&amp;amp;single=true Generally stocked lab inventory ]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;h3&amp;gt;[[Vendors]]&amp;lt;/h3&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;h3&amp;gt;Other Software&amp;lt;/h3&amp;gt;&lt;br /&gt;
*[[List of Useful Software for Download]]&lt;br /&gt;
*Circuit Schematics and PCB Layout&lt;br /&gt;
*LaTex Document Preparation&lt;br /&gt;
** [http://meta.wikimedia.org/wiki/Help:Formula Mathematical Formulae]&lt;br /&gt;
** Document Formatting&lt;br /&gt;
** [[LaTeX Software Setup|Software Setup]]&lt;br /&gt;
** IEEE Styles&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;h3&amp;gt;[[Other Lab Equipment]]&amp;lt;/h3&amp;gt;&lt;br /&gt;
* Prototyping Tools&lt;br /&gt;
** [[Tektronix TDS220 Oscilloscope]]&lt;br /&gt;
** [[Tektronix CFG253 Function Generator]]&lt;br /&gt;
** [[media:Mastech_power_supply_manual.pdf|Mastech Power Supply]]&lt;br /&gt;
** Fluke III Multimeter&lt;br /&gt;
** Benchtop Multimeter&lt;br /&gt;
** Powered Breadboard&lt;br /&gt;
** Soldering Iron&lt;br /&gt;
* [http://ediacaran.mech.northwestern.edu/neuromech/index.php/Lab_Equipment High Performance Neuromechatronics Benches]&lt;br /&gt;
* The Sensoray 626 DAQ Card&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;h3&amp;gt;Course Material&amp;lt;/h3&amp;gt;&lt;br /&gt;
* [[ME 224 Experimental Engineering]]&lt;br /&gt;
* [http://lims.mech.northwestern.edu/~lynch/courses/ME333/2008/index.html ME 333 Introduction to Mechatronics]&lt;br /&gt;
** [[Lab 5]]&lt;br /&gt;
** [[Suggested final projects]]&lt;br /&gt;
** [[ME 333 final projects]]&lt;br /&gt;
&amp;lt;!--&lt;br /&gt;
* [http://www.mech.northwestern.edu/hartmann/ME333_CourseInformation.html ME 333 Mechatronics]&lt;br /&gt;
--&amp;gt;&lt;br /&gt;
* [http://www.mech.northwestern.edu/courses/433/ ME 433 Advanced Mechatronics] &lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;h3&amp;gt;Miscellaneous&amp;lt;/h3&amp;gt;&lt;br /&gt;
* [[Swarm Robot Project]]&lt;br /&gt;
** [[Swarm Robot Project Links]]&lt;br /&gt;
&lt;br /&gt;
* [[Indoor Localization System]]&lt;br /&gt;
* [[Robot Helicopter Project]]&lt;br /&gt;
* [[E-Puck Color Sensing Project]]&lt;br /&gt;
* [[Guitar Tunning Project]]&lt;/div&gt;</summary>
		<author><name>DanJohnson</name></author>
	</entry>
	<entry>
		<id>https://hades.mech.northwestern.edu//index.php?title=Waveform_Generation_with_AD9833,_and_SPI&amp;diff=9174</id>
		<title>Waveform Generation with AD9833, and SPI</title>
		<link rel="alternate" type="text/html" href="https://hades.mech.northwestern.edu//index.php?title=Waveform_Generation_with_AD9833,_and_SPI&amp;diff=9174"/>
		<updated>2008-12-09T17:49:19Z</updated>

		<summary type="html">&lt;p&gt;DanJohnson: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Image:AD9833Connsmall.jpg|right]]The AD9833 is a programmable waveform generator capable of creating sine, triangular, or square wave outputs in a frequency range of 0 to 12.5 MHz.  It has two 28-bit frequency registers and two 12-bit phase registers that can be written to and output from the VOUT pin.  This chip is perfectly suited for use with the PIC 18F4520, as it uses SPI communication for its setup and control.  A connection diagram for the AD9833 is given to the right.  The MCLK pin is tied directly to the oscillator of the PIC, and the three SPI communication lines are connected to three I/O pins on the PIC (in this case pins A1, A2, and A3).&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
In order to establish communication between the PIC and the AD9833, we need to set up the SPI for the pins we wish to use.  The following code should be included in your program.&lt;br /&gt;
&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 #use spi(DO = PIN_A3, CLK = PIN_A2, ENABLE = PIN_A1, BITS = 16, MASTER, ENABLE_ACTIVE = 0, MSB_FIRST, IDLE = 1)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
The first three arguments determine which three pins we will be using: DO is the &amp;quot;SDATA&amp;quot; pin of the AD9833, CLK is the &amp;quot;SCLK&amp;quot; pin, and ENABLE is the &amp;quot;FSYNC&amp;quot; pin.  The next argument states that the max number of bits in one transfer is 16.  The next argument specifies that the PIC is the master and the AD9833 is the slave.  The AD9833&#039;s FSYNC pin is active low, and it accepts the most significant bit (MSB) of each transfer first.  The SCLK pin is also specified to be kept high when not in use.  After this initial setup, the SPI communication is quite straightforward.  We simply use the function &#039;&#039;&#039;spi_xfer()&#039;&#039;&#039; whenever we want to send information via SPI to the AD9833.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
Now that we can talk to the waveform generator, we need to know what it needs to be told to produce what we want.  Each of the 16 bits transferred has a meaning, and these meanings are described in the Table below.  Note that the if a frequency register is being written to (first two bits = 01 or 10), the last 14 bits are the value of the write, and do not have the same meaning as specified in the table.  Similarly, if a phase register is being written to (first two bits = 11), the last 12 bits are the value of the write.  Only if the control register is being written to (first two bits = 00) are most of the meanings specified in the table applicable.&lt;br /&gt;
&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{| border=&amp;quot;1&amp;quot; cellspacing=&amp;quot;0&amp;quot; cellpadding=&amp;quot;3&amp;quot; &lt;br /&gt;
|-&lt;br /&gt;
!Bit!! Significance&lt;br /&gt;
|-&lt;br /&gt;
|D15,D14(MSB) || 10 = FREQ1 write, 01 = FREQ0 write, 11 = PHASE write, 00 = control write&lt;br /&gt;
|-&lt;br /&gt;
|D13 ||If D15,D14 = 00, 0 = individual LSB and MSB FREQ write, 1 = both LSB and MSB FREQ writes consecutively&lt;br /&gt;
|-&lt;br /&gt;
| ||If D15,D14 = 11, 0 = PHASE0 write, 1 = PHASE1 write&lt;br /&gt;
|-&lt;br /&gt;
|D12||0 = writing LSB independently, 1 = writing MSB independently&lt;br /&gt;
|-&lt;br /&gt;
|D11||0 = output FREQ0, 1 = output FREQ1&lt;br /&gt;
|-&lt;br /&gt;
|D10||0 = output PHASE0, 1 = output PHASE1&lt;br /&gt;
|-&lt;br /&gt;
|D9||Reserved.  Must be 0.&lt;br /&gt;
|-&lt;br /&gt;
|D8||0 = RESET disabled, 1 = RESET enabled&lt;br /&gt;
|-&lt;br /&gt;
|D7||0 = internal clock is enabled, 1 = internal clock is disabled&lt;br /&gt;
|-&lt;br /&gt;
|D6||0 = onboard DAC is active for sine and triangle wave output, 1 = put DAC to sleep for square wave output&lt;br /&gt;
|-&lt;br /&gt;
|D5||0 = output depends on D1, 1 = output is a square wave&lt;br /&gt;
|-&lt;br /&gt;
|D4||Reserved.  Must be 0.&lt;br /&gt;
|-&lt;br /&gt;
|D3||0 = square wave of half frequency output, 1 = square wave output&lt;br /&gt;
|-&lt;br /&gt;
|D2||Reserved.  Must be 0.&lt;br /&gt;
|-&lt;br /&gt;
|D1||If D5 = 1, D1 = 0. Otherwise 0 = sine output, 1 = triangle output&lt;br /&gt;
|-&lt;br /&gt;
|D0||Reserved.  Must be 0.&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Obviously this is a lot of information to pass to the waveform generator, but this setup can be performed with only a few SPI transfers.  This is nearly all you need to know to set the AD9833, but there are two more critical relationships:&lt;br /&gt;
&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;math&amp;gt;f_{out}=\frac{f_{MCLK}}{2^{28}}\times FREQREG&amp;lt;/math&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;math&amp;gt;\Phi_{shift} = \frac{2\pi}{4096}\times PHASEREG&amp;lt;/math&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
In other words, the output frequency and phase shift are not the values of the frequency or phase registers.  They are related by the above equations, so the values you send to the registers need to be modified from the actual frequency and phase shift.  For instance, if we sent 200 to the FREQ register and 100 to the PHASE register, and we were using a 20 MHz MCLK, we would output a 14.9 Hz wave with a phase shift of 0.15 radians.&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
In order to setup or update the AD9833 you first need to reset it, then transfer the frequency and phase information, then &amp;quot;unreset&amp;quot; it.  For example, if we wanted to output a 20 kHz square wave with no phase shift, we would send the following:&lt;br /&gt;
&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
 spi_xfer(0b0010000101101000);&lt;br /&gt;
&lt;br /&gt;
This resets the AD9833 (D8), tells it that we will be using the next two transfers to input both LSB and MSB (D13) of the FREQ0 register (D11), the internal clock is enabled (D7), the DAC has been put to sleep (D6), the output is to be a square wave (D5), and the square wave frequency is not to be divided by two (D3).&lt;br /&gt;
&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
 spi_xfer(0b0101100010010011);&lt;br /&gt;
 spi_xfer(0b0100000000010000);&lt;br /&gt;
&lt;br /&gt;
These transfers are writing to the value of the FREQ0 register (D15-D14), with the last 14 bits of each transfer representing first the LSB, then the MSB of the value.  This writes a value of 0000000001000001100010010011 (268435 decimal) to the FREQ0 register.  If we use the formula above, we see this corresponds to an output frequency of 20 kHz.&lt;br /&gt;
&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
 spi_xfer(0b1100000000000000);&lt;br /&gt;
&lt;br /&gt;
This transfer is writing to the PHASE0 register (D15,D14,D13) and is writing a twelve bit value of zero (D11-D0).&lt;br /&gt;
&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
 spi_xfer(0b0000000001101000);&lt;br /&gt;
&lt;br /&gt;
This transfer &amp;quot;unresets&amp;quot; the AD9833 (D8).&lt;br /&gt;
&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
With a small variation in the values of the five transfers, all of the frequency and phase registers can be written to and output from the VOUT pin of the AD9833.&lt;/div&gt;</summary>
		<author><name>DanJohnson</name></author>
	</entry>
	<entry>
		<id>https://hades.mech.northwestern.edu//index.php?title=Waveform_Generation_with_AD9833,_and_SPI&amp;diff=9173</id>
		<title>Waveform Generation with AD9833, and SPI</title>
		<link rel="alternate" type="text/html" href="https://hades.mech.northwestern.edu//index.php?title=Waveform_Generation_with_AD9833,_and_SPI&amp;diff=9173"/>
		<updated>2008-12-09T17:42:51Z</updated>

		<summary type="html">&lt;p&gt;DanJohnson: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Image:AD9833Connsmall.jpg|right]]The AD9833 is a programmable waveform generator capable of creating sine, triangular, or square wave outputs in a frequency range of 0 to 12.5 MHz.  It has two 28-bit frequency registers and two 12-bit phase registers that can be written to and output from the VOUT pin.  This chip is perfectly suited for use with the PIC 18F4520, as it uses SPI communication for its setup and control.  A connection diagram for the AD9833 is given to the right.  The MCLK pin is tied directly to the oscillator of the PIC, and the three SPI communication lines are connected to three I/O pins on the PIC (in this case pins A1, A2, and A3).&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
In order to establish communication between the PIC and the AD9833, we need to set up the SPI for the pins we wish to use.  The following code should be included in your program.&lt;br /&gt;
&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 #use spi(DO = PIN_A3, CLK = PIN_A2, ENABLE = PIN_A1, BITS = 16, MASTER, ENABLE_ACTIVE = 0, MSB_FIRST, IDLE = 1)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
The first three arguments determine which three pins we will be using: DO is the &amp;quot;SDATA&amp;quot; pin of the AD9833, CLK is the &amp;quot;SCLK&amp;quot; pin, and ENABLE is the &amp;quot;FSYNC&amp;quot; pin.  The next argument states that the max number of bits in one transfer is 16.  The next argument specifies that the PIC is the master and the AD9833 is the slave.  The AD9833&#039;s FSYNC pin is active low, and it accepts the most significant bit (MSB) of each transfer first.  The SCLK pin is also specified to be kept high when not in use.  After this initial setup, the SPI communication is quite straightforward.  We simply use the function &#039;&#039;&#039;spi_xfer()&#039;&#039;&#039; whenever we want to send information via SPI to the AD9833.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
Now that we can talk to the waveform generator, we need to know what it needs to be told to produce what we want.  Each of the 16 bits transferred has a meaning, and these meanings are described in the Table below.  Note that the if a frequency register is being written to (first two bits = 01 or 10), the last 14 bits are the value of the write, and do not have the same meaning as specified in the table.  Similarly, if a phase register is being written to (first two bits = 11), the last 12 bits are the value of the write.  Only if the control register is being written to (first two bits = 00) are most of the meanings specified in the table applicable.&lt;br /&gt;
&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{| border=&amp;quot;1&amp;quot; cellspacing=&amp;quot;0&amp;quot; cellpadding=&amp;quot;3&amp;quot; &lt;br /&gt;
|-&lt;br /&gt;
!Bit!! Significance&lt;br /&gt;
|-&lt;br /&gt;
|D15,D14(MSB) || 10 = FREQ1 write, 01 = FREQ0 write, 11 = PHASE write, 00 = control write&lt;br /&gt;
|-&lt;br /&gt;
|D13 ||If D15,D14 = 00, 0 = individual LSB and MSB FREQ write, 1 = both LSB and MSB FREQ writes consecutively&lt;br /&gt;
|-&lt;br /&gt;
| ||If D15,D14 = 11, 0 = PHASE0 write, 1 = PHASE1 write&lt;br /&gt;
|-&lt;br /&gt;
|D12||0 = writing LSB independently, 1 = writing MSB independently&lt;br /&gt;
|-&lt;br /&gt;
|D11||0 = output FREQ0, 1 = output FREQ1&lt;br /&gt;
|-&lt;br /&gt;
|D10||0 = output PHASE0, 1 = output PHASE1&lt;br /&gt;
|-&lt;br /&gt;
|D9||Reserved.  Must be 0.&lt;br /&gt;
|-&lt;br /&gt;
|D8||0 = RESET disabled, 1 = RESET enabled&lt;br /&gt;
|-&lt;br /&gt;
|D7||0 = internal clock is enabled, 1 = internal clock is disabled&lt;br /&gt;
|-&lt;br /&gt;
|D6||0 = onboard DAC is active for sine and triangle wave output, 1 = put DAC to sleep for square wave output&lt;br /&gt;
|-&lt;br /&gt;
|D5||0 = output depends on D1, 1 = output is a square wave&lt;br /&gt;
|-&lt;br /&gt;
|D4||Reserved.  Must be 0.&lt;br /&gt;
|-&lt;br /&gt;
|D3||0 = square wave of half frequency output, 1 = square wave output&lt;br /&gt;
|-&lt;br /&gt;
|D2||Reserved.  Must be 0.&lt;br /&gt;
|-&lt;br /&gt;
|D1||If D5 = 1, D1 = 0. Otherwise 0 = sine output, 1 = triangle output&lt;br /&gt;
|-&lt;br /&gt;
|D0||Reserved.  Must be 0.&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Obviously this is a lot of information to pass to the waveform generator, but this setup can be performed with only a few SPI transfers.  This is nearly all you need to know to set the AD9833, but there are two more critical relationships:&lt;br /&gt;
&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;math&amp;gt;f_{out}=\frac{f_{MCLK}}{2^{28}}\times FREQREG&amp;lt;/math&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;math&amp;gt;\Phi_{shift} = \frac{2\pi}{4096}\times PHASEREG&amp;lt;/math&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
In other words, the output frequency and phase shift are not the values of the frequency or phase registers.  They are related by the above equations, so the values you send to the registers need to be modified from the actual frequency and phase shift.  For instance, if we sent 200 to the FREQ register and 100 to the PHASE register, and we were using a 20 MHz MCLK, we would output a 14.9 Hz wave with a phase shift of 0.15 radians.&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
In order to setup or update the AD9833 you first need to reset it, then transfer the frequency and phase information, then &amp;quot;unreset&amp;quot; it.  For example, if we wanted to output a 20 kHz square wave with no phase shift, we would send the following:&lt;br /&gt;
&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
 spi_xfer(0b0010000101101000);&lt;br /&gt;
&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;/div&gt;</summary>
		<author><name>DanJohnson</name></author>
	</entry>
	<entry>
		<id>https://hades.mech.northwestern.edu//index.php?title=Waveform_Generation_with_AD9833,_and_SPI&amp;diff=9172</id>
		<title>Waveform Generation with AD9833, and SPI</title>
		<link rel="alternate" type="text/html" href="https://hades.mech.northwestern.edu//index.php?title=Waveform_Generation_with_AD9833,_and_SPI&amp;diff=9172"/>
		<updated>2008-12-09T17:32:56Z</updated>

		<summary type="html">&lt;p&gt;DanJohnson: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Image:AD9833Connsmall.jpg|right]]The AD9833 is a programmable waveform generator capable of creating sine, triangular, or square wave outputs in a frequency range of 0 to 12.5 MHz.  It has two 28-bit frequency registers and two 12-bit phase registers that can be written to and output from the VOUT pin.  This chip is perfectly suited for use with the PIC 18F4520, as it uses SPI communication for its setup and control.  A connection diagram for the AD9833 is given to the right.  The MCLK pin is tied directly to the oscillator of the PIC, and the three SPI communication lines are connected to three I/O pins on the PIC (in this case pins A1, A2, and A3).&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
In order to establish communication between the PIC and the AD9833, we need to set up the SPI for the pins we wish to use.  The following code should be included in your program.&lt;br /&gt;
&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 #use spi(DO = PIN_A3, CLK = PIN_A2, ENABLE = PIN_A1, BITS = 16, MASTER, ENABLE_ACTIVE = 0, MSB_FIRST, IDLE = 1)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
The first three arguments determine which three pins we will be using: DO is the &amp;quot;SDATA&amp;quot; pin of the AD9833, CLK is the &amp;quot;SCLK&amp;quot; pin, and ENABLE is the &amp;quot;FSYNC&amp;quot; pin.  The next argument states that the max number of bits in one transfer is 16.  The next argument specifies that the PIC is the master and the AD9833 is the slave.  The AD9833&#039;s FSYNC pin is active low, and it accepts the most significant bit (MSB) of each transfer first.  The SCLK pin is also specified to be kept high when not in use.  After this initial setup, the SPI communication is quite straightforward.  We simply use the function &#039;&#039;&#039;spi_xfer()&#039;&#039;&#039; whenever we want to send information via SPI to the AD9833.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
Now that we can talk to the waveform generator, we need to know what it needs to be told to produce what we want.  Each of the 16 bits transferred has a meaning, and these meanings are described in the Table below.  Note that the if a frequency register is being written to (first two bits = 01 or 10), the last 14 bits are the value of the write, and do not have the same meaning as specified in the table.  Similarly, if a phase register is being written to (first two bits = 11), the last 12 bits are the value of the write.  Only if the control register is being written to (first two bits = 00) are most of the meanings specified in the table applicable.&lt;br /&gt;
&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{| border=&amp;quot;1&amp;quot; cellspacing=&amp;quot;0&amp;quot; cellpadding=&amp;quot;3&amp;quot; align=&amp;quot;left&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
!Bit!! Significance&lt;br /&gt;
|-&lt;br /&gt;
|D15,D14(MSB) || 10 = FREQ1 write, 01 = FREQ0 write, 11 = PHASE write, 00 = control write&lt;br /&gt;
|-&lt;br /&gt;
|D13 ||If D15,D14 = 00, 0 = individual LSB and MSB FREQ write, 1 = both LSB and MSB FREQ writes consecutively&lt;br /&gt;
|-&lt;br /&gt;
| ||If D15,D14 = 11, 0 = PHASE0 write, 1 = PHASE1 write&lt;br /&gt;
|-&lt;br /&gt;
|D12||0 = writing LSB independently, 1 = writing MSB independently&lt;br /&gt;
|-&lt;br /&gt;
|D11||0 = output FREQ0, 1 = output FREQ1&lt;br /&gt;
|-&lt;br /&gt;
|D10||0 = output PHASE0, 1 = output PHASE1&lt;br /&gt;
|-&lt;br /&gt;
|D9||Reserved.  Must be 0.&lt;br /&gt;
|-&lt;br /&gt;
|D8||0 = RESET disabled, 1 = RESET enabled&lt;br /&gt;
|-&lt;br /&gt;
|D7||0 = internal clock is enabled, 1 = internal clock is disabled&lt;br /&gt;
|-&lt;br /&gt;
|D6||0 = onboard DAC is active for sine and triangle wave output, 1 = put DAC to sleep for square wave output&lt;br /&gt;
|-&lt;br /&gt;
|D5||0 = output depends on D1, 1 = output is a square wave&lt;br /&gt;
|-&lt;br /&gt;
|D4||Reserved.  Must be 0.&lt;br /&gt;
|-&lt;br /&gt;
|D3||0 = square wave of half frequency output, 1 = square wave output&lt;br /&gt;
|-&lt;br /&gt;
|D2||Reserved.  Must be 0.&lt;br /&gt;
|-&lt;br /&gt;
|D1||If D5 = 1, D1 = 0. Otherwise 0 = sine output, 1 = triangle output&lt;br /&gt;
|-&lt;br /&gt;
|D0||Reserved.  Must be 0.&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;/div&gt;</summary>
		<author><name>DanJohnson</name></author>
	</entry>
	<entry>
		<id>https://hades.mech.northwestern.edu//index.php?title=Waveform_Generation_with_AD9833,_and_SPI&amp;diff=9171</id>
		<title>Waveform Generation with AD9833, and SPI</title>
		<link rel="alternate" type="text/html" href="https://hades.mech.northwestern.edu//index.php?title=Waveform_Generation_with_AD9833,_and_SPI&amp;diff=9171"/>
		<updated>2008-12-09T17:02:40Z</updated>

		<summary type="html">&lt;p&gt;DanJohnson: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Image:AD9833Connsmall.jpg|right]]The AD9833 is a programmable waveform generator capable of creating sine, triangular, or square wave outputs in a frequency range of 0 to 12.5 MHz.  It has two 28-bit frequency registers and two 12-bit phase registers that can be written to and output from the VOUT pin.  This chip is perfectly suited for use with the PIC 18F4520, as it uses SPI communication for its setup and control.  A connection diagram for the AD9833 is given to the right.  The MCLK pin is tied directly to the oscillator of the PIC, and the three SPI communication lines are connected to three I/O pins on the PIC (in this case pins A1, A2, and A3).&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
In order to establish communication between the PIC and the AD9833, we need to set up the SPI for the pins we wish to use.  The following code should be included in your program.&lt;br /&gt;
&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 #use spi(DO = PIN_A3, CLK = PIN_A2, ENABLE = PIN_A1, BITS = 16, MASTER, ENABLE_ACTIVE = 0, MSB_FIRST, IDLE = 1)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
The first three arguments determine which three pins we will be using: DO is the &amp;quot;SDATA&amp;quot; pin of the AD9833, CLK is the &amp;quot;SCLK&amp;quot; pin, and ENABLE is the &amp;quot;FSYNC&amp;quot; pin.  The next argument states that the max number of bits in one transfer is 16.  The next argument specifies that the PIC is the master and the AD9833 is the slave.  The AD9833&#039;s FSYNC pin is active low, and it accepts the most significant bit (MSB) of each transfer first.  The SCLK pin is also specified to be kept high when not in use.  After this initial setup, the SPI communication is quite straightforward.  We simply use the function &#039;&#039;&#039;spi_xfer()&#039;&#039;&#039; whenever we want to send information via SPI to the AD9833.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
Now that we can talk to the waveform generator, we need to know what it needs to be told to produce what we want.  Each of the 16 bits transferred has a meaning, and these meanings are described in the Table below.&lt;br /&gt;
&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{| border=&amp;quot;1&amp;quot; cellspacing=&amp;quot;2&amp;quot; cellpadding=&amp;quot;3&amp;quot; align=&amp;quot;center&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
!Bit!! Significance&lt;br /&gt;
|-&lt;br /&gt;
|D15,D14(MSB) || 10 = FREQ1 write, 01 = FREQ0 write, 11 = PHASE write, 00 = control write&lt;br /&gt;
|-&lt;br /&gt;
|D13 ||If D15,D14 = 10 or 01, 0 = individual LSB and MSB write, 1 = both LSB and MSB writes consecutively&lt;br /&gt;
|-&lt;br /&gt;
| ||If D15,D14 = 11&lt;br /&gt;
|-&lt;br /&gt;
|.esym||IDE file containing comment information and definitions from header file&lt;br /&gt;
|-&lt;br /&gt;
|.hex||Programmable output file compatible with all programmers&lt;br /&gt;
|-&lt;br /&gt;
|.lst||Line by line listing of source code along with generated assembly code&lt;br /&gt;
|-&lt;br /&gt;
|.pjt||Main project file&lt;br /&gt;
|-&lt;br /&gt;
|.sta||Memory usage summary (statistics)&lt;br /&gt;
|-&lt;br /&gt;
|.sym||List of symbols used and their corresponding registers&lt;br /&gt;
|-&lt;br /&gt;
|.tre||Shows every function used in the source code, and the memory used by each&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;/div&gt;</summary>
		<author><name>DanJohnson</name></author>
	</entry>
	<entry>
		<id>https://hades.mech.northwestern.edu//index.php?title=Waveform_Generation_with_AD9833,_and_SPI&amp;diff=9170</id>
		<title>Waveform Generation with AD9833, and SPI</title>
		<link rel="alternate" type="text/html" href="https://hades.mech.northwestern.edu//index.php?title=Waveform_Generation_with_AD9833,_and_SPI&amp;diff=9170"/>
		<updated>2008-12-09T16:42:13Z</updated>

		<summary type="html">&lt;p&gt;DanJohnson: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Image:AD9833Connsmall.jpg|right]]The AD9833 is a programmable waveform generator capable of creating sine, triangular, or square wave outputs in a frequency range of 0 to 12.5 MHz.  It has two frequency registers and two phase registers that can be written to and output from the VOUT pin.  This chip is perfectly suited for use with the PIC 18F4520, as it uses SPI communication for its setup and control.  A connection diagram for the AD9833 is given to the right.  The MCLK pin is tied directly to the oscillator of the PIC, and the three SPI communication lines are connected to three I/O pins on the PIC (in this case pins A1, A2, and A3).&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
In order to establish communication between the PIC and the AD9833, we need to set up the SPI for the pins we wish to use.  The following code should be included in your program.&lt;br /&gt;
&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 #use spi(DO = PIN_A3, CLK = PIN_A2, ENABLE = PIN_A1, BITS = 16, MASTER, ENABLE_ACTIVE = 0, MSB_FIRST, IDLE = 1)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
The first three arguments determine which three pins we will be using: DO is the &amp;quot;SDATA&amp;quot; pin of the AD9833, CLK is the &amp;quot;SCLK&amp;quot; pin, and ENABLE is the &amp;quot;FSYNC&amp;quot; pin.  The next argument states that the max number of bits in one transfer is 16.  The next argument specifies that the PIC is the master and the AD9833 is the slave.  The AD9833&#039;s FSYNC pin is active low, and it accepts the most significant bit (MSB) of each transfer first.  The SCLK pin is also specified to be kept high when not in use.  After this initial setup, the SPI communication is quite straightforward.  We simply use the function &#039;&#039;&#039;spi_xfer()&#039;&#039;&#039; whenever we want to send information via SPI to the AD9833.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
Now that we can talk to the waveform generator, we need to know what it needs to be told to produce what we want.  Each of the 16 bits transferred has a meaning, and these meanings are described in the Table below.&lt;/div&gt;</summary>
		<author><name>DanJohnson</name></author>
	</entry>
	<entry>
		<id>https://hades.mech.northwestern.edu//index.php?title=Waveform_Generation_with_AD9833,_and_SPI&amp;diff=9169</id>
		<title>Waveform Generation with AD9833, and SPI</title>
		<link rel="alternate" type="text/html" href="https://hades.mech.northwestern.edu//index.php?title=Waveform_Generation_with_AD9833,_and_SPI&amp;diff=9169"/>
		<updated>2008-12-09T16:32:02Z</updated>

		<summary type="html">&lt;p&gt;DanJohnson: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Image:AD9833Connsmall.jpg|right]]The AD9833 is a programmable waveform generator capable of creating sine, triangular, or square wave outputs in a frequency range of 0 to 12.5 MHz.  It has two frequency registers and two phase registers that can be written to and output from the VOUT pin.  This chip is perfectly suited for use with the PIC 18F4520, as it uses SPI communication for its setup and control.  A connection diagram for the AD9833 is given to the right.  The MCLK pin is tied directly to the oscillator of the PIC, and the three SPI communication lines are connected to three I/O pins on the PIC (in this case pins A1, A2, and A3).&lt;/div&gt;</summary>
		<author><name>DanJohnson</name></author>
	</entry>
	<entry>
		<id>https://hades.mech.northwestern.edu//index.php?title=File:AD9833Connsmall.jpg&amp;diff=9168</id>
		<title>File:AD9833Connsmall.jpg</title>
		<link rel="alternate" type="text/html" href="https://hades.mech.northwestern.edu//index.php?title=File:AD9833Connsmall.jpg&amp;diff=9168"/>
		<updated>2008-12-09T16:27:44Z</updated>

		<summary type="html">&lt;p&gt;DanJohnson: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>DanJohnson</name></author>
	</entry>
	<entry>
		<id>https://hades.mech.northwestern.edu//index.php?title=File:AD9833Conn.jpg&amp;diff=9167</id>
		<title>File:AD9833Conn.jpg</title>
		<link rel="alternate" type="text/html" href="https://hades.mech.northwestern.edu//index.php?title=File:AD9833Conn.jpg&amp;diff=9167"/>
		<updated>2008-12-09T16:18:29Z</updated>

		<summary type="html">&lt;p&gt;DanJohnson: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>DanJohnson</name></author>
	</entry>
	<entry>
		<id>https://hades.mech.northwestern.edu//index.php?title=Waveform_Generation_with_AD9833,_and_SPI&amp;diff=9166</id>
		<title>Waveform Generation with AD9833, and SPI</title>
		<link rel="alternate" type="text/html" href="https://hades.mech.northwestern.edu//index.php?title=Waveform_Generation_with_AD9833,_and_SPI&amp;diff=9166"/>
		<updated>2008-12-09T16:18:16Z</updated>

		<summary type="html">&lt;p&gt;DanJohnson: /* The AD9833 Waveform Generator and SPI Interface */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;The AD9833 is a programmable waveform generator capable of creating sine, triangular, or square wave outputs in a frequency range of 0 to 12.5 MHz.  It has two frequency registers and two phase registers that can be written to and output from the VOUT pin.  This chip is perfectly suited for use with the PIC 18F4520, as it uses SPI communication for its setup and control.  A connection diagram for the AD9833 is given to the right.[[Image:AD9833Conn.jpg]]&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
The MCLK pin is tied directly to the oscillator of the PIC, and the three SPI communication lines are connected to three I/O pins on the PIC (in this case pins A1, A2, and A3).&lt;/div&gt;</summary>
		<author><name>DanJohnson</name></author>
	</entry>
	<entry>
		<id>https://hades.mech.northwestern.edu//index.php?title=Waveform_Generation_with_AD9833,_and_SPI&amp;diff=9165</id>
		<title>Waveform Generation with AD9833, and SPI</title>
		<link rel="alternate" type="text/html" href="https://hades.mech.northwestern.edu//index.php?title=Waveform_Generation_with_AD9833,_and_SPI&amp;diff=9165"/>
		<updated>2008-12-09T16:10:29Z</updated>

		<summary type="html">&lt;p&gt;DanJohnson: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=The AD9833 Waveform Generator and SPI Interface=&lt;/div&gt;</summary>
		<author><name>DanJohnson</name></author>
	</entry>
	<entry>
		<id>https://hades.mech.northwestern.edu//index.php?title=Main_Page&amp;diff=9164</id>
		<title>Main Page</title>
		<link rel="alternate" type="text/html" href="https://hades.mech.northwestern.edu//index.php?title=Main_Page&amp;diff=9164"/>
		<updated>2008-12-09T16:09:37Z</updated>

		<summary type="html">&lt;p&gt;DanJohnson: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;The Northwestern University mechatronics design wiki provides reference material on the theory and applications of electronics, sensors, actuators, etc., for use in mechatronics-related research and projects.  Practical applications often refer to equipment and supplies available in the [http://mechatronics.mech.northwestern.edu/ Northwestern Mechatronics Design Lab].&lt;br /&gt;
&lt;br /&gt;
Important:  Please be sure to read the [http://mechatronics.mech.northwestern.edu/mech-rules.pdf Rules for Using the Mechatronics Design Lab].&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;h3&amp;gt;Design Competition 2008&amp;lt;/h3&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Wiki pages on sensors, actuators, programming, and microcontrollers: use pages below&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
* [http://www.mech.northwestern.edu/courses/433/Writeups/QuickStart/ Parts in the DC2008 quick start pack]&lt;br /&gt;
* [http://peshkin.mech.northwestern.edu/pic/info/piccintro_2008-01-24.pdf PIC C intro slides, as presented 2008/01/24 (pdf)]&lt;br /&gt;
* [http://peshkin.mech.northwestern.edu/pic/info/picinterfacing_2008-01-28.pdf PIC interfacing slides, as presented 2008/01/28 (pdf)]&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;h3&amp;gt;Sensors and actuators for DC&amp;lt;/h3&amp;gt;&lt;br /&gt;
* [[Using Solderless Breadboard|Solderless Breadboard &amp;amp; wiring that works]]&lt;br /&gt;
* [[Using LEDs &amp;amp; IREDs]]&lt;br /&gt;
* [[Using a laser]]&lt;br /&gt;
* [[Sensing optical tape|Infrared reflectivity]]&lt;br /&gt;
** Using phototransistors&lt;br /&gt;
** Sensing optical tape&lt;br /&gt;
* [[Comparators | Comparators : the analog digital interface]]&lt;br /&gt;
* [[Driving a DC Motor using PWM]]&lt;br /&gt;
* [http://www.robotroom.com/FaulhaberGearmotor.html Faulhaber MiniMotor SA gearmotor with encoder], as well as [[Actuators_Available_in_the_Mechatronics_Lab#Faulhaber_1524E006S_motor_with_141:1_gearhead_and_HES164A_magnetic_quadrature_encoder|the local wiki page]]&lt;br /&gt;
* [[Adding a magnetic encoder to a GM3 Gearmotor]]&lt;br /&gt;
** Using magnetic switches (Hall Effect)&lt;br /&gt;
* [[Driving using a single MOSFET | Driving a DC motor using a single MOSFET]]&lt;br /&gt;
* [[High-current devices|Driving high-current devices: several options]]&lt;br /&gt;
* [[Driving a Stepper Motor]]&lt;br /&gt;
* [[Driving an RC Servo]]&lt;br /&gt;
* [[Accelerometers]]&lt;br /&gt;
* [[Strain gauges]]&lt;br /&gt;
* [[Using the Basic Stamp Microcontroller|Basic Stamp Microcontroller]] &amp;lt;b&amp;gt;Not recommended for DC2008&amp;lt;/b&amp;gt;&lt;br /&gt;
* [http://www.mech.northwestern.edu/courses/433/Writeups/Battery_NiMH/ NiMH rechargable batteries and chargers]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;h3&amp;gt; [http://peshkin.mech.northwestern.edu/datasheets Prof. Peshkin&#039;s favorite datasheets]&amp;lt;/h3&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;h3&amp;gt;PIC 18F4520 prototyping board &amp;lt;/h3&amp;gt;&lt;br /&gt;
*[[4520 Board intro|Prototyping board intro]]&lt;br /&gt;
*[[4520 Board construction|Assembling the 18F4520 prototyping board, circuit, parts]]&lt;br /&gt;
*[[4520 Board use|Using the 18F4520 prototyping board]]&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;h3&amp;gt;Programming with CCS C &amp;lt;/h3&amp;gt;&lt;br /&gt;
*[[C language|The C language]]&lt;br /&gt;
*[[CCS C|CCS C, specifically for the 18F4520]]&lt;br /&gt;
*[[Embedded Programming Tips for CCS C]]&lt;br /&gt;
*[[CCS IDE|Using the CCS development environment]]&lt;br /&gt;
*[[Debugging C on a PIC]]&lt;br /&gt;
*[[More debugging tips]]&lt;br /&gt;
*[http://www.ccsinfo.com/forum/ CCS user forum]&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;h3&amp;gt;Interfacing and skeleton code for the PIC 18F4520&amp;lt;/h3&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;b&amp;gt;These topics have wiki pages &amp;lt;i&amp;gt;and&amp;lt;/i&amp;gt; sample code available&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;b&amp;gt;[http://peshkin.mech.northwestern.edu/pic/code Link to all sample code here.]&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
* [[Digital inputs &amp;amp; outputs]] (filename: DigitalIO)&lt;br /&gt;
* [[Analog Input]] (filename: AnalogInput)&lt;br /&gt;
** reading a trimpot&lt;br /&gt;
** reading a phototransistor&lt;br /&gt;
** amplified phototransistor, and IRED strobing&lt;br /&gt;
** using an instrumentation amp (example: for a strain gauge)&lt;br /&gt;
* [[Analog Output|Analog Output, and the I2C bus]] (filename: AnalogOutput)&lt;br /&gt;
* [[Waveform Generation with AD9833, and SPI]] (filename: AD9833)&lt;br /&gt;
*[[Pulse width modulation|Pulse width modulation (PWM) for driving motors or other high current devices]] (filename: MotorPWM)&lt;br /&gt;
** using H-bridges&lt;br /&gt;
* [[Interrupts]]&lt;br /&gt;
* [[Quadrature decoding in software]] (filename: QuadratureSoft)&lt;br /&gt;
* [[Quadrature decoding in hardware, or just counters]] (filename: QuadratureHard)&lt;br /&gt;
* [[Running RC servos]] (filename: RCservoSoft &amp;amp; RCservoHard)&lt;br /&gt;
* [[Watchdog timer]] (filename: Watchdog)&lt;br /&gt;
* [[PIC RS232|RS-232 serial communication between a PC and a PIC]] (filename: RS232)&lt;br /&gt;
* [[C Example: Serial LCD|Text output to a serial LCD display]]&lt;br /&gt;
* [[C Example: Parallel Interfacing with LCDs|Text output to a parallel LCD display]]&lt;br /&gt;
* [[Servo skeleton with fast &amp;amp; slow interrupts]]&lt;br /&gt;
* [[XBee radio communication between PICs]] (and between a PC and a PIC)&lt;br /&gt;
* [[I2C communication between PICs]]&lt;br /&gt;
* [[Serial communication with Matlab]]&lt;br /&gt;
* [[SPI communication between PICs]] &amp;lt;b&amp;gt; (Note:  this function has not been successfully tested)&amp;lt;/b&amp;gt;&lt;br /&gt;
* [[Microphones]]&lt;br /&gt;
* [[Ambient light color sensing]]&lt;br /&gt;
* [[Controlling a seven segment display]]&lt;br /&gt;
* [[Storing constant data in program memory]]&lt;br /&gt;
* [[PIC computation time benchmarks]]&lt;br /&gt;
* [[Stepper motor control with the PIC]]&lt;br /&gt;
* [[Global Positioning System]]&lt;br /&gt;
* [[IR communication between PICs]] &amp;lt;b&amp;gt; (Note:  this function has not been successfully tested) &amp;lt;/b&amp;gt;&lt;br /&gt;
* [[Interfacing to External EEPROM]]&lt;br /&gt;
* [[I2C Motor Controller]]&lt;br /&gt;
* [[Interfacing with a Photodiode Array]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;b&amp;gt;These topics have sample code available, but no wiki pages yet&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;b&amp;gt;[http://peshkin.mech.northwestern.edu/pic/code Link to all sample code here.]&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Counter0 - Counting pulses with Timer0]&lt;br /&gt;
* Counter1 - Counting pulses with Timer1]&lt;br /&gt;
* Interrupt0 - Periodic servo cycles using interrupt routines, 10mS &amp;amp; slower; Timer 0]&lt;br /&gt;
* Interrupt2 - Periodic servo cycles using interrupt routines; 10mS &amp;amp; faster; Timer 2]&lt;br /&gt;
* InterruptExternal - Interrupts generated by an external pulse]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;b&amp;gt;These topics need more development&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;b&amp;gt;[http://peshkin.mech.northwestern.edu/pic/code Link to all sample code here.]&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
* AnalogOutputParallel - Analog output using 8 digital lines]&lt;br /&gt;
* PIC-to-PIC communication &lt;br /&gt;
* Zigbee radio communication&lt;br /&gt;
* Modulated IR communication&lt;br /&gt;
* Strobing LEDs or IREDs for better range and immunity to background light&lt;br /&gt;
* I2C communication &lt;br /&gt;
* CAN bus&lt;br /&gt;
* Capturing data to Matlab&lt;br /&gt;
* Running stepper motors&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;h3&amp;gt;PIC Microcontrollers&amp;lt;/h3&amp;gt;&lt;br /&gt;
* [[PIC Microcontrollers with CCS Compiler]], for DC, 333, etc, using the CCS ICD-U40 device &amp;lt;b&amp;gt;[this section has been replaced by the material above]&amp;lt;/b&amp;gt;&lt;br /&gt;
* [[PIC Microcontrollers with C18 Compiler]], for e-puck, or using the Microchip ICD device or&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;h3&amp;gt;e-puck Mobile Robot&amp;lt;/h3&amp;gt;&lt;br /&gt;
* [[e-puck Mobile Robot]]&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;h3&amp;gt;[[Printing Circuit Boards]]&amp;lt;/h3&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;h3&amp;gt; Basic Electronics &amp;lt;/h3&amp;gt;&lt;br /&gt;
* [http://hades.mech.northwestern.edu/wiki/index.php/Category:Electronics Electronics]&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;h3&amp;gt;Analog and Digital chips&amp;lt;/h3&amp;gt;&lt;br /&gt;
* [[Comparators | Comparators: the analog to digital interface]]&lt;br /&gt;
* [http://en.wikipedia.org/wiki/Operational_amplifier_applications Opamps : building blocks of analog computation]&lt;br /&gt;
* [http://www.mech.northwestern.edu/courses/433/Writeups/InstAmp/instamp.htm Instrumentation amps, and NU circuit board for them]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=all/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;h3&amp;gt;[[:Category:Sensors|Sensors]]&amp;lt;/h3&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* [[Potentiometers|Angle, Linear Position: Potentiometers]]&lt;br /&gt;
* [[Optointerrupter|Beam Breaker: Optointerrupter]]&lt;br /&gt;
* [[Optoreflector|Proximity: Optoreflector]]&lt;br /&gt;
* [[Sensing optical tape|Infrared reflectivity : Sensing optical tape]]&lt;br /&gt;
* [[Reed Switch|Proximity: Reed Switch]]&lt;br /&gt;
* [[Hall Effect Sensor|Proximity, Angle: Hall Effect Sensor]]&lt;br /&gt;
* [[Rotary Encoder|Angle: Rotary Encoder]]&lt;br /&gt;
* Angular Velocity: Tachometer&lt;br /&gt;
* [[Photodiodes and Phototransistors|Light: Photodiodes and Phototransistors]]&lt;br /&gt;
* [[Photocell|Ambient Light: Photocell]]&lt;br /&gt;
* [[Thermistor|Temperature: Thermistor]]&lt;br /&gt;
* Temperature: Thermotransistor IC&lt;br /&gt;
* Audio: [[Microphones]]&lt;br /&gt;
* [[Accelerometers|Tilt, Acceleration: Accelerometers]]&lt;br /&gt;
* [[Strain Gauge|Force: Strain Gauge]]&lt;br /&gt;
* Current: Current Sense Resistor&lt;br /&gt;
* [[Limit Switch|Contact: Microswitch (Limit Switch)]]&lt;br /&gt;
* [[Ambient light color sensing]]&lt;br /&gt;
* [[Global Positioning System]]&lt;br /&gt;
* [[Optics]]&lt;br /&gt;
* [[Optical Locating]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=all/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;h3&amp;gt;[[:Category:Actuators|Actuators]]&amp;lt;/h3&amp;gt;&lt;br /&gt;
[[image:All-actuators-captions-small.jpg|thumb|300px|[[Actuators Available in the Mechatronics Lab|Available Actuators]]|right]]&lt;br /&gt;
&lt;br /&gt;
* [[Brushed DC Motor Theory|Brushed DC Motors]]&lt;br /&gt;
** [[Choosing a Motor and Gearing Combination|Choosing a Motor and Gearing Combination]]&lt;br /&gt;
** [[Linear Amplifier Motor Driver|Driving Using a Linear Amplifier]]&lt;br /&gt;
** [[Driving using a single MOSFET|Driving using a single MOSFET]]&lt;br /&gt;
** [[Pulse Width Modulation|Driving Using Pulse Width Modulation]]&lt;br /&gt;
** [[PIC PWM Motor Driver]]&lt;br /&gt;
** [[Gear Motor]]&lt;br /&gt;
*** [http://www.mech.northwestern.edu/courses/433/Writeups/AddEncoderHobbyEngGearMotor Adding a rotation encoder to a gearmotor]&lt;br /&gt;
* [[Brushless DC Motors]]&lt;br /&gt;
** [[Driving Brushless DC Motors]]&lt;br /&gt;
* [[Stepper Motor Theory|Stepper Motors]]&lt;br /&gt;
** [[Stepper Motor Circuits|Driving Stepper Motors]]&lt;br /&gt;
** [[Unipolar Stepper Motor Driver Circuit]]&lt;br /&gt;
** [[Bipolar Stepper Motor Driver Circuit]]&lt;br /&gt;
* [[RC Servo Theory|RC Servos]]&lt;br /&gt;
** [[555 Servo Circuit|Driving Your Servo Using a 555 Timer]]&lt;br /&gt;
* [[Solenoid Theory|Solenoids]]&lt;br /&gt;
** Practice: Driving Your Solenoid&lt;br /&gt;
* AC Motors&lt;br /&gt;
** [[Using the Yaskawa Motors]]&lt;br /&gt;
* [[Actuators Available in the Mechatronics Lab]]&lt;br /&gt;
&amp;lt;br clear=all/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;h3&amp;gt;Mechanical Design&amp;lt;/h3&amp;gt;&lt;br /&gt;
*Mechanics of Materials&lt;br /&gt;
**Beam Mechanics&lt;br /&gt;
**[[Mohr&#039;s Circle]]&lt;br /&gt;
*Failure Theories&lt;br /&gt;
**Static Loading&lt;br /&gt;
**Variable Loading and Fatigue&lt;br /&gt;
*Fastening&lt;br /&gt;
**Nuts and Bolts&lt;br /&gt;
**Keys and Keyways&lt;br /&gt;
**Press-fits&lt;br /&gt;
**Set Screws&lt;br /&gt;
*Support&lt;br /&gt;
**Housings&lt;br /&gt;
**Shafts&lt;br /&gt;
**[[Bearings]]&lt;br /&gt;
*Transmission&lt;br /&gt;
**Rigid: [[Gears]]&lt;br /&gt;
**Flexible: Belts, Chains&lt;br /&gt;
**Motion Connection/Separation: Clutches, Brakes, Couplings&lt;br /&gt;
*Linkages&lt;br /&gt;
**Serial Chains&lt;br /&gt;
**Parallel and Closed-Loop Chains&lt;br /&gt;
*Other: springs/dampers, cams, etc.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=all/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;h3&amp;gt;The PC/104 Stack&amp;lt;/h3&amp;gt;&lt;br /&gt;
[[Image:Img0174.jpg|thumb|300px|[[PC104 Overview|The PC104 Stack]]|right]]&lt;br /&gt;
* [[PC104 Overview|Overview]]&lt;br /&gt;
* [[The PC/104 Lab Kit]]&lt;br /&gt;
* Hardware:&lt;br /&gt;
** [[Advantech CPU Card]]&lt;br /&gt;
** [[Sensoray 526 Data Aquisition Card]]&lt;br /&gt;
&lt;br /&gt;
** [http://www.mech.northwestern.edu/courses/433/Writeups/PC104BoB/stack.htm#power[Power Components]]&lt;br /&gt;
** [http://www.mech.northwestern.edu/courses/433/Writeups/PC104BoB/stack.htm#electrical[I/O Electronics: Analog I/O, Digital I/O, Encoder Connections]]&lt;br /&gt;
* Advanced: Creating a Working Stack from Parts&lt;br /&gt;
** [http://www.mech.northwestern.edu/courses/433/Writeups/PC104BoB/stack.htm [Building the Breakout Board]]&lt;br /&gt;
** [http://www.mech.northwestern.edu/courses/433/Writeups/PC104BoB/stack.htm#ribboncables[Breakout Board Ribbon Cables]]&lt;br /&gt;
** [http://www.mech.northwestern.edu/courses/433/Writeups/PC104BoB/stack.htm#mechanical[Assembling the PC104 Stack]]&lt;br /&gt;
** &#039;&#039;&#039;[[Creating an xPC Flash Boot Disk]]&#039;&#039;&#039; &amp;lt;- when new version of MATLAB&lt;br /&gt;
* Custom Boards&lt;br /&gt;
** Dual PWM Motor Controller&lt;br /&gt;
** Dual Linear Amplifier Motor Controller&lt;br /&gt;
&amp;lt;br clear=all/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;h3&amp;gt;xPC Target Real-Time Operating System&amp;lt;/h3&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* [[xPC Overview|Overview of Real-Time Programming with Simulink and xPC Target]]&lt;br /&gt;
* [[Configuring xPC Target PC|Configuring xPC Host/Target PC]]&lt;br /&gt;
* [[Creating a Simple xPC Program|&#039;&#039;&#039;Quickstart&#039;&#039;&#039;:Creating a simple xPC Program]]&lt;br /&gt;
* [[Common xPC Blocks|Commonly Used Blocks]]&lt;br /&gt;
* [[Using the Host Scope]]&lt;br /&gt;
*Advanced&lt;br /&gt;
** Model Properties&lt;br /&gt;
** [[XPC M-file Communication|M-file communication]]&lt;br /&gt;
** Using outside of the lab&lt;br /&gt;
** [[media:standalone.pdf|Standalone Mode]]&lt;br /&gt;
** Stateflow&lt;br /&gt;
* Code Examples&lt;br /&gt;
** [[Controlling a DC Motor with an Encoder]]&lt;br /&gt;
** Something With State Machine&lt;br /&gt;
** [[Using RS-232 and Printing to LCD]]&lt;br /&gt;
**[[UDP Communications between Target and Host PC]]&lt;br /&gt;
** M-functions and S-functions&lt;br /&gt;
** [[xPC Code From Student Projects]]&lt;br /&gt;
&amp;lt;br clear=all/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;h3&amp;gt;QNX Real-Time Operating System&amp;lt;/h3&amp;gt;&lt;br /&gt;
*[[media:qnxtemplate.zip|QNX Control Program with Interrupts]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=all/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;h3&amp;gt;Lab Supplies and Data Sheets&amp;lt;/h3&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* [http://spreadsheets.google.com/pub?key=pa_bNAhFF-OvvxpSje1KDYg&amp;amp;output=html&amp;amp;gid=0&amp;amp;single=true Generally stocked lab inventory ]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;h3&amp;gt;[[Vendors]]&amp;lt;/h3&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;h3&amp;gt;Other Software&amp;lt;/h3&amp;gt;&lt;br /&gt;
*[[List of Useful Software for Download]]&lt;br /&gt;
*Circuit Schematics and PCB Layout&lt;br /&gt;
*LaTex Document Preparation&lt;br /&gt;
** [http://meta.wikimedia.org/wiki/Help:Formula Mathematical Formulae]&lt;br /&gt;
** Document Formatting&lt;br /&gt;
** [[LaTeX Software Setup|Software Setup]]&lt;br /&gt;
** IEEE Styles&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;h3&amp;gt;[[Other Lab Equipment]]&amp;lt;/h3&amp;gt;&lt;br /&gt;
* Prototyping Tools&lt;br /&gt;
** [[Tektronix TDS220 Oscilloscope]]&lt;br /&gt;
** [[Tektronix CFG253 Function Generator]]&lt;br /&gt;
** [[media:Mastech_power_supply_manual.pdf|Mastech Power Supply]]&lt;br /&gt;
** Fluke III Multimeter&lt;br /&gt;
** Benchtop Multimeter&lt;br /&gt;
** Powered Breadboard&lt;br /&gt;
** Soldering Iron&lt;br /&gt;
* [http://ediacaran.mech.northwestern.edu/neuromech/index.php/Lab_Equipment High Performance Neuromechatronics Benches]&lt;br /&gt;
* The Sensoray 626 DAQ Card&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;h3&amp;gt;Course Material&amp;lt;/h3&amp;gt;&lt;br /&gt;
* [[ME 224 Experimental Engineering]]&lt;br /&gt;
* [http://lims.mech.northwestern.edu/~lynch/courses/ME333/2008/index.html ME 333 Introduction to Mechatronics]&lt;br /&gt;
** [[Lab 5]]&lt;br /&gt;
** [[Suggested final projects]]&lt;br /&gt;
** [[ME 333 final projects]]&lt;br /&gt;
&amp;lt;!--&lt;br /&gt;
* [http://www.mech.northwestern.edu/hartmann/ME333_CourseInformation.html ME 333 Mechatronics]&lt;br /&gt;
--&amp;gt;&lt;br /&gt;
* [http://www.mech.northwestern.edu/courses/433/ ME 433 Advanced Mechatronics] &lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;h3&amp;gt;Miscellaneous&amp;lt;/h3&amp;gt;&lt;br /&gt;
* [[Swarm Robot Project]]&lt;br /&gt;
** [[Swarm Robot Project Links]]&lt;br /&gt;
&lt;br /&gt;
* [[Indoor Localization System]]&lt;br /&gt;
* [[Robot Helicopter Project]]&lt;br /&gt;
* [[E-Puck Color Sensing Project]]&lt;br /&gt;
* [[Guitar Tunning Project]]&lt;/div&gt;</summary>
		<author><name>DanJohnson</name></author>
	</entry>
	<entry>
		<id>https://hades.mech.northwestern.edu//index.php?title=Analog_Output&amp;diff=9163</id>
		<title>Analog Output</title>
		<link rel="alternate" type="text/html" href="https://hades.mech.northwestern.edu//index.php?title=Analog_Output&amp;diff=9163"/>
		<updated>2008-12-09T15:18:59Z</updated>

		<summary type="html">&lt;p&gt;DanJohnson: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;The PIC has 13 analog inputs, but no analog outputs.  If you need an analog output there are at least three ways to get it:&lt;br /&gt;
&lt;br /&gt;
* Use a PWM output.  The duty cycle range of 0% to 100% implies an average output voltage between 0V and 5V.  You can use an RC low-pass filter to smooth the output.  The smoother you make it, the slower it will be to reflect changes in the duty cycle.&lt;br /&gt;
&lt;br /&gt;
* Connect 8 digital output lines (perhaps the whole D port) to a parallel DAC chip (digital to analog converter) such as the DAC0800.  That&#039;s a lot of wires, and uses up a lot of your PIC pins, but it&#039;s conceptually simple.  An instruction such as output_D(ivalue) is then all you need: ivalue=0 becomes 0V and ivalue=255 becomes 5V.&lt;br /&gt;
&lt;br /&gt;
* Use a serial DAC chip such as the MAX517, as described next.  This requires only 2 communication wires, and several DAC chips (and other chips) can share the same bus.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;2-wire serial communication: the i2c bus&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
There are a lot of chips available that communicate via a serial protocol called i2c (&amp;quot;i squared c&amp;quot;).  This requires only two communication lines: SCL and SDA  (plus a common ground of course).  SCL refers to a CLock signal and SDA to a stream of DAta bits.  Many chips can share this 2-wire bus.  The PIC would ordinarily be Bus Master, and select whichever chip it wishes to talk to by sending a one-byte address code.  PIC-to-PIC communication can also be set up using i2c.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The 4520 PIC can control the i2c bus lines using a hardware i2c controller, or a software controller.   The timing of software-controlled bus signals can be disrupted by interrupts, so hardware is often preferable.  The software controller can use any pins for SCL and SDA.  The hardware controller can only use RC3 and RC4.  Sadly RC3 is just about the only pin that is NOT available at the 4520 board&#039;s edge connector, but you can connect to it on the PCB itself near pin 18 of the PIC 4520.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Image:i2c-dac.gif|right]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Wiring an i2c bus&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
We&#039;ll illustrate an i2c bus with two MAX517 DAC chips.   The SCL and SDA lines need pull-up resistors as shown.  (Without them, i2c instructions cause the PIC to wait forever for the bus to clear.)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The i2c bus lines are wired in common to all i2c slave devices; here we have just two MAX517 DAC chips.  Each slave must have a different one-byte address.  In the case of the MAX517, six of the bits of this address are fixed by the manufacturer and two are selected by you when wiring the chip.  In binary the address is 0101 1**0, or in hex 0x58, 0x5A, 0x5C, or 0x5E.   The two variable bits are chosen by wiring the AD1 and AD0 pins high or low.  So in the circuit shown we can address the two DACs as 0x58 and 0x5A.  (The prefix 0x means &amp;quot;this is a hexidecimal number&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The PIC is then responsible to send a series of bytes to control a DAC.  It sends an address byte to make the proper chip pay attention, then a command byte which for these simple chips is just zero, and then a data byte containing the value to convert to analog: value 0 becomes 0V and value 255 becomes 5V.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Using the DAC&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The DAC has a Vref input, which scales the output voltage.  If you tie Vref to +5V, the output voltage ranges 0V to 5V, but also any noise on the 5V rail will become noise on the DAC&#039;s output.  You can use a cleaner Vref if you wish.  See the MAX517 documentation.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
To command the DAC, see the code MAX517.c in AnalogOutput.   The &amp;quot;#USE&amp;quot; line configures the i2c controller.  Subsequent i2c instructions to take control of the bus, send the address byte (0x58), the command byte (0), and the desired data byte (i in this case), and release the bus.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
 #use i2c(MASTER, FAST, SCL=PIN_C3, SDA=PIN_C4, FORCE_HW)    // use hardware i2c controller&lt;br /&gt;
 &lt;br /&gt;
 i2c_start();        // take control of the bus; impose &amp;quot;start&amp;quot; levels&lt;br /&gt;
 i2c_write(0x58);    // address. 0101 1&amp;lt;font color=&amp;quot;#FF0000&amp;quot;&amp;gt;00&amp;lt;/font&amp;gt;0.   Red bits are selected by 2 pins high or low on MAX517&lt;br /&gt;
 i2c_write(0);       // command.  just zero&lt;br /&gt;
 i2c_write(i);       // data.  Translated to analog output voltage&lt;br /&gt;
 i2c_stop();         // release the bus&lt;/div&gt;</summary>
		<author><name>DanJohnson</name></author>
	</entry>
	<entry>
		<id>https://hades.mech.northwestern.edu//index.php?title=Analog_Output&amp;diff=9162</id>
		<title>Analog Output</title>
		<link rel="alternate" type="text/html" href="https://hades.mech.northwestern.edu//index.php?title=Analog_Output&amp;diff=9162"/>
		<updated>2008-12-09T15:07:04Z</updated>

		<summary type="html">&lt;p&gt;DanJohnson: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;The PIC has 13 analog inputs, but no analog outputs.  If you need an analog output there are at least three ways to get it:&lt;br /&gt;
&lt;br /&gt;
* Use a PWM output.  The duty cycle range of 0% to 100% implies an average output voltage between 0V and 5V.  You can use an RC low-pass filter to smooth the output.  The smoother you make it, the slower it will be to reflect changes in the duty cycle.&lt;br /&gt;
&lt;br /&gt;
* Connect 8 digital output lines (perhaps the whole D port) to a parallel DAC chip (digital to analog converter) such as the DAC0800.  That&#039;s a lot of wires, and uses up a lot of your PIC pins, but it&#039;s conceptually simple.  An instruction such as output_D(ivalue) is then all you need: ivalue=0 becomes 0V and ivalue=255 becomes 5V.&lt;br /&gt;
&lt;br /&gt;
* Use a serial DAC chip such as the MAX517, as described next.  This requires only 2 communication wires, and several DAC chips (and other chips) can share the same bus.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;2-wire serial communication: the i2c bus&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
There are a lot of chips available that communicate via a serial protocol called i2c (&amp;quot;i squared c&amp;quot;).  This requires only two communication lines: SCL and SDA  (plus a common ground of course).  SCL refers to a CLock signal and SDA to a stream of DAta bits.  Many chips can share this 2-wire bus.  The PIC would ordinarily be Bus Master, and select whichever chip it wishes to talk to by sending a one-byte address code.  PIC-to-PIC communication can also be set up using i2c.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The 4520 PIC can control the i2c bus lines using a hardware i2c controller, or a software controller.   The timing of software-controlled bus signals can be disrupted by interrupts, so hardware is often preferable.  The software controller can use any pins for SCL and SDA.  The hardware controller can only use RC3 and RC4.  Sadly RC3 is just about the only pin that is NOT available at the 4520 board&#039;s edge connector, but you can connect to it on the PCB itself near pin 18 of the PIC 4520.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Image:i2c-dac.gif|right]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Wiring an i2c bus&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
We&#039;ll illustrate an i2c bus with two MAX517 DAC chips.   The SCL and SDA lines need pull-up resistors as shown.  (Without them, i2c instructions cause the PIC to wait forever for the bus to clear.)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The i2c bus lines are wired in common to all i2c slave devices; here we have just two MAX517 DAC chips.  Each slave must have a different one-byte address.  In the case of the MAX517, six of the bits of this address are fixed by the manufacturer and two are selected by you when wiring the chip.  In binary the address is 0101 1**0, or in hex 0x58, 0x59, 0x5A, or 0x5B.   The last two bits are chosen by wiring the AD1 and AD0 pins high or low.  So in the circuit shown we can address the two DACs as 0x58 and 0x59.  (The prefix 0x means &amp;quot;this is a hexidecimal number&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The PIC is then responsible to send a series of bytes to control a DAC.  It sends an address byte to make the proper chip pay attention, then a command byte which for these simple chips is just zero, and then a data byte containing the value to convert to analog: value 0 becomes 0V and value 255 becomes 5V.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Using the DAC&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The DAC has a Vref input, which scales the output voltage.  If you tie Vref to +5V, the output voltage ranges 0V to 5V, but also any noise on the 5V rail will become noise on the DAC&#039;s output.  You can use a cleaner Vref if you wish.  See the MAX517 documentation.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
To command the DAC, see the code MAX517.c in AnalogOutput.   The &amp;quot;#USE&amp;quot; line configures the i2c controller.  Subsequent i2c instructions to take control of the bus, send the address byte (0x58), the command byte (0), and the desired data byte (i in this case), and release the bus.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
 #use i2c(MASTER, FAST, SCL=PIN_C3, SDA=PIN_C4, FORCE_HW)    // use hardware i2c controller&lt;br /&gt;
 &lt;br /&gt;
 i2c_start();        // take control of the bus; impose &amp;quot;start&amp;quot; levels&lt;br /&gt;
 i2c_write(0x58);    // address. 0101 1&amp;lt;font color=&amp;quot;#FF0000&amp;quot;&amp;gt;00&amp;lt;/font&amp;gt;0.   Red bits are selected by 2 pins high or low on MAX517&lt;br /&gt;
 i2c_write(0);       // command.  just zero&lt;br /&gt;
 i2c_write(i);       // data.  Translated to analog output voltage&lt;br /&gt;
 i2c_stop();         // release the bus&lt;/div&gt;</summary>
		<author><name>DanJohnson</name></author>
	</entry>
	<entry>
		<id>https://hades.mech.northwestern.edu//index.php?title=Comparators&amp;diff=9161</id>
		<title>Comparators</title>
		<link rel="alternate" type="text/html" href="https://hades.mech.northwestern.edu//index.php?title=Comparators&amp;diff=9161"/>
		<updated>2008-12-09T14:53:31Z</updated>

		<summary type="html">&lt;p&gt;DanJohnson: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[image:just5.jpg|right]] A comparator subtracts two voltages and gives you a logic output.  Thus it lives at the boundary between the analog world of continuous voltages, and the digital world of 1&#039;s and 0&#039;s, represented by +5V and 0V, logic high and logic low.&lt;br /&gt;
&lt;br /&gt;
Comparators have two inputs, called inverting and non-inverting inputs, and labeled simply - and + on a circuit diagram.   We will call the potential at these inputs V&amp;lt;sub&amp;gt;--&amp;lt;/sub&amp;gt; and V&amp;lt;sub&amp;gt;+&amp;lt;/sub&amp;gt;.   Don&#039;t confuse these inputs with power supply connections!  See figure 1: inputs on the side, power on the top and bottom.   Often power is not even shown, but if you neglect to provide it the chip won&#039;t work.  &lt;br /&gt;
&lt;br /&gt;
The output of a comparator is logic high (+5V) if V&amp;lt;sub&amp;gt;+&amp;lt;/sub&amp;gt; &amp;gt; V&amp;lt;sub&amp;gt;--&amp;lt;/sub&amp;gt;  and low (0V) if V&amp;lt;sub&amp;gt;+&amp;lt;/sub&amp;gt; &amp;lt; V&amp;lt;sub&amp;gt;--&amp;lt;/sub&amp;gt; .   If they are within about 1mV of equal, anything goes.&lt;br /&gt;
&lt;br /&gt;
Comparators are much like opamps, but opamps intend to have a continuous output Vout = G(V&amp;lt;sub&amp;gt;+&amp;lt;/sub&amp;gt; - V&amp;lt;sub&amp;gt;--&amp;lt;/sub&amp;gt;), where comparators intend to saturate, that is, always to have a full positive or zero output. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[image:light.jpg|right]] An ideal comparator, like an ideal opamp, has infinite input impedance.  That means that it observes the voltage at its input while allowing no current to flow.  Real comparators are pretty close to this ideal, swallowing only a few nA.  This is very useful when you have a high impedance signal (having very little current available) such as a phototransistor.&lt;br /&gt;
&lt;br /&gt;
An ideal comparator, like an ideal opamp, has zero output impedance.  That means, when it drives its output to 0V, it will maintain 0V regardless of how much current it has to sink in order to do so.  Real comparators are pretty good -- if forced to sink too much current they may burn up, but the output voltage won&#039;t rise more than 100mV or so.  &lt;br /&gt;
&lt;br /&gt;
We will focus on the LM311P, a particularly nice comparator. Look up its datasheet.    In the application shown, it is performing as a thresholding detector for a phototransistor.  The trimmer potentiometer sets V- to an adjustable potential between 0V and 5V.  If the phototransistor receives enough light and conducts enough current to bring V+ above the potential of V-, the output of the comparator goes high.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[image:lm311p.jpg|right]] The LM311P, like most comparators, is open-collector.  That means it is capable of grounding its output to indicate logic low, but that&#039;s all it can do.  It cannot drive its output high (to +5V for instance).  All it can do to indicate logic high output is NOT ground its output.  It&#039;s your job to pull the output high (with a &amp;quot;pull up resistor&amp;quot;) and the LM311P will pull it low when it needs to.  &lt;br /&gt;
&lt;br /&gt;
Why don&#039;t they include a pull up resistor inside?  Sometimes they do.   However, the open collector output allows you to pull it up to other voltages besides +5 at your whim, for instance to +3 or +24, or to drive an LED (and its limiting resisitor.)  You can also arrange several comparators &amp;quot;wired OR&amp;quot;, meaning the outputs of several comparators are connected and if any of them pulls the output to ground, it dominates all the others.  You couldn&#039;t do that if one was pulling the output high and another pulling it low.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
There are several limitations, but comparators are nevertheless very easy, robust, useful components.&lt;br /&gt;
&lt;br /&gt;
* Comparators are limited in amount of current they can sink (sink means take to ground.)  They can overheat and die.   This one can sink 50mA -- a lot by comparator standards.&lt;br /&gt;
&lt;br /&gt;
* Comparators are limited in the pull-up voltage they can withstand.  This one can withstand +50V (positive only, mind you!)  That&#039;s also huge.&lt;br /&gt;
&lt;br /&gt;
* LM311P has several connections you didn&#039;t want to know about: strobe, balance, and emitter.   Tie strobe and balance to Vcc+ (the positive supply) and the emitter to Vcc- (which is usually ground)&lt;br /&gt;
&lt;br /&gt;
* LM311 runs happily with Vcc+ = 5V and Vcc- = 0V.  There are many other ways to use it&lt;br /&gt;
&lt;br /&gt;
* LM311 allows its inputs to range independently anywhere from +15 to -15, without damage.  Many comparators are much more finicky.  For many, the range of the inputs must not exceed the range between the power supply rails (e.g. 0 to +5)&lt;br /&gt;
&lt;br /&gt;
==Comparators with Hysteresis==&lt;br /&gt;
You may run into a problem with implementing a comparator circuit as described above if your input signal has any noise in it, especially in the &#039;&#039;anything goes&#039;&#039; region where the two inputs (inverting and non-inverting) are nearly equal.  The noise in the signal could cause the comparator output to flicker, as shown on the right. In order to eliminate this flickering behavior, a hysteresis band can be added to the comparator.[[image:comparatorflicker.jpg|right]] &lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
A comparator with hysteresis has two important thresholds: upper and lower.  Unlike a simple comparator, however, the output of the comparator doesn&#039;t depend solely on whether the input is above or below one of these thresholds.  It depends on both the current state of the output &#039;&#039;&#039;and&#039;&#039;&#039; the current value of the input.  If the output is high, it will stay high until the input voltage drops below the lower threshold.  If the output is low, it will stay low until the input voltage rises above the upper threshold.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
A common example of a hysteresis band is the thermostat in your house.  If the system is cooling, it will cool the house down to a given temperature and then turn off.  It will not turn on until the room has heated up a certain amount again, otherwise it would be turning off and on quite rapidly.  This difference in temperatures allowed before the cooling turns back on is a hysteresis band.  If the system is currently on, the &#039;&#039;high&#039;&#039; output, it will stay on until the temperature is below a lower threshold.  If the system is off, the &#039;&#039;low&#039;&#039; output, it will stay off until the temperature is above an upper threshold.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In order to implement this electronically, we can use a comparator as shown in the circuit diagram below.  This circuit creates a noninverting comparator with hysteresis.[[Image:hysteresiscomparatorcircuit.jpg]]&lt;br /&gt;
&lt;br /&gt;
The important equations for setting the thresholds of the hysteresis band are as follows:&lt;br /&gt;
&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;math&amp;gt;V_{ref} = V_{cc}\left(\frac{R4}{R4+R3}\right)&amp;lt;/math&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;math&amp;gt;V_{U} = V_{ref}\left(\frac{R1+R2}{R2}\right)&amp;lt;/math&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;math&amp;gt;V_{L} = \frac{V_{ref}\left(R1+R2\right)-V_{cc}\left(R1\right)}{R2}&amp;lt;/math&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
where &amp;lt;math&amp;gt;V_U&amp;lt;/math&amp;gt; is the upper threshold and &amp;lt;math&amp;gt;V_L&amp;lt;/math&amp;gt; is the lower threshold of the hysteresis band.  The output of this circuit is shown below for a given input.&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
[[Image:hysteresiscomparatoroutput.jpg]]&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
* [http://www.maxim-ic.com/appnotes.cfm/an_pk/3616 &#039;&#039;Adding Extra Hysteresis to Comparators&#039;&#039;, Maxim IC]&lt;/div&gt;</summary>
		<author><name>DanJohnson</name></author>
	</entry>
	<entry>
		<id>https://hades.mech.northwestern.edu//index.php?title=File:Hysteresiscomparatoroutput.jpg&amp;diff=9160</id>
		<title>File:Hysteresiscomparatoroutput.jpg</title>
		<link rel="alternate" type="text/html" href="https://hades.mech.northwestern.edu//index.php?title=File:Hysteresiscomparatoroutput.jpg&amp;diff=9160"/>
		<updated>2008-12-09T14:38:09Z</updated>

		<summary type="html">&lt;p&gt;DanJohnson: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>DanJohnson</name></author>
	</entry>
	<entry>
		<id>https://hades.mech.northwestern.edu//index.php?title=Comparators&amp;diff=9159</id>
		<title>Comparators</title>
		<link rel="alternate" type="text/html" href="https://hades.mech.northwestern.edu//index.php?title=Comparators&amp;diff=9159"/>
		<updated>2008-12-09T14:37:31Z</updated>

		<summary type="html">&lt;p&gt;DanJohnson: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[image:just5.jpg|right]] A comparator subtracts two voltages and gives you a logic output.  Thus it lives at the boundary between the analog world of continuous voltages, and the digital world of 1&#039;s and 0&#039;s, represented by +5V and 0V, logic high and logic low.&lt;br /&gt;
&lt;br /&gt;
Comparators have two inputs, called inverting and non-inverting inputs, and labeled simply - and + on a circuit diagram.   We will call the potential at these inputs V&amp;lt;sub&amp;gt;--&amp;lt;/sub&amp;gt; and V&amp;lt;sub&amp;gt;+&amp;lt;/sub&amp;gt;.   Don&#039;t confuse these inputs with power supply connections!  See figure 1: inputs on the side, power on the top and bottom.   Often power is not even shown, but if you neglect to provide it the chip won&#039;t work.  &lt;br /&gt;
&lt;br /&gt;
The output of a comparator is logic high (+5V) if V&amp;lt;sub&amp;gt;+&amp;lt;/sub&amp;gt; &amp;gt; V&amp;lt;sub&amp;gt;--&amp;lt;/sub&amp;gt;  and low (0V) if V&amp;lt;sub&amp;gt;+&amp;lt;/sub&amp;gt; &amp;lt; V&amp;lt;sub&amp;gt;--&amp;lt;/sub&amp;gt; .   If they are within about 1mV of equal, anything goes.&lt;br /&gt;
&lt;br /&gt;
Comparators are much like opamps, but opamps intend to have a continuous output Vout = G(V&amp;lt;sub&amp;gt;+&amp;lt;/sub&amp;gt; - V&amp;lt;sub&amp;gt;--&amp;lt;/sub&amp;gt;), where comparators intend to saturate, that is, always to have a full positive or zero output. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[image:light.jpg|right]] An ideal comparator, like an ideal opamp, has infinite input impedance.  That means that it observes the voltage at its input while allowing no current to flow.  Real comparators are pretty close to this ideal, swallowing only a few nA.  This is very useful when you have a high impedance signal (having very little current available) such as a phototransistor.&lt;br /&gt;
&lt;br /&gt;
An ideal comparator, like an ideal opamp, has zero output impedance.  That means, when it drives its output to 0V, it will maintain 0V regardless of how much current it has to sink in order to do so.  Real comparators are pretty good -- if forced to sink too much current they may burn up, but the output voltage won&#039;t rise more than 100mV or so.  &lt;br /&gt;
&lt;br /&gt;
We will focus on the LM311P, a particularly nice comparator. Look up its datasheet.    In the application shown, it is performing as a thresholding detector for a phototransistor.  The trimmer potentiometer sets V- to an adjustable potential between 0V and 5V.  If the phototransistor receives enough light and conducts enough current to bring V+ above the potential of V-, the output of the comparator goes high.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[image:lm311p.jpg|right]] The LM311P, like most comparators, is open-collector.  That means it is capable of grounding its output to indicate logic low, but that&#039;s all it can do.  It cannot drive its output high (to +5V for instance).  All it can do to indicate logic high output is NOT ground its output.  It&#039;s your job to pull the output high (with a &amp;quot;pull up resistor&amp;quot;) and the LM311P will pull it low when it needs to.  &lt;br /&gt;
&lt;br /&gt;
Why don&#039;t they include a pull up resistor inside?  Sometimes they do.   However, the open collector output allows you to pull it up to other voltages besides +5 at your whim, for instance to +3 or +24, or to drive an LED (and its limiting resisitor.)  You can also arrange several comparators &amp;quot;wired OR&amp;quot;, meaning the outputs of several comparators are connected and if any of them pulls the output to ground, it dominates all the others.  You couldn&#039;t do that if one was pulling the output high and another pulling it low.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
There are several limitations, but comparators are nevertheless very easy, robust, useful components.&lt;br /&gt;
&lt;br /&gt;
* Comparators are limited in amount of current they can sink (sink means take to ground.)  They can overheat and die.   This one can sink 50mA -- a lot by comparator standards.&lt;br /&gt;
&lt;br /&gt;
* Comparators are limited in the pull-up voltage they can withstand.  This one can withstand +50V (positive only, mind you!)  That&#039;s also huge.&lt;br /&gt;
&lt;br /&gt;
* LM311P has several connections you didn&#039;t want to know about: strobe, balance, and emitter.   Tie strobe and balance to Vcc+ (the positive supply) and the emitter to Vcc- (which is usually ground)&lt;br /&gt;
&lt;br /&gt;
* LM311 runs happily with Vcc+ = 5V and Vcc- = 0V.  There are many other ways to use it&lt;br /&gt;
&lt;br /&gt;
* LM311 allows its inputs to range independently anywhere from +15 to -15, without damage.  Many comparators are much more finicky.  For many, the range of the inputs must not exceed the range between the power supply rails (e.g. 0 to +5)&lt;br /&gt;
&lt;br /&gt;
==Comparators with Hysteresis==&lt;br /&gt;
You may run into a problem with implementing a comparator circuit as described above if your input signal has any noise in it, especially in the &#039;&#039;anything goes&#039;&#039; region where the two inputs (inverting and non-inverting) are nearly equal.  The noise in the signal could cause the comparator output to flicker, as shown on the right. In order to eliminate this flickering behavior, a hysteresis band can be added to the comparator.[[image:comparatorflicker.jpg|right]] &lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
A comparator with hysteresis has two important thresholds: upper and lower.  Unlike a simple comparator, however, the output of the comparator doesn&#039;t depend solely on whether the input is above or below one of these thresholds.  It depends on both the current state of the output &#039;&#039;&#039;and&#039;&#039;&#039; the current value of the input.  If the output is high, it will stay high until the input voltage drops below the lower threshold.  If the output is low, it will stay low until the input voltage rises above the upper threshold.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
A common example of a hysteresis band is the thermostat in your house.  If the system is cooling, it will cool the house down to a given temperature and then turn off.  It will not turn on until the room has heated up a certain amount again, otherwise it would be turning off and on quite rapidly.  This difference in temperatures allowed before the cooling turns back on is a hysteresis band.  If the system is currently on, the &#039;&#039;high&#039;&#039; output, it will stay on until the temperature is below a lower threshold.  If the system is off, the &#039;&#039;low&#039;&#039; output, it will stay off until the temperature is above an upper threshold.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In order to implement this electronically, we can use a comparator as shown in the circuit diagram below.  This circuit creates a noninverting comparator with hysteresis.[[Image:hysteresiscomparatorcircuit.jpg]]&lt;br /&gt;
&lt;br /&gt;
The important equations for setting the thresholds of the hysteresis band are as follows:&lt;br /&gt;
&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;math&amp;gt;V_{ref} = V_{cc}\left(\frac{R4}{R4+R3}\right)&amp;lt;/math&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;math&amp;gt;V_{U} = V_{ref}\left(\frac{R1+R2}{R2}\right)&amp;lt;/math&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;math&amp;gt;V_{L} = \frac{V_{ref}\left(R1+R2\right)-V_{cc}\left(R1\right)}{R2}&amp;lt;/math&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
where &amp;lt;math&amp;gt;V_U&amp;lt;/math&amp;gt; is the upper threshold and &amp;lt;math&amp;gt;V_L&amp;lt;/math&amp;gt; is the lower threshold of the hysteresis band.  The output of this circuit is shown below for a given input.&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
[[Image:hysteresiscomparatoroutput.jpg]]&lt;/div&gt;</summary>
		<author><name>DanJohnson</name></author>
	</entry>
	<entry>
		<id>https://hades.mech.northwestern.edu//index.php?title=File:Hysteresiscomparatorcircuit.jpg&amp;diff=9158</id>
		<title>File:Hysteresiscomparatorcircuit.jpg</title>
		<link rel="alternate" type="text/html" href="https://hades.mech.northwestern.edu//index.php?title=File:Hysteresiscomparatorcircuit.jpg&amp;diff=9158"/>
		<updated>2008-12-09T14:32:32Z</updated>

		<summary type="html">&lt;p&gt;DanJohnson: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>DanJohnson</name></author>
	</entry>
	<entry>
		<id>https://hades.mech.northwestern.edu//index.php?title=Comparators&amp;diff=9157</id>
		<title>Comparators</title>
		<link rel="alternate" type="text/html" href="https://hades.mech.northwestern.edu//index.php?title=Comparators&amp;diff=9157"/>
		<updated>2008-12-09T14:32:10Z</updated>

		<summary type="html">&lt;p&gt;DanJohnson: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[image:just5.jpg|right]] A comparator subtracts two voltages and gives you a logic output.  Thus it lives at the boundary between the analog world of continuous voltages, and the digital world of 1&#039;s and 0&#039;s, represented by +5V and 0V, logic high and logic low.&lt;br /&gt;
&lt;br /&gt;
Comparators have two inputs, called inverting and non-inverting inputs, and labeled simply - and + on a circuit diagram.   We will call the potential at these inputs V&amp;lt;sub&amp;gt;--&amp;lt;/sub&amp;gt; and V&amp;lt;sub&amp;gt;+&amp;lt;/sub&amp;gt;.   Don&#039;t confuse these inputs with power supply connections!  See figure 1: inputs on the side, power on the top and bottom.   Often power is not even shown, but if you neglect to provide it the chip won&#039;t work.  &lt;br /&gt;
&lt;br /&gt;
The output of a comparator is logic high (+5V) if V&amp;lt;sub&amp;gt;+&amp;lt;/sub&amp;gt; &amp;gt; V&amp;lt;sub&amp;gt;--&amp;lt;/sub&amp;gt;  and low (0V) if V&amp;lt;sub&amp;gt;+&amp;lt;/sub&amp;gt; &amp;lt; V&amp;lt;sub&amp;gt;--&amp;lt;/sub&amp;gt; .   If they are within about 1mV of equal, anything goes.&lt;br /&gt;
&lt;br /&gt;
Comparators are much like opamps, but opamps intend to have a continuous output Vout = G(V&amp;lt;sub&amp;gt;+&amp;lt;/sub&amp;gt; - V&amp;lt;sub&amp;gt;--&amp;lt;/sub&amp;gt;), where comparators intend to saturate, that is, always to have a full positive or zero output. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[image:light.jpg|right]] An ideal comparator, like an ideal opamp, has infinite input impedance.  That means that it observes the voltage at its input while allowing no current to flow.  Real comparators are pretty close to this ideal, swallowing only a few nA.  This is very useful when you have a high impedance signal (having very little current available) such as a phototransistor.&lt;br /&gt;
&lt;br /&gt;
An ideal comparator, like an ideal opamp, has zero output impedance.  That means, when it drives its output to 0V, it will maintain 0V regardless of how much current it has to sink in order to do so.  Real comparators are pretty good -- if forced to sink too much current they may burn up, but the output voltage won&#039;t rise more than 100mV or so.  &lt;br /&gt;
&lt;br /&gt;
We will focus on the LM311P, a particularly nice comparator. Look up its datasheet.    In the application shown, it is performing as a thresholding detector for a phototransistor.  The trimmer potentiometer sets V- to an adjustable potential between 0V and 5V.  If the phototransistor receives enough light and conducts enough current to bring V+ above the potential of V-, the output of the comparator goes high.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[image:lm311p.jpg|right]] The LM311P, like most comparators, is open-collector.  That means it is capable of grounding its output to indicate logic low, but that&#039;s all it can do.  It cannot drive its output high (to +5V for instance).  All it can do to indicate logic high output is NOT ground its output.  It&#039;s your job to pull the output high (with a &amp;quot;pull up resistor&amp;quot;) and the LM311P will pull it low when it needs to.  &lt;br /&gt;
&lt;br /&gt;
Why don&#039;t they include a pull up resistor inside?  Sometimes they do.   However, the open collector output allows you to pull it up to other voltages besides +5 at your whim, for instance to +3 or +24, or to drive an LED (and its limiting resisitor.)  You can also arrange several comparators &amp;quot;wired OR&amp;quot;, meaning the outputs of several comparators are connected and if any of them pulls the output to ground, it dominates all the others.  You couldn&#039;t do that if one was pulling the output high and another pulling it low.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
There are several limitations, but comparators are nevertheless very easy, robust, useful components.&lt;br /&gt;
&lt;br /&gt;
* Comparators are limited in amount of current they can sink (sink means take to ground.)  They can overheat and die.   This one can sink 50mA -- a lot by comparator standards.&lt;br /&gt;
&lt;br /&gt;
* Comparators are limited in the pull-up voltage they can withstand.  This one can withstand +50V (positive only, mind you!)  That&#039;s also huge.&lt;br /&gt;
&lt;br /&gt;
* LM311P has several connections you didn&#039;t want to know about: strobe, balance, and emitter.   Tie strobe and balance to Vcc+ (the positive supply) and the emitter to Vcc- (which is usually ground)&lt;br /&gt;
&lt;br /&gt;
* LM311 runs happily with Vcc+ = 5V and Vcc- = 0V.  There are many other ways to use it&lt;br /&gt;
&lt;br /&gt;
* LM311 allows its inputs to range independently anywhere from +15 to -15, without damage.  Many comparators are much more finicky.  For many, the range of the inputs must not exceed the range between the power supply rails (e.g. 0 to +5)&lt;br /&gt;
&lt;br /&gt;
==Comparators with Hysteresis==&lt;br /&gt;
You may run into a problem with implementing a comparator circuit as described above if your input signal has any noise in it, especially in the &#039;&#039;anything goes&#039;&#039; region where the two inputs (inverting and non-inverting) are nearly equal.  The noise in the signal could cause the comparator output to flicker, as shown on the right. In order to eliminate this flickering behavior, a hysteresis band can be added to the comparator.[[image:comparatorflicker.jpg|right]] &lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
A comparator with hysteresis has two important thresholds: upper and lower.  Unlike a simple comparator, however, the output of the comparator doesn&#039;t depend solely on whether the input is above or below one of these thresholds.  It depends on both the current state of the output &#039;&#039;&#039;and&#039;&#039;&#039; the current value of the input.  If the output is high, it will stay high until the input voltage drops below the lower threshold.  If the output is low, it will stay low until the input voltage rises above the upper threshold.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
A common example of a hysteresis band is the thermostat in your house.  If the system is cooling, it will cool the house down to a given temperature and then turn off.  It will not turn on until the room has heated up a certain amount again, otherwise it would be turning off and on quite rapidly.  This difference in temperatures allowed before the cooling turns back on is a hysteresis band.  If the system is currently on, the &#039;&#039;high&#039;&#039; output, it will stay on until the temperature is below a lower threshold.  If the system is off, the &#039;&#039;low&#039;&#039; output, it will stay off until the temperature is above an upper threshold.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In order to implement this electronically, we can use a comparator as shown in the circuit diagram below.  This circuit creates a noninverting comparator with hysteresis.[[Image:hysteresiscomparatorcircuit.jpg]]&lt;/div&gt;</summary>
		<author><name>DanJohnson</name></author>
	</entry>
	<entry>
		<id>https://hades.mech.northwestern.edu//index.php?title=File:Hysteresiscomparatorcircuit.JPG&amp;diff=9156</id>
		<title>File:Hysteresiscomparatorcircuit.JPG</title>
		<link rel="alternate" type="text/html" href="https://hades.mech.northwestern.edu//index.php?title=File:Hysteresiscomparatorcircuit.JPG&amp;diff=9156"/>
		<updated>2008-12-09T14:30:20Z</updated>

		<summary type="html">&lt;p&gt;DanJohnson: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>DanJohnson</name></author>
	</entry>
	<entry>
		<id>https://hades.mech.northwestern.edu//index.php?title=File:Comparatorflicker.jpg&amp;diff=9155</id>
		<title>File:Comparatorflicker.jpg</title>
		<link rel="alternate" type="text/html" href="https://hades.mech.northwestern.edu//index.php?title=File:Comparatorflicker.jpg&amp;diff=9155"/>
		<updated>2008-12-09T14:19:09Z</updated>

		<summary type="html">&lt;p&gt;DanJohnson: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>DanJohnson</name></author>
	</entry>
	<entry>
		<id>https://hades.mech.northwestern.edu//index.php?title=Comparators&amp;diff=9154</id>
		<title>Comparators</title>
		<link rel="alternate" type="text/html" href="https://hades.mech.northwestern.edu//index.php?title=Comparators&amp;diff=9154"/>
		<updated>2008-12-09T14:17:07Z</updated>

		<summary type="html">&lt;p&gt;DanJohnson: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[image:just5.jpg|right]] A comparator subtracts two voltages and gives you a logic output.  Thus it lives at the boundary between the analog world of continuous voltages, and the digital world of 1&#039;s and 0&#039;s, represented by +5V and 0V, logic high and logic low.&lt;br /&gt;
&lt;br /&gt;
Comparators have two inputs, called inverting and non-inverting inputs, and labeled simply - and + on a circuit diagram.   We will call the potential at these inputs V&amp;lt;sub&amp;gt;--&amp;lt;/sub&amp;gt; and V&amp;lt;sub&amp;gt;+&amp;lt;/sub&amp;gt;.   Don&#039;t confuse these inputs with power supply connections!  See figure 1: inputs on the side, power on the top and bottom.   Often power is not even shown, but if you neglect to provide it the chip won&#039;t work.  &lt;br /&gt;
&lt;br /&gt;
The output of a comparator is logic high (+5V) if V&amp;lt;sub&amp;gt;+&amp;lt;/sub&amp;gt; &amp;gt; V&amp;lt;sub&amp;gt;--&amp;lt;/sub&amp;gt;  and low (0V) if V&amp;lt;sub&amp;gt;+&amp;lt;/sub&amp;gt; &amp;lt; V&amp;lt;sub&amp;gt;--&amp;lt;/sub&amp;gt; .   If they are within about 1mV of equal, anything goes.&lt;br /&gt;
&lt;br /&gt;
Comparators are much like opamps, but opamps intend to have a continuous output Vout = G(V&amp;lt;sub&amp;gt;+&amp;lt;/sub&amp;gt; - V&amp;lt;sub&amp;gt;--&amp;lt;/sub&amp;gt;), where comparators intend to saturate, that is, always to have a full positive or zero output. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[image:light.jpg|right]] An ideal comparator, like an ideal opamp, has infinite input impedance.  That means that it observes the voltage at its input while allowing no current to flow.  Real comparators are pretty close to this ideal, swallowing only a few nA.  This is very useful when you have a high impedance signal (having very little current available) such as a phototransistor.&lt;br /&gt;
&lt;br /&gt;
An ideal comparator, like an ideal opamp, has zero output impedance.  That means, when it drives its output to 0V, it will maintain 0V regardless of how much current it has to sink in order to do so.  Real comparators are pretty good -- if forced to sink too much current they may burn up, but the output voltage won&#039;t rise more than 100mV or so.  &lt;br /&gt;
&lt;br /&gt;
We will focus on the LM311P, a particularly nice comparator. Look up its datasheet.    In the application shown, it is performing as a thresholding detector for a phototransistor.  The trimmer potentiometer sets V- to an adjustable potential between 0V and 5V.  If the phototransistor receives enough light and conducts enough current to bring V+ above the potential of V-, the output of the comparator goes high.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[image:lm311p.jpg|right]] The LM311P, like most comparators, is open-collector.  That means it is capable of grounding its output to indicate logic low, but that&#039;s all it can do.  It cannot drive its output high (to +5V for instance).  All it can do to indicate logic high output is NOT ground its output.  It&#039;s your job to pull the output high (with a &amp;quot;pull up resistor&amp;quot;) and the LM311P will pull it low when it needs to.  &lt;br /&gt;
&lt;br /&gt;
Why don&#039;t they include a pull up resistor inside?  Sometimes they do.   However, the open collector output allows you to pull it up to other voltages besides +5 at your whim, for instance to +3 or +24, or to drive an LED (and its limiting resisitor.)  You can also arrange several comparators &amp;quot;wired OR&amp;quot;, meaning the outputs of several comparators are connected and if any of them pulls the output to ground, it dominates all the others.  You couldn&#039;t do that if one was pulling the output high and another pulling it low.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
There are several limitations, but comparators are nevertheless very easy, robust, useful components.&lt;br /&gt;
&lt;br /&gt;
* Comparators are limited in amount of current they can sink (sink means take to ground.)  They can overheat and die.   This one can sink 50mA -- a lot by comparator standards.&lt;br /&gt;
&lt;br /&gt;
* Comparators are limited in the pull-up voltage they can withstand.  This one can withstand +50V (positive only, mind you!)  That&#039;s also huge.&lt;br /&gt;
&lt;br /&gt;
* LM311P has several connections you didn&#039;t want to know about: strobe, balance, and emitter.   Tie strobe and balance to Vcc+ (the positive supply) and the emitter to Vcc- (which is usually ground)&lt;br /&gt;
&lt;br /&gt;
* LM311 runs happily with Vcc+ = 5V and Vcc- = 0V.  There are many other ways to use it&lt;br /&gt;
&lt;br /&gt;
* LM311 allows its inputs to range independently anywhere from +15 to -15, without damage.  Many comparators are much more finicky.  For many, the range of the inputs must not exceed the range between the power supply rails (e.g. 0 to +5)&lt;br /&gt;
&lt;br /&gt;
==Comparators with Hysteresis==&lt;br /&gt;
You may run into a problem with implementing a comparator circuit as described above if your input signal has any noise in it, especially in the &#039;&#039;anything goes&#039;&#039; region where the two inputs (inverting and non-inverting) are nearly equal.  The noise in the signal could cause the comparator output to flicker, as shown on the right. [[image:comparatorflicker.jpg|right]]&lt;/div&gt;</summary>
		<author><name>DanJohnson</name></author>
	</entry>
</feed>