Order from us for quality, customized work in due time of your choice.
LAB REPORT #2Name
Date
Course Code
Table of contents
AbstractPage 3
Introduction
Sin Wave Generator Page 4
Square Wave GeneratorPage 5-6
Saw tooth Wave GeneratorPage 7
ConclusionPage 8
Abstract
The experiment detailed herein was done in classroom. The purpose was to project all the waves on oscilloscope provide by the code teacher. The teacher had explained and showed us Square Wave, Sine Wave and Triangle/Saw tooth Wave. Through C#, the code was embedded into the Net Duino. The circuit that had been made earlier was connected to the Oscilloscope. The three waves were seen in the attacked oscilloscope.
Introduction
The lab report commences by the introduction of the three above mentioned waves. All the waves were generated using the same voltages. The oscilloscope helps to take screen shot of the waves. Additionally, each wave was represented using a code. The Waves are presented as show through the code placed in NetDuino.
Sine Wave Generator
using System;
using System.Net;
using System.Net.Sockets;
using System.Threading;
using Microsoft.SPOT;
using Microsoft.SPOT.Hardware;
using SecretLabs.NETMF.Hardware;
using SecretLabs.NETMF.Hardware.NetduinoPlus;
// Gives a PWM output that, its duty cycle varies as a function of a sine wave.
//It is like DAC. To see a Sine wave on scope pass the output through a low pass RC filter.
//Also if you connect the output to a LED its intensity varies like a sine wave.
namespace NetduinoPlusPWM_SineWave{
public class Program
{
public static void Main()
{
int value = 0;
int degree = 0;
//PWM pwm = new PWM(Pins.GPIO_PIN_D5);
PWM pwm = new PWM(Cpu.PWMChannel.PWM_3, 500, 0.5, false);//PIN D10
while (true)
{
degree += 1; // lets go from 0 to 360 degree over and over
degree %= 360; //remainder of 0-359
// sin() function returns an integer from -1000 to 1000. We need to shift it up by a 1000 to become positive
value = 1000 + Microsoft.SPOT.Math.Sin(degree); // value is between 0 and 2000
uint nValue = (uint)((value) / 20); // lets scale value from 0-2000 to 0-100. The percent duty cycle is nValue pwm.DutyCycle = (((float)(nValue))/100); // set the duty-cycle to a specific nvalue //Thread.Sleep(10);
// Debug.Print(degree.ToString());
// Debug.Print(value.ToString());
// Debug.Print(nValue.ToString());
}
}
}
-27622516383000 }
Description
In this starting wave generator which is Sine wave, the section of the law indicates the real code of the wave and also a screen shot as obtained from Oscilloscope.
Square Wave Generator
using System;
using System.Net;
using System.Net.Sockets;
using System.Threading;
using Microsoft.SPOT;
using Microsoft.SPOT.Hardware;
using SecretLabs.NETMF.Hardware;
using SecretLabs.NETMF.Hardware.NetduinoPlus;
namespace NetduinoPlusApplication1
{
public class Program
{
static long DelayTicks;
static long ticks;
//long DelayTicks = 500*10; //#ticks for 500us
static void delay(long duration)
{
DelayTicks = duration * 10; //period and measured in microseconds
ticks = Utility.GetMachineTime().Ticks; // capture current time and put it in ticks
while ((Utility.GetMachineTime().Ticks – ticks) < DelayTicks) ;
}
public static void Main()
{
// Make ramp wave
OutputPort led = new OutputPort(Pins.GPIO_PIN_D0, false);
long period = 1000; //1=1usec
long lowTime=0;
while (true)
{
lowTime+=20; //increase the low time part of the pulse
if (lowTime >= period)
// turn LED ON
led.Write(true);
// let it be ON
delay(period – lowTime); //high time is period – lowTime
// turn LED OFF and let it stay OFF
led.Write(false);
delay(lowTime);
lowTime = 0;
}
}
}
}
033274000
Description
In this second wave generator, the real code of Sine waves and the screen shot obtained from oscilloscope is shown.
Saw Tooth Wave Generator
using System;
using System.Net;
using System.Net.Sockets;
using System.Threading;
using Microsoft.SPOT;
using Microsoft.SPOT.Hardware;
using SecretLabs.NETMF.Hardware;
using SecretLabs.NETMF.Hardware.NetduinoPlus;
namespace NetduinoPlusApplication1
{
public class Program
{
public static void Main()
{ //uses hardware pwm. LED is connected to PIN D10 (PWM_3) and a grounded resisior of 220
double dutyCycle = 0;
//at port PWM3, freq=1000hz, duty cycle=0.5 and output not inverted.
var pwm = new PWM(Cpu.PWMChannel.PWM_3, 1000, 0.5, false);//PIN D10
var button = new InputPort(Pins.ONBOARD_SW1, false, Port.ResistorMode.Disabled);
pwm.Start();
while (true) //keep polling
{
if (button.Read() == true) //if button pressed
{
if (dutyCycle < 1)
dutyCycle = dutyCycle + .05; //as long as the button pressed increment the duty cycle
else dutyCycle = 0;
pwm.DutyCycle = dutyCycle;
Thread.Sleep(300); //to avoid multiple read of the key pressed
}
}
}
}
}
Description
In the last and third section, Saw tooth wave is shown. This section of the experiment shows the actual Saw tooth wave code and screen shot as indicated through Oscilloscope.
Conclusion
At the end of the experiment the conclusion was that regardless of similar voltages across all the three waves, suppose there is a change in frequencies of the waves, the way waves are presented in oscilloscope can differ. Also, I observed that minus having the correct code into the NetDuino. The projection and the circuit would not be accurate as would be expected.
Order from us for quality, customized work in due time of your choice.
Leave a Reply