<?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=LawrenceChen</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=LawrenceChen"/>
	<link rel="alternate" type="text/html" href="https://hades.mech.northwestern.edu//index.php/Special:Contributions/LawrenceChen"/>
	<updated>2026-05-24T19:46:26Z</updated>
	<subtitle>User contributions</subtitle>
	<generator>MediaWiki 1.43.8</generator>
	<entry>
		<id>https://hades.mech.northwestern.edu//index.php?title=PIC32MX:_Sinusoidal_Analog_Output&amp;diff=18432</id>
		<title>PIC32MX: Sinusoidal Analog Output</title>
		<link rel="alternate" type="text/html" href="https://hades.mech.northwestern.edu//index.php?title=PIC32MX:_Sinusoidal_Analog_Output&amp;diff=18432"/>
		<updated>2010-05-31T03:21:40Z</updated>

		<summary type="html">&lt;p&gt;LawrenceChen: /* Frequency */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;The PIC32 is actually incapable of directly creating an analog output. Instead, the PIC32 can perform pulse width modulation (PWM) to create an average analog output. At a given frequency, PWM varies the time that the output pin is on (output is 3.3V) to create the duty cycle which can simulate voltages between 0V and 3.3V. For example, if the duty cycle is 50%, the PIC32 holds the pin at 3.3V 50% of the time and 0V for the other 50%. The average output voltage is then 1.65V. If the pin is connected to an external RC circuit, the PWM can be integrated. By varying the duty cycle sinusoidally, the output with an RC circuit can resemble a sinusoid. Thus, to create the sinusoidal output, a sinusoidal wave must be divided into a discrete number of points. These points can then be converted to a list of duty cycles to represent the sinusoid.&lt;br /&gt;
&lt;br /&gt;
The three most important parameters in creating the sinusoidal analog output are the the number of points per period, the RC time constant, and the sinusoid frequency. The combination of the sinusoid frequency and the points per period helps tell the PIC when to change the duty cycle. The RC constant of an external RC circuit is important in creating smooth and accurate curves and in improving the quality of the output signal.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The code for the analog output will first generate a lookup table. This table contains values for the specific duty cycles and will generate the number of duty cycles based on the number of points specified by the user. After generating the table, the code goes through a loop which tells the board to output the appropriate PWM corresponding to the duty cycle in the lookup table at each time step. The timing for the loop is determined by an interrupt which runs a frequency, &amp;lt;math&amp;gt;f&amp;lt;/math&amp;gt;, which tells the PIC when to switch to the next appropriate PWM from the lookup table. By looping through the duty cycles at the same time intervals, the output voltage is varied to match that of a sine wave. The external RC circuit acts to store the charges from the PWM and smooth the final output voltage to yield the sine wave. Without this external RC circuit, the output would only be a series of pulses matching the duty cycle at a given time.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The equation governing the sine wave is &lt;br /&gt;
&amp;lt;math&amp;gt;y=A*sin(\frac{2 \pi}{N*i})&amp;lt;/math&amp;gt;&lt;br /&gt;
where &amp;lt;math&amp;gt;A&amp;lt;/math&amp;gt; is the amplitude of the sinusoid, &amp;lt;math&amp;gt;N&amp;lt;/math&amp;gt; is the number of points and &amp;lt;math&amp;gt;i&amp;lt;/math&amp;gt; is the index.&lt;br /&gt;
&lt;br /&gt;
The equation governing the duty cycle is &lt;br /&gt;
&amp;lt;math&amp;gt;duty cycle = \frac{MAX\_DUTY}{2}y + \frac{MAX\_DUTY}{2}&amp;lt;/math&amp;gt;&lt;br /&gt;
where the &amp;lt;math&amp;gt;MAX\_DUTY&amp;lt;/math&amp;gt; is determined by the frequency of the PWM.&lt;br /&gt;
&lt;br /&gt;
The examples below have a PWM frequency of 20kHz.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Number of Points Per Period==&lt;br /&gt;
Selecting the number of points to use to generate the sine wave is important because choosing too few will result in a very rough sine wave. When the number of points is too low, you can actually see multiple RC charging graphs between each point. However, if we choose too many points, a peak appears at what should be 0V on the sine wave. To prevent this peek from occurring, one could insert an “if” statement in the lookup table generation loop that replaces all of the occurring 0’s into 1’s. Inclusion of the if statement would result in no true 0V output for that particular output. The ideal number of points for 25Hz is around 200 points.&lt;br /&gt;
&lt;br /&gt;
[[Image:500pts10Hz.jpg|frame|This demonstrates what happens when you pick too many points. The output signal has a peak occurring at the 0V area. This output signal used 500 points at 10Hz.]]&lt;br /&gt;
&lt;br /&gt;
[[Image:100pts25Hz.jpg|left|frame|This demonstrates what an ideal analog output should look like. This output was generated using 100 points at 25Hz.]]&lt;br /&gt;
&lt;br /&gt;
[[Image:10pts25Hz.jpg|center|frame|This demonstrates what happens when you select too few points. The output signal shows the capacitor charging. In this case, 10 points at 25Hz are used in generating the analog output.]]&lt;br /&gt;
&lt;br /&gt;
==RC Time Constant==&lt;br /&gt;
&lt;br /&gt;
The RC time constant plays a big role in creating the sine wave. By increasing the RC constant, the quality of the output signal is increased, where &amp;quot;quality&amp;quot; refers to the oscillations that appear around the sine wave that occur because of PWM. A larger oscillation around the sine wave means that it is of poorer quality. Despite having such advantages, a larger RC constant will result in a phase lag which causes a delay between the output of the PIC and the output from the whole circuit.&lt;br /&gt;
&lt;br /&gt;
[[Image:RCcompare.jpg|center|frame|The sine waves were generated at 25Hz with 100 points. The sine wave labeled 1 was generated with an RC constant of 4.7 x 10^-5, the sine wave labeled 2 was generated using an RC constant 2.2 x 10^-4 and the sine wave labeled 5 was generated using an RC constant 4.7 x 10^-3. Notice that sine waves 1 and 2 are almost synchronized, but sine waves 1 and 5 have a phase lag caused by the high RC constant. The improvement in quality is also visible in these two graphs. Sine wave 5 has an RC constant that&#039;s 100 times larger than that of sine wave 1, and there&#039;s very significant improvement in the quality of the output signal.]]&lt;br /&gt;
&lt;br /&gt;
==Frequency==&lt;br /&gt;
&lt;br /&gt;
There are two important frequencies that affect the performance of the PIC in generating the analog output. The first is the cut-off frequency, and the second is the sine frequency.&lt;br /&gt;
&lt;br /&gt;
The cut-off frequency is a function of the RC time constant. The equation to determine the cut-off frequency is &lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;f_c = \frac{1}{2 \pi R C}  \text{ Hz}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
where &amp;lt;math&amp;gt;f_c&amp;lt;/math&amp;gt; is the cut-off frequency (&amp;lt;math&amp;gt;\text{Hz}&amp;lt;/math&amp;gt;), &amp;lt;math&amp;gt;R&amp;lt;/math&amp;gt; is the resistance (&amp;lt;math&amp;gt;\Omega&amp;lt;/math&amp;gt;&#039;s) and &amp;lt;math&amp;gt;C&amp;lt;/math&amp;gt; is the capacitance (F).&lt;br /&gt;
&lt;br /&gt;
This cut-off frequency can cause a loss in the output amplitude. The determination of if the cut-off frequency is too high depends on the sine frequency. If the cut-off frequency is too high (RC constant is too low) relative to the sine frequency, then the output signal may be very noisy and may also have a decreased amplitude. If the cut-off frequency is too low (RC constant is too high) relative to the sine frequency, then the final output signal through the RC circuit will be more likely to have a decreased amplitude, thus you&#039;ll only get a limited range of voltages. Below are some results from experimentation with varying sine frequencies.&lt;br /&gt;
&lt;br /&gt;
[[Image:10HzRC4-7.jpg|left|frame|Oscilloscope reading of the sinusoidal analog output with a Sine Frequency of 10Hz with a resistor of 47 kOhms and a capacitor of 0.1 microFarads. The Peak to Peak Voltage reading is 3.2V. ]]&lt;br /&gt;
&lt;br /&gt;
[[Image:30HzRC4-7.jpg|right|frame|Oscilloscope reading of the sinusoidal analog output with a Sine Frequency of 30Hz with a resistor of 47 kOhms and a capacitor of 0.1 microFarads. The Peak to Peak Voltage reading is 2.68V.]]&lt;br /&gt;
&lt;br /&gt;
[[Image:20HzRC4-7.jpg|center|frame|Oscilloscope reading of the sinusoidal analog output with a Sine Frequency of 20Hz with a resistor of 47 kOhms and a capacitor of 0.1 microFarads. The Peak to Peak Voltage reading is 2.96V.]]&lt;br /&gt;
&lt;br /&gt;
[[Image:Pk2PkVSFreq.jpg|center|frame|Graph of the results from an experiment. This experiment had a cutoff frequency of 33Hz (47kOhm resistor; 0.1 microFarad capacitor). If the sine frequency is too low relative to the cutoff frequency, the amplitude of the voltage may be smaller than the maximum output. If the sine frequency is too high relative to the cutoff frequency, the amplitude of the voltage also decreases. Thus it is ideal to pick a frequency that&#039;s in the middle ground, if possible.]]&lt;br /&gt;
&lt;br /&gt;
==Sample Code==&lt;br /&gt;
&lt;br /&gt;
This sample code creates an analog output on PINS D0 and D1 using 200 points at a sine frequency of 25Hz.&lt;br /&gt;
&lt;br /&gt;
 /******************************************************&lt;br /&gt;
 Sinusoidal Output&lt;br /&gt;
 */&lt;br /&gt;
 &lt;br /&gt;
 #include &amp;quot;HardwareProfile.h&amp;quot;&lt;br /&gt;
 #include &amp;quot;math.h&amp;quot; &lt;br /&gt;
 &lt;br /&gt;
 #define DESIRED_BAUDRATE    	(9600)      // The desired BaudRate&lt;br /&gt;
 #define NUM_POINTS_PER_PERIOD		200&lt;br /&gt;
 &lt;br /&gt;
 int timeStep = 0;&lt;br /&gt;
 int LookupTable[NUM_POINTS_PER_PERIOD];&lt;br /&gt;
 &lt;br /&gt;
 int main(void)&lt;br /&gt;
 {&lt;br /&gt;
 	int sineFreq = 25;&lt;br /&gt;
 	int interruptFreq = NUM_POINTS_PER_PERIOD * sineFreq;&lt;br /&gt;
 	int periodValue = (SYS_FREQ / interruptFreq / 1) - 1;&lt;br /&gt;
 	&lt;br /&gt;
 	// Configure the proper PB frequency and the number of wait states&lt;br /&gt;
 	SYSTEMConfigPerformance(SYS_FREQ);&lt;br /&gt;
 &lt;br /&gt;
 	// Allow vector interrupts&lt;br /&gt;
 	INTEnableSystemMultiVectoredInt();&lt;br /&gt;
 	&lt;br /&gt;
 	// init OC1 module, on pin D0&lt;br /&gt;
 	OpenOC1( OC_ON | OC_TIMER2_SRC | OC_PWM_FAULT_PIN_DISABLE, 0, 0);&lt;br /&gt;
 	// init OC1 module, on pin D1&lt;br /&gt;
 	OpenOC2( OC_ON | OC_TIMER2_SRC | OC_PWM_FAULT_PIN_DISABLE, 0, 0);&lt;br /&gt;
 	&lt;br /&gt;
 	// init Timer2 mode and period (PR2) // produces 20kHz PWM&lt;br /&gt;
 	OpenTimer2( T2_ON | T2_PS_1_1 | T2_SOURCE_INT, 3999);&lt;br /&gt;
 &lt;br /&gt;
 &lt;br /&gt;
 	int i;&lt;br /&gt;
 	for (i = 0; i &amp;lt; NUM_POINTS_PER_PERIOD; i++)&lt;br /&gt;
 	{&lt;br /&gt;
 		LookupTable[i] = (int)(3999/2 * sin(2*M_PI/NUM_POINTS_PER_PERIOD*i)+ 3999/2); &lt;br /&gt;
 	}&lt;br /&gt;
 	&lt;br /&gt;
 &lt;br /&gt;
 	// init Timer3 for Sinusoid Interrupt&lt;br /&gt;
 	// Assume Prescalar is 2&lt;br /&gt;
 	// Need to verify that SYS_FREQ / sineFreq / numPoints &amp;lt; 65534&lt;br /&gt;
 	OpenTimer3( T3_ON | T3_PS_1_1 | T3_SOURCE_INT, periodValue); &lt;br /&gt;
 	&lt;br /&gt;
 	mT3SetIntPriority( 7); 	// set Timer3 Interrupt Priority&lt;br /&gt;
 	mT3ClearIntFlag(); 		// clear interrupt flag&lt;br /&gt;
 	mT3IntEnable( 1);		// enable timer3 interrupts&lt;br /&gt;
 &lt;br /&gt;
 	// this will store the string for the LCD&lt;br /&gt;
 	char LCDbuffer[33]; &lt;br /&gt;
 &lt;br /&gt;
 	while(1)&lt;br /&gt;
 	{&lt;br /&gt;
 		// Timer 3 ISR takes care of the code&lt;br /&gt;
 	}&lt;br /&gt;
 &lt;br /&gt;
 	CloseOC1();&lt;br /&gt;
 	&lt;br /&gt;
 }//end main&lt;br /&gt;
  &lt;br /&gt;
 // interrput code&lt;br /&gt;
 void __ISR( _TIMER_3_VECTOR, ipl7) T3Interrupt( void)&lt;br /&gt;
 {&lt;br /&gt;
 	if (++timeStep &amp;gt;= NUM_POINTS_PER_PERIOD)&lt;br /&gt;
 	{&lt;br /&gt;
 		timeStep = 0;&lt;br /&gt;
 	}&lt;br /&gt;
 	&lt;br /&gt;
 	SetDCOC1PWM(LookupTable[timeStep]);&lt;br /&gt;
 	SetDCOC2PWM(LookupTable[timeStep]);&lt;br /&gt;
 	&lt;br /&gt;
 	// clear interrupt flag and exit&lt;br /&gt;
 	mT3ClearIntFlag();&lt;br /&gt;
 } // T3 Interrupt&lt;/div&gt;</summary>
		<author><name>LawrenceChen</name></author>
	</entry>
	<entry>
		<id>https://hades.mech.northwestern.edu//index.php?title=File:Pk2PkVSFreq.jpg&amp;diff=18431</id>
		<title>File:Pk2PkVSFreq.jpg</title>
		<link rel="alternate" type="text/html" href="https://hades.mech.northwestern.edu//index.php?title=File:Pk2PkVSFreq.jpg&amp;diff=18431"/>
		<updated>2010-05-31T03:21:10Z</updated>

		<summary type="html">&lt;p&gt;LawrenceChen: uploaded a new version of &amp;quot;Image:Pk2PkVSFreq.jpg&amp;quot;: Graph of the voltage amplitudes with varying sine frequencies and a cutoff frequency of 33 Hz.&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Graph of the voltage amplitudes with varying sine frequencies and a cutoff frequency of 33 Hz.&lt;/div&gt;</summary>
		<author><name>LawrenceChen</name></author>
	</entry>
	<entry>
		<id>https://hades.mech.northwestern.edu//index.php?title=File:Pk2PkVSFreq.jpg&amp;diff=18430</id>
		<title>File:Pk2PkVSFreq.jpg</title>
		<link rel="alternate" type="text/html" href="https://hades.mech.northwestern.edu//index.php?title=File:Pk2PkVSFreq.jpg&amp;diff=18430"/>
		<updated>2010-05-31T03:19:53Z</updated>

		<summary type="html">&lt;p&gt;LawrenceChen: Graph of the voltage amplitudes with varying sine frequencies and a cutoff frequency of 33 Hz.&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Graph of the voltage amplitudes with varying sine frequencies and a cutoff frequency of 33 Hz.&lt;/div&gt;</summary>
		<author><name>LawrenceChen</name></author>
	</entry>
	<entry>
		<id>https://hades.mech.northwestern.edu//index.php?title=PIC32MX:_Sinusoidal_Analog_Output&amp;diff=18429</id>
		<title>PIC32MX: Sinusoidal Analog Output</title>
		<link rel="alternate" type="text/html" href="https://hades.mech.northwestern.edu//index.php?title=PIC32MX:_Sinusoidal_Analog_Output&amp;diff=18429"/>
		<updated>2010-05-31T03:14:53Z</updated>

		<summary type="html">&lt;p&gt;LawrenceChen: /* Sample Code */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;The PIC32 is actually incapable of directly creating an analog output. Instead, the PIC32 can perform pulse width modulation (PWM) to create an average analog output. At a given frequency, PWM varies the time that the output pin is on (output is 3.3V) to create the duty cycle which can simulate voltages between 0V and 3.3V. For example, if the duty cycle is 50%, the PIC32 holds the pin at 3.3V 50% of the time and 0V for the other 50%. The average output voltage is then 1.65V. If the pin is connected to an external RC circuit, the PWM can be integrated. By varying the duty cycle sinusoidally, the output with an RC circuit can resemble a sinusoid. Thus, to create the sinusoidal output, a sinusoidal wave must be divided into a discrete number of points. These points can then be converted to a list of duty cycles to represent the sinusoid.&lt;br /&gt;
&lt;br /&gt;
The three most important parameters in creating the sinusoidal analog output are the the number of points per period, the RC time constant, and the sinusoid frequency. The combination of the sinusoid frequency and the points per period helps tell the PIC when to change the duty cycle. The RC constant of an external RC circuit is important in creating smooth and accurate curves and in improving the quality of the output signal.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The code for the analog output will first generate a lookup table. This table contains values for the specific duty cycles and will generate the number of duty cycles based on the number of points specified by the user. After generating the table, the code goes through a loop which tells the board to output the appropriate PWM corresponding to the duty cycle in the lookup table at each time step. The timing for the loop is determined by an interrupt which runs a frequency, &amp;lt;math&amp;gt;f&amp;lt;/math&amp;gt;, which tells the PIC when to switch to the next appropriate PWM from the lookup table. By looping through the duty cycles at the same time intervals, the output voltage is varied to match that of a sine wave. The external RC circuit acts to store the charges from the PWM and smooth the final output voltage to yield the sine wave. Without this external RC circuit, the output would only be a series of pulses matching the duty cycle at a given time.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The equation governing the sine wave is &lt;br /&gt;
&amp;lt;math&amp;gt;y=A*sin(\frac{2 \pi}{N*i})&amp;lt;/math&amp;gt;&lt;br /&gt;
where &amp;lt;math&amp;gt;A&amp;lt;/math&amp;gt; is the amplitude of the sinusoid, &amp;lt;math&amp;gt;N&amp;lt;/math&amp;gt; is the number of points and &amp;lt;math&amp;gt;i&amp;lt;/math&amp;gt; is the index.&lt;br /&gt;
&lt;br /&gt;
The equation governing the duty cycle is &lt;br /&gt;
&amp;lt;math&amp;gt;duty cycle = \frac{MAX\_DUTY}{2}y + \frac{MAX\_DUTY}{2}&amp;lt;/math&amp;gt;&lt;br /&gt;
where the &amp;lt;math&amp;gt;MAX\_DUTY&amp;lt;/math&amp;gt; is determined by the frequency of the PWM.&lt;br /&gt;
&lt;br /&gt;
The examples below have a PWM frequency of 20kHz.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Number of Points Per Period==&lt;br /&gt;
Selecting the number of points to use to generate the sine wave is important because choosing too few will result in a very rough sine wave. When the number of points is too low, you can actually see multiple RC charging graphs between each point. However, if we choose too many points, a peak appears at what should be 0V on the sine wave. To prevent this peek from occurring, one could insert an “if” statement in the lookup table generation loop that replaces all of the occurring 0’s into 1’s. Inclusion of the if statement would result in no true 0V output for that particular output. The ideal number of points for 25Hz is around 200 points.&lt;br /&gt;
&lt;br /&gt;
[[Image:500pts10Hz.jpg|frame|This demonstrates what happens when you pick too many points. The output signal has a peak occurring at the 0V area. This output signal used 500 points at 10Hz.]]&lt;br /&gt;
&lt;br /&gt;
[[Image:100pts25Hz.jpg|left|frame|This demonstrates what an ideal analog output should look like. This output was generated using 100 points at 25Hz.]]&lt;br /&gt;
&lt;br /&gt;
[[Image:10pts25Hz.jpg|center|frame|This demonstrates what happens when you select too few points. The output signal shows the capacitor charging. In this case, 10 points at 25Hz are used in generating the analog output.]]&lt;br /&gt;
&lt;br /&gt;
==RC Time Constant==&lt;br /&gt;
&lt;br /&gt;
The RC time constant plays a big role in creating the sine wave. By increasing the RC constant, the quality of the output signal is increased, where &amp;quot;quality&amp;quot; refers to the oscillations that appear around the sine wave that occur because of PWM. A larger oscillation around the sine wave means that it is of poorer quality. Despite having such advantages, a larger RC constant will result in a phase lag which causes a delay between the output of the PIC and the output from the whole circuit.&lt;br /&gt;
&lt;br /&gt;
[[Image:RCcompare.jpg|center|frame|The sine waves were generated at 25Hz with 100 points. The sine wave labeled 1 was generated with an RC constant of 4.7 x 10^-5, the sine wave labeled 2 was generated using an RC constant 2.2 x 10^-4 and the sine wave labeled 5 was generated using an RC constant 4.7 x 10^-3. Notice that sine waves 1 and 2 are almost synchronized, but sine waves 1 and 5 have a phase lag caused by the high RC constant. The improvement in quality is also visible in these two graphs. Sine wave 5 has an RC constant that&#039;s 100 times larger than that of sine wave 1, and there&#039;s very significant improvement in the quality of the output signal.]]&lt;br /&gt;
&lt;br /&gt;
==Frequency==&lt;br /&gt;
&lt;br /&gt;
There are two important frequencies that affect the performance of the PIC in generating the analog output. The first is the cut-off frequency, and the second is the sine frequency.&lt;br /&gt;
&lt;br /&gt;
The cut-off frequency is a function of the RC time constant. The equation to determine the cut-off frequency is &lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;f_c = \frac{1}{2 \pi R C}  \text{ Hz}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
where &amp;lt;math&amp;gt;f_c&amp;lt;/math&amp;gt; is the cut-off frequency (&amp;lt;math&amp;gt;\text{Hz}&amp;lt;/math&amp;gt;), &amp;lt;math&amp;gt;R&amp;lt;/math&amp;gt; is the resistance (&amp;lt;math&amp;gt;\Omega&amp;lt;/math&amp;gt;&#039;s) and &amp;lt;math&amp;gt;C&amp;lt;/math&amp;gt; is the capacitance (F).&lt;br /&gt;
&lt;br /&gt;
This cut-off frequency can cause a loss in the output amplitude. The determination of if the cut-off frequency is too high depends on the sine frequency. If the cut-off frequency is too high (RC constant is too low) relative to the sine frequency, then the output signal may be very noisy and may also have a decreased amplitude. If the cut-off frequency is too low (RC constant is too high) relative to the sine frequency, then the final output signal through the RC circuit will be more likely to have a decreased amplitude, thus you&#039;ll only get a limited range of voltages. Below are some results from experimentation with varying sine frequencies.&lt;br /&gt;
&lt;br /&gt;
[[Image:10HzRC4-7.jpg|left|frame|Oscilloscope reading of the sinusoidal analog output with a Sine Frequency of 10Hz with a resistor of 47 kOhms and a capacitor of 0.1 microFarads. The Peak to Peak Voltage reading is 3.2V. ]]&lt;br /&gt;
&lt;br /&gt;
[[Image:30HzRC4-7.jpg|right|frame|Oscilloscope reading of the sinusoidal analog output with a Sine Frequency of 30Hz with a resistor of 47 kOhms and a capacitor of 0.1 microFarads. The Peak to Peak Voltage reading is 2.68V.]]&lt;br /&gt;
&lt;br /&gt;
[[Image:20HzRC4-7.jpg|center|frame|Oscilloscope reading of the sinusoidal analog output with a Sine Frequency of 20Hz with a resistor of 47 kOhms and a capacitor of 0.1 microFarads. The Peak to Peak Voltage reading is 2.96V.]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Sample Code==&lt;br /&gt;
&lt;br /&gt;
This sample code creates an analog output on PINS D0 and D1 using 200 points at a sine frequency of 25Hz.&lt;br /&gt;
&lt;br /&gt;
 /******************************************************&lt;br /&gt;
 Sinusoidal Output&lt;br /&gt;
 */&lt;br /&gt;
 &lt;br /&gt;
 #include &amp;quot;HardwareProfile.h&amp;quot;&lt;br /&gt;
 #include &amp;quot;math.h&amp;quot; &lt;br /&gt;
 &lt;br /&gt;
 #define DESIRED_BAUDRATE    	(9600)      // The desired BaudRate&lt;br /&gt;
 #define NUM_POINTS_PER_PERIOD		200&lt;br /&gt;
 &lt;br /&gt;
 int timeStep = 0;&lt;br /&gt;
 int LookupTable[NUM_POINTS_PER_PERIOD];&lt;br /&gt;
 &lt;br /&gt;
 int main(void)&lt;br /&gt;
 {&lt;br /&gt;
 	int sineFreq = 25;&lt;br /&gt;
 	int interruptFreq = NUM_POINTS_PER_PERIOD * sineFreq;&lt;br /&gt;
 	int periodValue = (SYS_FREQ / interruptFreq / 1) - 1;&lt;br /&gt;
 	&lt;br /&gt;
 	// Configure the proper PB frequency and the number of wait states&lt;br /&gt;
 	SYSTEMConfigPerformance(SYS_FREQ);&lt;br /&gt;
 &lt;br /&gt;
 	// Allow vector interrupts&lt;br /&gt;
 	INTEnableSystemMultiVectoredInt();&lt;br /&gt;
 	&lt;br /&gt;
 	// init OC1 module, on pin D0&lt;br /&gt;
 	OpenOC1( OC_ON | OC_TIMER2_SRC | OC_PWM_FAULT_PIN_DISABLE, 0, 0);&lt;br /&gt;
 	// init OC1 module, on pin D1&lt;br /&gt;
 	OpenOC2( OC_ON | OC_TIMER2_SRC | OC_PWM_FAULT_PIN_DISABLE, 0, 0);&lt;br /&gt;
 	&lt;br /&gt;
 	// init Timer2 mode and period (PR2) // produces 20kHz PWM&lt;br /&gt;
 	OpenTimer2( T2_ON | T2_PS_1_1 | T2_SOURCE_INT, 3999);&lt;br /&gt;
 &lt;br /&gt;
 &lt;br /&gt;
 	int i;&lt;br /&gt;
 	for (i = 0; i &amp;lt; NUM_POINTS_PER_PERIOD; i++)&lt;br /&gt;
 	{&lt;br /&gt;
 		LookupTable[i] = (int)(3999/2 * sin(2*M_PI/NUM_POINTS_PER_PERIOD*i)+ 3999/2); &lt;br /&gt;
 	}&lt;br /&gt;
 	&lt;br /&gt;
 &lt;br /&gt;
 	// init Timer3 for Sinusoid Interrupt&lt;br /&gt;
 	// Assume Prescalar is 2&lt;br /&gt;
 	// Need to verify that SYS_FREQ / sineFreq / numPoints &amp;lt; 65534&lt;br /&gt;
 	OpenTimer3( T3_ON | T3_PS_1_1 | T3_SOURCE_INT, periodValue); &lt;br /&gt;
 	&lt;br /&gt;
 	mT3SetIntPriority( 7); 	// set Timer3 Interrupt Priority&lt;br /&gt;
 	mT3ClearIntFlag(); 		// clear interrupt flag&lt;br /&gt;
 	mT3IntEnable( 1);		// enable timer3 interrupts&lt;br /&gt;
 &lt;br /&gt;
 	// this will store the string for the LCD&lt;br /&gt;
 	char LCDbuffer[33]; &lt;br /&gt;
 &lt;br /&gt;
 	while(1)&lt;br /&gt;
 	{&lt;br /&gt;
 		// Timer 3 ISR takes care of the code&lt;br /&gt;
 	}&lt;br /&gt;
 &lt;br /&gt;
 	CloseOC1();&lt;br /&gt;
 	&lt;br /&gt;
 }//end main&lt;br /&gt;
  &lt;br /&gt;
 // interrput code&lt;br /&gt;
 void __ISR( _TIMER_3_VECTOR, ipl7) T3Interrupt( void)&lt;br /&gt;
 {&lt;br /&gt;
 	if (++timeStep &amp;gt;= NUM_POINTS_PER_PERIOD)&lt;br /&gt;
 	{&lt;br /&gt;
 		timeStep = 0;&lt;br /&gt;
 	}&lt;br /&gt;
 	&lt;br /&gt;
 	SetDCOC1PWM(LookupTable[timeStep]);&lt;br /&gt;
 	SetDCOC2PWM(LookupTable[timeStep]);&lt;br /&gt;
 	&lt;br /&gt;
 	// clear interrupt flag and exit&lt;br /&gt;
 	mT3ClearIntFlag();&lt;br /&gt;
 } // T3 Interrupt&lt;/div&gt;</summary>
		<author><name>LawrenceChen</name></author>
	</entry>
	<entry>
		<id>https://hades.mech.northwestern.edu//index.php?title=PIC32MX:_Sinusoidal_Analog_Output&amp;diff=18428</id>
		<title>PIC32MX: Sinusoidal Analog Output</title>
		<link rel="alternate" type="text/html" href="https://hades.mech.northwestern.edu//index.php?title=PIC32MX:_Sinusoidal_Analog_Output&amp;diff=18428"/>
		<updated>2010-05-31T03:13:30Z</updated>

		<summary type="html">&lt;p&gt;LawrenceChen: /* Frequency */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;The PIC32 is actually incapable of directly creating an analog output. Instead, the PIC32 can perform pulse width modulation (PWM) to create an average analog output. At a given frequency, PWM varies the time that the output pin is on (output is 3.3V) to create the duty cycle which can simulate voltages between 0V and 3.3V. For example, if the duty cycle is 50%, the PIC32 holds the pin at 3.3V 50% of the time and 0V for the other 50%. The average output voltage is then 1.65V. If the pin is connected to an external RC circuit, the PWM can be integrated. By varying the duty cycle sinusoidally, the output with an RC circuit can resemble a sinusoid. Thus, to create the sinusoidal output, a sinusoidal wave must be divided into a discrete number of points. These points can then be converted to a list of duty cycles to represent the sinusoid.&lt;br /&gt;
&lt;br /&gt;
The three most important parameters in creating the sinusoidal analog output are the the number of points per period, the RC time constant, and the sinusoid frequency. The combination of the sinusoid frequency and the points per period helps tell the PIC when to change the duty cycle. The RC constant of an external RC circuit is important in creating smooth and accurate curves and in improving the quality of the output signal.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The code for the analog output will first generate a lookup table. This table contains values for the specific duty cycles and will generate the number of duty cycles based on the number of points specified by the user. After generating the table, the code goes through a loop which tells the board to output the appropriate PWM corresponding to the duty cycle in the lookup table at each time step. The timing for the loop is determined by an interrupt which runs a frequency, &amp;lt;math&amp;gt;f&amp;lt;/math&amp;gt;, which tells the PIC when to switch to the next appropriate PWM from the lookup table. By looping through the duty cycles at the same time intervals, the output voltage is varied to match that of a sine wave. The external RC circuit acts to store the charges from the PWM and smooth the final output voltage to yield the sine wave. Without this external RC circuit, the output would only be a series of pulses matching the duty cycle at a given time.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The equation governing the sine wave is &lt;br /&gt;
&amp;lt;math&amp;gt;y=A*sin(\frac{2 \pi}{N*i})&amp;lt;/math&amp;gt;&lt;br /&gt;
where &amp;lt;math&amp;gt;A&amp;lt;/math&amp;gt; is the amplitude of the sinusoid, &amp;lt;math&amp;gt;N&amp;lt;/math&amp;gt; is the number of points and &amp;lt;math&amp;gt;i&amp;lt;/math&amp;gt; is the index.&lt;br /&gt;
&lt;br /&gt;
The equation governing the duty cycle is &lt;br /&gt;
&amp;lt;math&amp;gt;duty cycle = \frac{MAX\_DUTY}{2}y + \frac{MAX\_DUTY}{2}&amp;lt;/math&amp;gt;&lt;br /&gt;
where the &amp;lt;math&amp;gt;MAX\_DUTY&amp;lt;/math&amp;gt; is determined by the frequency of the PWM.&lt;br /&gt;
&lt;br /&gt;
The examples below have a PWM frequency of 20kHz.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Number of Points Per Period==&lt;br /&gt;
Selecting the number of points to use to generate the sine wave is important because choosing too few will result in a very rough sine wave. When the number of points is too low, you can actually see multiple RC charging graphs between each point. However, if we choose too many points, a peak appears at what should be 0V on the sine wave. To prevent this peek from occurring, one could insert an “if” statement in the lookup table generation loop that replaces all of the occurring 0’s into 1’s. Inclusion of the if statement would result in no true 0V output for that particular output. The ideal number of points for 25Hz is around 200 points.&lt;br /&gt;
&lt;br /&gt;
[[Image:500pts10Hz.jpg|frame|This demonstrates what happens when you pick too many points. The output signal has a peak occurring at the 0V area. This output signal used 500 points at 10Hz.]]&lt;br /&gt;
&lt;br /&gt;
[[Image:100pts25Hz.jpg|left|frame|This demonstrates what an ideal analog output should look like. This output was generated using 100 points at 25Hz.]]&lt;br /&gt;
&lt;br /&gt;
[[Image:10pts25Hz.jpg|center|frame|This demonstrates what happens when you select too few points. The output signal shows the capacitor charging. In this case, 10 points at 25Hz are used in generating the analog output.]]&lt;br /&gt;
&lt;br /&gt;
==RC Time Constant==&lt;br /&gt;
&lt;br /&gt;
The RC time constant plays a big role in creating the sine wave. By increasing the RC constant, the quality of the output signal is increased, where &amp;quot;quality&amp;quot; refers to the oscillations that appear around the sine wave that occur because of PWM. A larger oscillation around the sine wave means that it is of poorer quality. Despite having such advantages, a larger RC constant will result in a phase lag which causes a delay between the output of the PIC and the output from the whole circuit.&lt;br /&gt;
&lt;br /&gt;
[[Image:RCcompare.jpg|center|frame|The sine waves were generated at 25Hz with 100 points. The sine wave labeled 1 was generated with an RC constant of 4.7 x 10^-5, the sine wave labeled 2 was generated using an RC constant 2.2 x 10^-4 and the sine wave labeled 5 was generated using an RC constant 4.7 x 10^-3. Notice that sine waves 1 and 2 are almost synchronized, but sine waves 1 and 5 have a phase lag caused by the high RC constant. The improvement in quality is also visible in these two graphs. Sine wave 5 has an RC constant that&#039;s 100 times larger than that of sine wave 1, and there&#039;s very significant improvement in the quality of the output signal.]]&lt;br /&gt;
&lt;br /&gt;
==Frequency==&lt;br /&gt;
&lt;br /&gt;
There are two important frequencies that affect the performance of the PIC in generating the analog output. The first is the cut-off frequency, and the second is the sine frequency.&lt;br /&gt;
&lt;br /&gt;
The cut-off frequency is a function of the RC time constant. The equation to determine the cut-off frequency is &lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;f_c = \frac{1}{2 \pi R C}  \text{ Hz}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
where &amp;lt;math&amp;gt;f_c&amp;lt;/math&amp;gt; is the cut-off frequency (&amp;lt;math&amp;gt;\text{Hz}&amp;lt;/math&amp;gt;), &amp;lt;math&amp;gt;R&amp;lt;/math&amp;gt; is the resistance (&amp;lt;math&amp;gt;\Omega&amp;lt;/math&amp;gt;&#039;s) and &amp;lt;math&amp;gt;C&amp;lt;/math&amp;gt; is the capacitance (F).&lt;br /&gt;
&lt;br /&gt;
This cut-off frequency can cause a loss in the output amplitude. The determination of if the cut-off frequency is too high depends on the sine frequency. If the cut-off frequency is too high (RC constant is too low) relative to the sine frequency, then the output signal may be very noisy and may also have a decreased amplitude. If the cut-off frequency is too low (RC constant is too high) relative to the sine frequency, then the final output signal through the RC circuit will be more likely to have a decreased amplitude, thus you&#039;ll only get a limited range of voltages. Below are some results from experimentation with varying sine frequencies.&lt;br /&gt;
&lt;br /&gt;
[[Image:10HzRC4-7.jpg|left|frame|Oscilloscope reading of the sinusoidal analog output with a Sine Frequency of 10Hz with a resistor of 47 kOhms and a capacitor of 0.1 microFarads. The Peak to Peak Voltage reading is 3.2V. ]]&lt;br /&gt;
&lt;br /&gt;
[[Image:30HzRC4-7.jpg|right|frame|Oscilloscope reading of the sinusoidal analog output with a Sine Frequency of 30Hz with a resistor of 47 kOhms and a capacitor of 0.1 microFarads. The Peak to Peak Voltage reading is 2.68V.]]&lt;br /&gt;
&lt;br /&gt;
[[Image:20HzRC4-7.jpg|center|frame|Oscilloscope reading of the sinusoidal analog output with a Sine Frequency of 20Hz with a resistor of 47 kOhms and a capacitor of 0.1 microFarads. The Peak to Peak Voltage reading is 2.96V.]]&lt;br /&gt;
&lt;br /&gt;
==Sample Code==&lt;br /&gt;
&lt;br /&gt;
This sample code creates an analog output on PINS D0 and D1 using 200 points at a sine frequency of 25Hz.&lt;br /&gt;
&lt;br /&gt;
 /******************************************************&lt;br /&gt;
 Sinusoidal Output&lt;br /&gt;
 */&lt;br /&gt;
 &lt;br /&gt;
 #include &amp;quot;HardwareProfile.h&amp;quot;&lt;br /&gt;
 #include &amp;quot;math.h&amp;quot; &lt;br /&gt;
 &lt;br /&gt;
 #define DESIRED_BAUDRATE    	(9600)      // The desired BaudRate&lt;br /&gt;
 #define NUM_POINTS_PER_PERIOD		200&lt;br /&gt;
 &lt;br /&gt;
 int timeStep = 0;&lt;br /&gt;
 int LookupTable[NUM_POINTS_PER_PERIOD];&lt;br /&gt;
 &lt;br /&gt;
 int main(void)&lt;br /&gt;
 {&lt;br /&gt;
 	int sineFreq = 25;&lt;br /&gt;
 	int interruptFreq = NUM_POINTS_PER_PERIOD * sineFreq;&lt;br /&gt;
 	int periodValue = (SYS_FREQ / interruptFreq / 1) - 1;&lt;br /&gt;
 	&lt;br /&gt;
 	// Configure the proper PB frequency and the number of wait states&lt;br /&gt;
 	SYSTEMConfigPerformance(SYS_FREQ);&lt;br /&gt;
 &lt;br /&gt;
 	// Allow vector interrupts&lt;br /&gt;
 	INTEnableSystemMultiVectoredInt();&lt;br /&gt;
 	&lt;br /&gt;
 	// init OC1 module, on pin D0&lt;br /&gt;
 	OpenOC1( OC_ON | OC_TIMER2_SRC | OC_PWM_FAULT_PIN_DISABLE, 0, 0);&lt;br /&gt;
 	// init OC1 module, on pin D1&lt;br /&gt;
 	OpenOC2( OC_ON | OC_TIMER2_SRC | OC_PWM_FAULT_PIN_DISABLE, 0, 0);&lt;br /&gt;
 	&lt;br /&gt;
 	// init Timer2 mode and period (PR2) // produces 20kHz PWM&lt;br /&gt;
 	OpenTimer2( T2_ON | T2_PS_1_1 | T2_SOURCE_INT, 3999);&lt;br /&gt;
 &lt;br /&gt;
 &lt;br /&gt;
 	int i;&lt;br /&gt;
 	for (i = 0; i &amp;lt; NUM_POINTS_PER_PERIOD; i++)&lt;br /&gt;
 	{&lt;br /&gt;
 		LookupTable[i] = (int)(3999/2 * sin(2*M_PI/NUM_POINTS_PER_PERIOD*i)+ 3999/2); &lt;br /&gt;
 	}&lt;br /&gt;
 	&lt;br /&gt;
 &lt;br /&gt;
 	// init Timer3 for Sinusoid Interrupt&lt;br /&gt;
 	// Assume Prescalar is 2&lt;br /&gt;
 	// Need to verify that SYS_FREQ / sineFreq / numPoints &amp;lt; 65534&lt;br /&gt;
 	OpenTimer3( T3_ON | T3_PS_1_1 | T3_SOURCE_INT, periodValue); &lt;br /&gt;
 	&lt;br /&gt;
 	mT3SetIntPriority( 7); 	// set Timer3 Interrupt Priority&lt;br /&gt;
 	mT3ClearIntFlag(); 		// clear interrupt flag&lt;br /&gt;
 	mT3IntEnable( 1);		// enable timer3 interrupts&lt;br /&gt;
 &lt;br /&gt;
 	// this will store the string for the LCD&lt;br /&gt;
 	char LCDbuffer[33]; &lt;br /&gt;
 &lt;br /&gt;
 	while(1)&lt;br /&gt;
 	{&lt;br /&gt;
 		// Timer 3 ISR takes care of the code&lt;br /&gt;
 	}&lt;br /&gt;
 &lt;br /&gt;
 	CloseOC1();&lt;br /&gt;
 	&lt;br /&gt;
 }//end main&lt;br /&gt;
  &lt;br /&gt;
 // interrput code&lt;br /&gt;
 void __ISR( _TIMER_3_VECTOR, ipl7) T3Interrupt( void)&lt;br /&gt;
 {&lt;br /&gt;
 	if (++timeStep &amp;gt;= NUM_POINTS_PER_PERIOD)&lt;br /&gt;
 	{&lt;br /&gt;
 		timeStep = 0;&lt;br /&gt;
 	}&lt;br /&gt;
 	&lt;br /&gt;
 	SetDCOC1PWM(LookupTable[timeStep]);&lt;br /&gt;
 	SetDCOC2PWM(LookupTable[timeStep]);&lt;br /&gt;
 	&lt;br /&gt;
 	// clear interrupt flag and exit&lt;br /&gt;
 	mT3ClearIntFlag();&lt;br /&gt;
 } // T3 Interrupt&lt;/div&gt;</summary>
		<author><name>LawrenceChen</name></author>
	</entry>
	<entry>
		<id>https://hades.mech.northwestern.edu//index.php?title=File:30HzRC4-7.jpg&amp;diff=18427</id>
		<title>File:30HzRC4-7.jpg</title>
		<link rel="alternate" type="text/html" href="https://hades.mech.northwestern.edu//index.php?title=File:30HzRC4-7.jpg&amp;diff=18427"/>
		<updated>2010-05-31T03:12:47Z</updated>

		<summary type="html">&lt;p&gt;LawrenceChen: uploaded a new version of &amp;quot;Image:30HzRC4-7.jpg&amp;quot;: Oscilloscope reading of the sinusoidal analog output with a sine frequency of 30Hz, a resistor of 47 kOhms, and a capacitor of 0.1 microFarads.&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Oscilloscope reading of the sinusoidal analog output with a sine frequency of 25Hz, a resistor of 47 kOhms, and a capacitor of 0.1 microFarads.&lt;/div&gt;</summary>
		<author><name>LawrenceChen</name></author>
	</entry>
	<entry>
		<id>https://hades.mech.northwestern.edu//index.php?title=File:10HzRC4-7.jpg&amp;diff=18426</id>
		<title>File:10HzRC4-7.jpg</title>
		<link rel="alternate" type="text/html" href="https://hades.mech.northwestern.edu//index.php?title=File:10HzRC4-7.jpg&amp;diff=18426"/>
		<updated>2010-05-31T03:11:51Z</updated>

		<summary type="html">&lt;p&gt;LawrenceChen: uploaded a new version of &amp;quot;Image:10HzRC4-7.jpg&amp;quot;: Oscilloscope reading of the sinusoidal analog output with a sine frequency of 10Hz, a resistor of 47kOhms and a capacitor of 0.1 microFarads&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Oscilloscope reading of the sinusoidal analog output. Sine Frequency=10Hz, R=47 kOhms and C=0.1 microFarads.&lt;/div&gt;</summary>
		<author><name>LawrenceChen</name></author>
	</entry>
	<entry>
		<id>https://hades.mech.northwestern.edu//index.php?title=File:20HzRC4-7.jpg&amp;diff=18425</id>
		<title>File:20HzRC4-7.jpg</title>
		<link rel="alternate" type="text/html" href="https://hades.mech.northwestern.edu//index.php?title=File:20HzRC4-7.jpg&amp;diff=18425"/>
		<updated>2010-05-31T03:09:15Z</updated>

		<summary type="html">&lt;p&gt;LawrenceChen: uploaded a new version of &amp;quot;Image:20HzRC4-7.jpg&amp;quot;: Oscilloscope reading of the sinusoidal analog output with a sine frequency of 20 Hz, a resistor of 47 kOhms and a capacitor of 0.1 microFarads&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Oscilloscope reading of the sinusoidal analog output with a sine frequency of 25Hz, resistor of 47kOhms, and a capacitor of 0.1 microFarads.&lt;/div&gt;</summary>
		<author><name>LawrenceChen</name></author>
	</entry>
	<entry>
		<id>https://hades.mech.northwestern.edu//index.php?title=PIC32MX:_Sinusoidal_Analog_Output&amp;diff=18424</id>
		<title>PIC32MX: Sinusoidal Analog Output</title>
		<link rel="alternate" type="text/html" href="https://hades.mech.northwestern.edu//index.php?title=PIC32MX:_Sinusoidal_Analog_Output&amp;diff=18424"/>
		<updated>2010-05-31T03:05:53Z</updated>

		<summary type="html">&lt;p&gt;LawrenceChen: /* Frequency */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;The PIC32 is actually incapable of directly creating an analog output. Instead, the PIC32 can perform pulse width modulation (PWM) to create an average analog output. At a given frequency, PWM varies the time that the output pin is on (output is 3.3V) to create the duty cycle which can simulate voltages between 0V and 3.3V. For example, if the duty cycle is 50%, the PIC32 holds the pin at 3.3V 50% of the time and 0V for the other 50%. The average output voltage is then 1.65V. If the pin is connected to an external RC circuit, the PWM can be integrated. By varying the duty cycle sinusoidally, the output with an RC circuit can resemble a sinusoid. Thus, to create the sinusoidal output, a sinusoidal wave must be divided into a discrete number of points. These points can then be converted to a list of duty cycles to represent the sinusoid.&lt;br /&gt;
&lt;br /&gt;
The three most important parameters in creating the sinusoidal analog output are the the number of points per period, the RC time constant, and the sinusoid frequency. The combination of the sinusoid frequency and the points per period helps tell the PIC when to change the duty cycle. The RC constant of an external RC circuit is important in creating smooth and accurate curves and in improving the quality of the output signal.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The code for the analog output will first generate a lookup table. This table contains values for the specific duty cycles and will generate the number of duty cycles based on the number of points specified by the user. After generating the table, the code goes through a loop which tells the board to output the appropriate PWM corresponding to the duty cycle in the lookup table at each time step. The timing for the loop is determined by an interrupt which runs a frequency, &amp;lt;math&amp;gt;f&amp;lt;/math&amp;gt;, which tells the PIC when to switch to the next appropriate PWM from the lookup table. By looping through the duty cycles at the same time intervals, the output voltage is varied to match that of a sine wave. The external RC circuit acts to store the charges from the PWM and smooth the final output voltage to yield the sine wave. Without this external RC circuit, the output would only be a series of pulses matching the duty cycle at a given time.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The equation governing the sine wave is &lt;br /&gt;
&amp;lt;math&amp;gt;y=A*sin(\frac{2 \pi}{N*i})&amp;lt;/math&amp;gt;&lt;br /&gt;
where &amp;lt;math&amp;gt;A&amp;lt;/math&amp;gt; is the amplitude of the sinusoid, &amp;lt;math&amp;gt;N&amp;lt;/math&amp;gt; is the number of points and &amp;lt;math&amp;gt;i&amp;lt;/math&amp;gt; is the index.&lt;br /&gt;
&lt;br /&gt;
The equation governing the duty cycle is &lt;br /&gt;
&amp;lt;math&amp;gt;duty cycle = \frac{MAX\_DUTY}{2}y + \frac{MAX\_DUTY}{2}&amp;lt;/math&amp;gt;&lt;br /&gt;
where the &amp;lt;math&amp;gt;MAX\_DUTY&amp;lt;/math&amp;gt; is determined by the frequency of the PWM.&lt;br /&gt;
&lt;br /&gt;
The examples below have a PWM frequency of 20kHz.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Number of Points Per Period==&lt;br /&gt;
Selecting the number of points to use to generate the sine wave is important because choosing too few will result in a very rough sine wave. When the number of points is too low, you can actually see multiple RC charging graphs between each point. However, if we choose too many points, a peak appears at what should be 0V on the sine wave. To prevent this peek from occurring, one could insert an “if” statement in the lookup table generation loop that replaces all of the occurring 0’s into 1’s. Inclusion of the if statement would result in no true 0V output for that particular output. The ideal number of points for 25Hz is around 200 points.&lt;br /&gt;
&lt;br /&gt;
[[Image:500pts10Hz.jpg|frame|This demonstrates what happens when you pick too many points. The output signal has a peak occurring at the 0V area. This output signal used 500 points at 10Hz.]]&lt;br /&gt;
&lt;br /&gt;
[[Image:100pts25Hz.jpg|left|frame|This demonstrates what an ideal analog output should look like. This output was generated using 100 points at 25Hz.]]&lt;br /&gt;
&lt;br /&gt;
[[Image:10pts25Hz.jpg|center|frame|This demonstrates what happens when you select too few points. The output signal shows the capacitor charging. In this case, 10 points at 25Hz are used in generating the analog output.]]&lt;br /&gt;
&lt;br /&gt;
==RC Time Constant==&lt;br /&gt;
&lt;br /&gt;
The RC time constant plays a big role in creating the sine wave. By increasing the RC constant, the quality of the output signal is increased, where &amp;quot;quality&amp;quot; refers to the oscillations that appear around the sine wave that occur because of PWM. A larger oscillation around the sine wave means that it is of poorer quality. Despite having such advantages, a larger RC constant will result in a phase lag which causes a delay between the output of the PIC and the output from the whole circuit.&lt;br /&gt;
&lt;br /&gt;
[[Image:RCcompare.jpg|center|frame|The sine waves were generated at 25Hz with 100 points. The sine wave labeled 1 was generated with an RC constant of 4.7 x 10^-5, the sine wave labeled 2 was generated using an RC constant 2.2 x 10^-4 and the sine wave labeled 5 was generated using an RC constant 4.7 x 10^-3. Notice that sine waves 1 and 2 are almost synchronized, but sine waves 1 and 5 have a phase lag caused by the high RC constant. The improvement in quality is also visible in these two graphs. Sine wave 5 has an RC constant that&#039;s 100 times larger than that of sine wave 1, and there&#039;s very significant improvement in the quality of the output signal.]]&lt;br /&gt;
&lt;br /&gt;
==Frequency==&lt;br /&gt;
&lt;br /&gt;
There are two important frequencies that affect the performance of the PIC in generating the analog output. The first is the cut-off frequency, and the second is the sine frequency.&lt;br /&gt;
&lt;br /&gt;
The cut-off frequency is a function of the RC time constant. The equation to determine the cut-off frequency is &lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;f_c = \frac{1}{2 \pi R C}  \text{ Hz}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
where &amp;lt;math&amp;gt;f_c&amp;lt;/math&amp;gt; is the cut-off frequency (&amp;lt;math&amp;gt;\text{Hz}&amp;lt;/math&amp;gt;), &amp;lt;math&amp;gt;R&amp;lt;/math&amp;gt; is the resistance (&amp;lt;math&amp;gt;\Omega&amp;lt;/math&amp;gt;&#039;s) and &amp;lt;math&amp;gt;C&amp;lt;/math&amp;gt; is the capacitance (F).&lt;br /&gt;
&lt;br /&gt;
This cut-off frequency can cause a loss in the output amplitude. The determination of if the cut-off frequency is too high depends on the sine frequency. If the cut-off frequency is too high (RC constant is too low) relative to the sine frequency, then the output signal may be very noisy and may also have a decreased amplitude. If the cut-off frequency is too low (RC constant is too high) relative to the sine frequency, then the final output signal through the RC circuit will be more likely to have a decreased amplitude, thus you&#039;ll only get a limited range of voltages. Below are some results from experimentation with varying sine frequencies.&lt;br /&gt;
&lt;br /&gt;
[[Image:10HzRC4-7.jpg|left|frame|Oscilloscope reading of the sinusoidal analog output with a Sine Frequency of 25Hz with a resistor of 47 kOhms and a capacitor of 0.1 microFarads. The Peak to Peak Voltage reading is 3.2V. ]]&lt;br /&gt;
&lt;br /&gt;
[[Image:30HzRC4-7.jpg|right|frame|Oscilloscope reading of the sinusoidal analog output with a Sine Frequency of 25Hz with a resistor of 47 kOhms and a capacitor of 0.1 microFarads. The Peak to Peak Voltage reading is 2.68V.]]&lt;br /&gt;
&lt;br /&gt;
[[Image:20HzRC4-7.jpg|center|frame|Oscilloscope reading of the sinusoidal analog output with a Sine Frequency of 25Hz with a resistor of 47 kOhms and a capacitor of 0.1 microFarads. The Peak to Peak Voltage reading is 2.96V.]]&lt;br /&gt;
&lt;br /&gt;
==Sample Code==&lt;br /&gt;
&lt;br /&gt;
This sample code creates an analog output on PINS D0 and D1 using 200 points at a sine frequency of 25Hz.&lt;br /&gt;
&lt;br /&gt;
 /******************************************************&lt;br /&gt;
 Sinusoidal Output&lt;br /&gt;
 */&lt;br /&gt;
 &lt;br /&gt;
 #include &amp;quot;HardwareProfile.h&amp;quot;&lt;br /&gt;
 #include &amp;quot;math.h&amp;quot; &lt;br /&gt;
 &lt;br /&gt;
 #define DESIRED_BAUDRATE    	(9600)      // The desired BaudRate&lt;br /&gt;
 #define NUM_POINTS_PER_PERIOD		200&lt;br /&gt;
 &lt;br /&gt;
 int timeStep = 0;&lt;br /&gt;
 int LookupTable[NUM_POINTS_PER_PERIOD];&lt;br /&gt;
 &lt;br /&gt;
 int main(void)&lt;br /&gt;
 {&lt;br /&gt;
 	int sineFreq = 25;&lt;br /&gt;
 	int interruptFreq = NUM_POINTS_PER_PERIOD * sineFreq;&lt;br /&gt;
 	int periodValue = (SYS_FREQ / interruptFreq / 1) - 1;&lt;br /&gt;
 	&lt;br /&gt;
 	// Configure the proper PB frequency and the number of wait states&lt;br /&gt;
 	SYSTEMConfigPerformance(SYS_FREQ);&lt;br /&gt;
 &lt;br /&gt;
 	// Allow vector interrupts&lt;br /&gt;
 	INTEnableSystemMultiVectoredInt();&lt;br /&gt;
 	&lt;br /&gt;
 	// init OC1 module, on pin D0&lt;br /&gt;
 	OpenOC1( OC_ON | OC_TIMER2_SRC | OC_PWM_FAULT_PIN_DISABLE, 0, 0);&lt;br /&gt;
 	// init OC1 module, on pin D1&lt;br /&gt;
 	OpenOC2( OC_ON | OC_TIMER2_SRC | OC_PWM_FAULT_PIN_DISABLE, 0, 0);&lt;br /&gt;
 	&lt;br /&gt;
 	// init Timer2 mode and period (PR2) // produces 20kHz PWM&lt;br /&gt;
 	OpenTimer2( T2_ON | T2_PS_1_1 | T2_SOURCE_INT, 3999);&lt;br /&gt;
 &lt;br /&gt;
 &lt;br /&gt;
 	int i;&lt;br /&gt;
 	for (i = 0; i &amp;lt; NUM_POINTS_PER_PERIOD; i++)&lt;br /&gt;
 	{&lt;br /&gt;
 		LookupTable[i] = (int)(3999/2 * sin(2*M_PI/NUM_POINTS_PER_PERIOD*i)+ 3999/2); &lt;br /&gt;
 	}&lt;br /&gt;
 	&lt;br /&gt;
 &lt;br /&gt;
 	// init Timer3 for Sinusoid Interrupt&lt;br /&gt;
 	// Assume Prescalar is 2&lt;br /&gt;
 	// Need to verify that SYS_FREQ / sineFreq / numPoints &amp;lt; 65534&lt;br /&gt;
 	OpenTimer3( T3_ON | T3_PS_1_1 | T3_SOURCE_INT, periodValue); &lt;br /&gt;
 	&lt;br /&gt;
 	mT3SetIntPriority( 7); 	// set Timer3 Interrupt Priority&lt;br /&gt;
 	mT3ClearIntFlag(); 		// clear interrupt flag&lt;br /&gt;
 	mT3IntEnable( 1);		// enable timer3 interrupts&lt;br /&gt;
 &lt;br /&gt;
 	// this will store the string for the LCD&lt;br /&gt;
 	char LCDbuffer[33]; &lt;br /&gt;
 &lt;br /&gt;
 	while(1)&lt;br /&gt;
 	{&lt;br /&gt;
 		// Timer 3 ISR takes care of the code&lt;br /&gt;
 	}&lt;br /&gt;
 &lt;br /&gt;
 	CloseOC1();&lt;br /&gt;
 	&lt;br /&gt;
 }//end main&lt;br /&gt;
  &lt;br /&gt;
 // interrput code&lt;br /&gt;
 void __ISR( _TIMER_3_VECTOR, ipl7) T3Interrupt( void)&lt;br /&gt;
 {&lt;br /&gt;
 	if (++timeStep &amp;gt;= NUM_POINTS_PER_PERIOD)&lt;br /&gt;
 	{&lt;br /&gt;
 		timeStep = 0;&lt;br /&gt;
 	}&lt;br /&gt;
 	&lt;br /&gt;
 	SetDCOC1PWM(LookupTable[timeStep]);&lt;br /&gt;
 	SetDCOC2PWM(LookupTable[timeStep]);&lt;br /&gt;
 	&lt;br /&gt;
 	// clear interrupt flag and exit&lt;br /&gt;
 	mT3ClearIntFlag();&lt;br /&gt;
 } // T3 Interrupt&lt;/div&gt;</summary>
		<author><name>LawrenceChen</name></author>
	</entry>
	<entry>
		<id>https://hades.mech.northwestern.edu//index.php?title=File:30HzRC4-7.jpg&amp;diff=18423</id>
		<title>File:30HzRC4-7.jpg</title>
		<link rel="alternate" type="text/html" href="https://hades.mech.northwestern.edu//index.php?title=File:30HzRC4-7.jpg&amp;diff=18423"/>
		<updated>2010-05-31T03:05:42Z</updated>

		<summary type="html">&lt;p&gt;LawrenceChen: Oscilloscope reading of the sinusoidal analog output with a sine frequency of 25Hz, a resistor of 47 kOhms, and a capacitor of 0.1 microFarads.&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Oscilloscope reading of the sinusoidal analog output with a sine frequency of 25Hz, a resistor of 47 kOhms, and a capacitor of 0.1 microFarads.&lt;/div&gt;</summary>
		<author><name>LawrenceChen</name></author>
	</entry>
	<entry>
		<id>https://hades.mech.northwestern.edu//index.php?title=PIC32MX:_Sinusoidal_Analog_Output&amp;diff=18422</id>
		<title>PIC32MX: Sinusoidal Analog Output</title>
		<link rel="alternate" type="text/html" href="https://hades.mech.northwestern.edu//index.php?title=PIC32MX:_Sinusoidal_Analog_Output&amp;diff=18422"/>
		<updated>2010-05-31T03:03:37Z</updated>

		<summary type="html">&lt;p&gt;LawrenceChen: /* Frequency */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;The PIC32 is actually incapable of directly creating an analog output. Instead, the PIC32 can perform pulse width modulation (PWM) to create an average analog output. At a given frequency, PWM varies the time that the output pin is on (output is 3.3V) to create the duty cycle which can simulate voltages between 0V and 3.3V. For example, if the duty cycle is 50%, the PIC32 holds the pin at 3.3V 50% of the time and 0V for the other 50%. The average output voltage is then 1.65V. If the pin is connected to an external RC circuit, the PWM can be integrated. By varying the duty cycle sinusoidally, the output with an RC circuit can resemble a sinusoid. Thus, to create the sinusoidal output, a sinusoidal wave must be divided into a discrete number of points. These points can then be converted to a list of duty cycles to represent the sinusoid.&lt;br /&gt;
&lt;br /&gt;
The three most important parameters in creating the sinusoidal analog output are the the number of points per period, the RC time constant, and the sinusoid frequency. The combination of the sinusoid frequency and the points per period helps tell the PIC when to change the duty cycle. The RC constant of an external RC circuit is important in creating smooth and accurate curves and in improving the quality of the output signal.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The code for the analog output will first generate a lookup table. This table contains values for the specific duty cycles and will generate the number of duty cycles based on the number of points specified by the user. After generating the table, the code goes through a loop which tells the board to output the appropriate PWM corresponding to the duty cycle in the lookup table at each time step. The timing for the loop is determined by an interrupt which runs a frequency, &amp;lt;math&amp;gt;f&amp;lt;/math&amp;gt;, which tells the PIC when to switch to the next appropriate PWM from the lookup table. By looping through the duty cycles at the same time intervals, the output voltage is varied to match that of a sine wave. The external RC circuit acts to store the charges from the PWM and smooth the final output voltage to yield the sine wave. Without this external RC circuit, the output would only be a series of pulses matching the duty cycle at a given time.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The equation governing the sine wave is &lt;br /&gt;
&amp;lt;math&amp;gt;y=A*sin(\frac{2 \pi}{N*i})&amp;lt;/math&amp;gt;&lt;br /&gt;
where &amp;lt;math&amp;gt;A&amp;lt;/math&amp;gt; is the amplitude of the sinusoid, &amp;lt;math&amp;gt;N&amp;lt;/math&amp;gt; is the number of points and &amp;lt;math&amp;gt;i&amp;lt;/math&amp;gt; is the index.&lt;br /&gt;
&lt;br /&gt;
The equation governing the duty cycle is &lt;br /&gt;
&amp;lt;math&amp;gt;duty cycle = \frac{MAX\_DUTY}{2}y + \frac{MAX\_DUTY}{2}&amp;lt;/math&amp;gt;&lt;br /&gt;
where the &amp;lt;math&amp;gt;MAX\_DUTY&amp;lt;/math&amp;gt; is determined by the frequency of the PWM.&lt;br /&gt;
&lt;br /&gt;
The examples below have a PWM frequency of 20kHz.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Number of Points Per Period==&lt;br /&gt;
Selecting the number of points to use to generate the sine wave is important because choosing too few will result in a very rough sine wave. When the number of points is too low, you can actually see multiple RC charging graphs between each point. However, if we choose too many points, a peak appears at what should be 0V on the sine wave. To prevent this peek from occurring, one could insert an “if” statement in the lookup table generation loop that replaces all of the occurring 0’s into 1’s. Inclusion of the if statement would result in no true 0V output for that particular output. The ideal number of points for 25Hz is around 200 points.&lt;br /&gt;
&lt;br /&gt;
[[Image:500pts10Hz.jpg|frame|This demonstrates what happens when you pick too many points. The output signal has a peak occurring at the 0V area. This output signal used 500 points at 10Hz.]]&lt;br /&gt;
&lt;br /&gt;
[[Image:100pts25Hz.jpg|left|frame|This demonstrates what an ideal analog output should look like. This output was generated using 100 points at 25Hz.]]&lt;br /&gt;
&lt;br /&gt;
[[Image:10pts25Hz.jpg|center|frame|This demonstrates what happens when you select too few points. The output signal shows the capacitor charging. In this case, 10 points at 25Hz are used in generating the analog output.]]&lt;br /&gt;
&lt;br /&gt;
==RC Time Constant==&lt;br /&gt;
&lt;br /&gt;
The RC time constant plays a big role in creating the sine wave. By increasing the RC constant, the quality of the output signal is increased, where &amp;quot;quality&amp;quot; refers to the oscillations that appear around the sine wave that occur because of PWM. A larger oscillation around the sine wave means that it is of poorer quality. Despite having such advantages, a larger RC constant will result in a phase lag which causes a delay between the output of the PIC and the output from the whole circuit.&lt;br /&gt;
&lt;br /&gt;
[[Image:RCcompare.jpg|center|frame|The sine waves were generated at 25Hz with 100 points. The sine wave labeled 1 was generated with an RC constant of 4.7 x 10^-5, the sine wave labeled 2 was generated using an RC constant 2.2 x 10^-4 and the sine wave labeled 5 was generated using an RC constant 4.7 x 10^-3. Notice that sine waves 1 and 2 are almost synchronized, but sine waves 1 and 5 have a phase lag caused by the high RC constant. The improvement in quality is also visible in these two graphs. Sine wave 5 has an RC constant that&#039;s 100 times larger than that of sine wave 1, and there&#039;s very significant improvement in the quality of the output signal.]]&lt;br /&gt;
&lt;br /&gt;
==Frequency==&lt;br /&gt;
&lt;br /&gt;
There are two important frequencies that affect the performance of the PIC in generating the analog output. The first is the cut-off frequency, and the second is the sine frequency.&lt;br /&gt;
&lt;br /&gt;
The cut-off frequency is a function of the RC time constant. The equation to determine the cut-off frequency is &lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;f_c = \frac{1}{2 \pi R C}  \text{ Hz}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
where &amp;lt;math&amp;gt;f_c&amp;lt;/math&amp;gt; is the cut-off frequency (&amp;lt;math&amp;gt;\text{Hz}&amp;lt;/math&amp;gt;), &amp;lt;math&amp;gt;R&amp;lt;/math&amp;gt; is the resistance (&amp;lt;math&amp;gt;\Omega&amp;lt;/math&amp;gt;&#039;s) and &amp;lt;math&amp;gt;C&amp;lt;/math&amp;gt; is the capacitance (F).&lt;br /&gt;
&lt;br /&gt;
This cut-off frequency can cause a loss in the output amplitude. The determination of if the cut-off frequency is too high depends on the sine frequency. If the cut-off frequency is too high (RC constant is too low) relative to the sine frequency, then the output signal may be very noisy and may also have a decreased amplitude. If the cut-off frequency is too low (RC constant is too high) relative to the sine frequency, then the final output signal through the RC circuit will be more likely to have a decreased amplitude, thus you&#039;ll only get a limited range of voltages. Below are some results from experimentation with varying sine frequencies.&lt;br /&gt;
&lt;br /&gt;
[[Image:10HzRC4-7.jpg|left|frame|Oscilloscope reading of the sinusoidal analog output with a Sine Frequency of 25Hz with a resistor of 47 kOhms and a capacitor of 0.1 microFarads. The Peak to Peak Voltage reading is 3.2V. ]]&lt;br /&gt;
&lt;br /&gt;
[[Image:20HzRC4-7.jpg|right|frame|Oscilloscope reading of the sinusoidal analog output with a Sine Frequency of 25Hz with a resistor of 47 kOhms and a capacitor of 0.1 microFarads. The Peak to Peak Voltage reading is 2.96V.]]&lt;br /&gt;
&lt;br /&gt;
==Sample Code==&lt;br /&gt;
&lt;br /&gt;
This sample code creates an analog output on PINS D0 and D1 using 200 points at a sine frequency of 25Hz.&lt;br /&gt;
&lt;br /&gt;
 /******************************************************&lt;br /&gt;
 Sinusoidal Output&lt;br /&gt;
 */&lt;br /&gt;
 &lt;br /&gt;
 #include &amp;quot;HardwareProfile.h&amp;quot;&lt;br /&gt;
 #include &amp;quot;math.h&amp;quot; &lt;br /&gt;
 &lt;br /&gt;
 #define DESIRED_BAUDRATE    	(9600)      // The desired BaudRate&lt;br /&gt;
 #define NUM_POINTS_PER_PERIOD		200&lt;br /&gt;
 &lt;br /&gt;
 int timeStep = 0;&lt;br /&gt;
 int LookupTable[NUM_POINTS_PER_PERIOD];&lt;br /&gt;
 &lt;br /&gt;
 int main(void)&lt;br /&gt;
 {&lt;br /&gt;
 	int sineFreq = 25;&lt;br /&gt;
 	int interruptFreq = NUM_POINTS_PER_PERIOD * sineFreq;&lt;br /&gt;
 	int periodValue = (SYS_FREQ / interruptFreq / 1) - 1;&lt;br /&gt;
 	&lt;br /&gt;
 	// Configure the proper PB frequency and the number of wait states&lt;br /&gt;
 	SYSTEMConfigPerformance(SYS_FREQ);&lt;br /&gt;
 &lt;br /&gt;
 	// Allow vector interrupts&lt;br /&gt;
 	INTEnableSystemMultiVectoredInt();&lt;br /&gt;
 	&lt;br /&gt;
 	// init OC1 module, on pin D0&lt;br /&gt;
 	OpenOC1( OC_ON | OC_TIMER2_SRC | OC_PWM_FAULT_PIN_DISABLE, 0, 0);&lt;br /&gt;
 	// init OC1 module, on pin D1&lt;br /&gt;
 	OpenOC2( OC_ON | OC_TIMER2_SRC | OC_PWM_FAULT_PIN_DISABLE, 0, 0);&lt;br /&gt;
 	&lt;br /&gt;
 	// init Timer2 mode and period (PR2) // produces 20kHz PWM&lt;br /&gt;
 	OpenTimer2( T2_ON | T2_PS_1_1 | T2_SOURCE_INT, 3999);&lt;br /&gt;
 &lt;br /&gt;
 &lt;br /&gt;
 	int i;&lt;br /&gt;
 	for (i = 0; i &amp;lt; NUM_POINTS_PER_PERIOD; i++)&lt;br /&gt;
 	{&lt;br /&gt;
 		LookupTable[i] = (int)(3999/2 * sin(2*M_PI/NUM_POINTS_PER_PERIOD*i)+ 3999/2); &lt;br /&gt;
 	}&lt;br /&gt;
 	&lt;br /&gt;
 &lt;br /&gt;
 	// init Timer3 for Sinusoid Interrupt&lt;br /&gt;
 	// Assume Prescalar is 2&lt;br /&gt;
 	// Need to verify that SYS_FREQ / sineFreq / numPoints &amp;lt; 65534&lt;br /&gt;
 	OpenTimer3( T3_ON | T3_PS_1_1 | T3_SOURCE_INT, periodValue); &lt;br /&gt;
 	&lt;br /&gt;
 	mT3SetIntPriority( 7); 	// set Timer3 Interrupt Priority&lt;br /&gt;
 	mT3ClearIntFlag(); 		// clear interrupt flag&lt;br /&gt;
 	mT3IntEnable( 1);		// enable timer3 interrupts&lt;br /&gt;
 &lt;br /&gt;
 	// this will store the string for the LCD&lt;br /&gt;
 	char LCDbuffer[33]; &lt;br /&gt;
 &lt;br /&gt;
 	while(1)&lt;br /&gt;
 	{&lt;br /&gt;
 		// Timer 3 ISR takes care of the code&lt;br /&gt;
 	}&lt;br /&gt;
 &lt;br /&gt;
 	CloseOC1();&lt;br /&gt;
 	&lt;br /&gt;
 }//end main&lt;br /&gt;
  &lt;br /&gt;
 // interrput code&lt;br /&gt;
 void __ISR( _TIMER_3_VECTOR, ipl7) T3Interrupt( void)&lt;br /&gt;
 {&lt;br /&gt;
 	if (++timeStep &amp;gt;= NUM_POINTS_PER_PERIOD)&lt;br /&gt;
 	{&lt;br /&gt;
 		timeStep = 0;&lt;br /&gt;
 	}&lt;br /&gt;
 	&lt;br /&gt;
 	SetDCOC1PWM(LookupTable[timeStep]);&lt;br /&gt;
 	SetDCOC2PWM(LookupTable[timeStep]);&lt;br /&gt;
 	&lt;br /&gt;
 	// clear interrupt flag and exit&lt;br /&gt;
 	mT3ClearIntFlag();&lt;br /&gt;
 } // T3 Interrupt&lt;/div&gt;</summary>
		<author><name>LawrenceChen</name></author>
	</entry>
	<entry>
		<id>https://hades.mech.northwestern.edu//index.php?title=File:20HzRC4-7.jpg&amp;diff=18421</id>
		<title>File:20HzRC4-7.jpg</title>
		<link rel="alternate" type="text/html" href="https://hades.mech.northwestern.edu//index.php?title=File:20HzRC4-7.jpg&amp;diff=18421"/>
		<updated>2010-05-31T03:02:38Z</updated>

		<summary type="html">&lt;p&gt;LawrenceChen: Oscilloscope reading of the sinusoidal analog output with a sine frequency of 25Hz, resistor of 47kOhms, and a capacitor of 0.1 microFarads.&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Oscilloscope reading of the sinusoidal analog output with a sine frequency of 25Hz, resistor of 47kOhms, and a capacitor of 0.1 microFarads.&lt;/div&gt;</summary>
		<author><name>LawrenceChen</name></author>
	</entry>
	<entry>
		<id>https://hades.mech.northwestern.edu//index.php?title=PIC32MX:_Sinusoidal_Analog_Output&amp;diff=18420</id>
		<title>PIC32MX: Sinusoidal Analog Output</title>
		<link rel="alternate" type="text/html" href="https://hades.mech.northwestern.edu//index.php?title=PIC32MX:_Sinusoidal_Analog_Output&amp;diff=18420"/>
		<updated>2010-05-31T03:00:14Z</updated>

		<summary type="html">&lt;p&gt;LawrenceChen: /* Frequency */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;The PIC32 is actually incapable of directly creating an analog output. Instead, the PIC32 can perform pulse width modulation (PWM) to create an average analog output. At a given frequency, PWM varies the time that the output pin is on (output is 3.3V) to create the duty cycle which can simulate voltages between 0V and 3.3V. For example, if the duty cycle is 50%, the PIC32 holds the pin at 3.3V 50% of the time and 0V for the other 50%. The average output voltage is then 1.65V. If the pin is connected to an external RC circuit, the PWM can be integrated. By varying the duty cycle sinusoidally, the output with an RC circuit can resemble a sinusoid. Thus, to create the sinusoidal output, a sinusoidal wave must be divided into a discrete number of points. These points can then be converted to a list of duty cycles to represent the sinusoid.&lt;br /&gt;
&lt;br /&gt;
The three most important parameters in creating the sinusoidal analog output are the the number of points per period, the RC time constant, and the sinusoid frequency. The combination of the sinusoid frequency and the points per period helps tell the PIC when to change the duty cycle. The RC constant of an external RC circuit is important in creating smooth and accurate curves and in improving the quality of the output signal.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The code for the analog output will first generate a lookup table. This table contains values for the specific duty cycles and will generate the number of duty cycles based on the number of points specified by the user. After generating the table, the code goes through a loop which tells the board to output the appropriate PWM corresponding to the duty cycle in the lookup table at each time step. The timing for the loop is determined by an interrupt which runs a frequency, &amp;lt;math&amp;gt;f&amp;lt;/math&amp;gt;, which tells the PIC when to switch to the next appropriate PWM from the lookup table. By looping through the duty cycles at the same time intervals, the output voltage is varied to match that of a sine wave. The external RC circuit acts to store the charges from the PWM and smooth the final output voltage to yield the sine wave. Without this external RC circuit, the output would only be a series of pulses matching the duty cycle at a given time.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The equation governing the sine wave is &lt;br /&gt;
&amp;lt;math&amp;gt;y=A*sin(\frac{2 \pi}{N*i})&amp;lt;/math&amp;gt;&lt;br /&gt;
where &amp;lt;math&amp;gt;A&amp;lt;/math&amp;gt; is the amplitude of the sinusoid, &amp;lt;math&amp;gt;N&amp;lt;/math&amp;gt; is the number of points and &amp;lt;math&amp;gt;i&amp;lt;/math&amp;gt; is the index.&lt;br /&gt;
&lt;br /&gt;
The equation governing the duty cycle is &lt;br /&gt;
&amp;lt;math&amp;gt;duty cycle = \frac{MAX\_DUTY}{2}y + \frac{MAX\_DUTY}{2}&amp;lt;/math&amp;gt;&lt;br /&gt;
where the &amp;lt;math&amp;gt;MAX\_DUTY&amp;lt;/math&amp;gt; is determined by the frequency of the PWM.&lt;br /&gt;
&lt;br /&gt;
The examples below have a PWM frequency of 20kHz.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Number of Points Per Period==&lt;br /&gt;
Selecting the number of points to use to generate the sine wave is important because choosing too few will result in a very rough sine wave. When the number of points is too low, you can actually see multiple RC charging graphs between each point. However, if we choose too many points, a peak appears at what should be 0V on the sine wave. To prevent this peek from occurring, one could insert an “if” statement in the lookup table generation loop that replaces all of the occurring 0’s into 1’s. Inclusion of the if statement would result in no true 0V output for that particular output. The ideal number of points for 25Hz is around 200 points.&lt;br /&gt;
&lt;br /&gt;
[[Image:500pts10Hz.jpg|frame|This demonstrates what happens when you pick too many points. The output signal has a peak occurring at the 0V area. This output signal used 500 points at 10Hz.]]&lt;br /&gt;
&lt;br /&gt;
[[Image:100pts25Hz.jpg|left|frame|This demonstrates what an ideal analog output should look like. This output was generated using 100 points at 25Hz.]]&lt;br /&gt;
&lt;br /&gt;
[[Image:10pts25Hz.jpg|center|frame|This demonstrates what happens when you select too few points. The output signal shows the capacitor charging. In this case, 10 points at 25Hz are used in generating the analog output.]]&lt;br /&gt;
&lt;br /&gt;
==RC Time Constant==&lt;br /&gt;
&lt;br /&gt;
The RC time constant plays a big role in creating the sine wave. By increasing the RC constant, the quality of the output signal is increased, where &amp;quot;quality&amp;quot; refers to the oscillations that appear around the sine wave that occur because of PWM. A larger oscillation around the sine wave means that it is of poorer quality. Despite having such advantages, a larger RC constant will result in a phase lag which causes a delay between the output of the PIC and the output from the whole circuit.&lt;br /&gt;
&lt;br /&gt;
[[Image:RCcompare.jpg|center|frame|The sine waves were generated at 25Hz with 100 points. The sine wave labeled 1 was generated with an RC constant of 4.7 x 10^-5, the sine wave labeled 2 was generated using an RC constant 2.2 x 10^-4 and the sine wave labeled 5 was generated using an RC constant 4.7 x 10^-3. Notice that sine waves 1 and 2 are almost synchronized, but sine waves 1 and 5 have a phase lag caused by the high RC constant. The improvement in quality is also visible in these two graphs. Sine wave 5 has an RC constant that&#039;s 100 times larger than that of sine wave 1, and there&#039;s very significant improvement in the quality of the output signal.]]&lt;br /&gt;
&lt;br /&gt;
==Frequency==&lt;br /&gt;
&lt;br /&gt;
There are two important frequencies that affect the performance of the PIC in generating the analog output. The first is the cut-off frequency, and the second is the sine frequency.&lt;br /&gt;
&lt;br /&gt;
The cut-off frequency is a function of the RC time constant. The equation to determine the cut-off frequency is &lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;f_c = \frac{1}{2 \pi R C}  \text{ Hz}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
where &amp;lt;math&amp;gt;f_c&amp;lt;/math&amp;gt; is the cut-off frequency (&amp;lt;math&amp;gt;\text{Hz}&amp;lt;/math&amp;gt;), &amp;lt;math&amp;gt;R&amp;lt;/math&amp;gt; is the resistance (&amp;lt;math&amp;gt;\Omega&amp;lt;/math&amp;gt;&#039;s) and &amp;lt;math&amp;gt;C&amp;lt;/math&amp;gt; is the capacitance (F).&lt;br /&gt;
&lt;br /&gt;
This cut-off frequency can cause a loss in the output amplitude. The determination of if the cut-off frequency is too high depends on the sine frequency. If the cut-off frequency is too high (RC constant is too low) relative to the sine frequency, then the output signal may be very noisy and may also have a decreased amplitude. If the cut-off frequency is too low (RC constant is too high) relative to the sine frequency, then the final output signal through the RC circuit will be more likely to have a decreased amplitude, thus you&#039;ll only get a limited range of voltages. Below are some results from experimentation with varying sine frequencies.&lt;br /&gt;
&lt;br /&gt;
[[Image:10HzRC4-7.jpg|left|frame|Oscilloscope reading of the sinusoidal analog output with a Sine Frequency of 25Hz with a resistor of 47 kOhms and a capacitor of 0.1 microFarads.]]&lt;br /&gt;
&lt;br /&gt;
==Sample Code==&lt;br /&gt;
&lt;br /&gt;
This sample code creates an analog output on PINS D0 and D1 using 200 points at a sine frequency of 25Hz.&lt;br /&gt;
&lt;br /&gt;
 /******************************************************&lt;br /&gt;
 Sinusoidal Output&lt;br /&gt;
 */&lt;br /&gt;
 &lt;br /&gt;
 #include &amp;quot;HardwareProfile.h&amp;quot;&lt;br /&gt;
 #include &amp;quot;math.h&amp;quot; &lt;br /&gt;
 &lt;br /&gt;
 #define DESIRED_BAUDRATE    	(9600)      // The desired BaudRate&lt;br /&gt;
 #define NUM_POINTS_PER_PERIOD		200&lt;br /&gt;
 &lt;br /&gt;
 int timeStep = 0;&lt;br /&gt;
 int LookupTable[NUM_POINTS_PER_PERIOD];&lt;br /&gt;
 &lt;br /&gt;
 int main(void)&lt;br /&gt;
 {&lt;br /&gt;
 	int sineFreq = 25;&lt;br /&gt;
 	int interruptFreq = NUM_POINTS_PER_PERIOD * sineFreq;&lt;br /&gt;
 	int periodValue = (SYS_FREQ / interruptFreq / 1) - 1;&lt;br /&gt;
 	&lt;br /&gt;
 	// Configure the proper PB frequency and the number of wait states&lt;br /&gt;
 	SYSTEMConfigPerformance(SYS_FREQ);&lt;br /&gt;
 &lt;br /&gt;
 	// Allow vector interrupts&lt;br /&gt;
 	INTEnableSystemMultiVectoredInt();&lt;br /&gt;
 	&lt;br /&gt;
 	// init OC1 module, on pin D0&lt;br /&gt;
 	OpenOC1( OC_ON | OC_TIMER2_SRC | OC_PWM_FAULT_PIN_DISABLE, 0, 0);&lt;br /&gt;
 	// init OC1 module, on pin D1&lt;br /&gt;
 	OpenOC2( OC_ON | OC_TIMER2_SRC | OC_PWM_FAULT_PIN_DISABLE, 0, 0);&lt;br /&gt;
 	&lt;br /&gt;
 	// init Timer2 mode and period (PR2) // produces 20kHz PWM&lt;br /&gt;
 	OpenTimer2( T2_ON | T2_PS_1_1 | T2_SOURCE_INT, 3999);&lt;br /&gt;
 &lt;br /&gt;
 &lt;br /&gt;
 	int i;&lt;br /&gt;
 	for (i = 0; i &amp;lt; NUM_POINTS_PER_PERIOD; i++)&lt;br /&gt;
 	{&lt;br /&gt;
 		LookupTable[i] = (int)(3999/2 * sin(2*M_PI/NUM_POINTS_PER_PERIOD*i)+ 3999/2); &lt;br /&gt;
 	}&lt;br /&gt;
 	&lt;br /&gt;
 &lt;br /&gt;
 	// init Timer3 for Sinusoid Interrupt&lt;br /&gt;
 	// Assume Prescalar is 2&lt;br /&gt;
 	// Need to verify that SYS_FREQ / sineFreq / numPoints &amp;lt; 65534&lt;br /&gt;
 	OpenTimer3( T3_ON | T3_PS_1_1 | T3_SOURCE_INT, periodValue); &lt;br /&gt;
 	&lt;br /&gt;
 	mT3SetIntPriority( 7); 	// set Timer3 Interrupt Priority&lt;br /&gt;
 	mT3ClearIntFlag(); 		// clear interrupt flag&lt;br /&gt;
 	mT3IntEnable( 1);		// enable timer3 interrupts&lt;br /&gt;
 &lt;br /&gt;
 	// this will store the string for the LCD&lt;br /&gt;
 	char LCDbuffer[33]; &lt;br /&gt;
 &lt;br /&gt;
 	while(1)&lt;br /&gt;
 	{&lt;br /&gt;
 		// Timer 3 ISR takes care of the code&lt;br /&gt;
 	}&lt;br /&gt;
 &lt;br /&gt;
 	CloseOC1();&lt;br /&gt;
 	&lt;br /&gt;
 }//end main&lt;br /&gt;
  &lt;br /&gt;
 // interrput code&lt;br /&gt;
 void __ISR( _TIMER_3_VECTOR, ipl7) T3Interrupt( void)&lt;br /&gt;
 {&lt;br /&gt;
 	if (++timeStep &amp;gt;= NUM_POINTS_PER_PERIOD)&lt;br /&gt;
 	{&lt;br /&gt;
 		timeStep = 0;&lt;br /&gt;
 	}&lt;br /&gt;
 	&lt;br /&gt;
 	SetDCOC1PWM(LookupTable[timeStep]);&lt;br /&gt;
 	SetDCOC2PWM(LookupTable[timeStep]);&lt;br /&gt;
 	&lt;br /&gt;
 	// clear interrupt flag and exit&lt;br /&gt;
 	mT3ClearIntFlag();&lt;br /&gt;
 } // T3 Interrupt&lt;/div&gt;</summary>
		<author><name>LawrenceChen</name></author>
	</entry>
	<entry>
		<id>https://hades.mech.northwestern.edu//index.php?title=File:10HzRC4-7.jpg&amp;diff=18419</id>
		<title>File:10HzRC4-7.jpg</title>
		<link rel="alternate" type="text/html" href="https://hades.mech.northwestern.edu//index.php?title=File:10HzRC4-7.jpg&amp;diff=18419"/>
		<updated>2010-05-31T02:57:46Z</updated>

		<summary type="html">&lt;p&gt;LawrenceChen: Oscilloscope reading of the sinusoidal analog output. Sine Frequency=10Hz, R=47 kOhms and C=0.1 microFarads.&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Oscilloscope reading of the sinusoidal analog output. Sine Frequency=10Hz, R=47 kOhms and C=0.1 microFarads.&lt;/div&gt;</summary>
		<author><name>LawrenceChen</name></author>
	</entry>
	<entry>
		<id>https://hades.mech.northwestern.edu//index.php?title=PIC32MX:_Sinusoidal_Analog_Output&amp;diff=18418</id>
		<title>PIC32MX: Sinusoidal Analog Output</title>
		<link rel="alternate" type="text/html" href="https://hades.mech.northwestern.edu//index.php?title=PIC32MX:_Sinusoidal_Analog_Output&amp;diff=18418"/>
		<updated>2010-05-31T02:54:25Z</updated>

		<summary type="html">&lt;p&gt;LawrenceChen: /* Frequency */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;The PIC32 is actually incapable of directly creating an analog output. Instead, the PIC32 can perform pulse width modulation (PWM) to create an average analog output. At a given frequency, PWM varies the time that the output pin is on (output is 3.3V) to create the duty cycle which can simulate voltages between 0V and 3.3V. For example, if the duty cycle is 50%, the PIC32 holds the pin at 3.3V 50% of the time and 0V for the other 50%. The average output voltage is then 1.65V. If the pin is connected to an external RC circuit, the PWM can be integrated. By varying the duty cycle sinusoidally, the output with an RC circuit can resemble a sinusoid. Thus, to create the sinusoidal output, a sinusoidal wave must be divided into a discrete number of points. These points can then be converted to a list of duty cycles to represent the sinusoid.&lt;br /&gt;
&lt;br /&gt;
The three most important parameters in creating the sinusoidal analog output are the the number of points per period, the RC time constant, and the sinusoid frequency. The combination of the sinusoid frequency and the points per period helps tell the PIC when to change the duty cycle. The RC constant of an external RC circuit is important in creating smooth and accurate curves and in improving the quality of the output signal.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The code for the analog output will first generate a lookup table. This table contains values for the specific duty cycles and will generate the number of duty cycles based on the number of points specified by the user. After generating the table, the code goes through a loop which tells the board to output the appropriate PWM corresponding to the duty cycle in the lookup table at each time step. The timing for the loop is determined by an interrupt which runs a frequency, &amp;lt;math&amp;gt;f&amp;lt;/math&amp;gt;, which tells the PIC when to switch to the next appropriate PWM from the lookup table. By looping through the duty cycles at the same time intervals, the output voltage is varied to match that of a sine wave. The external RC circuit acts to store the charges from the PWM and smooth the final output voltage to yield the sine wave. Without this external RC circuit, the output would only be a series of pulses matching the duty cycle at a given time.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The equation governing the sine wave is &lt;br /&gt;
&amp;lt;math&amp;gt;y=A*sin(\frac{2 \pi}{N*i})&amp;lt;/math&amp;gt;&lt;br /&gt;
where &amp;lt;math&amp;gt;A&amp;lt;/math&amp;gt; is the amplitude of the sinusoid, &amp;lt;math&amp;gt;N&amp;lt;/math&amp;gt; is the number of points and &amp;lt;math&amp;gt;i&amp;lt;/math&amp;gt; is the index.&lt;br /&gt;
&lt;br /&gt;
The equation governing the duty cycle is &lt;br /&gt;
&amp;lt;math&amp;gt;duty cycle = \frac{MAX\_DUTY}{2}y + \frac{MAX\_DUTY}{2}&amp;lt;/math&amp;gt;&lt;br /&gt;
where the &amp;lt;math&amp;gt;MAX\_DUTY&amp;lt;/math&amp;gt; is determined by the frequency of the PWM.&lt;br /&gt;
&lt;br /&gt;
The examples below have a PWM frequency of 20kHz.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Number of Points Per Period==&lt;br /&gt;
Selecting the number of points to use to generate the sine wave is important because choosing too few will result in a very rough sine wave. When the number of points is too low, you can actually see multiple RC charging graphs between each point. However, if we choose too many points, a peak appears at what should be 0V on the sine wave. To prevent this peek from occurring, one could insert an “if” statement in the lookup table generation loop that replaces all of the occurring 0’s into 1’s. Inclusion of the if statement would result in no true 0V output for that particular output. The ideal number of points for 25Hz is around 200 points.&lt;br /&gt;
&lt;br /&gt;
[[Image:500pts10Hz.jpg|frame|This demonstrates what happens when you pick too many points. The output signal has a peak occurring at the 0V area. This output signal used 500 points at 10Hz.]]&lt;br /&gt;
&lt;br /&gt;
[[Image:100pts25Hz.jpg|left|frame|This demonstrates what an ideal analog output should look like. This output was generated using 100 points at 25Hz.]]&lt;br /&gt;
&lt;br /&gt;
[[Image:10pts25Hz.jpg|center|frame|This demonstrates what happens when you select too few points. The output signal shows the capacitor charging. In this case, 10 points at 25Hz are used in generating the analog output.]]&lt;br /&gt;
&lt;br /&gt;
==RC Time Constant==&lt;br /&gt;
&lt;br /&gt;
The RC time constant plays a big role in creating the sine wave. By increasing the RC constant, the quality of the output signal is increased, where &amp;quot;quality&amp;quot; refers to the oscillations that appear around the sine wave that occur because of PWM. A larger oscillation around the sine wave means that it is of poorer quality. Despite having such advantages, a larger RC constant will result in a phase lag which causes a delay between the output of the PIC and the output from the whole circuit.&lt;br /&gt;
&lt;br /&gt;
[[Image:RCcompare.jpg|center|frame|The sine waves were generated at 25Hz with 100 points. The sine wave labeled 1 was generated with an RC constant of 4.7 x 10^-5, the sine wave labeled 2 was generated using an RC constant 2.2 x 10^-4 and the sine wave labeled 5 was generated using an RC constant 4.7 x 10^-3. Notice that sine waves 1 and 2 are almost synchronized, but sine waves 1 and 5 have a phase lag caused by the high RC constant. The improvement in quality is also visible in these two graphs. Sine wave 5 has an RC constant that&#039;s 100 times larger than that of sine wave 1, and there&#039;s very significant improvement in the quality of the output signal.]]&lt;br /&gt;
&lt;br /&gt;
==Frequency==&lt;br /&gt;
&lt;br /&gt;
There are two important frequencies that affect the performance of the PIC in generating the analog output. The first is the cut-off frequency, and the second is the sine frequency.&lt;br /&gt;
&lt;br /&gt;
The cut-off frequency is a function of the RC time constant. The equation to determine the cut-off frequency is &lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;f_c = \frac{1}{2 \pi R C}  \text{ Hz}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
where &amp;lt;math&amp;gt;f_c&amp;lt;/math&amp;gt; is the cut-off frequency (&amp;lt;math&amp;gt;\text{Hz}&amp;lt;/math&amp;gt;), &amp;lt;math&amp;gt;R&amp;lt;/math&amp;gt; is the resistance (&amp;lt;math&amp;gt;\Omega&amp;lt;/math&amp;gt;&#039;s) and &amp;lt;math&amp;gt;C&amp;lt;/math&amp;gt; is the capacitance (F).&lt;br /&gt;
&lt;br /&gt;
This cut-off frequency can cause a loss in the output amplitude. The determination of if the cut-off frequency is too high depends on the sine frequency. If the cut-off frequency is too high (RC constant is too low) relative to the sine frequency, then the output signal may be very noisy and may also have a decreased amplitude. If the cut-off frequency is too low (RC constant is too high) relative to the sine frequency, then the final output signal through the RC circuit will be more likely to have a decreased amplitude, thus you&#039;ll only get a limited range of voltages. Below are some results from experimentation with varying sine frequencies.&lt;br /&gt;
&lt;br /&gt;
[[Image:.jpg]]&lt;br /&gt;
&lt;br /&gt;
==Sample Code==&lt;br /&gt;
&lt;br /&gt;
This sample code creates an analog output on PINS D0 and D1 using 200 points at a sine frequency of 25Hz.&lt;br /&gt;
&lt;br /&gt;
 /******************************************************&lt;br /&gt;
 Sinusoidal Output&lt;br /&gt;
 */&lt;br /&gt;
 &lt;br /&gt;
 #include &amp;quot;HardwareProfile.h&amp;quot;&lt;br /&gt;
 #include &amp;quot;math.h&amp;quot; &lt;br /&gt;
 &lt;br /&gt;
 #define DESIRED_BAUDRATE    	(9600)      // The desired BaudRate&lt;br /&gt;
 #define NUM_POINTS_PER_PERIOD		200&lt;br /&gt;
 &lt;br /&gt;
 int timeStep = 0;&lt;br /&gt;
 int LookupTable[NUM_POINTS_PER_PERIOD];&lt;br /&gt;
 &lt;br /&gt;
 int main(void)&lt;br /&gt;
 {&lt;br /&gt;
 	int sineFreq = 25;&lt;br /&gt;
 	int interruptFreq = NUM_POINTS_PER_PERIOD * sineFreq;&lt;br /&gt;
 	int periodValue = (SYS_FREQ / interruptFreq / 1) - 1;&lt;br /&gt;
 	&lt;br /&gt;
 	// Configure the proper PB frequency and the number of wait states&lt;br /&gt;
 	SYSTEMConfigPerformance(SYS_FREQ);&lt;br /&gt;
 &lt;br /&gt;
 	// Allow vector interrupts&lt;br /&gt;
 	INTEnableSystemMultiVectoredInt();&lt;br /&gt;
 	&lt;br /&gt;
 	// init OC1 module, on pin D0&lt;br /&gt;
 	OpenOC1( OC_ON | OC_TIMER2_SRC | OC_PWM_FAULT_PIN_DISABLE, 0, 0);&lt;br /&gt;
 	// init OC1 module, on pin D1&lt;br /&gt;
 	OpenOC2( OC_ON | OC_TIMER2_SRC | OC_PWM_FAULT_PIN_DISABLE, 0, 0);&lt;br /&gt;
 	&lt;br /&gt;
 	// init Timer2 mode and period (PR2) // produces 20kHz PWM&lt;br /&gt;
 	OpenTimer2( T2_ON | T2_PS_1_1 | T2_SOURCE_INT, 3999);&lt;br /&gt;
 &lt;br /&gt;
 &lt;br /&gt;
 	int i;&lt;br /&gt;
 	for (i = 0; i &amp;lt; NUM_POINTS_PER_PERIOD; i++)&lt;br /&gt;
 	{&lt;br /&gt;
 		LookupTable[i] = (int)(3999/2 * sin(2*M_PI/NUM_POINTS_PER_PERIOD*i)+ 3999/2); &lt;br /&gt;
 	}&lt;br /&gt;
 	&lt;br /&gt;
 &lt;br /&gt;
 	// init Timer3 for Sinusoid Interrupt&lt;br /&gt;
 	// Assume Prescalar is 2&lt;br /&gt;
 	// Need to verify that SYS_FREQ / sineFreq / numPoints &amp;lt; 65534&lt;br /&gt;
 	OpenTimer3( T3_ON | T3_PS_1_1 | T3_SOURCE_INT, periodValue); &lt;br /&gt;
 	&lt;br /&gt;
 	mT3SetIntPriority( 7); 	// set Timer3 Interrupt Priority&lt;br /&gt;
 	mT3ClearIntFlag(); 		// clear interrupt flag&lt;br /&gt;
 	mT3IntEnable( 1);		// enable timer3 interrupts&lt;br /&gt;
 &lt;br /&gt;
 	// this will store the string for the LCD&lt;br /&gt;
 	char LCDbuffer[33]; &lt;br /&gt;
 &lt;br /&gt;
 	while(1)&lt;br /&gt;
 	{&lt;br /&gt;
 		// Timer 3 ISR takes care of the code&lt;br /&gt;
 	}&lt;br /&gt;
 &lt;br /&gt;
 	CloseOC1();&lt;br /&gt;
 	&lt;br /&gt;
 }//end main&lt;br /&gt;
  &lt;br /&gt;
 // interrput code&lt;br /&gt;
 void __ISR( _TIMER_3_VECTOR, ipl7) T3Interrupt( void)&lt;br /&gt;
 {&lt;br /&gt;
 	if (++timeStep &amp;gt;= NUM_POINTS_PER_PERIOD)&lt;br /&gt;
 	{&lt;br /&gt;
 		timeStep = 0;&lt;br /&gt;
 	}&lt;br /&gt;
 	&lt;br /&gt;
 	SetDCOC1PWM(LookupTable[timeStep]);&lt;br /&gt;
 	SetDCOC2PWM(LookupTable[timeStep]);&lt;br /&gt;
 	&lt;br /&gt;
 	// clear interrupt flag and exit&lt;br /&gt;
 	mT3ClearIntFlag();&lt;br /&gt;
 } // T3 Interrupt&lt;/div&gt;</summary>
		<author><name>LawrenceChen</name></author>
	</entry>
	<entry>
		<id>https://hades.mech.northwestern.edu//index.php?title=PIC32MX:_Sinusoidal_Analog_Output&amp;diff=18417</id>
		<title>PIC32MX: Sinusoidal Analog Output</title>
		<link rel="alternate" type="text/html" href="https://hades.mech.northwestern.edu//index.php?title=PIC32MX:_Sinusoidal_Analog_Output&amp;diff=18417"/>
		<updated>2010-05-31T02:54:09Z</updated>

		<summary type="html">&lt;p&gt;LawrenceChen: /* Frequency */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;The PIC32 is actually incapable of directly creating an analog output. Instead, the PIC32 can perform pulse width modulation (PWM) to create an average analog output. At a given frequency, PWM varies the time that the output pin is on (output is 3.3V) to create the duty cycle which can simulate voltages between 0V and 3.3V. For example, if the duty cycle is 50%, the PIC32 holds the pin at 3.3V 50% of the time and 0V for the other 50%. The average output voltage is then 1.65V. If the pin is connected to an external RC circuit, the PWM can be integrated. By varying the duty cycle sinusoidally, the output with an RC circuit can resemble a sinusoid. Thus, to create the sinusoidal output, a sinusoidal wave must be divided into a discrete number of points. These points can then be converted to a list of duty cycles to represent the sinusoid.&lt;br /&gt;
&lt;br /&gt;
The three most important parameters in creating the sinusoidal analog output are the the number of points per period, the RC time constant, and the sinusoid frequency. The combination of the sinusoid frequency and the points per period helps tell the PIC when to change the duty cycle. The RC constant of an external RC circuit is important in creating smooth and accurate curves and in improving the quality of the output signal.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The code for the analog output will first generate a lookup table. This table contains values for the specific duty cycles and will generate the number of duty cycles based on the number of points specified by the user. After generating the table, the code goes through a loop which tells the board to output the appropriate PWM corresponding to the duty cycle in the lookup table at each time step. The timing for the loop is determined by an interrupt which runs a frequency, &amp;lt;math&amp;gt;f&amp;lt;/math&amp;gt;, which tells the PIC when to switch to the next appropriate PWM from the lookup table. By looping through the duty cycles at the same time intervals, the output voltage is varied to match that of a sine wave. The external RC circuit acts to store the charges from the PWM and smooth the final output voltage to yield the sine wave. Without this external RC circuit, the output would only be a series of pulses matching the duty cycle at a given time.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The equation governing the sine wave is &lt;br /&gt;
&amp;lt;math&amp;gt;y=A*sin(\frac{2 \pi}{N*i})&amp;lt;/math&amp;gt;&lt;br /&gt;
where &amp;lt;math&amp;gt;A&amp;lt;/math&amp;gt; is the amplitude of the sinusoid, &amp;lt;math&amp;gt;N&amp;lt;/math&amp;gt; is the number of points and &amp;lt;math&amp;gt;i&amp;lt;/math&amp;gt; is the index.&lt;br /&gt;
&lt;br /&gt;
The equation governing the duty cycle is &lt;br /&gt;
&amp;lt;math&amp;gt;duty cycle = \frac{MAX\_DUTY}{2}y + \frac{MAX\_DUTY}{2}&amp;lt;/math&amp;gt;&lt;br /&gt;
where the &amp;lt;math&amp;gt;MAX\_DUTY&amp;lt;/math&amp;gt; is determined by the frequency of the PWM.&lt;br /&gt;
&lt;br /&gt;
The examples below have a PWM frequency of 20kHz.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Number of Points Per Period==&lt;br /&gt;
Selecting the number of points to use to generate the sine wave is important because choosing too few will result in a very rough sine wave. When the number of points is too low, you can actually see multiple RC charging graphs between each point. However, if we choose too many points, a peak appears at what should be 0V on the sine wave. To prevent this peek from occurring, one could insert an “if” statement in the lookup table generation loop that replaces all of the occurring 0’s into 1’s. Inclusion of the if statement would result in no true 0V output for that particular output. The ideal number of points for 25Hz is around 200 points.&lt;br /&gt;
&lt;br /&gt;
[[Image:500pts10Hz.jpg|frame|This demonstrates what happens when you pick too many points. The output signal has a peak occurring at the 0V area. This output signal used 500 points at 10Hz.]]&lt;br /&gt;
&lt;br /&gt;
[[Image:100pts25Hz.jpg|left|frame|This demonstrates what an ideal analog output should look like. This output was generated using 100 points at 25Hz.]]&lt;br /&gt;
&lt;br /&gt;
[[Image:10pts25Hz.jpg|center|frame|This demonstrates what happens when you select too few points. The output signal shows the capacitor charging. In this case, 10 points at 25Hz are used in generating the analog output.]]&lt;br /&gt;
&lt;br /&gt;
==RC Time Constant==&lt;br /&gt;
&lt;br /&gt;
The RC time constant plays a big role in creating the sine wave. By increasing the RC constant, the quality of the output signal is increased, where &amp;quot;quality&amp;quot; refers to the oscillations that appear around the sine wave that occur because of PWM. A larger oscillation around the sine wave means that it is of poorer quality. Despite having such advantages, a larger RC constant will result in a phase lag which causes a delay between the output of the PIC and the output from the whole circuit.&lt;br /&gt;
&lt;br /&gt;
[[Image:RCcompare.jpg|center|frame|The sine waves were generated at 25Hz with 100 points. The sine wave labeled 1 was generated with an RC constant of 4.7 x 10^-5, the sine wave labeled 2 was generated using an RC constant 2.2 x 10^-4 and the sine wave labeled 5 was generated using an RC constant 4.7 x 10^-3. Notice that sine waves 1 and 2 are almost synchronized, but sine waves 1 and 5 have a phase lag caused by the high RC constant. The improvement in quality is also visible in these two graphs. Sine wave 5 has an RC constant that&#039;s 100 times larger than that of sine wave 1, and there&#039;s very significant improvement in the quality of the output signal.]]&lt;br /&gt;
&lt;br /&gt;
==Frequency==&lt;br /&gt;
&lt;br /&gt;
There are two important frequencies that affect the performance of the PIC in generating the analog output. The first is the cut-off frequency, and the second is the sine frequency.&lt;br /&gt;
&lt;br /&gt;
The cut-off frequency is a function of the RC time constant. The equation to determine the cut-off frequency is &lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;f_c = \frac{1}{2 \pi R C}  \text{ Hz}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
where &amp;lt;math&amp;gt;f_c&amp;lt;/math&amp;gt; is the cut-off frequency (&amp;lt;math&amp;gt;\text{Hz}&amp;lt;/math&amp;gt;), &amp;lt;math&amp;gt;R&amp;lt;/math&amp;gt; is the resistance (&amp;lt;math&amp;gt;\Omega&amp;lt;/math&amp;gt;&#039;s) and &amp;lt;math&amp;gt;C&amp;lt;/math&amp;gt; is the capacitance (F).&lt;br /&gt;
&lt;br /&gt;
This cut-off frequency can cause a loss in the output amplitude. The determination of if the cut-off frequency is too high depends on the sine frequency. If the cut-off frequency is too high (RC constant is too low) relative to the sine frequency, then the output signal may be very noisy and may also have a decreased amplitude. If the cut-off frequency is too low (RC constant is too high) relative to the sine frequency, then the final output signal through the RC circuit will be more likely to have a decreased amplitude, thus you&#039;ll only get a limited range of voltages. Below are some results from experimentation with varying sine frequencies.&lt;br /&gt;
&lt;br /&gt;
[[Image:Example.jpg|Example.jpg]]&lt;br /&gt;
&lt;br /&gt;
==Sample Code==&lt;br /&gt;
&lt;br /&gt;
This sample code creates an analog output on PINS D0 and D1 using 200 points at a sine frequency of 25Hz.&lt;br /&gt;
&lt;br /&gt;
 /******************************************************&lt;br /&gt;
 Sinusoidal Output&lt;br /&gt;
 */&lt;br /&gt;
 &lt;br /&gt;
 #include &amp;quot;HardwareProfile.h&amp;quot;&lt;br /&gt;
 #include &amp;quot;math.h&amp;quot; &lt;br /&gt;
 &lt;br /&gt;
 #define DESIRED_BAUDRATE    	(9600)      // The desired BaudRate&lt;br /&gt;
 #define NUM_POINTS_PER_PERIOD		200&lt;br /&gt;
 &lt;br /&gt;
 int timeStep = 0;&lt;br /&gt;
 int LookupTable[NUM_POINTS_PER_PERIOD];&lt;br /&gt;
 &lt;br /&gt;
 int main(void)&lt;br /&gt;
 {&lt;br /&gt;
 	int sineFreq = 25;&lt;br /&gt;
 	int interruptFreq = NUM_POINTS_PER_PERIOD * sineFreq;&lt;br /&gt;
 	int periodValue = (SYS_FREQ / interruptFreq / 1) - 1;&lt;br /&gt;
 	&lt;br /&gt;
 	// Configure the proper PB frequency and the number of wait states&lt;br /&gt;
 	SYSTEMConfigPerformance(SYS_FREQ);&lt;br /&gt;
 &lt;br /&gt;
 	// Allow vector interrupts&lt;br /&gt;
 	INTEnableSystemMultiVectoredInt();&lt;br /&gt;
 	&lt;br /&gt;
 	// init OC1 module, on pin D0&lt;br /&gt;
 	OpenOC1( OC_ON | OC_TIMER2_SRC | OC_PWM_FAULT_PIN_DISABLE, 0, 0);&lt;br /&gt;
 	// init OC1 module, on pin D1&lt;br /&gt;
 	OpenOC2( OC_ON | OC_TIMER2_SRC | OC_PWM_FAULT_PIN_DISABLE, 0, 0);&lt;br /&gt;
 	&lt;br /&gt;
 	// init Timer2 mode and period (PR2) // produces 20kHz PWM&lt;br /&gt;
 	OpenTimer2( T2_ON | T2_PS_1_1 | T2_SOURCE_INT, 3999);&lt;br /&gt;
 &lt;br /&gt;
 &lt;br /&gt;
 	int i;&lt;br /&gt;
 	for (i = 0; i &amp;lt; NUM_POINTS_PER_PERIOD; i++)&lt;br /&gt;
 	{&lt;br /&gt;
 		LookupTable[i] = (int)(3999/2 * sin(2*M_PI/NUM_POINTS_PER_PERIOD*i)+ 3999/2); &lt;br /&gt;
 	}&lt;br /&gt;
 	&lt;br /&gt;
 &lt;br /&gt;
 	// init Timer3 for Sinusoid Interrupt&lt;br /&gt;
 	// Assume Prescalar is 2&lt;br /&gt;
 	// Need to verify that SYS_FREQ / sineFreq / numPoints &amp;lt; 65534&lt;br /&gt;
 	OpenTimer3( T3_ON | T3_PS_1_1 | T3_SOURCE_INT, periodValue); &lt;br /&gt;
 	&lt;br /&gt;
 	mT3SetIntPriority( 7); 	// set Timer3 Interrupt Priority&lt;br /&gt;
 	mT3ClearIntFlag(); 		// clear interrupt flag&lt;br /&gt;
 	mT3IntEnable( 1);		// enable timer3 interrupts&lt;br /&gt;
 &lt;br /&gt;
 	// this will store the string for the LCD&lt;br /&gt;
 	char LCDbuffer[33]; &lt;br /&gt;
 &lt;br /&gt;
 	while(1)&lt;br /&gt;
 	{&lt;br /&gt;
 		// Timer 3 ISR takes care of the code&lt;br /&gt;
 	}&lt;br /&gt;
 &lt;br /&gt;
 	CloseOC1();&lt;br /&gt;
 	&lt;br /&gt;
 }//end main&lt;br /&gt;
  &lt;br /&gt;
 // interrput code&lt;br /&gt;
 void __ISR( _TIMER_3_VECTOR, ipl7) T3Interrupt( void)&lt;br /&gt;
 {&lt;br /&gt;
 	if (++timeStep &amp;gt;= NUM_POINTS_PER_PERIOD)&lt;br /&gt;
 	{&lt;br /&gt;
 		timeStep = 0;&lt;br /&gt;
 	}&lt;br /&gt;
 	&lt;br /&gt;
 	SetDCOC1PWM(LookupTable[timeStep]);&lt;br /&gt;
 	SetDCOC2PWM(LookupTable[timeStep]);&lt;br /&gt;
 	&lt;br /&gt;
 	// clear interrupt flag and exit&lt;br /&gt;
 	mT3ClearIntFlag();&lt;br /&gt;
 } // T3 Interrupt&lt;/div&gt;</summary>
		<author><name>LawrenceChen</name></author>
	</entry>
	<entry>
		<id>https://hades.mech.northwestern.edu//index.php?title=PIC32MX:_Sinusoidal_Analog_Output&amp;diff=18387</id>
		<title>PIC32MX: Sinusoidal Analog Output</title>
		<link rel="alternate" type="text/html" href="https://hades.mech.northwestern.edu//index.php?title=PIC32MX:_Sinusoidal_Analog_Output&amp;diff=18387"/>
		<updated>2010-05-09T05:04:19Z</updated>

		<summary type="html">&lt;p&gt;LawrenceChen: /* Frequency */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;The PIC32 is actually incapable of directly creating an analog output. Instead, the PIC32 can perform pulse width modulation (PWM) to create an average analog output. At a given frequency, PWM varies the time that the output pin is on (output is 3.3V) to create the duty cycle which can simulate voltages between 0V and 3.3V. For example, if the duty cycle is 50%, the PIC32 holds the pin at 3.3V 50% of the time and 0V for the other 50%. The average output voltage is then 1.65V. If the pin is connected to an external RC circuit, the PWM can be integrated. By varying the duty cycle sinusoidally, the output with an RC circuit can resemble a sinusoid. Thus, to create the sinusoidal output, a sinusoidal wave must be divided into a discrete number of points. These points can then be converted to a list of duty cycles to represent the sinusoid.&lt;br /&gt;
&lt;br /&gt;
The three most important parameters in creating the sinusoidal analog output are the the number of points per period, the RC time constant, and the sinusoid frequency. The combination of the cutoff frequency and the points per period helps tell the PIC when to change the duty cycle. The RC constant of an external RC circuit is important in creating smooth and accurate curves and in improving the quality of the output signal.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The code for the analog output will first generate a lookup table. This table contains values for the specific duty cycles and will generate the number of duty cycles based on the number of points specified by the user. After generating the table, the code goes through a loop which tells the board to output the appropriate PWM corresponding to the duty cycle in the lookup table at each time step. The timing for the loop is determined by an interrupt which runs a frequency, &amp;lt;math&amp;gt;f&amp;lt;/math&amp;gt;, which tells the PIC when to switch to the next appropriate PWM from the lookup table. By looping through the duty cycles at the same time intervals, the output voltage is varied to match that of a sine wave. The external RC circuit acts to store the charges from the PWM and smooth the final output voltage to yield the sine wave. Without this external RC circuit, the output would only be a series of pulses matching the duty cycle at a given time.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The equation governing the sine wave is &lt;br /&gt;
&amp;lt;math&amp;gt;y=A*sin(\frac{2 \pi}{N*i})&amp;lt;/math&amp;gt;&lt;br /&gt;
where &amp;lt;math&amp;gt;A&amp;lt;/math&amp;gt; is the amplitude of the sinusoid, &amp;lt;math&amp;gt;N&amp;lt;/math&amp;gt; is the number of points and &amp;lt;math&amp;gt;i&amp;lt;/math&amp;gt; is the index.&lt;br /&gt;
&lt;br /&gt;
The equation governing the duty cycle is &lt;br /&gt;
&amp;lt;math&amp;gt;duty cycle = \frac{MAX\_DUTY}{2y} + \frac{MAX\_DUTY}{2}&amp;lt;/math&amp;gt;&lt;br /&gt;
where the &amp;lt;math&amp;gt;MAX\_DUTY&amp;lt;/math&amp;gt; is determined by the frequency of the PWM.&lt;br /&gt;
&lt;br /&gt;
The examples below have a PWM frequency of 20kHz.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Number of Points Per Period==&lt;br /&gt;
Selecting the number of points to use to generate the sine wave is important because choosing too few will result in a very rough sine wave. When the number of points is too low, you can actually see multiple RC charging graphs between each point. However, if we choose too many points, a peak appears at what should be 0V on the sine wave. To prevent this peek from occurring, one could insert an “if” statement in the lookup table generation loop that replaces all of the occurring 0’s into 1’s. Inclusion of the if statement would result in no true 0V output for that particular output. The ideal number of points for 25Hz is around 200 points.&lt;br /&gt;
&lt;br /&gt;
[[Image:500pts10Hz.jpg|frame|This demonstrates what happens when you pick too many points. The output signal has a peak occurring at the 0V area. This output signal used 500 points at 10Hz.]]&lt;br /&gt;
&lt;br /&gt;
[[Image:100pts25Hz.jpg|left|frame|This demonstrates what an ideal analog output should look like. This output was generated using 100 points at 25Hz.]]&lt;br /&gt;
&lt;br /&gt;
[[Image:10pts25Hz.jpg|center|frame|This demonstrates what happens when you select too few points. The output signal shows the capacitor charging. In this case, 10 points at 25Hz are used in generating the analog output.]]&lt;br /&gt;
&lt;br /&gt;
==RC Time Constant==&lt;br /&gt;
&lt;br /&gt;
The RC time constant plays a big role in creating the sine wave. By increasing the RC constant, the quality of the output signal is increased, where &amp;quot;quality&amp;quot; refers to the oscillations that appear around the sine wave that occur because of PWM. A larger oscillation around the sine wave means that it is of poorer quality. Despite having such advantages, a larger RC constant will result in a phase lag which causes a delay between the output of the PIC and the output from the whole circuit.&lt;br /&gt;
&lt;br /&gt;
[[Image:RCcompare.jpg|center|frame|The sine waves were generated at 25Hz with 100 points. The sine wave labeled 1 was generated with an RC constant of 4.7 x 10^-5, the sine wave labeled 2 was generated using an RC constant 2.2 x 10^-4 and the sine wave labeled 5 was generated using an RC constant 4.7 x 10^-3. Notice that sine waves 1 and 2 are almost synchronized, but sine waves 1 and 5 have a phase lag caused by the high RC constant. The improvement in quality is also visible in these two graphs. Sine wave 5 has an RC constant that&#039;s 100 times larger than that of sine wave 1, and there&#039;s very significant improvement in the quality of the output signal.]]&lt;br /&gt;
&lt;br /&gt;
==Frequency==&lt;br /&gt;
&lt;br /&gt;
There are two important frequencies that affect the performance of the PIC in generating the analog output. The first is the cut-off frequency, and the second is the sine frequency.&lt;br /&gt;
&lt;br /&gt;
The cut-off frequency is a function of the RC time constant. The equation to determine the cut-off frequency is &lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;f_c = \frac{1}{2 \pi R C}  \text{ Hz}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
where &amp;lt;math&amp;gt;f_c&amp;lt;/math&amp;gt; is the cut-off frequency (&amp;lt;math&amp;gt;\text{Hz}&amp;lt;/math&amp;gt;), &amp;lt;math&amp;gt;R&amp;lt;/math&amp;gt; is the resistance (&amp;lt;math&amp;gt;\Omega&amp;lt;/math&amp;gt;&#039;s) and &amp;lt;math&amp;gt;C&amp;lt;/math&amp;gt; is the capacitance (F).&lt;br /&gt;
&lt;br /&gt;
This cut-off frequency can cause a loss in the output amplitude. The determination of if the cut-off frequency is too high depends on the sine frequency. If the cut-off frequency is too high (RC constant is too low) relative to the sine frequency, then the output signal will be very noisy and not as clear. If the cut-off frequency is too low (RC constant is too high) relative to the sine frequency, then the final output signal through the RC circuit will be more likely to have a decreased amplitude, thus you&#039;ll only get a limited range of voltages.&lt;br /&gt;
&lt;br /&gt;
==Sample Code==&lt;br /&gt;
&lt;br /&gt;
This sample code creates an analog output on PINS D0 and D1 using 200 points at a sine frequency of 25Hz.&lt;br /&gt;
&lt;br /&gt;
 /******************************************************&lt;br /&gt;
 Sinusoidal Output&lt;br /&gt;
 */&lt;br /&gt;
 &lt;br /&gt;
 #include &amp;quot;HardwareProfile.h&amp;quot;&lt;br /&gt;
 #include &amp;quot;math.h&amp;quot; &lt;br /&gt;
 &lt;br /&gt;
 #define DESIRED_BAUDRATE    	(9600)      // The desired BaudRate&lt;br /&gt;
 #define NUM_POINTS_PER_PERIOD		200&lt;br /&gt;
 &lt;br /&gt;
 int timeStep = 0;&lt;br /&gt;
 int LookupTable[NUM_POINTS_PER_PERIOD];&lt;br /&gt;
 &lt;br /&gt;
 int main(void)&lt;br /&gt;
 {&lt;br /&gt;
 	int sineFreq = 25;&lt;br /&gt;
 	int interruptFreq = NUM_POINTS_PER_PERIOD * sineFreq;&lt;br /&gt;
 	int periodValue = (SYS_FREQ / interruptFreq / 1) - 1;&lt;br /&gt;
 	&lt;br /&gt;
 	// Configure the proper PB frequency and the number of wait states&lt;br /&gt;
 	SYSTEMConfigPerformance(SYS_FREQ);&lt;br /&gt;
 &lt;br /&gt;
 	// Allow vector interrupts&lt;br /&gt;
 	INTEnableSystemMultiVectoredInt();&lt;br /&gt;
 	&lt;br /&gt;
 	// init OC1 module, on pin D0&lt;br /&gt;
 	OpenOC1( OC_ON | OC_TIMER2_SRC | OC_PWM_FAULT_PIN_DISABLE, 0, 0);&lt;br /&gt;
 	// init OC1 module, on pin D1&lt;br /&gt;
 	OpenOC2( OC_ON | OC_TIMER2_SRC | OC_PWM_FAULT_PIN_DISABLE, 0, 0);&lt;br /&gt;
 	&lt;br /&gt;
 	// init Timer2 mode and period (PR2) // produces 20kHz PWM&lt;br /&gt;
 	OpenTimer2( T2_ON | T2_PS_1_1 | T2_SOURCE_INT, 3999);&lt;br /&gt;
 &lt;br /&gt;
 &lt;br /&gt;
 	int i;&lt;br /&gt;
 	for (i = 0; i &amp;lt; NUM_POINTS_PER_PERIOD; i++)&lt;br /&gt;
 	{&lt;br /&gt;
 		LookupTable[i] = (int)(3999/2 * sin(2*M_PI/NUM_POINTS_PER_PERIOD*i)+ 3999/2); &lt;br /&gt;
 	}&lt;br /&gt;
 	&lt;br /&gt;
 &lt;br /&gt;
 	// init Timer3 for Sinusoid Interrupt&lt;br /&gt;
 	// Assume Prescalar is 2&lt;br /&gt;
 	// Need to verify that SYS_FREQ / sineFreq / numPoints &amp;lt; 65534&lt;br /&gt;
 	OpenTimer3( T3_ON | T3_PS_1_1 | T3_SOURCE_INT, periodValue); &lt;br /&gt;
 	&lt;br /&gt;
 	mT3SetIntPriority( 7); 	// set Timer3 Interrupt Priority&lt;br /&gt;
 	mT3ClearIntFlag(); 		// clear interrupt flag&lt;br /&gt;
 	mT3IntEnable( 1);		// enable timer3 interrupts&lt;br /&gt;
 &lt;br /&gt;
 	// this will store the string for the LCD&lt;br /&gt;
 	char LCDbuffer[33]; &lt;br /&gt;
 &lt;br /&gt;
 	while(1)&lt;br /&gt;
 	{&lt;br /&gt;
 		// Timer 3 ISR takes care of the code&lt;br /&gt;
 	}&lt;br /&gt;
 &lt;br /&gt;
 	CloseOC1();&lt;br /&gt;
 	&lt;br /&gt;
 }//end main&lt;br /&gt;
  &lt;br /&gt;
 // interrput code&lt;br /&gt;
 void __ISR( _TIMER_3_VECTOR, ipl7) T3Interrupt( void)&lt;br /&gt;
 {&lt;br /&gt;
 	if (++timeStep &amp;gt;= NUM_POINTS_PER_PERIOD)&lt;br /&gt;
 	{&lt;br /&gt;
 		timeStep = 0;&lt;br /&gt;
 	}&lt;br /&gt;
 	&lt;br /&gt;
 	SetDCOC1PWM(LookupTable[timeStep]);&lt;br /&gt;
 	SetDCOC2PWM(LookupTable[timeStep]);&lt;br /&gt;
 	&lt;br /&gt;
 	// clear interrupt flag and exit&lt;br /&gt;
 	mT3ClearIntFlag();&lt;br /&gt;
 } // T3 Interrupt&lt;/div&gt;</summary>
		<author><name>LawrenceChen</name></author>
	</entry>
	<entry>
		<id>https://hades.mech.northwestern.edu//index.php?title=PIC32MX:_Sinusoidal_Analog_Output&amp;diff=18386</id>
		<title>PIC32MX: Sinusoidal Analog Output</title>
		<link rel="alternate" type="text/html" href="https://hades.mech.northwestern.edu//index.php?title=PIC32MX:_Sinusoidal_Analog_Output&amp;diff=18386"/>
		<updated>2010-05-09T04:56:28Z</updated>

		<summary type="html">&lt;p&gt;LawrenceChen: /* Sine Frequency */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;The PIC32 is actually incapable of directly creating an analog output. Instead, the PIC32 can perform pulse width modulation (PWM) to create an average analog output. At a given frequency, PWM varies the time that the output pin is on (output is 3.3V) to create the duty cycle which can simulate voltages between 0V and 3.3V. For example, if the duty cycle is 50%, the PIC32 holds the pin at 3.3V 50% of the time and 0V for the other 50%. The average output voltage is then 1.65V. If the pin is connected to an external RC circuit, the PWM can be integrated. By varying the duty cycle sinusoidally, the output with an RC circuit can resemble a sinusoid. Thus, to create the sinusoidal output, a sinusoidal wave must be divided into a discrete number of points. These points can then be converted to a list of duty cycles to represent the sinusoid.&lt;br /&gt;
&lt;br /&gt;
The three most important parameters in creating the sinusoidal analog output are the the number of points per period, the RC time constant, and the sinusoid frequency. The combination of the cutoff frequency and the points per period helps tell the PIC when to change the duty cycle. The RC constant of an external RC circuit is important in creating smooth and accurate curves and in improving the quality of the output signal.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The code for the analog output will first generate a lookup table. This table contains values for the specific duty cycles and will generate the number of duty cycles based on the number of points specified by the user. After generating the table, the code goes through a loop which tells the board to output the appropriate PWM corresponding to the duty cycle in the lookup table at each time step. The timing for the loop is determined by an interrupt which runs a frequency, &amp;lt;math&amp;gt;f&amp;lt;/math&amp;gt;, which tells the PIC when to switch to the next appropriate PWM from the lookup table. By looping through the duty cycles at the same time intervals, the output voltage is varied to match that of a sine wave. The external RC circuit acts to store the charges from the PWM and smooth the final output voltage to yield the sine wave. Without this external RC circuit, the output would only be a series of pulses matching the duty cycle at a given time.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The equation governing the sine wave is &lt;br /&gt;
&amp;lt;math&amp;gt;y=A*sin(\frac{2 \pi}{N*i})&amp;lt;/math&amp;gt;&lt;br /&gt;
where &amp;lt;math&amp;gt;A&amp;lt;/math&amp;gt; is the amplitude of the sinusoid, &amp;lt;math&amp;gt;N&amp;lt;/math&amp;gt; is the number of points and &amp;lt;math&amp;gt;i&amp;lt;/math&amp;gt; is the index.&lt;br /&gt;
&lt;br /&gt;
The equation governing the duty cycle is &lt;br /&gt;
&amp;lt;math&amp;gt;duty cycle = \frac{MAX\_DUTY}{2y} + \frac{MAX\_DUTY}{2}&amp;lt;/math&amp;gt;&lt;br /&gt;
where the &amp;lt;math&amp;gt;MAX\_DUTY&amp;lt;/math&amp;gt; is determined by the frequency of the PWM.&lt;br /&gt;
&lt;br /&gt;
The examples below have a PWM frequency of 20kHz.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Number of Points Per Period==&lt;br /&gt;
Selecting the number of points to use to generate the sine wave is important because choosing too few will result in a very rough sine wave. When the number of points is too low, you can actually see multiple RC charging graphs between each point. However, if we choose too many points, a peak appears at what should be 0V on the sine wave. To prevent this peek from occurring, one could insert an “if” statement in the lookup table generation loop that replaces all of the occurring 0’s into 1’s. Inclusion of the if statement would result in no true 0V output for that particular output. The ideal number of points for 25Hz is around 200 points.&lt;br /&gt;
&lt;br /&gt;
[[Image:500pts10Hz.jpg|frame|This demonstrates what happens when you pick too many points. The output signal has a peak occurring at the 0V area. This output signal used 500 points at 10Hz.]]&lt;br /&gt;
&lt;br /&gt;
[[Image:100pts25Hz.jpg|left|frame|This demonstrates what an ideal analog output should look like. This output was generated using 100 points at 25Hz.]]&lt;br /&gt;
&lt;br /&gt;
[[Image:10pts25Hz.jpg|center|frame|This demonstrates what happens when you select too few points. The output signal shows the capacitor charging. In this case, 10 points at 25Hz are used in generating the analog output.]]&lt;br /&gt;
&lt;br /&gt;
==RC Time Constant==&lt;br /&gt;
&lt;br /&gt;
The RC time constant plays a big role in creating the sine wave. By increasing the RC constant, the quality of the output signal is increased, where &amp;quot;quality&amp;quot; refers to the oscillations that appear around the sine wave that occur because of PWM. A larger oscillation around the sine wave means that it is of poorer quality. Despite having such advantages, a larger RC constant will result in a phase lag which causes a delay between the output of the PIC and the output from the whole circuit.&lt;br /&gt;
&lt;br /&gt;
[[Image:RCcompare.jpg|center|frame|The sine waves were generated at 25Hz with 100 points. The sine wave labeled 1 was generated with an RC constant of 4.7 x 10^-5, the sine wave labeled 2 was generated using an RC constant 2.2 x 10^-4 and the sine wave labeled 5 was generated using an RC constant 4.7 x 10^-3. Notice that sine waves 1 and 2 are almost synchronized, but sine waves 1 and 5 have a phase lag caused by the high RC constant. The improvement in quality is also visible in these two graphs. Sine wave 5 has an RC constant that&#039;s 100 times larger than that of sine wave 1, and there&#039;s very significant improvement in the quality of the output signal.]]&lt;br /&gt;
&lt;br /&gt;
==Frequency==&lt;br /&gt;
&lt;br /&gt;
There are two important frequencies that affect the performance of the PIC in generating the analog output. The first is the cut-off frequency, and the second is the sine frequency.&lt;br /&gt;
&lt;br /&gt;
The cut-off frequency is a function of the RC time constant. The equation to determine this cut-off frequency is &lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;f_c = \frac{1}{2 \pi R C}  \text{ Hz}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
where &amp;lt;math&amp;gt;f_c&amp;lt;/math&amp;gt; is the cut-off frequency (&amp;lt;math&amp;gt;\text{Hz}&amp;lt;/math&amp;gt;), &amp;lt;math&amp;gt;R&amp;lt;/math&amp;gt; is the resistance (&amp;lt;math&amp;gt;\Omega&amp;lt;/math&amp;gt;&#039;s) and &amp;lt;math&amp;gt;C&amp;lt;/math&amp;gt; is the capacitance (F).&lt;br /&gt;
&lt;br /&gt;
This cut-off frequency can cause a loss in the output amplitude.If the cut-off frequency is too high (RC constant is too low), then the output signal will be very noisy and not as clear. If the cut-off frequency is too low (RC constant is too high), then the final output signal through the RC circuit will be more likely to have a decreased amplitude, thus you&#039;ll only get a limited range of voltages.&lt;br /&gt;
&lt;br /&gt;
==Sample Code==&lt;br /&gt;
&lt;br /&gt;
This sample code creates an analog output on PINS D0 and D1 using 200 points at a sine frequency of 25Hz.&lt;br /&gt;
&lt;br /&gt;
 /******************************************************&lt;br /&gt;
 Sinusoidal Output&lt;br /&gt;
 */&lt;br /&gt;
 &lt;br /&gt;
 #include &amp;quot;HardwareProfile.h&amp;quot;&lt;br /&gt;
 #include &amp;quot;math.h&amp;quot; &lt;br /&gt;
 &lt;br /&gt;
 #define DESIRED_BAUDRATE    	(9600)      // The desired BaudRate&lt;br /&gt;
 #define NUM_POINTS_PER_PERIOD		200&lt;br /&gt;
 &lt;br /&gt;
 int timeStep = 0;&lt;br /&gt;
 int LookupTable[NUM_POINTS_PER_PERIOD];&lt;br /&gt;
 &lt;br /&gt;
 int main(void)&lt;br /&gt;
 {&lt;br /&gt;
 	int sineFreq = 25;&lt;br /&gt;
 	int interruptFreq = NUM_POINTS_PER_PERIOD * sineFreq;&lt;br /&gt;
 	int periodValue = (SYS_FREQ / interruptFreq / 1) - 1;&lt;br /&gt;
 	&lt;br /&gt;
 	// Configure the proper PB frequency and the number of wait states&lt;br /&gt;
 	SYSTEMConfigPerformance(SYS_FREQ);&lt;br /&gt;
 &lt;br /&gt;
 	// Allow vector interrupts&lt;br /&gt;
 	INTEnableSystemMultiVectoredInt();&lt;br /&gt;
 	&lt;br /&gt;
 	// init OC1 module, on pin D0&lt;br /&gt;
 	OpenOC1( OC_ON | OC_TIMER2_SRC | OC_PWM_FAULT_PIN_DISABLE, 0, 0);&lt;br /&gt;
 	// init OC1 module, on pin D1&lt;br /&gt;
 	OpenOC2( OC_ON | OC_TIMER2_SRC | OC_PWM_FAULT_PIN_DISABLE, 0, 0);&lt;br /&gt;
 	&lt;br /&gt;
 	// init Timer2 mode and period (PR2) // produces 20kHz PWM&lt;br /&gt;
 	OpenTimer2( T2_ON | T2_PS_1_1 | T2_SOURCE_INT, 3999);&lt;br /&gt;
 &lt;br /&gt;
 &lt;br /&gt;
 	int i;&lt;br /&gt;
 	for (i = 0; i &amp;lt; NUM_POINTS_PER_PERIOD; i++)&lt;br /&gt;
 	{&lt;br /&gt;
 		LookupTable[i] = (int)(3999/2 * sin(2*M_PI/NUM_POINTS_PER_PERIOD*i)+ 3999/2); &lt;br /&gt;
 	}&lt;br /&gt;
 	&lt;br /&gt;
 &lt;br /&gt;
 	// init Timer3 for Sinusoid Interrupt&lt;br /&gt;
 	// Assume Prescalar is 2&lt;br /&gt;
 	// Need to verify that SYS_FREQ / sineFreq / numPoints &amp;lt; 65534&lt;br /&gt;
 	OpenTimer3( T3_ON | T3_PS_1_1 | T3_SOURCE_INT, periodValue); &lt;br /&gt;
 	&lt;br /&gt;
 	mT3SetIntPriority( 7); 	// set Timer3 Interrupt Priority&lt;br /&gt;
 	mT3ClearIntFlag(); 		// clear interrupt flag&lt;br /&gt;
 	mT3IntEnable( 1);		// enable timer3 interrupts&lt;br /&gt;
 &lt;br /&gt;
 	// this will store the string for the LCD&lt;br /&gt;
 	char LCDbuffer[33]; &lt;br /&gt;
 &lt;br /&gt;
 	while(1)&lt;br /&gt;
 	{&lt;br /&gt;
 		// Timer 3 ISR takes care of the code&lt;br /&gt;
 	}&lt;br /&gt;
 &lt;br /&gt;
 	CloseOC1();&lt;br /&gt;
 	&lt;br /&gt;
 }//end main&lt;br /&gt;
  &lt;br /&gt;
 // interrput code&lt;br /&gt;
 void __ISR( _TIMER_3_VECTOR, ipl7) T3Interrupt( void)&lt;br /&gt;
 {&lt;br /&gt;
 	if (++timeStep &amp;gt;= NUM_POINTS_PER_PERIOD)&lt;br /&gt;
 	{&lt;br /&gt;
 		timeStep = 0;&lt;br /&gt;
 	}&lt;br /&gt;
 	&lt;br /&gt;
 	SetDCOC1PWM(LookupTable[timeStep]);&lt;br /&gt;
 	SetDCOC2PWM(LookupTable[timeStep]);&lt;br /&gt;
 	&lt;br /&gt;
 	// clear interrupt flag and exit&lt;br /&gt;
 	mT3ClearIntFlag();&lt;br /&gt;
 } // T3 Interrupt&lt;/div&gt;</summary>
		<author><name>LawrenceChen</name></author>
	</entry>
	<entry>
		<id>https://hades.mech.northwestern.edu//index.php?title=PIC32MX:_Sinusoidal_Analog_Output&amp;diff=18385</id>
		<title>PIC32MX: Sinusoidal Analog Output</title>
		<link rel="alternate" type="text/html" href="https://hades.mech.northwestern.edu//index.php?title=PIC32MX:_Sinusoidal_Analog_Output&amp;diff=18385"/>
		<updated>2010-05-09T04:33:06Z</updated>

		<summary type="html">&lt;p&gt;LawrenceChen: /* Sine Frequency */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;The PIC32 is actually incapable of directly creating an analog output. Instead, the PIC32 can perform pulse width modulation (PWM) to create an average analog output. At a given frequency, PWM varies the time that the output pin is on (output is 3.3V) to create the duty cycle which can simulate voltages between 0V and 3.3V. For example, if the duty cycle is 50%, the PIC32 holds the pin at 3.3V 50% of the time and 0V for the other 50%. The average output voltage is then 1.65V. If the pin is connected to an external RC circuit, the PWM can be integrated. By varying the duty cycle sinusoidally, the output with an RC circuit can resemble a sinusoid. Thus, to create the sinusoidal output, a sinusoidal wave must be divided into a discrete number of points. These points can then be converted to a list of duty cycles to represent the sinusoid.&lt;br /&gt;
&lt;br /&gt;
The three most important parameters in creating the sinusoidal analog output are the the number of points per period, the RC time constant, and the sinusoid frequency. The combination of the cutoff frequency and the points per period helps tell the PIC when to change the duty cycle. The RC constant of an external RC circuit is important in creating smooth and accurate curves and in improving the quality of the output signal.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The code for the analog output will first generate a lookup table. This table contains values for the specific duty cycles and will generate the number of duty cycles based on the number of points specified by the user. After generating the table, the code goes through a loop which tells the board to output the appropriate PWM corresponding to the duty cycle in the lookup table at each time step. The timing for the loop is determined by an interrupt which runs a frequency, &amp;lt;math&amp;gt;f&amp;lt;/math&amp;gt;, which tells the PIC when to switch to the next appropriate PWM from the lookup table. By looping through the duty cycles at the same time intervals, the output voltage is varied to match that of a sine wave. The external RC circuit acts to store the charges from the PWM and smooth the final output voltage to yield the sine wave. Without this external RC circuit, the output would only be a series of pulses matching the duty cycle at a given time.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The equation governing the sine wave is &lt;br /&gt;
&amp;lt;math&amp;gt;y=A*sin(\frac{2 \pi}{N*i})&amp;lt;/math&amp;gt;&lt;br /&gt;
where &amp;lt;math&amp;gt;A&amp;lt;/math&amp;gt; is the amplitude of the sinusoid, &amp;lt;math&amp;gt;N&amp;lt;/math&amp;gt; is the number of points and &amp;lt;math&amp;gt;i&amp;lt;/math&amp;gt; is the index.&lt;br /&gt;
&lt;br /&gt;
The equation governing the duty cycle is &lt;br /&gt;
&amp;lt;math&amp;gt;duty cycle = \frac{MAX\_DUTY}{2y} + \frac{MAX\_DUTY}{2}&amp;lt;/math&amp;gt;&lt;br /&gt;
where the &amp;lt;math&amp;gt;MAX\_DUTY&amp;lt;/math&amp;gt; is determined by the frequency of the PWM.&lt;br /&gt;
&lt;br /&gt;
The examples below have a PWM frequency of 20kHz.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Number of Points Per Period==&lt;br /&gt;
Selecting the number of points to use to generate the sine wave is important because choosing too few will result in a very rough sine wave. When the number of points is too low, you can actually see multiple RC charging graphs between each point. However, if we choose too many points, a peak appears at what should be 0V on the sine wave. To prevent this peek from occurring, one could insert an “if” statement in the lookup table generation loop that replaces all of the occurring 0’s into 1’s. Inclusion of the if statement would result in no true 0V output for that particular output. The ideal number of points for 25Hz is around 200 points.&lt;br /&gt;
&lt;br /&gt;
[[Image:500pts10Hz.jpg|frame|This demonstrates what happens when you pick too many points. The output signal has a peak occurring at the 0V area. This output signal used 500 points at 10Hz.]]&lt;br /&gt;
&lt;br /&gt;
[[Image:100pts25Hz.jpg|left|frame|This demonstrates what an ideal analog output should look like. This output was generated using 100 points at 25Hz.]]&lt;br /&gt;
&lt;br /&gt;
[[Image:10pts25Hz.jpg|center|frame|This demonstrates what happens when you select too few points. The output signal shows the capacitor charging. In this case, 10 points at 25Hz are used in generating the analog output.]]&lt;br /&gt;
&lt;br /&gt;
==RC Time Constant==&lt;br /&gt;
&lt;br /&gt;
The RC time constant plays a big role in creating the sine wave. By increasing the RC constant, the quality of the output signal is increased, where &amp;quot;quality&amp;quot; refers to the oscillations that appear around the sine wave that occur because of PWM. A larger oscillation around the sine wave means that it is of poorer quality. Despite having such advantages, a larger RC constant will result in a phase lag which causes a delay between the output of the PIC and the output from the whole circuit.&lt;br /&gt;
&lt;br /&gt;
[[Image:RCcompare.jpg|center|frame|The sine waves were generated at 25Hz with 100 points. The sine wave labeled 1 was generated with an RC constant of 4.7 x 10^-5, the sine wave labeled 2 was generated using an RC constant 2.2 x 10^-4 and the sine wave labeled 5 was generated using an RC constant 4.7 x 10^-3. Notice that sine waves 1 and 2 are almost synchronized, but sine waves 1 and 5 have a phase lag caused by the high RC constant. The improvement in quality is also visible in these two graphs. Sine wave 5 has an RC constant that&#039;s 100 times larger than that of sine wave 1, and there&#039;s very significant improvement in the quality of the output signal.]]&lt;br /&gt;
&lt;br /&gt;
==Frequency==&lt;br /&gt;
&lt;br /&gt;
==Sample Code==&lt;br /&gt;
&lt;br /&gt;
This sample code creates an analog output on PINS D0 and D1 using 200 points at a sine frequency of 25Hz.&lt;br /&gt;
&lt;br /&gt;
 /******************************************************&lt;br /&gt;
 Sinusoidal Output&lt;br /&gt;
 */&lt;br /&gt;
 &lt;br /&gt;
 #include &amp;quot;HardwareProfile.h&amp;quot;&lt;br /&gt;
 #include &amp;quot;math.h&amp;quot; &lt;br /&gt;
 &lt;br /&gt;
 #define DESIRED_BAUDRATE    	(9600)      // The desired BaudRate&lt;br /&gt;
 #define NUM_POINTS_PER_PERIOD		200&lt;br /&gt;
 &lt;br /&gt;
 int timeStep = 0;&lt;br /&gt;
 int LookupTable[NUM_POINTS_PER_PERIOD];&lt;br /&gt;
 &lt;br /&gt;
 int main(void)&lt;br /&gt;
 {&lt;br /&gt;
 	int sineFreq = 25;&lt;br /&gt;
 	int interruptFreq = NUM_POINTS_PER_PERIOD * sineFreq;&lt;br /&gt;
 	int periodValue = (SYS_FREQ / interruptFreq / 1) - 1;&lt;br /&gt;
 	&lt;br /&gt;
 	// Configure the proper PB frequency and the number of wait states&lt;br /&gt;
 	SYSTEMConfigPerformance(SYS_FREQ);&lt;br /&gt;
 &lt;br /&gt;
 	// Allow vector interrupts&lt;br /&gt;
 	INTEnableSystemMultiVectoredInt();&lt;br /&gt;
 	&lt;br /&gt;
 	// init OC1 module, on pin D0&lt;br /&gt;
 	OpenOC1( OC_ON | OC_TIMER2_SRC | OC_PWM_FAULT_PIN_DISABLE, 0, 0);&lt;br /&gt;
 	// init OC1 module, on pin D1&lt;br /&gt;
 	OpenOC2( OC_ON | OC_TIMER2_SRC | OC_PWM_FAULT_PIN_DISABLE, 0, 0);&lt;br /&gt;
 	&lt;br /&gt;
 	// init Timer2 mode and period (PR2) // produces 20kHz PWM&lt;br /&gt;
 	OpenTimer2( T2_ON | T2_PS_1_1 | T2_SOURCE_INT, 3999);&lt;br /&gt;
 &lt;br /&gt;
 &lt;br /&gt;
 	int i;&lt;br /&gt;
 	for (i = 0; i &amp;lt; NUM_POINTS_PER_PERIOD; i++)&lt;br /&gt;
 	{&lt;br /&gt;
 		LookupTable[i] = (int)(3999/2 * sin(2*M_PI/NUM_POINTS_PER_PERIOD*i)+ 3999/2); &lt;br /&gt;
 	}&lt;br /&gt;
 	&lt;br /&gt;
 &lt;br /&gt;
 	// init Timer3 for Sinusoid Interrupt&lt;br /&gt;
 	// Assume Prescalar is 2&lt;br /&gt;
 	// Need to verify that SYS_FREQ / sineFreq / numPoints &amp;lt; 65534&lt;br /&gt;
 	OpenTimer3( T3_ON | T3_PS_1_1 | T3_SOURCE_INT, periodValue); &lt;br /&gt;
 	&lt;br /&gt;
 	mT3SetIntPriority( 7); 	// set Timer3 Interrupt Priority&lt;br /&gt;
 	mT3ClearIntFlag(); 		// clear interrupt flag&lt;br /&gt;
 	mT3IntEnable( 1);		// enable timer3 interrupts&lt;br /&gt;
 &lt;br /&gt;
 	// this will store the string for the LCD&lt;br /&gt;
 	char LCDbuffer[33]; &lt;br /&gt;
 &lt;br /&gt;
 	while(1)&lt;br /&gt;
 	{&lt;br /&gt;
 		// Timer 3 ISR takes care of the code&lt;br /&gt;
 	}&lt;br /&gt;
 &lt;br /&gt;
 	CloseOC1();&lt;br /&gt;
 	&lt;br /&gt;
 }//end main&lt;br /&gt;
  &lt;br /&gt;
 // interrput code&lt;br /&gt;
 void __ISR( _TIMER_3_VECTOR, ipl7) T3Interrupt( void)&lt;br /&gt;
 {&lt;br /&gt;
 	if (++timeStep &amp;gt;= NUM_POINTS_PER_PERIOD)&lt;br /&gt;
 	{&lt;br /&gt;
 		timeStep = 0;&lt;br /&gt;
 	}&lt;br /&gt;
 	&lt;br /&gt;
 	SetDCOC1PWM(LookupTable[timeStep]);&lt;br /&gt;
 	SetDCOC2PWM(LookupTable[timeStep]);&lt;br /&gt;
 	&lt;br /&gt;
 	// clear interrupt flag and exit&lt;br /&gt;
 	mT3ClearIntFlag();&lt;br /&gt;
 } // T3 Interrupt&lt;/div&gt;</summary>
		<author><name>LawrenceChen</name></author>
	</entry>
	<entry>
		<id>https://hades.mech.northwestern.edu//index.php?title=PIC32MX:_Sinusoidal_Analog_Output&amp;diff=18384</id>
		<title>PIC32MX: Sinusoidal Analog Output</title>
		<link rel="alternate" type="text/html" href="https://hades.mech.northwestern.edu//index.php?title=PIC32MX:_Sinusoidal_Analog_Output&amp;diff=18384"/>
		<updated>2010-05-09T04:31:41Z</updated>

		<summary type="html">&lt;p&gt;LawrenceChen: /* RC Time Constant */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;The PIC32 is actually incapable of directly creating an analog output. Instead, the PIC32 can perform pulse width modulation (PWM) to create an average analog output. At a given frequency, PWM varies the time that the output pin is on (output is 3.3V) to create the duty cycle which can simulate voltages between 0V and 3.3V. For example, if the duty cycle is 50%, the PIC32 holds the pin at 3.3V 50% of the time and 0V for the other 50%. The average output voltage is then 1.65V. If the pin is connected to an external RC circuit, the PWM can be integrated. By varying the duty cycle sinusoidally, the output with an RC circuit can resemble a sinusoid. Thus, to create the sinusoidal output, a sinusoidal wave must be divided into a discrete number of points. These points can then be converted to a list of duty cycles to represent the sinusoid.&lt;br /&gt;
&lt;br /&gt;
The three most important parameters in creating the sinusoidal analog output are the the number of points per period, the RC time constant, and the sinusoid frequency. The combination of the cutoff frequency and the points per period helps tell the PIC when to change the duty cycle. The RC constant of an external RC circuit is important in creating smooth and accurate curves and in improving the quality of the output signal.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The code for the analog output will first generate a lookup table. This table contains values for the specific duty cycles and will generate the number of duty cycles based on the number of points specified by the user. After generating the table, the code goes through a loop which tells the board to output the appropriate PWM corresponding to the duty cycle in the lookup table at each time step. The timing for the loop is determined by an interrupt which runs a frequency, &amp;lt;math&amp;gt;f&amp;lt;/math&amp;gt;, which tells the PIC when to switch to the next appropriate PWM from the lookup table. By looping through the duty cycles at the same time intervals, the output voltage is varied to match that of a sine wave. The external RC circuit acts to store the charges from the PWM and smooth the final output voltage to yield the sine wave. Without this external RC circuit, the output would only be a series of pulses matching the duty cycle at a given time.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The equation governing the sine wave is &lt;br /&gt;
&amp;lt;math&amp;gt;y=A*sin(\frac{2 \pi}{N*i})&amp;lt;/math&amp;gt;&lt;br /&gt;
where &amp;lt;math&amp;gt;A&amp;lt;/math&amp;gt; is the amplitude of the sinusoid, &amp;lt;math&amp;gt;N&amp;lt;/math&amp;gt; is the number of points and &amp;lt;math&amp;gt;i&amp;lt;/math&amp;gt; is the index.&lt;br /&gt;
&lt;br /&gt;
The equation governing the duty cycle is &lt;br /&gt;
&amp;lt;math&amp;gt;duty cycle = \frac{MAX\_DUTY}{2y} + \frac{MAX\_DUTY}{2}&amp;lt;/math&amp;gt;&lt;br /&gt;
where the &amp;lt;math&amp;gt;MAX\_DUTY&amp;lt;/math&amp;gt; is determined by the frequency of the PWM.&lt;br /&gt;
&lt;br /&gt;
The examples below have a PWM frequency of 20kHz.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Number of Points Per Period==&lt;br /&gt;
Selecting the number of points to use to generate the sine wave is important because choosing too few will result in a very rough sine wave. When the number of points is too low, you can actually see multiple RC charging graphs between each point. However, if we choose too many points, a peak appears at what should be 0V on the sine wave. To prevent this peek from occurring, one could insert an “if” statement in the lookup table generation loop that replaces all of the occurring 0’s into 1’s. Inclusion of the if statement would result in no true 0V output for that particular output. The ideal number of points for 25Hz is around 200 points.&lt;br /&gt;
&lt;br /&gt;
[[Image:500pts10Hz.jpg|frame|This demonstrates what happens when you pick too many points. The output signal has a peak occurring at the 0V area. This output signal used 500 points at 10Hz.]]&lt;br /&gt;
&lt;br /&gt;
[[Image:100pts25Hz.jpg|left|frame|This demonstrates what an ideal analog output should look like. This output was generated using 100 points at 25Hz.]]&lt;br /&gt;
&lt;br /&gt;
[[Image:10pts25Hz.jpg|center|frame|This demonstrates what happens when you select too few points. The output signal shows the capacitor charging. In this case, 10 points at 25Hz are used in generating the analog output.]]&lt;br /&gt;
&lt;br /&gt;
==RC Time Constant==&lt;br /&gt;
&lt;br /&gt;
The RC time constant plays a big role in creating the sine wave. By increasing the RC constant, the quality of the output signal is increased, where &amp;quot;quality&amp;quot; refers to the oscillations that appear around the sine wave that occur because of PWM. A larger oscillation around the sine wave means that it is of poorer quality. Despite having such advantages, a larger RC constant will result in a phase lag which causes a delay between the output of the PIC and the output from the whole circuit.&lt;br /&gt;
&lt;br /&gt;
[[Image:RCcompare.jpg|center|frame|The sine waves were generated at 25Hz with 100 points. The sine wave labeled 1 was generated with an RC constant of 4.7 x 10^-5, the sine wave labeled 2 was generated using an RC constant 2.2 x 10^-4 and the sine wave labeled 5 was generated using an RC constant 4.7 x 10^-3. Notice that sine waves 1 and 2 are almost synchronized, but sine waves 1 and 5 have a phase lag caused by the high RC constant. The improvement in quality is also visible in these two graphs. Sine wave 5 has an RC constant that&#039;s 100 times larger than that of sine wave 1, and there&#039;s very significant improvement in the quality of the output signal.]]&lt;br /&gt;
&lt;br /&gt;
==Sine Frequency==&lt;br /&gt;
&lt;br /&gt;
==Sample Code==&lt;br /&gt;
&lt;br /&gt;
This sample code creates an analog output on PINS D0 and D1 using 200 points at a sine frequency of 25Hz.&lt;br /&gt;
&lt;br /&gt;
 /******************************************************&lt;br /&gt;
 Sinusoidal Output&lt;br /&gt;
 */&lt;br /&gt;
 &lt;br /&gt;
 #include &amp;quot;HardwareProfile.h&amp;quot;&lt;br /&gt;
 #include &amp;quot;math.h&amp;quot; &lt;br /&gt;
 &lt;br /&gt;
 #define DESIRED_BAUDRATE    	(9600)      // The desired BaudRate&lt;br /&gt;
 #define NUM_POINTS_PER_PERIOD		200&lt;br /&gt;
 &lt;br /&gt;
 int timeStep = 0;&lt;br /&gt;
 int LookupTable[NUM_POINTS_PER_PERIOD];&lt;br /&gt;
 &lt;br /&gt;
 int main(void)&lt;br /&gt;
 {&lt;br /&gt;
 	int sineFreq = 25;&lt;br /&gt;
 	int interruptFreq = NUM_POINTS_PER_PERIOD * sineFreq;&lt;br /&gt;
 	int periodValue = (SYS_FREQ / interruptFreq / 1) - 1;&lt;br /&gt;
 	&lt;br /&gt;
 	// Configure the proper PB frequency and the number of wait states&lt;br /&gt;
 	SYSTEMConfigPerformance(SYS_FREQ);&lt;br /&gt;
 &lt;br /&gt;
 	// Allow vector interrupts&lt;br /&gt;
 	INTEnableSystemMultiVectoredInt();&lt;br /&gt;
 	&lt;br /&gt;
 	// init OC1 module, on pin D0&lt;br /&gt;
 	OpenOC1( OC_ON | OC_TIMER2_SRC | OC_PWM_FAULT_PIN_DISABLE, 0, 0);&lt;br /&gt;
 	// init OC1 module, on pin D1&lt;br /&gt;
 	OpenOC2( OC_ON | OC_TIMER2_SRC | OC_PWM_FAULT_PIN_DISABLE, 0, 0);&lt;br /&gt;
 	&lt;br /&gt;
 	// init Timer2 mode and period (PR2) // produces 20kHz PWM&lt;br /&gt;
 	OpenTimer2( T2_ON | T2_PS_1_1 | T2_SOURCE_INT, 3999);&lt;br /&gt;
 &lt;br /&gt;
 &lt;br /&gt;
 	int i;&lt;br /&gt;
 	for (i = 0; i &amp;lt; NUM_POINTS_PER_PERIOD; i++)&lt;br /&gt;
 	{&lt;br /&gt;
 		LookupTable[i] = (int)(3999/2 * sin(2*M_PI/NUM_POINTS_PER_PERIOD*i)+ 3999/2); &lt;br /&gt;
 	}&lt;br /&gt;
 	&lt;br /&gt;
 &lt;br /&gt;
 	// init Timer3 for Sinusoid Interrupt&lt;br /&gt;
 	// Assume Prescalar is 2&lt;br /&gt;
 	// Need to verify that SYS_FREQ / sineFreq / numPoints &amp;lt; 65534&lt;br /&gt;
 	OpenTimer3( T3_ON | T3_PS_1_1 | T3_SOURCE_INT, periodValue); &lt;br /&gt;
 	&lt;br /&gt;
 	mT3SetIntPriority( 7); 	// set Timer3 Interrupt Priority&lt;br /&gt;
 	mT3ClearIntFlag(); 		// clear interrupt flag&lt;br /&gt;
 	mT3IntEnable( 1);		// enable timer3 interrupts&lt;br /&gt;
 &lt;br /&gt;
 	// this will store the string for the LCD&lt;br /&gt;
 	char LCDbuffer[33]; &lt;br /&gt;
 &lt;br /&gt;
 	while(1)&lt;br /&gt;
 	{&lt;br /&gt;
 		// Timer 3 ISR takes care of the code&lt;br /&gt;
 	}&lt;br /&gt;
 &lt;br /&gt;
 	CloseOC1();&lt;br /&gt;
 	&lt;br /&gt;
 }//end main&lt;br /&gt;
  &lt;br /&gt;
 // interrput code&lt;br /&gt;
 void __ISR( _TIMER_3_VECTOR, ipl7) T3Interrupt( void)&lt;br /&gt;
 {&lt;br /&gt;
 	if (++timeStep &amp;gt;= NUM_POINTS_PER_PERIOD)&lt;br /&gt;
 	{&lt;br /&gt;
 		timeStep = 0;&lt;br /&gt;
 	}&lt;br /&gt;
 	&lt;br /&gt;
 	SetDCOC1PWM(LookupTable[timeStep]);&lt;br /&gt;
 	SetDCOC2PWM(LookupTable[timeStep]);&lt;br /&gt;
 	&lt;br /&gt;
 	// clear interrupt flag and exit&lt;br /&gt;
 	mT3ClearIntFlag();&lt;br /&gt;
 } // T3 Interrupt&lt;/div&gt;</summary>
		<author><name>LawrenceChen</name></author>
	</entry>
	<entry>
		<id>https://hades.mech.northwestern.edu//index.php?title=PIC32MX:_Sinusoidal_Analog_Output&amp;diff=18383</id>
		<title>PIC32MX: Sinusoidal Analog Output</title>
		<link rel="alternate" type="text/html" href="https://hades.mech.northwestern.edu//index.php?title=PIC32MX:_Sinusoidal_Analog_Output&amp;diff=18383"/>
		<updated>2010-05-09T04:18:07Z</updated>

		<summary type="html">&lt;p&gt;LawrenceChen: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;The PIC32 is actually incapable of directly creating an analog output. Instead, the PIC32 can perform pulse width modulation (PWM) to create an average analog output. At a given frequency, PWM varies the time that the output pin is on (output is 3.3V) to create the duty cycle which can simulate voltages between 0V and 3.3V. For example, if the duty cycle is 50%, the PIC32 holds the pin at 3.3V 50% of the time and 0V for the other 50%. The average output voltage is then 1.65V. If the pin is connected to an external RC circuit, the PWM can be integrated. By varying the duty cycle sinusoidally, the output with an RC circuit can resemble a sinusoid. Thus, to create the sinusoidal output, a sinusoidal wave must be divided into a discrete number of points. These points can then be converted to a list of duty cycles to represent the sinusoid.&lt;br /&gt;
&lt;br /&gt;
The three most important parameters in creating the sinusoidal analog output are the the number of points per period, the RC time constant, and the sinusoid frequency. The combination of the cutoff frequency and the points per period helps tell the PIC when to change the duty cycle. The RC constant of an external RC circuit is important in creating smooth and accurate curves and in improving the quality of the output signal.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The code for the analog output will first generate a lookup table. This table contains values for the specific duty cycles and will generate the number of duty cycles based on the number of points specified by the user. After generating the table, the code goes through a loop which tells the board to output the appropriate PWM corresponding to the duty cycle in the lookup table at each time step. The timing for the loop is determined by an interrupt which runs a frequency, &amp;lt;math&amp;gt;f&amp;lt;/math&amp;gt;, which tells the PIC when to switch to the next appropriate PWM from the lookup table. By looping through the duty cycles at the same time intervals, the output voltage is varied to match that of a sine wave. The external RC circuit acts to store the charges from the PWM and smooth the final output voltage to yield the sine wave. Without this external RC circuit, the output would only be a series of pulses matching the duty cycle at a given time.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The equation governing the sine wave is &lt;br /&gt;
&amp;lt;math&amp;gt;y=A*sin(\frac{2 \pi}{N*i})&amp;lt;/math&amp;gt;&lt;br /&gt;
where &amp;lt;math&amp;gt;A&amp;lt;/math&amp;gt; is the amplitude of the sinusoid, &amp;lt;math&amp;gt;N&amp;lt;/math&amp;gt; is the number of points and &amp;lt;math&amp;gt;i&amp;lt;/math&amp;gt; is the index.&lt;br /&gt;
&lt;br /&gt;
The equation governing the duty cycle is &lt;br /&gt;
&amp;lt;math&amp;gt;duty cycle = \frac{MAX\_DUTY}{2y} + \frac{MAX\_DUTY}{2}&amp;lt;/math&amp;gt;&lt;br /&gt;
where the &amp;lt;math&amp;gt;MAX\_DUTY&amp;lt;/math&amp;gt; is determined by the frequency of the PWM.&lt;br /&gt;
&lt;br /&gt;
The examples below have a PWM frequency of 20kHz.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Number of Points Per Period==&lt;br /&gt;
Selecting the number of points to use to generate the sine wave is important because choosing too few will result in a very rough sine wave. When the number of points is too low, you can actually see multiple RC charging graphs between each point. However, if we choose too many points, a peak appears at what should be 0V on the sine wave. To prevent this peek from occurring, one could insert an “if” statement in the lookup table generation loop that replaces all of the occurring 0’s into 1’s. Inclusion of the if statement would result in no true 0V output for that particular output. The ideal number of points for 25Hz is around 200 points.&lt;br /&gt;
&lt;br /&gt;
[[Image:500pts10Hz.jpg|frame|This demonstrates what happens when you pick too many points. The output signal has a peak occurring at the 0V area. This output signal used 500 points at 10Hz.]]&lt;br /&gt;
&lt;br /&gt;
[[Image:100pts25Hz.jpg|left|frame|This demonstrates what an ideal analog output should look like. This output was generated using 100 points at 25Hz.]]&lt;br /&gt;
&lt;br /&gt;
[[Image:10pts25Hz.jpg|center|frame|This demonstrates what happens when you select too few points. The output signal shows the capacitor charging. In this case, 10 points at 25Hz are used in generating the analog output.]]&lt;br /&gt;
&lt;br /&gt;
==RC Time Constant==&lt;br /&gt;
&lt;br /&gt;
The RC time constant plays a big role in creating the sine wave. By increasing the RC constant, the quality of the output signal is increased, where &amp;quot;quality&amp;quot; refers to the width of the output signals. Despite having such advantages, a larger RC constant will result in a phase lag which causes a delay between the output of the PIC and the output from the whole circuit.&lt;br /&gt;
&lt;br /&gt;
[[Image:RCcompare.jpg|center|frame|The sine waves were generated at 25Hz with 100 points. The sine wave labeled 1 was generated with an RC constant of 4.7 x 10^-5, the sine wave labeled 2 was generated using an RC constant 2.2 x 10^-4 and the sine wave labeled 5 was generated using an RC constant 4.7 x 10^-3. Notice that sine waves 1 and 2 are almost synchronized, but sine waves 1 and 5 have a time offset caused by the phase lag from the high RC constant.]]&lt;br /&gt;
&lt;br /&gt;
==Sine Frequency==&lt;br /&gt;
&lt;br /&gt;
==Sample Code==&lt;br /&gt;
&lt;br /&gt;
This sample code creates an analog output on PINS D0 and D1 using 200 points at a sine frequency of 25Hz.&lt;br /&gt;
&lt;br /&gt;
 /******************************************************&lt;br /&gt;
 Sinusoidal Output&lt;br /&gt;
 */&lt;br /&gt;
 &lt;br /&gt;
 #include &amp;quot;HardwareProfile.h&amp;quot;&lt;br /&gt;
 #include &amp;quot;math.h&amp;quot; &lt;br /&gt;
 &lt;br /&gt;
 #define DESIRED_BAUDRATE    	(9600)      // The desired BaudRate&lt;br /&gt;
 #define NUM_POINTS_PER_PERIOD		200&lt;br /&gt;
 &lt;br /&gt;
 int timeStep = 0;&lt;br /&gt;
 int LookupTable[NUM_POINTS_PER_PERIOD];&lt;br /&gt;
 &lt;br /&gt;
 int main(void)&lt;br /&gt;
 {&lt;br /&gt;
 	int sineFreq = 25;&lt;br /&gt;
 	int interruptFreq = NUM_POINTS_PER_PERIOD * sineFreq;&lt;br /&gt;
 	int periodValue = (SYS_FREQ / interruptFreq / 1) - 1;&lt;br /&gt;
 	&lt;br /&gt;
 	// Configure the proper PB frequency and the number of wait states&lt;br /&gt;
 	SYSTEMConfigPerformance(SYS_FREQ);&lt;br /&gt;
 &lt;br /&gt;
 	// Allow vector interrupts&lt;br /&gt;
 	INTEnableSystemMultiVectoredInt();&lt;br /&gt;
 	&lt;br /&gt;
 	// init OC1 module, on pin D0&lt;br /&gt;
 	OpenOC1( OC_ON | OC_TIMER2_SRC | OC_PWM_FAULT_PIN_DISABLE, 0, 0);&lt;br /&gt;
 	// init OC1 module, on pin D1&lt;br /&gt;
 	OpenOC2( OC_ON | OC_TIMER2_SRC | OC_PWM_FAULT_PIN_DISABLE, 0, 0);&lt;br /&gt;
 	&lt;br /&gt;
 	// init Timer2 mode and period (PR2) // produces 20kHz PWM&lt;br /&gt;
 	OpenTimer2( T2_ON | T2_PS_1_1 | T2_SOURCE_INT, 3999);&lt;br /&gt;
 &lt;br /&gt;
 &lt;br /&gt;
 	int i;&lt;br /&gt;
 	for (i = 0; i &amp;lt; NUM_POINTS_PER_PERIOD; i++)&lt;br /&gt;
 	{&lt;br /&gt;
 		LookupTable[i] = (int)(3999/2 * sin(2*M_PI/NUM_POINTS_PER_PERIOD*i)+ 3999/2); &lt;br /&gt;
 	}&lt;br /&gt;
 	&lt;br /&gt;
 &lt;br /&gt;
 	// init Timer3 for Sinusoid Interrupt&lt;br /&gt;
 	// Assume Prescalar is 2&lt;br /&gt;
 	// Need to verify that SYS_FREQ / sineFreq / numPoints &amp;lt; 65534&lt;br /&gt;
 	OpenTimer3( T3_ON | T3_PS_1_1 | T3_SOURCE_INT, periodValue); &lt;br /&gt;
 	&lt;br /&gt;
 	mT3SetIntPriority( 7); 	// set Timer3 Interrupt Priority&lt;br /&gt;
 	mT3ClearIntFlag(); 		// clear interrupt flag&lt;br /&gt;
 	mT3IntEnable( 1);		// enable timer3 interrupts&lt;br /&gt;
 &lt;br /&gt;
 	// this will store the string for the LCD&lt;br /&gt;
 	char LCDbuffer[33]; &lt;br /&gt;
 &lt;br /&gt;
 	while(1)&lt;br /&gt;
 	{&lt;br /&gt;
 		// Timer 3 ISR takes care of the code&lt;br /&gt;
 	}&lt;br /&gt;
 &lt;br /&gt;
 	CloseOC1();&lt;br /&gt;
 	&lt;br /&gt;
 }//end main&lt;br /&gt;
  &lt;br /&gt;
 // interrput code&lt;br /&gt;
 void __ISR( _TIMER_3_VECTOR, ipl7) T3Interrupt( void)&lt;br /&gt;
 {&lt;br /&gt;
 	if (++timeStep &amp;gt;= NUM_POINTS_PER_PERIOD)&lt;br /&gt;
 	{&lt;br /&gt;
 		timeStep = 0;&lt;br /&gt;
 	}&lt;br /&gt;
 	&lt;br /&gt;
 	SetDCOC1PWM(LookupTable[timeStep]);&lt;br /&gt;
 	SetDCOC2PWM(LookupTable[timeStep]);&lt;br /&gt;
 	&lt;br /&gt;
 	// clear interrupt flag and exit&lt;br /&gt;
 	mT3ClearIntFlag();&lt;br /&gt;
 } // T3 Interrupt&lt;/div&gt;</summary>
		<author><name>LawrenceChen</name></author>
	</entry>
	<entry>
		<id>https://hades.mech.northwestern.edu//index.php?title=PIC32MX:_Sinusoidal_Analog_Output&amp;diff=18382</id>
		<title>PIC32MX: Sinusoidal Analog Output</title>
		<link rel="alternate" type="text/html" href="https://hades.mech.northwestern.edu//index.php?title=PIC32MX:_Sinusoidal_Analog_Output&amp;diff=18382"/>
		<updated>2010-05-09T03:58:07Z</updated>

		<summary type="html">&lt;p&gt;LawrenceChen: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;The PIC32 is actually incapable of directly creating an analog output. Instead, the PIC32 can perform pulse width modulation (PWM) to create an average analog output. At a given frequency, PWM varies the time that the output pin is on (output is 3.3V) to create the duty cycle which can simulate voltages between 0V and 3.3V. For example, if the duty cycle is 50%, the PIC32 holds the pin at 3.3V 50% of the time and 0V for the other 50%. The average output voltage is then 1.65V. If the pin is connected to an external RC circuit, the PWM can be integrated. By varying the duty cycle sinusoidally, the output with an RC circuit can resemble a sinusoid. Thus, to create the sinusoidal output, a sinusoidal wave must be divided into a discrete number of points. These points can then be converted to a list of duty cycles to represent the sinusoid.&lt;br /&gt;
&lt;br /&gt;
The three most important parameters in creating the sinusoidal analog output are the the number of points per period, the RC time constant, and the sinusoid frequency. The combination of the cutoff frequency and the points per period helps tell the PIC when to change the duty cycle. The RC constant of an external RC circuit is important in creating smooth and accurate curves and in improving the quality of the output signal.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The code for the analog output will first generate a lookup table. This table contains values for the specific duty cycles and will generate the number of duty cycles based on the number of points specified by the user. After generating the table, the code goes through a loop which tells the board to output the appropriate PWM corresponding to the duty cycle in the lookup table at each time step. By looping through the duty cycles at the same time intervals, the output voltage is varied to match that of a sine wave. The external RC circuit acts as a buffer to store these voltages to smooth the final output voltage to yield the sine wave. Without this external RC circuit, the output would only be a series of pulses matching the duty cycle at a given time.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The equation governing the sine wave is &lt;br /&gt;
&amp;lt;math&amp;gt;y=A*sin(\frac{2 \pi}{N*i})&amp;lt;/math&amp;gt;&lt;br /&gt;
where &amp;lt;math&amp;gt;A&amp;lt;/math&amp;gt; is the amplitude of the sinusoid, &amp;lt;math&amp;gt;N&amp;lt;/math&amp;gt; is the number of points and &amp;lt;math&amp;gt;i&amp;lt;/math&amp;gt; is the index.&lt;br /&gt;
&lt;br /&gt;
The equation governing the duty cycle is &lt;br /&gt;
&amp;lt;math&amp;gt;duty cycle = \frac{MAX\_DUTY}{2y} + \frac{MAX\_DUTY}{2}&amp;lt;/math&amp;gt;&lt;br /&gt;
where the &amp;lt;math&amp;gt;MAX\_DUTY&amp;lt;/math&amp;gt; is determined by the frequency of the PWM&lt;br /&gt;
&lt;br /&gt;
The examples below have a PWM frequency of 20kHz.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Number of Points Per Period==&lt;br /&gt;
Selecting the number of points to use to generate the sine wave is important because choosing too few will result in a very rough sine wave. When the number of points is too low, you can actually see multiple RC charging graphs between each point. However, if we choose too many points, a peak appears at what should be 0V on the sine wave. To prevent this peek from occurring, one could insert an “if” statement in the lookup table generation loop that replaces all of the occurring 0’s into 1’s. Inclusion of the if statement would result in no true 0V output for that particular output. The ideal number of points for 25Hz is around 200 points.&lt;br /&gt;
&lt;br /&gt;
[[Image:500pts10Hz.jpg|frame|This demonstrates what happens when you pick too many points. The output signal has a peak occurring at the 0V area. This output signal used 500 points at 10Hz.]]&lt;br /&gt;
&lt;br /&gt;
[[Image:100pts25Hz.jpg|left|frame|This demonstrates what an ideal analog output should look like. This output was generated using 100 points at 25Hz.]]&lt;br /&gt;
&lt;br /&gt;
[[Image:10pts25Hz.jpg|center|frame|This demonstrates what happens when you select too few points. The output signal shows the capacitor charging. In this case, 10 points at 25Hz are used in generating the analog output.]]&lt;br /&gt;
&lt;br /&gt;
==RC Time Constant==&lt;br /&gt;
&lt;br /&gt;
The RC time constant plays a big role in creating the sine wave. By increasing the RC constant, the quality of the output signal is increased, where &amp;quot;quality&amp;quot; refers to the width of the output signals. Despite having such advantages, a larger RC constant will result in a phase lag which causes a delay between the output of the PIC and the output from the whole circuit.&lt;br /&gt;
&lt;br /&gt;
[[Image:RCcompare.jpg|center|frame|The sine waves were generated at 25Hz with 100 points. The sine wave labeled 1 was generated with an RC constant of 4.7 x 10^-5, the sine wave labeled 2 was generated using an RC constant 2.2 x 10^-4 and the sine wave labeled 5 was generated using an RC constant 4.7 x 10^-3. Notice that sine waves 1 and 2 are almost synchronized, but sine waves 1 and 5 have a time offset caused by the phase lag from the high RC constant.]]&lt;br /&gt;
&lt;br /&gt;
==Sine Frequency==&lt;br /&gt;
&lt;br /&gt;
==Sample Code==&lt;br /&gt;
&lt;br /&gt;
This sample code creates an analog output on PINS D0 and D1 using 200 points at a sine frequency of 25Hz.&lt;br /&gt;
&lt;br /&gt;
 /******************************************************&lt;br /&gt;
 Sinusoidal Output&lt;br /&gt;
 */&lt;br /&gt;
 &lt;br /&gt;
 #include &amp;quot;HardwareProfile.h&amp;quot;&lt;br /&gt;
 #include &amp;quot;math.h&amp;quot; &lt;br /&gt;
 &lt;br /&gt;
 #define DESIRED_BAUDRATE    	(9600)      // The desired BaudRate&lt;br /&gt;
 #define NUM_POINTS_PER_PERIOD		200&lt;br /&gt;
 &lt;br /&gt;
 int timeStep = 0;&lt;br /&gt;
 int LookupTable[NUM_POINTS_PER_PERIOD];&lt;br /&gt;
 &lt;br /&gt;
 int main(void)&lt;br /&gt;
 {&lt;br /&gt;
 	int sineFreq = 25;&lt;br /&gt;
 	int interruptFreq = NUM_POINTS_PER_PERIOD * sineFreq;&lt;br /&gt;
 	int periodValue = (SYS_FREQ / interruptFreq / 1) - 1;&lt;br /&gt;
 	&lt;br /&gt;
 	// Configure the proper PB frequency and the number of wait states&lt;br /&gt;
 	SYSTEMConfigPerformance(SYS_FREQ);&lt;br /&gt;
 &lt;br /&gt;
 	// Allow vector interrupts&lt;br /&gt;
 	INTEnableSystemMultiVectoredInt();&lt;br /&gt;
 	&lt;br /&gt;
 	// init OC1 module, on pin D0&lt;br /&gt;
 	OpenOC1( OC_ON | OC_TIMER2_SRC | OC_PWM_FAULT_PIN_DISABLE, 0, 0);&lt;br /&gt;
 	// init OC1 module, on pin D1&lt;br /&gt;
 	OpenOC2( OC_ON | OC_TIMER2_SRC | OC_PWM_FAULT_PIN_DISABLE, 0, 0);&lt;br /&gt;
 	&lt;br /&gt;
 	// init Timer2 mode and period (PR2) // produces 20kHz PWM&lt;br /&gt;
 	OpenTimer2( T2_ON | T2_PS_1_1 | T2_SOURCE_INT, 3999);&lt;br /&gt;
 &lt;br /&gt;
 &lt;br /&gt;
 	int i;&lt;br /&gt;
 	for (i = 0; i &amp;lt; NUM_POINTS_PER_PERIOD; i++)&lt;br /&gt;
 	{&lt;br /&gt;
 		LookupTable[i] = (int)(3999/2 * sin(2*M_PI/NUM_POINTS_PER_PERIOD*i)+ 3999/2); &lt;br /&gt;
 	}&lt;br /&gt;
 	&lt;br /&gt;
 &lt;br /&gt;
 	// init Timer3 for Sinusoid Interrupt&lt;br /&gt;
 	// Assume Prescalar is 2&lt;br /&gt;
 	// Need to verify that SYS_FREQ / sineFreq / numPoints &amp;lt; 65534&lt;br /&gt;
 	OpenTimer3( T3_ON | T3_PS_1_1 | T3_SOURCE_INT, periodValue); &lt;br /&gt;
 	&lt;br /&gt;
 	mT3SetIntPriority( 7); 	// set Timer3 Interrupt Priority&lt;br /&gt;
 	mT3ClearIntFlag(); 		// clear interrupt flag&lt;br /&gt;
 	mT3IntEnable( 1);		// enable timer3 interrupts&lt;br /&gt;
 &lt;br /&gt;
 	// this will store the string for the LCD&lt;br /&gt;
 	char LCDbuffer[33]; &lt;br /&gt;
 &lt;br /&gt;
 	while(1)&lt;br /&gt;
 	{&lt;br /&gt;
 		// Timer 3 ISR takes care of the code&lt;br /&gt;
 	}&lt;br /&gt;
 &lt;br /&gt;
 	CloseOC1();&lt;br /&gt;
 	&lt;br /&gt;
 }//end main&lt;br /&gt;
  &lt;br /&gt;
 // interrput code&lt;br /&gt;
 void __ISR( _TIMER_3_VECTOR, ipl7) T3Interrupt( void)&lt;br /&gt;
 {&lt;br /&gt;
 	if (++timeStep &amp;gt;= NUM_POINTS_PER_PERIOD)&lt;br /&gt;
 	{&lt;br /&gt;
 		timeStep = 0;&lt;br /&gt;
 	}&lt;br /&gt;
 	&lt;br /&gt;
 	SetDCOC1PWM(LookupTable[timeStep]);&lt;br /&gt;
 	SetDCOC2PWM(LookupTable[timeStep]);&lt;br /&gt;
 	&lt;br /&gt;
 	// clear interrupt flag and exit&lt;br /&gt;
 	mT3ClearIntFlag();&lt;br /&gt;
 } // T3 Interrupt&lt;/div&gt;</summary>
		<author><name>LawrenceChen</name></author>
	</entry>
	<entry>
		<id>https://hades.mech.northwestern.edu//index.php?title=PIC32MX:_Sinusoidal_Analog_Output&amp;diff=18367</id>
		<title>PIC32MX: Sinusoidal Analog Output</title>
		<link rel="alternate" type="text/html" href="https://hades.mech.northwestern.edu//index.php?title=PIC32MX:_Sinusoidal_Analog_Output&amp;diff=18367"/>
		<updated>2010-05-03T02:28:24Z</updated>

		<summary type="html">&lt;p&gt;LawrenceChen: /* RC Time Constant */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;The PIC32 is actually incapable of directly creating an analog output. Instead, the PIC32 can perform pulse width modulation (PWM) in combination with an external RC circuit to create the analog output. Essentially, PWM varies the time that the output pin is on (output is 3.3V) and off (output is 0V) to create the duty cycle which can simulate voltages between 0V and 3.3V. For example, if the duty cycle puts out 3.3V for 50% of the time and 0V for the other 50%, the effective output voltage averages out to be 1.65V. Thus, to create the sinusoidal output, the sine wave must be divided into a number of points so that the PIC32 will know what duty cycle to output at what time. In essence, this method is similar to connecting the dots.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The three most important parameters in creating the sinusoidal analog output are the cutoff frequency, the number of points per period, and the RC time constant. The combination of the cutoff frequency and the points per period helps tell the PIC when to change the duty cycle. The RC constant of an external RC circuit is important in creating smooth and accurate curves and in improving the quality of the output signal.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The code for the analog output will first generate a lookup table. This table contains values for the specific duty cycles and will generate the number of duty cycles based on the number of points specified by the user. After generating the table, the code goes through a loop which tells the board to output the appropriate PWM corresponding to the duty cycle in the lookup table at each time step. By looping through the duty cycles at the same time intervals, the output voltage is varied to match that of a sine wave. The external RC circuit acts as a buffer to store these voltages to smooth the final output voltage to yield the sine wave. Without this external RC circuit, the output would only be a series of pulses matching the duty cycle at a given time.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The examples below have a PWM frequency of 20kHz.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
==Cutoff Frequency==&lt;br /&gt;
&lt;br /&gt;
To choose the cut-off frequency of the external RC circuit, you use the equation&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;f_c = \frac{1}{2 \pi R C}  \text{ Hz}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
where &amp;lt;math&amp;gt;f_c&amp;lt;/math&amp;gt; is the cut-off frequency (&amp;lt;math&amp;gt;\text{Hz}&amp;lt;/math&amp;gt;), &amp;lt;math&amp;gt;R&amp;lt;/math&amp;gt; is the resistance (&amp;lt;math&amp;gt;\Omega&amp;lt;/math&amp;gt;&#039;s) and &amp;lt;math&amp;gt;C&amp;lt;/math&amp;gt; is the capacitance (F). &lt;br /&gt;
&lt;br /&gt;
If the chosen cut-off frequency is too high (RC constant is too low), then the output signal will be very noisy and not as clear. If the chosen frequency is too low (RC constant is too high), then the final output signal through the RC circuit will be more likely to have a decreased amplitude, thus you&#039;ll only get a limited range of voltages.&lt;br /&gt;
&lt;br /&gt;
Whether or not the cut-off frequency is too high or too low depends on the frequency at which the board is outputting the PWM voltage. So as the output frequency of the board increases and approaches the cutoff frequency (thus the cutoff frequency would be too low), the amplitude of the final analog output voltage will be decreased.&lt;br /&gt;
&lt;br /&gt;
[[Image:RCcompare.jpg|center|frame|The sine waves were generated at 25Hz with 100 points. The sine wave labeled 1 was generated with an RC constant of 4.7 x 10^-5, the sine wave labeled 2 was generated using an RC constant 2.2 x 10^-4 and the sine wave labeled 5 was generated using an RC constant 4.7 x 10^-3. Notice that sine waves 1 and 2 have close to the same amplitudes (around 3.3V) but sine wave 1 has a very messy signal, thus the cutoff frequency would be too high. Also notice that sine wave 5 only has a maximum amplitude of 3.0V, thus the cutoff frequency would be too low.]]&lt;br /&gt;
&lt;br /&gt;
==Number of Points Per Period==&lt;br /&gt;
Selecting the number of points to use to generate the sine wave is important because choosing too few will result in a very rough sine wave. When the number of points is too low, you can actually see multiple RC charging graphs between each point. However, if we choose too many points, a peak appears at what should be 0V on the sine wave. To prevent this peek from occurring, one could insert an “if” statement in the lookup table generation loop that replaces all of the occurring 0’s into 1’s. Inclusion of the if statement would result in no true 0V output for that particular output. The ideal number of points for 25Hz is around 200 points.&lt;br /&gt;
&lt;br /&gt;
[[Image:500pts10Hz.jpg|frame|This demonstrates what happens when you pick too many points. The output signal has a peak occurring at the 0V area. This output signal used 500 points at 10Hz.]]&lt;br /&gt;
&lt;br /&gt;
[[Image:100pts25Hz.jpg|left|frame|This demonstrates what an ideal analog output should look like. This output was generated using 100 points at 25Hz.]]&lt;br /&gt;
&lt;br /&gt;
[[Image:10pts25Hz.jpg|center|frame|This demonstrates what happens when you select too few points. The output signal shows the capacitor charging. In this case, 10 points at 25Hz are used in generating the analog output.]]&lt;br /&gt;
&lt;br /&gt;
==RC Time Constant==&lt;br /&gt;
&lt;br /&gt;
The RC time constant plays a big role in creating the sine wave. By increasing the RC constant, the quality of the output signal is increased, where &amp;quot;quality&amp;quot; refers to the width of the output signals. Despite having such advantages, a larger RC constant will result in a phase lag which causes a delay between the output of the PIC and the output from the whole circuit.&lt;br /&gt;
&lt;br /&gt;
[[Image:RCcompare.jpg|center|frame|The sine waves were generated at 25Hz with 100 points. The sine wave labeled 1 was generated with an RC constant of 4.7 x 10^-5, the sine wave labeled 2 was generated using an RC constant 2.2 x 10^-4 and the sine wave labeled 5 was generated using an RC constant 4.7 x 10^-3. Notice that sine waves 1 and 2 are almost synchronized, but sine waves 1 and 5 have a time offset caused by the phase lag from the high RC constant.]]&lt;br /&gt;
&lt;br /&gt;
==Sample Code==&lt;br /&gt;
&lt;br /&gt;
This sample code creates an analog output on PINS D0 and D1 using 200 points at a sine frequency of 25Hz.&lt;br /&gt;
&lt;br /&gt;
 /******************************************************&lt;br /&gt;
 Sinusoidal Output&lt;br /&gt;
 */&lt;br /&gt;
 &lt;br /&gt;
 #include &amp;quot;HardwareProfile.h&amp;quot;&lt;br /&gt;
 #include &amp;quot;math.h&amp;quot; &lt;br /&gt;
 &lt;br /&gt;
 #define DESIRED_BAUDRATE    	(9600)      // The desired BaudRate&lt;br /&gt;
 #define NUM_POINTS_PER_PERIOD		200&lt;br /&gt;
 &lt;br /&gt;
 int timeStep = 0;&lt;br /&gt;
 int LookupTable[NUM_POINTS_PER_PERIOD];&lt;br /&gt;
 &lt;br /&gt;
 int main(void)&lt;br /&gt;
 {&lt;br /&gt;
 	int sineFreq = 25;&lt;br /&gt;
 	int interruptFreq = NUM_POINTS_PER_PERIOD * sineFreq;&lt;br /&gt;
 	int periodValue = (SYS_FREQ / interruptFreq / 1) - 1;&lt;br /&gt;
 	&lt;br /&gt;
 	// Configure the proper PB frequency and the number of wait states&lt;br /&gt;
 	SYSTEMConfigPerformance(SYS_FREQ);&lt;br /&gt;
 &lt;br /&gt;
 	// Allow vector interrupts&lt;br /&gt;
 	INTEnableSystemMultiVectoredInt();&lt;br /&gt;
 	&lt;br /&gt;
 	// init OC1 module, on pin D0&lt;br /&gt;
 	OpenOC1( OC_ON | OC_TIMER2_SRC | OC_PWM_FAULT_PIN_DISABLE, 0, 0);&lt;br /&gt;
 	// init OC1 module, on pin D1&lt;br /&gt;
 	OpenOC2( OC_ON | OC_TIMER2_SRC | OC_PWM_FAULT_PIN_DISABLE, 0, 0);&lt;br /&gt;
 	&lt;br /&gt;
 	// init Timer2 mode and period (PR2) // produces 20kHz PWM&lt;br /&gt;
 	OpenTimer2( T2_ON | T2_PS_1_1 | T2_SOURCE_INT, 3999);&lt;br /&gt;
 &lt;br /&gt;
 &lt;br /&gt;
 	int i;&lt;br /&gt;
 	for (i = 0; i &amp;lt; NUM_POINTS_PER_PERIOD; i++)&lt;br /&gt;
 	{&lt;br /&gt;
 		LookupTable[i] = (int)(3999/2 * sin(2*M_PI/NUM_POINTS_PER_PERIOD*i)+ 3999/2); &lt;br /&gt;
 	}&lt;br /&gt;
 	&lt;br /&gt;
 &lt;br /&gt;
 	// init Timer3 for Sinusoid Interrupt&lt;br /&gt;
 	// Assume Prescalar is 2&lt;br /&gt;
 	// Need to verify that SYS_FREQ / sineFreq / numPoints &amp;lt; 65534&lt;br /&gt;
 	OpenTimer3( T3_ON | T3_PS_1_1 | T3_SOURCE_INT, periodValue); &lt;br /&gt;
 	&lt;br /&gt;
 	mT3SetIntPriority( 7); 	// set Timer3 Interrupt Priority&lt;br /&gt;
 	mT3ClearIntFlag(); 		// clear interrupt flag&lt;br /&gt;
 	mT3IntEnable( 1);		// enable timer3 interrupts&lt;br /&gt;
 &lt;br /&gt;
 	// this will store the string for the LCD&lt;br /&gt;
 	char LCDbuffer[33]; &lt;br /&gt;
 &lt;br /&gt;
 	while(1)&lt;br /&gt;
 	{&lt;br /&gt;
 		// Timer 3 ISR takes care of the code&lt;br /&gt;
 	}&lt;br /&gt;
 &lt;br /&gt;
 	CloseOC1();&lt;br /&gt;
 	&lt;br /&gt;
 }//end main&lt;br /&gt;
  &lt;br /&gt;
 // interrput code&lt;br /&gt;
 void __ISR( _TIMER_3_VECTOR, ipl7) T3Interrupt( void)&lt;br /&gt;
 {&lt;br /&gt;
 	if (++timeStep &amp;gt;= NUM_POINTS_PER_PERIOD)&lt;br /&gt;
 	{&lt;br /&gt;
 		timeStep = 0;&lt;br /&gt;
 	}&lt;br /&gt;
 	&lt;br /&gt;
 	SetDCOC1PWM(LookupTable[timeStep]);&lt;br /&gt;
 	SetDCOC2PWM(LookupTable[timeStep]);&lt;br /&gt;
 	&lt;br /&gt;
 	// clear interrupt flag and exit&lt;br /&gt;
 	mT3ClearIntFlag();&lt;br /&gt;
 } // T3 Interrupt&lt;/div&gt;</summary>
		<author><name>LawrenceChen</name></author>
	</entry>
	<entry>
		<id>https://hades.mech.northwestern.edu//index.php?title=PIC32MX:_Sinusoidal_Analog_Output&amp;diff=18366</id>
		<title>PIC32MX: Sinusoidal Analog Output</title>
		<link rel="alternate" type="text/html" href="https://hades.mech.northwestern.edu//index.php?title=PIC32MX:_Sinusoidal_Analog_Output&amp;diff=18366"/>
		<updated>2010-05-03T02:26:54Z</updated>

		<summary type="html">&lt;p&gt;LawrenceChen: /* Cutoff Frequency */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;The PIC32 is actually incapable of directly creating an analog output. Instead, the PIC32 can perform pulse width modulation (PWM) in combination with an external RC circuit to create the analog output. Essentially, PWM varies the time that the output pin is on (output is 3.3V) and off (output is 0V) to create the duty cycle which can simulate voltages between 0V and 3.3V. For example, if the duty cycle puts out 3.3V for 50% of the time and 0V for the other 50%, the effective output voltage averages out to be 1.65V. Thus, to create the sinusoidal output, the sine wave must be divided into a number of points so that the PIC32 will know what duty cycle to output at what time. In essence, this method is similar to connecting the dots.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The three most important parameters in creating the sinusoidal analog output are the cutoff frequency, the number of points per period, and the RC time constant. The combination of the cutoff frequency and the points per period helps tell the PIC when to change the duty cycle. The RC constant of an external RC circuit is important in creating smooth and accurate curves and in improving the quality of the output signal.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The code for the analog output will first generate a lookup table. This table contains values for the specific duty cycles and will generate the number of duty cycles based on the number of points specified by the user. After generating the table, the code goes through a loop which tells the board to output the appropriate PWM corresponding to the duty cycle in the lookup table at each time step. By looping through the duty cycles at the same time intervals, the output voltage is varied to match that of a sine wave. The external RC circuit acts as a buffer to store these voltages to smooth the final output voltage to yield the sine wave. Without this external RC circuit, the output would only be a series of pulses matching the duty cycle at a given time.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The examples below have a PWM frequency of 20kHz.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
==Cutoff Frequency==&lt;br /&gt;
&lt;br /&gt;
To choose the cut-off frequency of the external RC circuit, you use the equation&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;f_c = \frac{1}{2 \pi R C}  \text{ Hz}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
where &amp;lt;math&amp;gt;f_c&amp;lt;/math&amp;gt; is the cut-off frequency (&amp;lt;math&amp;gt;\text{Hz}&amp;lt;/math&amp;gt;), &amp;lt;math&amp;gt;R&amp;lt;/math&amp;gt; is the resistance (&amp;lt;math&amp;gt;\Omega&amp;lt;/math&amp;gt;&#039;s) and &amp;lt;math&amp;gt;C&amp;lt;/math&amp;gt; is the capacitance (F). &lt;br /&gt;
&lt;br /&gt;
If the chosen cut-off frequency is too high (RC constant is too low), then the output signal will be very noisy and not as clear. If the chosen frequency is too low (RC constant is too high), then the final output signal through the RC circuit will be more likely to have a decreased amplitude, thus you&#039;ll only get a limited range of voltages.&lt;br /&gt;
&lt;br /&gt;
Whether or not the cut-off frequency is too high or too low depends on the frequency at which the board is outputting the PWM voltage. So as the output frequency of the board increases and approaches the cutoff frequency (thus the cutoff frequency would be too low), the amplitude of the final analog output voltage will be decreased.&lt;br /&gt;
&lt;br /&gt;
[[Image:RCcompare.jpg|center|frame|The sine waves were generated at 25Hz with 100 points. The sine wave labeled 1 was generated with an RC constant of 4.7 x 10^-5, the sine wave labeled 2 was generated using an RC constant 2.2 x 10^-4 and the sine wave labeled 5 was generated using an RC constant 4.7 x 10^-3. Notice that sine waves 1 and 2 have close to the same amplitudes (around 3.3V) but sine wave 1 has a very messy signal, thus the cutoff frequency would be too high. Also notice that sine wave 5 only has a maximum amplitude of 3.0V, thus the cutoff frequency would be too low.]]&lt;br /&gt;
&lt;br /&gt;
==Number of Points Per Period==&lt;br /&gt;
Selecting the number of points to use to generate the sine wave is important because choosing too few will result in a very rough sine wave. When the number of points is too low, you can actually see multiple RC charging graphs between each point. However, if we choose too many points, a peak appears at what should be 0V on the sine wave. To prevent this peek from occurring, one could insert an “if” statement in the lookup table generation loop that replaces all of the occurring 0’s into 1’s. Inclusion of the if statement would result in no true 0V output for that particular output. The ideal number of points for 25Hz is around 200 points.&lt;br /&gt;
&lt;br /&gt;
[[Image:500pts10Hz.jpg|frame|This demonstrates what happens when you pick too many points. The output signal has a peak occurring at the 0V area. This output signal used 500 points at 10Hz.]]&lt;br /&gt;
&lt;br /&gt;
[[Image:100pts25Hz.jpg|left|frame|This demonstrates what an ideal analog output should look like. This output was generated using 100 points at 25Hz.]]&lt;br /&gt;
&lt;br /&gt;
[[Image:10pts25Hz.jpg|center|frame|This demonstrates what happens when you select too few points. The output signal shows the capacitor charging. In this case, 10 points at 25Hz are used in generating the analog output.]]&lt;br /&gt;
&lt;br /&gt;
==RC Time Constant==&lt;br /&gt;
&lt;br /&gt;
The RC time constant plays a big role in creating the sine wave. By increasing the RC constant, the quality of the output signal is increased, where &amp;quot;quality&amp;quot; refers to the width of the output signals. Despite having such advantages, a larger RC constant will result in a phase lag which causes a delay between the output of the PIC and the output from the whole circuit.&lt;br /&gt;
&lt;br /&gt;
[[Image:RCcompare.jpg|center|frame|The sine waves were generated at 25Hz with 100 points. The sine wave labeled 1 was generated with an RC constant of 4.7 x 10^-5, the sine wave labeled 2 was generated using an RC constant 2.2 x 10^-4 and the sine wave labeled 5 was generated using an RC constant 4.7 x 10^-3. ]]&lt;br /&gt;
&lt;br /&gt;
==Sample Code==&lt;br /&gt;
&lt;br /&gt;
This sample code creates an analog output on PINS D0 and D1 using 200 points at a sine frequency of 25Hz.&lt;br /&gt;
&lt;br /&gt;
 /******************************************************&lt;br /&gt;
 Sinusoidal Output&lt;br /&gt;
 */&lt;br /&gt;
 &lt;br /&gt;
 #include &amp;quot;HardwareProfile.h&amp;quot;&lt;br /&gt;
 #include &amp;quot;math.h&amp;quot; &lt;br /&gt;
 &lt;br /&gt;
 #define DESIRED_BAUDRATE    	(9600)      // The desired BaudRate&lt;br /&gt;
 #define NUM_POINTS_PER_PERIOD		200&lt;br /&gt;
 &lt;br /&gt;
 int timeStep = 0;&lt;br /&gt;
 int LookupTable[NUM_POINTS_PER_PERIOD];&lt;br /&gt;
 &lt;br /&gt;
 int main(void)&lt;br /&gt;
 {&lt;br /&gt;
 	int sineFreq = 25;&lt;br /&gt;
 	int interruptFreq = NUM_POINTS_PER_PERIOD * sineFreq;&lt;br /&gt;
 	int periodValue = (SYS_FREQ / interruptFreq / 1) - 1;&lt;br /&gt;
 	&lt;br /&gt;
 	// Configure the proper PB frequency and the number of wait states&lt;br /&gt;
 	SYSTEMConfigPerformance(SYS_FREQ);&lt;br /&gt;
 &lt;br /&gt;
 	// Allow vector interrupts&lt;br /&gt;
 	INTEnableSystemMultiVectoredInt();&lt;br /&gt;
 	&lt;br /&gt;
 	// init OC1 module, on pin D0&lt;br /&gt;
 	OpenOC1( OC_ON | OC_TIMER2_SRC | OC_PWM_FAULT_PIN_DISABLE, 0, 0);&lt;br /&gt;
 	// init OC1 module, on pin D1&lt;br /&gt;
 	OpenOC2( OC_ON | OC_TIMER2_SRC | OC_PWM_FAULT_PIN_DISABLE, 0, 0);&lt;br /&gt;
 	&lt;br /&gt;
 	// init Timer2 mode and period (PR2) // produces 20kHz PWM&lt;br /&gt;
 	OpenTimer2( T2_ON | T2_PS_1_1 | T2_SOURCE_INT, 3999);&lt;br /&gt;
 &lt;br /&gt;
 &lt;br /&gt;
 	int i;&lt;br /&gt;
 	for (i = 0; i &amp;lt; NUM_POINTS_PER_PERIOD; i++)&lt;br /&gt;
 	{&lt;br /&gt;
 		LookupTable[i] = (int)(3999/2 * sin(2*M_PI/NUM_POINTS_PER_PERIOD*i)+ 3999/2); &lt;br /&gt;
 	}&lt;br /&gt;
 	&lt;br /&gt;
 &lt;br /&gt;
 	// init Timer3 for Sinusoid Interrupt&lt;br /&gt;
 	// Assume Prescalar is 2&lt;br /&gt;
 	// Need to verify that SYS_FREQ / sineFreq / numPoints &amp;lt; 65534&lt;br /&gt;
 	OpenTimer3( T3_ON | T3_PS_1_1 | T3_SOURCE_INT, periodValue); &lt;br /&gt;
 	&lt;br /&gt;
 	mT3SetIntPriority( 7); 	// set Timer3 Interrupt Priority&lt;br /&gt;
 	mT3ClearIntFlag(); 		// clear interrupt flag&lt;br /&gt;
 	mT3IntEnable( 1);		// enable timer3 interrupts&lt;br /&gt;
 &lt;br /&gt;
 	// this will store the string for the LCD&lt;br /&gt;
 	char LCDbuffer[33]; &lt;br /&gt;
 &lt;br /&gt;
 	while(1)&lt;br /&gt;
 	{&lt;br /&gt;
 		// Timer 3 ISR takes care of the code&lt;br /&gt;
 	}&lt;br /&gt;
 &lt;br /&gt;
 	CloseOC1();&lt;br /&gt;
 	&lt;br /&gt;
 }//end main&lt;br /&gt;
  &lt;br /&gt;
 // interrput code&lt;br /&gt;
 void __ISR( _TIMER_3_VECTOR, ipl7) T3Interrupt( void)&lt;br /&gt;
 {&lt;br /&gt;
 	if (++timeStep &amp;gt;= NUM_POINTS_PER_PERIOD)&lt;br /&gt;
 	{&lt;br /&gt;
 		timeStep = 0;&lt;br /&gt;
 	}&lt;br /&gt;
 	&lt;br /&gt;
 	SetDCOC1PWM(LookupTable[timeStep]);&lt;br /&gt;
 	SetDCOC2PWM(LookupTable[timeStep]);&lt;br /&gt;
 	&lt;br /&gt;
 	// clear interrupt flag and exit&lt;br /&gt;
 	mT3ClearIntFlag();&lt;br /&gt;
 } // T3 Interrupt&lt;/div&gt;</summary>
		<author><name>LawrenceChen</name></author>
	</entry>
	<entry>
		<id>https://hades.mech.northwestern.edu//index.php?title=PIC32MX:_Sinusoidal_Analog_Output&amp;diff=18365</id>
		<title>PIC32MX: Sinusoidal Analog Output</title>
		<link rel="alternate" type="text/html" href="https://hades.mech.northwestern.edu//index.php?title=PIC32MX:_Sinusoidal_Analog_Output&amp;diff=18365"/>
		<updated>2010-05-02T23:40:46Z</updated>

		<summary type="html">&lt;p&gt;LawrenceChen: /* Sample Code */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;The PIC32 is actually incapable of directly creating an analog output. Instead, the PIC32 can perform pulse width modulation (PWM) in combination with an external RC circuit to create the analog output. Essentially, PWM varies the time that the output pin is on (output is 3.3V) and off (output is 0V) to create the duty cycle which can simulate voltages between 0V and 3.3V. For example, if the duty cycle puts out 3.3V for 50% of the time and 0V for the other 50%, the effective output voltage averages out to be 1.65V. Thus, to create the sinusoidal output, the sine wave must be divided into a number of points so that the PIC32 will know what duty cycle to output at what time. In essence, this method is similar to connecting the dots.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The three most important parameters in creating the sinusoidal analog output are the cutoff frequency, the number of points per period, and the RC time constant. The combination of the cutoff frequency and the points per period helps tell the PIC when to change the duty cycle. The RC constant of an external RC circuit is important in creating smooth and accurate curves and in improving the quality of the output signal.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The code for the analog output will first generate a lookup table. This table contains values for the specific duty cycles and will generate the number of duty cycles based on the number of points specified by the user. After generating the table, the code goes through a loop which tells the board to output the appropriate PWM corresponding to the duty cycle in the lookup table at each time step. By looping through the duty cycles at the same time intervals, the output voltage is varied to match that of a sine wave. The external RC circuit acts as a buffer to store these voltages to smooth the final output voltage to yield the sine wave. Without this external RC circuit, the output would only be a series of pulses matching the duty cycle at a given time.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The examples below have a PWM frequency of 20kHz.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
==Cutoff Frequency==&lt;br /&gt;
&lt;br /&gt;
How to choose cut-off frequency -- what is the equation?&lt;br /&gt;
&lt;br /&gt;
Show picture if you choose your frequency to high and if you choose your frequency to low. &lt;br /&gt;
&lt;br /&gt;
Say something about how the amplitude decreases with high frequency&lt;br /&gt;
&lt;br /&gt;
==Number of Points Per Period==&lt;br /&gt;
Selecting the number of points to use to generate the sine wave is important because choosing too few will result in a very rough sine wave. When the number of points is too low, you can actually see multiple RC charging graphs between each point. However, if we choose too many points, a peak appears at what should be 0V on the sine wave. To prevent this peek from occurring, one could insert an “if” statement in the lookup table generation loop that replaces all of the occurring 0’s into 1’s. Inclusion of the if statement would result in no true 0V output for that particular output. The ideal number of points for 25Hz is around 200 points.&lt;br /&gt;
&lt;br /&gt;
[[Image:500pts10Hz.jpg|frame|This demonstrates what happens when you pick too many points. The output signal has a peak occurring at the 0V area. This output signal used 500 points at 10Hz.]]&lt;br /&gt;
&lt;br /&gt;
[[Image:100pts25Hz.jpg|left|frame|This demonstrates what an ideal analog output should look like. This output was generated using 100 points at 25Hz.]]&lt;br /&gt;
&lt;br /&gt;
[[Image:10pts25Hz.jpg|center|frame|This demonstrates what happens when you select too few points. The output signal shows the capacitor charging. In this case, 10 points at 25Hz are used in generating the analog output.]]&lt;br /&gt;
&lt;br /&gt;
==RC Time Constant==&lt;br /&gt;
&lt;br /&gt;
The RC time constant plays a big role in creating the sine wave. By increasing the RC constant, the quality of the output signal is increased, where &amp;quot;quality&amp;quot; refers to the width of the output signals. Despite having such advantages, a larger RC constant will result in a phase lag which causes a delay between the output of the PIC and the output from the whole circuit.&lt;br /&gt;
&lt;br /&gt;
[[Image:RCcompare.jpg|center|frame|The sine waves were generated at 25Hz with 100 points. The sine wave labeled 1 was generated with an RC constant of 4.7 x 10^-5, the sine wave labeled 2 was generated using an RC constant 2.2 x 10^-4 and the sine wave labeled 5 was generated using an RC constant 4.7 x 10^-3. ]]&lt;br /&gt;
&lt;br /&gt;
==Sample Code==&lt;br /&gt;
&lt;br /&gt;
This sample code creates an analog output on PINS D0 and D1 using 200 points at a sine frequency of 25Hz.&lt;br /&gt;
&lt;br /&gt;
 /******************************************************&lt;br /&gt;
 Sinusoidal Output&lt;br /&gt;
 */&lt;br /&gt;
 &lt;br /&gt;
 #include &amp;quot;HardwareProfile.h&amp;quot;&lt;br /&gt;
 #include &amp;quot;math.h&amp;quot; &lt;br /&gt;
 &lt;br /&gt;
 #define DESIRED_BAUDRATE    	(9600)      // The desired BaudRate&lt;br /&gt;
 #define NUM_POINTS_PER_PERIOD		200&lt;br /&gt;
 &lt;br /&gt;
 int timeStep = 0;&lt;br /&gt;
 int LookupTable[NUM_POINTS_PER_PERIOD];&lt;br /&gt;
 &lt;br /&gt;
 int main(void)&lt;br /&gt;
 {&lt;br /&gt;
 	int sineFreq = 25;&lt;br /&gt;
 	int interruptFreq = NUM_POINTS_PER_PERIOD * sineFreq;&lt;br /&gt;
 	int periodValue = (SYS_FREQ / interruptFreq / 1) - 1;&lt;br /&gt;
 	&lt;br /&gt;
 	// Configure the proper PB frequency and the number of wait states&lt;br /&gt;
 	SYSTEMConfigPerformance(SYS_FREQ);&lt;br /&gt;
 &lt;br /&gt;
 	// Allow vector interrupts&lt;br /&gt;
 	INTEnableSystemMultiVectoredInt();&lt;br /&gt;
 	&lt;br /&gt;
 	// init OC1 module, on pin D0&lt;br /&gt;
 	OpenOC1( OC_ON | OC_TIMER2_SRC | OC_PWM_FAULT_PIN_DISABLE, 0, 0);&lt;br /&gt;
 	// init OC1 module, on pin D1&lt;br /&gt;
 	OpenOC2( OC_ON | OC_TIMER2_SRC | OC_PWM_FAULT_PIN_DISABLE, 0, 0);&lt;br /&gt;
 	&lt;br /&gt;
 	// init Timer2 mode and period (PR2) // produces 20kHz PWM&lt;br /&gt;
 	OpenTimer2( T2_ON | T2_PS_1_1 | T2_SOURCE_INT, 3999);&lt;br /&gt;
 &lt;br /&gt;
 &lt;br /&gt;
 	int i;&lt;br /&gt;
 	for (i = 0; i &amp;lt; NUM_POINTS_PER_PERIOD; i++)&lt;br /&gt;
 	{&lt;br /&gt;
 		LookupTable[i] = (int)(3999/2 * sin(2*M_PI/NUM_POINTS_PER_PERIOD*i)+ 3999/2); &lt;br /&gt;
 	}&lt;br /&gt;
 	&lt;br /&gt;
 &lt;br /&gt;
 	// init Timer3 for Sinusoid Interrupt&lt;br /&gt;
 	// Assume Prescalar is 2&lt;br /&gt;
 	// Need to verify that SYS_FREQ / sineFreq / numPoints &amp;lt; 65534&lt;br /&gt;
 	OpenTimer3( T3_ON | T3_PS_1_1 | T3_SOURCE_INT, periodValue); &lt;br /&gt;
 	&lt;br /&gt;
 	mT3SetIntPriority( 7); 	// set Timer3 Interrupt Priority&lt;br /&gt;
 	mT3ClearIntFlag(); 		// clear interrupt flag&lt;br /&gt;
 	mT3IntEnable( 1);		// enable timer3 interrupts&lt;br /&gt;
 &lt;br /&gt;
 	// this will store the string for the LCD&lt;br /&gt;
 	char LCDbuffer[33]; &lt;br /&gt;
 &lt;br /&gt;
 	while(1)&lt;br /&gt;
 	{&lt;br /&gt;
 		// Timer 3 ISR takes care of the code&lt;br /&gt;
 	}&lt;br /&gt;
 &lt;br /&gt;
 	CloseOC1();&lt;br /&gt;
 	&lt;br /&gt;
 }//end main&lt;br /&gt;
  &lt;br /&gt;
 // interrput code&lt;br /&gt;
 void __ISR( _TIMER_3_VECTOR, ipl7) T3Interrupt( void)&lt;br /&gt;
 {&lt;br /&gt;
 	if (++timeStep &amp;gt;= NUM_POINTS_PER_PERIOD)&lt;br /&gt;
 	{&lt;br /&gt;
 		timeStep = 0;&lt;br /&gt;
 	}&lt;br /&gt;
 	&lt;br /&gt;
 	SetDCOC1PWM(LookupTable[timeStep]);&lt;br /&gt;
 	SetDCOC2PWM(LookupTable[timeStep]);&lt;br /&gt;
 	&lt;br /&gt;
 	// clear interrupt flag and exit&lt;br /&gt;
 	mT3ClearIntFlag();&lt;br /&gt;
 } // T3 Interrupt&lt;/div&gt;</summary>
		<author><name>LawrenceChen</name></author>
	</entry>
	<entry>
		<id>https://hades.mech.northwestern.edu//index.php?title=PIC32MX:_Sinusoidal_Analog_Output&amp;diff=18364</id>
		<title>PIC32MX: Sinusoidal Analog Output</title>
		<link rel="alternate" type="text/html" href="https://hades.mech.northwestern.edu//index.php?title=PIC32MX:_Sinusoidal_Analog_Output&amp;diff=18364"/>
		<updated>2010-05-02T23:30:50Z</updated>

		<summary type="html">&lt;p&gt;LawrenceChen: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;The PIC32 is actually incapable of directly creating an analog output. Instead, the PIC32 can perform pulse width modulation (PWM) in combination with an external RC circuit to create the analog output. Essentially, PWM varies the time that the output pin is on (output is 3.3V) and off (output is 0V) to create the duty cycle which can simulate voltages between 0V and 3.3V. For example, if the duty cycle puts out 3.3V for 50% of the time and 0V for the other 50%, the effective output voltage averages out to be 1.65V. Thus, to create the sinusoidal output, the sine wave must be divided into a number of points so that the PIC32 will know what duty cycle to output at what time. In essence, this method is similar to connecting the dots.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The three most important parameters in creating the sinusoidal analog output are the cutoff frequency, the number of points per period, and the RC time constant. The combination of the cutoff frequency and the points per period helps tell the PIC when to change the duty cycle. The RC constant of an external RC circuit is important in creating smooth and accurate curves and in improving the quality of the output signal.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The code for the analog output will first generate a lookup table. This table contains values for the specific duty cycles and will generate the number of duty cycles based on the number of points specified by the user. After generating the table, the code goes through a loop which tells the board to output the appropriate PWM corresponding to the duty cycle in the lookup table at each time step. By looping through the duty cycles at the same time intervals, the output voltage is varied to match that of a sine wave. The external RC circuit acts as a buffer to store these voltages to smooth the final output voltage to yield the sine wave. Without this external RC circuit, the output would only be a series of pulses matching the duty cycle at a given time.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The examples below have a PWM frequency of 20kHz.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
==Cutoff Frequency==&lt;br /&gt;
&lt;br /&gt;
How to choose cut-off frequency -- what is the equation?&lt;br /&gt;
&lt;br /&gt;
Show picture if you choose your frequency to high and if you choose your frequency to low. &lt;br /&gt;
&lt;br /&gt;
Say something about how the amplitude decreases with high frequency&lt;br /&gt;
&lt;br /&gt;
==Number of Points Per Period==&lt;br /&gt;
Selecting the number of points to use to generate the sine wave is important because choosing too few will result in a very rough sine wave. When the number of points is too low, you can actually see multiple RC charging graphs between each point. However, if we choose too many points, a peak appears at what should be 0V on the sine wave. To prevent this peek from occurring, one could insert an “if” statement in the lookup table generation loop that replaces all of the occurring 0’s into 1’s. Inclusion of the if statement would result in no true 0V output for that particular output. The ideal number of points for 25Hz is around 200 points.&lt;br /&gt;
&lt;br /&gt;
[[Image:500pts10Hz.jpg|frame|This demonstrates what happens when you pick too many points. The output signal has a peak occurring at the 0V area. This output signal used 500 points at 10Hz.]]&lt;br /&gt;
&lt;br /&gt;
[[Image:100pts25Hz.jpg|left|frame|This demonstrates what an ideal analog output should look like. This output was generated using 100 points at 25Hz.]]&lt;br /&gt;
&lt;br /&gt;
[[Image:10pts25Hz.jpg|center|frame|This demonstrates what happens when you select too few points. The output signal shows the capacitor charging. In this case, 10 points at 25Hz are used in generating the analog output.]]&lt;br /&gt;
&lt;br /&gt;
==RC Time Constant==&lt;br /&gt;
&lt;br /&gt;
The RC time constant plays a big role in creating the sine wave. By increasing the RC constant, the quality of the output signal is increased, where &amp;quot;quality&amp;quot; refers to the width of the output signals. Despite having such advantages, a larger RC constant will result in a phase lag which causes a delay between the output of the PIC and the output from the whole circuit.&lt;br /&gt;
&lt;br /&gt;
[[Image:RCcompare.jpg|center|frame|The sine waves were generated at 25Hz with 100 points. The sine wave labeled 1 was generated with an RC constant of 4.7 x 10^-5, the sine wave labeled 2 was generated using an RC constant 2.2 x 10^-4 and the sine wave labeled 5 was generated using an RC constant 4.7 x 10^-3. ]]&lt;br /&gt;
&lt;br /&gt;
==Sample Code==&lt;br /&gt;
&lt;br /&gt;
Include your sample code (this may need cleaned up a bit). &lt;br /&gt;
&lt;br /&gt;
 To make a box around the code, put a &#039;space&#039; in front of each line.&lt;/div&gt;</summary>
		<author><name>LawrenceChen</name></author>
	</entry>
	<entry>
		<id>https://hades.mech.northwestern.edu//index.php?title=PIC32MX:_Sinusoidal_Analog_Output&amp;diff=18362</id>
		<title>PIC32MX: Sinusoidal Analog Output</title>
		<link rel="alternate" type="text/html" href="https://hades.mech.northwestern.edu//index.php?title=PIC32MX:_Sinusoidal_Analog_Output&amp;diff=18362"/>
		<updated>2010-05-02T20:23:10Z</updated>

		<summary type="html">&lt;p&gt;LawrenceChen: /* Number of Points Per Period */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Overview:&lt;br /&gt;
&lt;br /&gt;
How do we obtain analog output? ie PWM (brief description)&lt;br /&gt;
&lt;br /&gt;
How do we get sinusoidal output? ie divide up sinusoid into N points, scale duty cycle accordingly&lt;br /&gt;
&lt;br /&gt;
General discussion about how cutoff frequency, number of points period (N) and the RC time constant matter.&lt;br /&gt;
&lt;br /&gt;
State that the examples here have PWM at 20kHz.&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
==Cutoff Frequency==&lt;br /&gt;
&lt;br /&gt;
How to choose cut-off frequency -- what is the equation?&lt;br /&gt;
&lt;br /&gt;
Show picture if you choose your frequency to high and if you choose your frequency to low. &lt;br /&gt;
&lt;br /&gt;
Say something about how the amplitude decreases with high frequency&lt;br /&gt;
&lt;br /&gt;
==Number of Points Per Period==&lt;br /&gt;
Selecting the number of points to use to generate the sine wave is important because choosing too few will result in a very rough sine wave. When the number of points is too low, you can actually see multiple RC charging graphs between each point. However, if we choose too many points, a peak appears at what should be 0V on the sine wave. To prevent this peek from occurring, one could insert an “if” statement in the lookup table generation loop that replaces all of the occurring 0’s into 1’s. Inclusion of the if statement would result in no true 0V output for that particular output. The ideal number of points for 25Hz is around 200 points.&lt;br /&gt;
&lt;br /&gt;
[[Image:500pts10Hz.jpg|frame|This demonstrates what happens when you pick too many points. The output signal has a peak occurring at the 0V area. This output signal used 500 points at 10Hz.]]&lt;br /&gt;
&lt;br /&gt;
[[Image:100pts25Hz.jpg|left|frame|This demonstrates what an ideal analog output should look like. This output was generated using 100 points at 25Hz.]]&lt;br /&gt;
&lt;br /&gt;
[[Image:10pts25Hz.jpg|center|frame|This demonstrates what happens when you select too few points. The output signal shows the capacitor charging. In this case, 10 points at 25Hz are used in generating the analog output.]]&lt;br /&gt;
&lt;br /&gt;
==RC Time Constant==&lt;br /&gt;
&lt;br /&gt;
The RC time constant plays a big role in creating the sine wave. By increasing the RC constant, the quality of the output signal is increased, where &amp;quot;quality&amp;quot; refers to the width of the output signals. Despite having such advantages, a larger RC constant will result in a phase lag which causes a delay between the output of the PIC and the output from the whole circuit.&lt;br /&gt;
&lt;br /&gt;
[[Image:RCcompare.jpg|center|frame|The sine waves were generated at 25Hz with 100 points. The sine wave labeled 1 was generated with an RC constant of 4.7 x 10^-5, the sine wave labeled 2 was generated using an RC constant 2.2 x 10^-4 and the sine wave labeled 5 was generated using an RC constant 4.7 x 10^-3. ]]&lt;br /&gt;
&lt;br /&gt;
==Sample Code==&lt;br /&gt;
&lt;br /&gt;
Include your sample code (this may need cleaned up a bit). &lt;br /&gt;
&lt;br /&gt;
 To make a box around the code, put a &#039;space&#039; in front of each line.&lt;/div&gt;</summary>
		<author><name>LawrenceChen</name></author>
	</entry>
	<entry>
		<id>https://hades.mech.northwestern.edu//index.php?title=PIC32MX:_Sinusoidal_Analog_Output&amp;diff=18361</id>
		<title>PIC32MX: Sinusoidal Analog Output</title>
		<link rel="alternate" type="text/html" href="https://hades.mech.northwestern.edu//index.php?title=PIC32MX:_Sinusoidal_Analog_Output&amp;diff=18361"/>
		<updated>2010-05-02T20:22:01Z</updated>

		<summary type="html">&lt;p&gt;LawrenceChen: /* Number of Points Per Period */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Overview:&lt;br /&gt;
&lt;br /&gt;
How do we obtain analog output? ie PWM (brief description)&lt;br /&gt;
&lt;br /&gt;
How do we get sinusoidal output? ie divide up sinusoid into N points, scale duty cycle accordingly&lt;br /&gt;
&lt;br /&gt;
General discussion about how cutoff frequency, number of points period (N) and the RC time constant matter.&lt;br /&gt;
&lt;br /&gt;
State that the examples here have PWM at 20kHz.&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
==Cutoff Frequency==&lt;br /&gt;
&lt;br /&gt;
How to choose cut-off frequency -- what is the equation?&lt;br /&gt;
&lt;br /&gt;
Show picture if you choose your frequency to high and if you choose your frequency to low. &lt;br /&gt;
&lt;br /&gt;
Say something about how the amplitude decreases with high frequency&lt;br /&gt;
&lt;br /&gt;
==Number of Points Per Period==&lt;br /&gt;
Selecting the number of points to use to generate the sine wave is important because choosing too few will result in a very rough sine wave. When the number of points is too low, you can actually see multiple RC charging graphs between each point. However, if we choose too many points, a peak appears at what should be 0V on the sine wave. To prevent this peek from occurring, one could insert an “if” statement in the lookup table generation loop that replaces all of the occurring 0’s into 1’s. Inclusion of the if statement would result in no true 0V output for that particular output. The ideal number of points for 25Hz is around 200 points.&lt;br /&gt;
&lt;br /&gt;
[[Image:10pts25Hz.jpg|frame|This demonstrates what happens when you select too few points. The output signal shows the capacitor charging. In this case, 10 points at 25Hz are used in generating the analog output.]]&lt;br /&gt;
&lt;br /&gt;
[[Image:500pts10Hz.jpg|left|frame|This demonstrates what happens when you pick too many points. The output signal has a peak occurring at the 0V area. This output signal used 500 points at 10Hz.]]&lt;br /&gt;
&lt;br /&gt;
[[Image:100pts25Hz.jpg|center|frame|This demonstrates what an ideal analog output should look like. This output was generated using 100 points at 25Hz.]]&lt;br /&gt;
&lt;br /&gt;
==RC Time Constant==&lt;br /&gt;
&lt;br /&gt;
The RC time constant plays a big role in creating the sine wave. By increasing the RC constant, the quality of the output signal is increased, where &amp;quot;quality&amp;quot; refers to the width of the output signals. Despite having such advantages, a larger RC constant will result in a phase lag which causes a delay between the output of the PIC and the output from the whole circuit.&lt;br /&gt;
&lt;br /&gt;
[[Image:RCcompare.jpg|center|frame|The sine waves were generated at 25Hz with 100 points. The sine wave labeled 1 was generated with an RC constant of 4.7 x 10^-5, the sine wave labeled 2 was generated using an RC constant 2.2 x 10^-4 and the sine wave labeled 5 was generated using an RC constant 4.7 x 10^-3. ]]&lt;br /&gt;
&lt;br /&gt;
==Sample Code==&lt;br /&gt;
&lt;br /&gt;
Include your sample code (this may need cleaned up a bit). &lt;br /&gt;
&lt;br /&gt;
 To make a box around the code, put a &#039;space&#039; in front of each line.&lt;/div&gt;</summary>
		<author><name>LawrenceChen</name></author>
	</entry>
	<entry>
		<id>https://hades.mech.northwestern.edu//index.php?title=PIC32MX:_Sinusoidal_Analog_Output&amp;diff=18360</id>
		<title>PIC32MX: Sinusoidal Analog Output</title>
		<link rel="alternate" type="text/html" href="https://hades.mech.northwestern.edu//index.php?title=PIC32MX:_Sinusoidal_Analog_Output&amp;diff=18360"/>
		<updated>2010-05-02T20:21:02Z</updated>

		<summary type="html">&lt;p&gt;LawrenceChen: /* Number of Points Per Period */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Overview:&lt;br /&gt;
&lt;br /&gt;
How do we obtain analog output? ie PWM (brief description)&lt;br /&gt;
&lt;br /&gt;
How do we get sinusoidal output? ie divide up sinusoid into N points, scale duty cycle accordingly&lt;br /&gt;
&lt;br /&gt;
General discussion about how cutoff frequency, number of points period (N) and the RC time constant matter.&lt;br /&gt;
&lt;br /&gt;
State that the examples here have PWM at 20kHz.&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
==Cutoff Frequency==&lt;br /&gt;
&lt;br /&gt;
How to choose cut-off frequency -- what is the equation?&lt;br /&gt;
&lt;br /&gt;
Show picture if you choose your frequency to high and if you choose your frequency to low. &lt;br /&gt;
&lt;br /&gt;
Say something about how the amplitude decreases with high frequency&lt;br /&gt;
&lt;br /&gt;
==Number of Points Per Period==&lt;br /&gt;
Selecting the number of points to use to generate the sine wave is important because choosing too few will result in a very rough sine wave. When the number of points is too low, you can actually see multiple RC charging graphs between each point. However, if we choose too many points, a peak appears at what should be 0V on the sine wave. To prevent this peek from occurring, one could insert an “if” statement in the lookup table generation loop that replaces all of the occurring 0’s into 1’s. Inclusion of the if statement would result in no true 0V output for that particular output. The ideal number of points for 25Hz is around 200 points.&lt;br /&gt;
&lt;br /&gt;
[[Image:10pts25Hz.jpg|center|frame|This demonstrates what happens when you select too few points. The output signal shows the capacitor charging. In this case, 10 points at 25Hz are used in generating the analog output.]]&lt;br /&gt;
&lt;br /&gt;
[[Image:500pts10Hz.jpg|center|frame|This demonstrates what happens when you pick too many points. The output signal has a peak occurring at the 0V area. This output signal used 500 points at 10Hz.]]&lt;br /&gt;
&lt;br /&gt;
[[Image:100pts25Hz.jpg|center|frame|This demonstrates what an ideal analog output should look like. This output was generated using 100 points at 25Hz.]]&lt;br /&gt;
&lt;br /&gt;
==RC Time Constant==&lt;br /&gt;
&lt;br /&gt;
The RC time constant plays a big role in creating the sine wave. By increasing the RC constant, the quality of the output signal is increased, where &amp;quot;quality&amp;quot; refers to the width of the output signals. Despite having such advantages, a larger RC constant will result in a phase lag which causes a delay between the output of the PIC and the output from the whole circuit.&lt;br /&gt;
&lt;br /&gt;
[[Image:RCcompare.jpg|center|frame|The sine waves were generated at 25Hz with 100 points. The sine wave labeled 1 was generated with an RC constant of 4.7 x 10^-5, the sine wave labeled 2 was generated using an RC constant 2.2 x 10^-4 and the sine wave labeled 5 was generated using an RC constant 4.7 x 10^-3. ]]&lt;br /&gt;
&lt;br /&gt;
==Sample Code==&lt;br /&gt;
&lt;br /&gt;
Include your sample code (this may need cleaned up a bit). &lt;br /&gt;
&lt;br /&gt;
 To make a box around the code, put a &#039;space&#039; in front of each line.&lt;/div&gt;</summary>
		<author><name>LawrenceChen</name></author>
	</entry>
	<entry>
		<id>https://hades.mech.northwestern.edu//index.php?title=File:500pts10Hz.jpg&amp;diff=18359</id>
		<title>File:500pts10Hz.jpg</title>
		<link rel="alternate" type="text/html" href="https://hades.mech.northwestern.edu//index.php?title=File:500pts10Hz.jpg&amp;diff=18359"/>
		<updated>2010-05-02T20:16:58Z</updated>

		<summary type="html">&lt;p&gt;LawrenceChen: Analog output using 500 points at 10Hz&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Analog output using 500 points at 10Hz&lt;/div&gt;</summary>
		<author><name>LawrenceChen</name></author>
	</entry>
	<entry>
		<id>https://hades.mech.northwestern.edu//index.php?title=File:100pts25Hz.jpg&amp;diff=18358</id>
		<title>File:100pts25Hz.jpg</title>
		<link rel="alternate" type="text/html" href="https://hades.mech.northwestern.edu//index.php?title=File:100pts25Hz.jpg&amp;diff=18358"/>
		<updated>2010-05-02T20:08:26Z</updated>

		<summary type="html">&lt;p&gt;LawrenceChen: Analog Output using 100 points at 25Hz&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Analog Output using 100 points at 25Hz&lt;/div&gt;</summary>
		<author><name>LawrenceChen</name></author>
	</entry>
	<entry>
		<id>https://hades.mech.northwestern.edu//index.php?title=File:10pts25Hz.jpg&amp;diff=18357</id>
		<title>File:10pts25Hz.jpg</title>
		<link rel="alternate" type="text/html" href="https://hades.mech.northwestern.edu//index.php?title=File:10pts25Hz.jpg&amp;diff=18357"/>
		<updated>2010-05-02T20:00:30Z</updated>

		<summary type="html">&lt;p&gt;LawrenceChen: Analog output of PIC32 using 10 pts at 25Hz&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Analog output of PIC32 using 10 pts at 25Hz&lt;/div&gt;</summary>
		<author><name>LawrenceChen</name></author>
	</entry>
	<entry>
		<id>https://hades.mech.northwestern.edu//index.php?title=PIC32MX:_Sinusoidal_Analog_Output&amp;diff=18356</id>
		<title>PIC32MX: Sinusoidal Analog Output</title>
		<link rel="alternate" type="text/html" href="https://hades.mech.northwestern.edu//index.php?title=PIC32MX:_Sinusoidal_Analog_Output&amp;diff=18356"/>
		<updated>2010-05-02T02:11:44Z</updated>

		<summary type="html">&lt;p&gt;LawrenceChen: /* RC Time Constant */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Overview:&lt;br /&gt;
&lt;br /&gt;
How do we obtain analog output? ie PWM (brief description)&lt;br /&gt;
&lt;br /&gt;
How do we get sinusoidal output? ie divide up sinusoid into N points, scale duty cycle accordingly&lt;br /&gt;
&lt;br /&gt;
General discussion about how cutoff frequency, number of points period (N) and the RC time constant matter.&lt;br /&gt;
&lt;br /&gt;
State that the examples here have PWM at 20kHz.&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
==Cutoff Frequency==&lt;br /&gt;
&lt;br /&gt;
How to choose cut-off frequency -- what is the equation?&lt;br /&gt;
&lt;br /&gt;
Show picture if you choose your frequency to high and if you choose your frequency to low. &lt;br /&gt;
&lt;br /&gt;
Say something about how the amplitude decreases with high frequency&lt;br /&gt;
&lt;br /&gt;
==Number of Points Per Period==&lt;br /&gt;
&lt;br /&gt;
Show Pictures of number of points to small - discuss that you see the capacitor charging&lt;br /&gt;
&lt;br /&gt;
Show picture of good number of points&lt;br /&gt;
&lt;br /&gt;
==RC Time Constant==&lt;br /&gt;
&lt;br /&gt;
The RC time constant plays a big role in creating the sine wave. By increasing the RC constant, the quality of the output signal is increased, where &amp;quot;quality&amp;quot; refers to the width of the output signals. Despite having such advantages, a larger RC constant will result in a phase lag which causes a delay between the output of the PIC and the output from the whole circuit.&lt;br /&gt;
&lt;br /&gt;
[[Image:RCcompare.jpg|center|frame|The sine waves were generated at 25Hz with 100 points. The sine wave labeled 1 was generated with an RC constant of 4.7 x 10^-5, the sine wave labeled 2 was generated using an RC constant 2.2 x 10^-4 and the sine wave labeled 5 was generated using an RC constant 4.7 x 10^-3. ]]&lt;br /&gt;
&lt;br /&gt;
==Sample Code==&lt;br /&gt;
&lt;br /&gt;
Include your sample code (this may need cleaned up a bit). &lt;br /&gt;
&lt;br /&gt;
 To make a box around the code, put a &#039;space&#039; in front of each line.&lt;/div&gt;</summary>
		<author><name>LawrenceChen</name></author>
	</entry>
	<entry>
		<id>https://hades.mech.northwestern.edu//index.php?title=File:RCcompare.jpg&amp;diff=18355</id>
		<title>File:RCcompare.jpg</title>
		<link rel="alternate" type="text/html" href="https://hades.mech.northwestern.edu//index.php?title=File:RCcompare.jpg&amp;diff=18355"/>
		<updated>2010-05-02T02:10:53Z</updated>

		<summary type="html">&lt;p&gt;LawrenceChen: uploaded a new version of &amp;quot;Image:RCcompare.jpg&amp;quot;: Analog output comparison of PIC32 with various RC constants.&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Analog output comparison of PIC32 with various RC constants.&lt;/div&gt;</summary>
		<author><name>LawrenceChen</name></author>
	</entry>
	<entry>
		<id>https://hades.mech.northwestern.edu//index.php?title=File:RCcompare.jpg&amp;diff=18354</id>
		<title>File:RCcompare.jpg</title>
		<link rel="alternate" type="text/html" href="https://hades.mech.northwestern.edu//index.php?title=File:RCcompare.jpg&amp;diff=18354"/>
		<updated>2010-05-02T02:06:35Z</updated>

		<summary type="html">&lt;p&gt;LawrenceChen: Analog output comparison of PIC32 with various RC constants.&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Analog output comparison of PIC32 with various RC constants.&lt;/div&gt;</summary>
		<author><name>LawrenceChen</name></author>
	</entry>
	<entry>
		<id>https://hades.mech.northwestern.edu//index.php?title=File:RCtest1-5.jpg&amp;diff=18353</id>
		<title>File:RCtest1-5.jpg</title>
		<link rel="alternate" type="text/html" href="https://hades.mech.northwestern.edu//index.php?title=File:RCtest1-5.jpg&amp;diff=18353"/>
		<updated>2010-05-02T01:57:40Z</updated>

		<summary type="html">&lt;p&gt;LawrenceChen: uploaded a new version of &amp;quot;Image:RCtest1-5.jpg&amp;quot;: The sine wave labeled 1 was generated with an RC constant of 4.7 x 10^-5 and 5 was generated using an RC constant 4.7 x 10^-3&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;The sine wave labeled 1 was generated with an RC constant of 4.7 x 10^-5 and 5 was generated using an RC constant 4.7 x 10^-3.&lt;/div&gt;</summary>
		<author><name>LawrenceChen</name></author>
	</entry>
	<entry>
		<id>https://hades.mech.northwestern.edu//index.php?title=File:RCtest1-5.jpg&amp;diff=18352</id>
		<title>File:RCtest1-5.jpg</title>
		<link rel="alternate" type="text/html" href="https://hades.mech.northwestern.edu//index.php?title=File:RCtest1-5.jpg&amp;diff=18352"/>
		<updated>2010-05-02T01:55:34Z</updated>

		<summary type="html">&lt;p&gt;LawrenceChen: The sine wave labeled 1 was generated with an RC constant of 4.7 x 10^-5 and 5 was generated using an RC constant 4.7 x 10^-3.&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;The sine wave labeled 1 was generated with an RC constant of 4.7 x 10^-5 and 5 was generated using an RC constant 4.7 x 10^-3.&lt;/div&gt;</summary>
		<author><name>LawrenceChen</name></author>
	</entry>
	<entry>
		<id>https://hades.mech.northwestern.edu//index.php?title=File:RCtest1-2.jpg&amp;diff=18351</id>
		<title>File:RCtest1-2.jpg</title>
		<link rel="alternate" type="text/html" href="https://hades.mech.northwestern.edu//index.php?title=File:RCtest1-2.jpg&amp;diff=18351"/>
		<updated>2010-05-02T01:47:27Z</updated>

		<summary type="html">&lt;p&gt;LawrenceChen: uploaded a new version of &amp;quot;Image:RCtest1-2.jpg&amp;quot;: The sine wave labeled 1 was generated with an RC constant of 4.7 x 10^-5 and 2 was generated using an RC constant 2.2 x 10^-4&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;The sine wave labeled 1 was generated with an RC constant of 4.7 x 10^-5 and 2 was generated using an RC constant 2.2 x 10^-4&lt;/div&gt;</summary>
		<author><name>LawrenceChen</name></author>
	</entry>
	<entry>
		<id>https://hades.mech.northwestern.edu//index.php?title=File:RCtest1-2.jpg&amp;diff=18350</id>
		<title>File:RCtest1-2.jpg</title>
		<link rel="alternate" type="text/html" href="https://hades.mech.northwestern.edu//index.php?title=File:RCtest1-2.jpg&amp;diff=18350"/>
		<updated>2010-05-02T01:43:02Z</updated>

		<summary type="html">&lt;p&gt;LawrenceChen: The sine wave labeled 1 was generated with an RC constant of 4.7 x 10^-5 and 2 was generated using an RC constant 2.2 x 10^-4&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;The sine wave labeled 1 was generated with an RC constant of 4.7 x 10^-5 and 2 was generated using an RC constant 2.2 x 10^-4&lt;/div&gt;</summary>
		<author><name>LawrenceChen</name></author>
	</entry>
</feed>