Download How to Create Square Waves in MATLAB

Survey
yes no Was this document useful for you?
   Thank you for your participation!

* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project

Document related concepts

Ground loop (electricity) wikipedia , lookup

Ohm's law wikipedia , lookup

Stepper motor wikipedia , lookup

Stray voltage wikipedia , lookup

Islanding wikipedia , lookup

Electrical ballast wikipedia , lookup

Voltage optimisation wikipedia , lookup

Mercury-arc valve wikipedia , lookup

Two-port network wikipedia , lookup

Power MOSFET wikipedia , lookup

Surge protector wikipedia , lookup

Current source wikipedia , lookup

P–n diode wikipedia , lookup

Heterodyne wikipedia , lookup

Power inverter wikipedia , lookup

Oscilloscope history wikipedia , lookup

Rectifier wikipedia , lookup

Mains electricity wikipedia , lookup

Diode wikipedia , lookup

Variable-frequency drive wikipedia , lookup

Alternating current wikipedia , lookup

Switched-mode power supply wikipedia , lookup

Power electronics wikipedia , lookup

Triode wikipedia , lookup

Buck converter wikipedia , lookup

Resistive opto-isolator wikipedia , lookup

Pulse-width modulation wikipedia , lookup

Opto-isolator wikipedia , lookup

Transcript
Data Acquisition Device (DAQ)
A DAQ is a cool little device that allows you to interface
hardware to a computer. Here is what we will do:
 Create a square wave in MATLAB
 Send the signal out through the DAQ as a voltage signal
applied across a series circuit (OUTPUT a Signal)
 Use the DAQ as a voltmeter to measure the voltage across
a resistor (INPUT the measurements)
 The DAQ will send these measurements back into MATLAB
so we can easily plot the voltage vs. time
National Instrument myDAQ
For this experiment, we will be
using one of the Analog
OUTPUT channels:
• Analog Output 0 channel
• AO0 is the output
• AGND is the ground
• This channel will
OUTPUT a square wave
to the circuit
National Instrument myDAQ
For this experiment, we will be
using one of the Analog INPUT
channels:
• Analog Input 0 channel
• AI0+ is the positive side
• AI0- is the negative side
• This channel is a
voltmeter and will be
used to measure the
voltage across the
resistor
Square Waves
•
•
•
•
A square wave is a periodic signal that oscillates between two values.
The period, T, is the time for one complete cycle (T = 1/f)
The frequency, f, is the number of cycles in 1 second (f = 1/T)
The duty cycle, tau, is the percentage of time the wave is at the higher value.
Period: T =
0.5 sec
Period: T =
0.5 sec
Frequency: f = 2 Hz (cycles/sec)
Frequency: f = 2 Hz
Duty cycle: tau =
50%
Duty cycle: tau = 80%
Average Value =
5V
Average Value =
8V
How to Create Square Waves
in MATLAB
1. Create a vector of times, t, typically based on the period of the square
wave.
2. Use the square function in MATLAB:
square(2*pi*frequency*t, tau)
Note: square wave will oscillate between -1 and +1
Example: Here is how the 2 Hz square wave on the previous page with the
80% duty cycle was created.
t = 0:0.001:1;
y = 5*square(2*pi*2*t,80)+5; % f = 2 Hz and tau = 80%
* Multiplying by 5 then adding 5 makes the square wave
go from 0 to 10.
Pulse Width Modulation
Square Waves with varying duty cycles are used in many control and
communication applications.
One very common application is to control the speed of a DC motor. The
duty cycle is increased to increase the speed of the motor and decreased
to reduce the motor speed.
This type of control is referred to as Pulse Width Modulation (PWM).
Our DAQs don’t source enough current to drive a motor so we will use
PWM to control the light level of a Light Emitting Diode (LED).
DIODES
Diodes are “one-way” devices that only allow current to flow in
one direction. An LED is a diode that emits light when sufficient
current is flowing through it. Diodes are used in many, many
applications such as:
• LED flashlights and light bulbs provide very bright light and
use significantly less power than incandescent bulbs, last
much longer than incandescent bulbs, and stay cool
• Diodes are used in circuits to convert AC power to DC
power (laptop chargers, phone chargers, appliances that
run on dc …)
• LEDs are used in displays, signs, and traffic signals
Light Emitting Diode (LED)
When the positive side of a
voltage source is applied to
the anode (+) side of an
LED, current will flow
through the circuit and the
LED will light up.
Anode (+)
Cathode (-)
Current
Flows
When the positive side of a
voltage source is applied to
the cathode (-) side of an LED,
current will not flow through
the circuit and the LED will not
light up.
Anode (+)
Cathode (-)
No
Current
Flows
Building the Circuit
How to build your circuit using the
breadboard:
1. Insert the leads of the resistor, LED,
and cables into the holes in the
breadboard, but don’t force them!
2. The openings A-E and F-J in each
numbered row in the breadboard are
electrically connected together, so
placing the leads of two components in
the same row will connect them
3. The openings in different numbered
rows are not electrically connected, so
each lead of a component should be in
a different row
4. Rows on opposite sides of the middle
break are not electrically connected
Connected
Not
Connected
Connected
Attaching Cables
screwdriver
How to attach a cable:
Cable
1. Insert the metal part of the end
cable into the port on the side
of the myDAQ – make sure
the metal part of the cable is
above the metal bar in the
port
2. Use the screwdriver to rotate
the screw on top of the port
clockwise to tighten the
connection to the cable
3. Pull GENTLY on the cable to
ensure that it is properly
connected to the DAQ Cable
Metal
bar
Correct
screwdriver
Metal
bar
end
Incorrect
Circuit