You are on page 1of 86

BuildIt

Oscilloscope 3
© 2018, Joseph Berardi
All rights are reserved.

Filename: BuildIt_Vol006_Oscilloscope_3_2018_0906a2.docx
Edition: 1
Book Series: BuildIt
Volume: 6
Social Media
Facebook.com: Berardi’s Electronic Projects

Table of Contents
BuildIt Oscilloscope 3
Warning
Disclaimer
Non-liability Statement
BuildIt Books
BuildIt Book List
Author’s Paperback Books (Year Published)
Introduction
Getting Started
Electronic Primer
Introduction to a Sketch
Arduino Home Page
Arduino Software Page
Arduino USB COM Port Driver
Installing the FTDI Virtual COM port driver
Arduino Board
Sketch Tutorial
Step 1
Arduino Uno Rev 3 Board Setup
Step 2
Arduino Uno Rev 3 Port Setup
Step 3
Arduino Uno Rev 3 New File
Step 4
Step 5
Arduino Uno Rev 3 Sketch Verify
Step 6
Upload Error
Step 7
Experiments
Experiment 1 - Blinking LED
Experiment 2 - Dim LED
Experiment 3 - Dim and Blink LED
Experiment 4 - PWM Square Wave and Serial Monitor
Experiment 5 - PWM Square Wave, RC Filter and Serial Plotter
Oscilloscope 3 Project
ADC0820 Analog-to-Digital Converter
Components Required
Definitions
Datasheet Information
ADC0820 Data Sheet Information
Electronic Parts Suppliers
Trademarks
References
Warning
Electricity can kill. You are responsible for your own safety. Electricity
improperly used can cause a fire or an explosion. Most of the projects in this
book are low voltage so there is little chance of electrical shock but working
improperly with electricity can cause serious injury or death. Never touch live
electrical circuits. Polarized components installed backwards tend to overheat or
explode.
Disclaimer
The author does not claim fitness, capabilities or performance for anything in
this book and your results may vary.
Non-liability Statement
The author, publisher and all associates disclaim any responsibility or liability
for injuries, damages or losses whatsoever for the use of this book.
BuildIt Books
The BuildIt book series are about electronic projects that were built by the
author. Most of the electronic projects in this series are standalone projects with
comprehensive documentation and photographs. The documentation may
includes the following: schematics, PCB artwork (when used), parts list,
description, assembly instructions and test results. Most of the electronic projects
can be built on a solderless breadboard or generic prototype board although the
author prefers making custom printed-circuit-boards. The more complex projects
such as the oscilloscopes usually require building multiple circuit boards and
integrating them together for the complete project.
For those just starting out building electronic projects the author has published
“Electronic Circuits 2nd Edition” that provides an introduction to electronic
theory and components. The “Electronic Projects for the Test Bench” book
provides an introduction to building electronic projects and it has a
comprehensive Electronic Reference section.
The author has published numerous paperback books for those who prefer them.
One of the advantages of paperback books is they are easy to make notes in
them.
BuildIt Book List
Volume 1: 555 Astable 2 Oscillator
Volume 2: Electronic Reference
Volume 3: How to Build Electronic Projects
Volume 4: Oscilloscope Tutorial
Volume 5: Oscilloscope 2
Volume 6: Oscilloscope 3
Volume 7: Oscilloscope 4 Standard
Volume 8: Oscilloscope 4 Premium
Volume 9: Oscilloscope 5
Volume 10: Oscilloscope 6

Author’s Paperback Books (Year Published)
Electronic Circuits 2nd Edition (2018)
The Electronic Circuits 2nd Edition book is the best book for getting started in
electronic circuits. This book is application oriented and covers resistor,
capacitor and inductor networks, transient circuits, RF Filters, transistor circuits,
oscillators, amplifiers, modulation, demodulation, digital logic and much more.
Electronic Projects for the Test Bench (2018)
This book has electronic projects that can be built with minimum project
building experience and most of them can be built on a solderless breadboard
although the author has made custom PCBs for them. This book emphasizes the
old-school approach and no computers or software is required. This book covers
most of the test equipment that normally is used on an electronic test station
including the oscilloscope 4 project.
Electronic Projects for Oscilloscopes 2017 (2017)
The focus of this book is building oscilloscope projects and the subsystems that
support them. This book emphasizes the new-school approach to electronic
projects making use of the Arduino embedded controller to greatly enhance the
oscilloscope capabilities and a PC Computer for the user interface. There are
sketch and FreeBASIC code examples in this book. This book includes
oscilloscope projects 1, 3, 6 and 7.
Electronic Circuits for Inventors (2016)
This book covers a diverse range of electronic circuits, it is more experiment
oriented than most of the other books. This book includes oscilloscope projects 2
and 5.
Electronic Projects for Oscilloscopes (2016, 2017 update)
This is the original oscilloscope projects book which was originally an old-
school book where no computers or programming was required. The 2017
update replaced a very complex project with a much simpler Arduino based
oscilloscope project. This book includes oscilloscope projects 2, 5 and 6.
Introduction
This book is a combination of an electronic project and a tutorial for using the
Arduino Uno Rev 3 board.
The Oscilloscope 3 project is a demonstration of turning an Arduino Uno Rev 3
board into an oscilloscope by attaching an external A/D converter integrated
circuit device to it. The required sketch program listings are included in this
book. The BuildIt Oscilloscope 6: Volume 10 book expands on what is learned
here by demonstrating how to use an application programming language to un-
tether the oscilloscope project from the Arduino IDE and make your own
graphical oscilloscope screen. The BuildIt Oscilloscope 6 book also shows
techniques to make the sketch code run faster to increase the sampling clock
frequency.
This book has a tutorial for learning the Arduino environment since it is intended
for novice project builders. There are several experiments to get hands-on
experience with the Arduino Uno board prior to attempting the Oscilloscope 3
project.
Getting Started
This book has a tutorial for learning how to use and program the Arduino Uno
Rev 3 board. If you already know how to do this then you will probably want to
skip the experiments. The experiments show how to use electronic components
that are compatible with the Uno board interfaces. For the experiments the
electronic circuits are built onto a solderless breadboard. This book is intended
for hobbyist although professionals may learn a thing or two from this book.
For those just starting out with no electronic experience, the “Electronic Projects
Volume 1: Getting Started” is strongly recommended since it introduces
electronic components, schematic symbols, their functions and places to
purchase such components.
This book is intended for beginners but only the first several experiments use the
physical layout method for showing the electrical connections. After that the
student is required to recognize component symbols and make the connections
as shown on the schematics. The physical layout method for showing
connections is only practical for the simplest of circuits and the later experiments
use schematics to show the electrical connections.
Electronic Primer
This primer is an over-simplification of electronic theory. If you don’t
understand the primer information then you are in need of a very basic tutorial
on electrical concepts and should read the “Electronic Circuits 2nd Edition”
book by Joseph Berardi.
Analog Signals
The analog signals for the experiments can be any value within the +5V (power
supply) and 0V (GND) range used by the Uno board.
Logic Levels
A logic level is equivalent to turning a light “on” or “off”. The logic level
voltages are just like the AC electricity in a home. The AC voltage may be
identified as 120VAC but it has a tolerance and the actual voltage may be
anywhere from 105 to 130 volts. For the Uno board the simplified logic level
threshold is 1.4 DC volts. In reality, the Uno board output voltage for logic
“HIGH” is near 5V and the output voltage for a logic LOW is near GND or the
zero volt reference. The Uno board logic output pins has a small series resistor to
help protect from burning out the driver so there may be a small voltage drop
across this protection resistor depending on the load current.
DC Voltages are fixed values while AC voltages vary with a repeating pattern
measured in cycles per second or frequency.
Frequency = 1/Time Period
Ohms Law
E=IR
The voltage across a load is equal to the resistance of the load times the current
flowing through the load.
E = voltage in volts
I = current in ampere
R= resistance in ohms
Prefix
Kilo (K) = 1,000
Meg (M) = 1,000,000
So 1.2K ohm is equal to 1200 ohms.
milli (m) – 1/1000
Polarity
Polarity is the direction of the current flow or when measured in voltage is either
a positive voltage or a negative voltage. A battery such as a car battery has a
positive and negative terminal.
The polarity of a power source or many devices is extremely important for
polarized components. Connecting a voltage or component in the reverse
direction will not work and in some cases can produce disastrous results. The
disaster can range from overheating to an outright explosion or fire.
A polarized component has a positive and negative terminal. There are many
ways to mark the polarity of a component. The simplest way is to mark a plus
symbol and a negative symbol at the appropriate terminals.
For an LED the package usually has a flat spot near the negative terminal.
For a diode a band marks the negative terminal.
For a NPN transistor the emitter goes to the negative side of the circuit and the
collector goes to the positive side of the circuit.
Some devices it may not be obvious that they are polarized so you must look
carefully for the marking.
Introduction to a Sketch
The sketch is the program run by the Arduino embedded microcontroller.
The Arduino sketch has two mandatory predefine functions. A sketch is a C-like
programming language.
The setup function is run once at reset. The reset occurs on power-up of the
board, pressing the reset button, uploading of the code or when initializing the
serial COM port from the host side.
The second mandatory function is the loop function.
The code within the loop function will be repeatedly run. The code starting at the
top will be executed down to the bottom, and then it starts over again. It is
essentially a while loop with no exit.
The sketch programming language is a C-like language with some added
predefined functions specific to the Arduino micro-controller.
The sketch code for the first experiment is minimal adding only five lines to the
minimum sketch code. The // characters identify a comment line and it is not
executed.
The digital pin 2 is set for the output mode using the pinMode function call.
The digitalWrite function is used to identify the pin number (2) and the logic
state for that pin which is a logic LOW for the first function call. To ensure the
human eye can see the pulsed illumination of the LED a 1 second delay is
inserted between turning “on” and “off” the LED. The logic HIGH state results
in about a 5V output where the output is sourcing the current through the LED
device causing it to illuminate.
void setup() {
// put your setup code here, to run once:
pinMode (2, OUTPUT);
}

void loop() {
// put your main code here, to run repeatedly:
digitalWrite(2,LOW);
delay (1000);
digitalWrite(2,HIGH);
delay(1000);
}
Arduino Home Page
To get the Arduino environment start at the Arduino home page. The
environment includes a source code editor, c compiler and downloader. The
environment is also known as the IDE which stands for Integrated Development
Environment. Although I may give some information regarding the Arduino
environment, the following website is the official source for all Arduino
software and documentation.
www.arduino.cc
When in doubt, go to the LEARNING menu item at the top of the page.

Arduino Software Page
Go to the software page to start a download.
Using the ZIP file download allows bypassing the Windows Installer method and
may be preferred.
https://www.arduino.cc/en/Main/Software

Arduino USB COM Port Driver
Although I provided screen captures to aid in leaning the environment, the
official website is the authority on how to use the Arduino software. There may
be a lot of steps to get the driver installed.

https://www.arduino.cc/en/Guide/Troubleshooting#toc1

The following is an Arduino excerpt from the official website for getting the
driver installed properly.

Drivers
Drivers provide a way for software on your computer (i.e. the Arduino software)
to talk to hardware you connect to your computer (the Arduino board). In the
case of Arduino, the drivers work by providing a virtual serial port (or virtual
COM port). The Arduino Uno and Mega 2560 use standard drivers (USB CDC)
provided by the operating system to communicate with the ATmega8U2 on the
board. Other Arduino boards use FTDI drivers to communicate with the FTDI
chip on the board (or in the USB-serial convertor).

The easiest way to check if the drivers for your board are installed correctly is by
opening the Tools > Serial Port menu in the Arduino software with the Arduino
board connected to your computer. Additional menu items should appear relative
to when you open the menu without the Arduino connected to your computer.
Note that it shouldn't matter what name the Arduino board's serial port gets
assigned as long as that's the one you pick from the menu.
On Windows 7 (particularly the 64-bit version), you might need to go into
the Device Manager and update the drivers for the Uno or Mega 2560. Just
right click on the device (the board should be connected to your
computer), and point Windows at the appropriate .inf file again. The .inf is
in the drivers/ directory of the Arduino software (not in the FTDI USB
Drivers sub-directory of it).
If you get this error when installing the Uno or Mega 2560 drivers on
Windows XP: "The system cannot find the file specified", you might try
this suggestion (about adding a "RunOnce" key to
"HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion").
On Linux …
Installing the FTDI Virtual COM port driver
I have installed the Arduino environment on several PCs and only installed the
COM port driver on my LAPTOP3, an older Windows PC which is only used for
my test bench equipment.
The following steps are what it took for me to get the driver installed properly on
LAPTOP3. I recommend going to the Arduino website and following the
directions there.
I copied from Folder:
Arduino/Download/ZIP/Arduino-1.8.0-windows.zip/Arduino-1.8.0/drivers/FTDI
USB Drivers
To the thumb-drive “2017_0331/drivers folder
Laptop3 – Compaq Presario C714NR Notebook – Windows Vista Home
Premium
Pentium Dual Core Processor, 60 GB Hard Drive
Step 1
I created a new folder on laptop3
Documents>Arduino
And copied folder 2017_0331 to it which has the driver folder
Step 2
Connect an Arduino board to the PC USB port
Step 3
To install the FTDI Virtual COM driver:
1. Go to the Windows Control Panel
(Start > Control Panel)
Device Manager
A new window pops up Found New Hardware
Select option: Locate and install driver software
After plugging in the USB connector, Device Manager now shows a new folder
labeled “Other devices” and the folder FT232R USB Uart has an exclamation
mark indicating it is not installed.
A new window pops up and select “Don’t search online”
Another window pops up indicating to insert disk that came with the device.
Select
I don’t have the disk, show me other options
Select
Browse my computer with checkbox checked for include subfolders
Select
Browse
Users/Joe/Documents/Arduino/drivers
Select
OK
Next
A new window pops up in red indicating “Windows can’t verify the publisher of
this software”
Select
Install this driver anyways
You should see the following message:
The software for this device has been successfully installed.
OK and Close
Installation failed
Now click on folder:
Other Devices > USB Serial Port
Select
Update Driver Software
Browse my computer
Select Folder
Use the same “drivers” folder previously selected
Next
A new window pops up in red indicating “Windows can’t verify the publisher of
this software”
Select
Install this driver anyways
This time the exclamation mark is gone indicating it is properly installed.
Step x
This step is optional. Verify serial port properties
Right-click the folder and properties
It shows USB Serial Port (COM4) properties
9600 baud
8 Data bits
No parity bit
1 stop biy
No flow control


Arduino Board
Arduino Uno REV 3 Board
The Arduino Uno REV 3 Board opens up the world of embedded controller to
the hobbyist and professionals alike. The boards are low cost, typically less than
$25 US.
Notice the signals labeling on the board along the black header connectors. This
is where the external connections to the Uno board are made.
The two top headers have the digital input/output pins numbered 0 through 13
along with a GND connection. Digital 0 and 1 are shared pins and should be
avoided. The bottom right header has the analog pins labeled A0 to A5. The
bottom left header has the power pins and the GND pins.

DIP Version with USB Port
Sketch Tutorial
A sketch is the code or software that is executed by the Arduino microcontroller.
Step 1
After the Arduino environment has been set up here are a few steps required to
set the target hardware and select which port that will be used to communicate
with the Arduino board. Go to the tools menu and select the Arduino/Genuino
Uno board.
Arduino Uno Rev 3 Board Setup
Step 2
Before the compiled code can be uploaded to the Uno board the appropriate port
must be selected. The Port menu option shows all available ports connected to
the Arduino board and when there is only one board, only one port option will be
shown.
Arduino Uno Rev 3 Port Setup
Step 3
Go to the File tab and select New to start a new sketch program.
Arduino Uno Rev 3 New File
Step 4
After creating a new sketch you will see a template for the minimum code that is
required in a sketch program. There are two predefined Arduino functions in the
C code that must be in every sketch. The setup function is executed only once at
reset which can be the button on the Uno board, power up, uploading the sketch
or when the port gets initialized. The loop function does just that, continuously
executing from top to bottom are and starting over again.
The following code can be executed but it doesn’t do anything as far as setting or
reading pins.
Step 5
Using the environment source code editor a program can be typed in. Once the
sketch is complete the “verify” operation c(checkmark icon) can be performed.
The first error found will be highlighted in a red color indication the error with a
message. I recommend saving the file with an appropriate name after passing the
verify operation. The sketch is ready to be uploaded using the right-arrow icon
next to the checkmark icon. Notice the keywords have color fonts and they are
case sensitive.
Arduino Uno Rev 3 Sketch Verify
The checkmark icon initiates the syntax checker for the source code.
Step 6
If have see this problem uploading screen either the Uno board is not plugged
into the USB port or the Port hasn’t been selected for the board being used.
When I switch to another Uno board I also have to switch the COM port. It is
possible to be connected to multiple Uno boards simultaneously.
Upload Error

Step 7
The “done uploading” message will indicate the code is running on the Uno
board.
Experiments
An experiment, at least for this book is building up a simple electronic circuit
which is made of components that can be placed onto a solderless breadboard.
An experiment is temporary and the construction of the circuit is temporary and
the components can be reused. The purpose of most experiments is a learning
exercise. An experiment may be to learn a concept or how a device works.
A solderless breadboard is used to hold these components which are specialized
boards full of holes. These breadboards allow components or wires to be
inserted into the holes. An electrical connection is made inside the hole to the
wire or component lead by a piece of metal. Strips of usually five holes are
connected together internally by this metal connector using mechanical pressure
to make the electrical connection. A five-hole strip allows five electrical
connections together.
Normally a circuit board requires some external connections and this is usually
done through connectors. A connector is a device for making both a physical and
electrical connection. Most connectors have a corresponding mate so many times
there is a male and female connector which can be plugged into each other.
The Arduino Uno Rev 3 board has header connectors. The single row headers
connector is along the edge of the board and signal for each pin are labeled on
the board and also on the side of the header. The header is the black single-row
connector capable of accepting a mating connector, jumper wires with male pins
attached to either end or simply #22 gauge copper hookup wire.
As a convenience the author used premade jumper wires with a male pin on each
end for most of the experiments.
The first experiment is intended as getting acquainted with the Arduino software,
Arduino Uno Rev 3 board and a solderless breadboard. A schematic is a
drawing that shows the electrical connection. Although some beginner books use
a mechanical drawing in lieu of a schematic showing the physical connections to
be made, this technique is impractical for any circuit of significance.
So it best for any serious experimenter to get acquainted with schematics and
translating the electrical connections into physical connections on whatever type
of board that is going to be used.
An experiment is meant to be a temporary creation for a learning exercise while
what is known as a project is meant to be a permanent build for a circuit. What
separate the two are projects that uses permanent connections between
components that make the circuit more reliable and more durable. Melting
solder, a mix of lead and tin is used to make a permanent electrical connection in
place of a pressure connection on a wire. A few of the experiments in this book
are built as projects.
Normally an experiment is more than just building up something or a circuit. For
electronic experiments it usually involves applying stimulus to a circuit and
monitoring the output to see how the circuit responds to the stimulus. There are
many ways to apply a stimulus and monitor or see a response.
When an embedded microcontroller is involved, it actions are programmable in
the form of software. A programming language such as C is required along with
a compiler that converts the source code into executable code.
The standard documentation for the experiments in this book is a schematic,
parts list, photograph of the experiment hardware, source code listing,
description of the experiment and possibly photographs or screen captures of the
output from the experiment.
Experiment 1 - Blinking LED
The Uno board is used to turn on and off the illumination of an LED using
digital pins. The pins must be set to output mode. Both the schematic drawing
and the experiment photograph show the configuration for the first three
experiments. The Uno connector has the pin names labeled on the board. The
modern symbol for a resistor is a rectangular box while the traditional symbol is
a zigzag line symbol shown later. A line on a schematic usually represents an
electrical connection or a wire also known as a jumper-wire (JW). It may not be
a straight line for hand drawn schematics and certainly won’t be for the wire on a
breadboard. The round symbol with a flat spot represents a mechanical symbol
for an LED with the flat side indicating the negative side.
The following schematic shows two LEDs with their current limiting resistors
that are connected to digital pins 2 and 3 with the negative side connected to the
GND pin. For this experiment the digital pins are configured as output pins using
the Arduino predefined pinMode function.
Schematic / Physical Connection Drawing

Components Required
Designator Category Description Part# Qty
MCU Micro- MCU,ARDUINO UNO SMD,REV3 2163840 1
controller 32K FLASH,1K EEPROM,USB,14
I/O
BB-small breadboard BREADBOARD,3.25"x2.125",400pnt 20601 1

R resistor Resistor Carbon Film 330 Ohm 1/2 661386 2
Watt 5%
D diode LED Uni-Color Red 660nm 2-Pin T-1 333973 2
3/4 Box
Light-Emitting Diode

JW wire Jumper wire, #22 solid copper with
insulation
JW wire JUMPER WIRE SET,M/M,65 PC,4 2237044
LENGHTS,5 COLORS (65 pieces,
male-male)
(Velleman WJW009)

Photograph



Sketch Code Listing 1

void setup() {
// put your setup code here, to run once:
pinMode (2, OUTPUT);
}

void loop() {
// put your main code here, to run repeatedly:
digitalWrite(2,LOW);
delay (1000);
digitalWrite(2,HIGH);
delay(1000);
}

PWM (Pulse Width Modulator)
The micro-controller chip has a built-in hardware function known as the PWM
or pulse-width modulator that runs independently of the code after initializing it.
At first look, you may think it is great to have an autonomous PWM that can be
used to generate variable width pulses but after closer scrutiny the Arduino
predefined functions are very limiting in its capability. For starters, the PWM
frequency is fixed around 500 hertz depending on the hardware versions which
is a low frequency by any standard. Second even though technically you can
modulate the pulse width, in practice it is not likely you will actually be
modulating the 500 HZ carrier. Some of this depends on what you call
modulation. Modulation is the technique of altering the transmission carrier
(amplitude, frequency or pulse-width) with the baseband data to be transmitted
on the carrier.
Changing the duty-cycle of a clock is not the same as modulating a carrier and
that subject is for a more advanced book.
The Arduino environment and Arduino pre-defined C-functions were obviously
created by hobbyist or software type people and apparently their knowledge of
electronic circuitry was limited and I will explain further.
Going through the Arduino documentation for the PWM function they describe
the primary purpose of the PWM capability is to produce a voltage that is
variable. In essence they are almost describing a digital-to-analog converter.
Well, for starters the PWM only changes the relationship of the logic state of a
digital output. Specifically the PWM only controls the percentage of time the
digital output is “on” and “off” known as duty-cycle. To further explain, in this
case an unloaded output will produce a voltage near 5V when it is “on” and near
0V when it is “off”. In digital logic, “on” means logic 1 or HIGH and “off”
means a logic 0 or LOW.
The uninformed may put a voltmeter on the PWM output and notice the DC
voltage reading varies proportionally with the duty-cycle and declare this an
analog output since the voltage can be varied. There is an old saying that
“ignorance is bliss” and this is truly the case for anyone thinking the PWM
output is an analog output. All you have to do is use the built-in analog-to-digital
converter and the monitor console to observe the PWM output, the voltage
reading is alternating between 0V and 5V. Using the waveform-monitor makes it
more visually apparent that the output is a classic digital clock and is not a fixed-
level analog output that the voltmeter might lead you to believe. The voltmeter
has a slow response time which results in it averaging the voltage and not
providing instantaneous readings. In summary the voltmeter is an integrator and
many loads such as a motor are also integrators and for those trial-and-error
engineers, yes you can use this digital output to adjust the average voltage for
controlling the speed of a motor but it is still a digital output.
One of the following experiments will demonstrate the PWM produces a digital
output and by adding a simple integrator or RC filter, turn the digital output into
an analog output controlled by the duty cycle of the PWM digital output.
Experiment 2 - Dim LED
The Uno board digital output is used to vary the duty cycle of a PWM (pulse
width modulator) clock which frequency is approximately 500 hertz. The slow
response time of the human eye will perceive the different brightness of the LED
illumination depending on the duty cycle. The duty cycle is the percentage of
time the clock is logic HIGH or LOW during a clock period. Although the
Arduino analogWrite function is used to control the pulse width, there is nothing
analog about using this output or function. In fact you are using a digital pin in
the output mode. The writers of the analogWrite function obviously didn’t
understand what the PWM does in terms of electronic theory.
See experiment 1 for schematic, component list and photograph.
The call to the Arduino predefine function, analogWrite, is used to control the
duty cycle of the approximately 500 hertz clock coming out of digital pin 3. The
PWM hardware generates the clock.
As you can see from the code the duty-cycle is being varied by the +10
increment resulting in the average voltage to the LED changing which is
perceived as a difference in intensity of the LED.

Sketch Code Listing 2



int dutycycle = 0;

void setup() {
// put your setup code here, to run once:
pinMode (2, OUTPUT);
}

void loop() {
// put your main code here, to run repeatedly:

analogWrite(3, dutycycle);
dutycycle=dutycycle+10;
delay(200);
}


Experiment 3 - Dim and Blink LED
This experiment demonstrates the LED is toggled on and off per each cycle of
ramping through the duty cycle for the PWM.
See experiment 1 for schematic and photograph.

Sketch Code Listing 3


int dutycycle = 0;
boolean toggle = HIGH;

void setup() {
// put your setup code here, to run once:
pinMode (2, OUTPUT);
pinMode (3, OUTPUT);
}

void loop() {
// put your main code here, to run repeatedly:

analogWrite(3, dutycycle);
dutycycle=dutycycle+10;
if (dutycycle > 255) dutycycle=0;
delay(200);
if (dutycycle==0) toggle = not toggle;
digitalWrite(2,toggle);
}

Experiment 4 - PWM Square Wave and Serial Monitor
This experiment continues using the PWM hardware and starts the introduction
to the Arduino serial monitor tool. Under the Tools tab in the Arduino
environment you will see both the Serial Monitor and Serial Plotter tools. Both
of these tools are very powerful and are intended for debugging the sketch code
and observing what the Arduino board is sending to the serial port.
The Serial.begin(9600) function call initializes the serial port.
The Serial.print (ain0) function call is an extension to the print function sending
the output to the serial port.
The 9600 sets the baud rate for the serial interface and this value is also the
default setting for the Serial Monitor.
The PWM (Pulse Width Modulator) section a few pages earlier in this book
describes the PWM hardware function.
This experiment will verify that the PWM output is truly digital and not analog
as described in the Arduino documentation.
The following schematic shows the connections for this and the next experiment.
For this experiment, the resistors are bypassed or not used, effectively pin A0 is
connected directly to pin D3.
This experiment uses the analog input to measure the voltage coming out of the
digital output. The measured voltage is sent to the serial port.
After uploading the sketch go to the Tools tab and select the Serial Monitor.
Observe the PWM digital pin is putting out an alternating near zero voltage and
near +5V voltage.
These are logic levels toggling between logic HIGH and LOW. The sketch set
the duty-cycle midway between 0 and 255 which is as near a square-wave you
can get.
The square-wave simplifies calculation the average voltage which is the mid-
point of the two voltages.
Schematic
Components Required
Designator Category Description Part# Qty
MCU Micro- MCU,ARDUINO UNO SMD,REV3 2163840 1
controller 32K FLASH,1K EEPROM,USB,14
I/O
BB-small breadboard BREADBOARD,3.25"x2.125",400pnt 20601 1




JW wire Jumper wire, #22 solid copper
JW wire JUMPER WIRE SET,M/M,65 PC,4 2237044
LENGHTS,5 COLORS (65 pieces,
male-male)
(Velleman WJW009)


Sketch Code Listing 4

//----------------------------------------------------------
// Analog_Voltmeter_2017_0704
// This program generates a clock with 50 percent duty cycle.
// The PWM is the clock source and the builtin analog-to-digital
// converters takes the voltage measurement.
// Connecting the PWM output directly to the A/D input will
// produce 0 and 5 volt readings because the PWM output is
// truly a digital output, with no load going from the
// positive rail to the negative rail. (+5V to 0V)
// test configuration 2 uses a low pass filter to obtain the
// average analog voltage which is 50 percent or 2.5V
// 1 meg ohm resistor and 1 uf capacitor is used
//-----------------------------------------------------------
// global variables
int dutycycle = 0;
float voltage = 99;
int ain0 = 55;

void setup() {
// put your setup code here, to run once:
pinMode (3, OUTPUT); // digital pin 3
Serial.begin(9600); // default baud rate for Serial Monitor
dutycycle = 128; // set up 500HZ clock with 50 percent duty cycle
analogWrite(3, dutycycle); // digital pin 3, bad arduino function name, s/b SetClockDutyCycle
}

void loop() {
// put your main code here, to run repeatedly:



ain0 = analogRead(0); // analog pin 0, warning open pin gives unpredictable value
voltage= ain0/205.0; // warning, requires .0 to yield float
Serial.print(ain0);
Serial.print(" ");
Serial.println(voltage); // Serial Monitor
delay(1000);
}
Screen Capture
Serial Monitor Output
The serial monitor shows the digital output of the PWM alternating between
logic high and low.
In this configuration the digital output (2) is fed directly to the analog input (0)
to measure the voltage of the PWM output.
Experiment 5 - PWM Square Wave, RC Filter and Serial Plotter
This experiments demonstrate how a simple resistor-capacitor filter can convert
a digital clock, an AC (alternating current) signal into a DC (direct current)
signal. The Serial Plotter tool is used this time to graphically observe the
waveforms.
For this experiment the direct connection between A0 and D3 is removed and
the resistor-capacitor filter is inserted between the A0 and D6 connection. The
analog input receives the filtered digital output signal for this experiment.
See the screen capture for the analog input signal.

Experiment Schematic
Components Required
Designator Category Description Part# Qty
MCU Micro- MCU,ARDUINO UNO SMD,REV3 2163840 1
controller 32K FLASH,1K EEPROM,USB,14
I/O
BB-small breadboard BREADBOARD,3.25"x2.125",400pnt 20601 1

R resistor Resistor Carbon Film 330 Ohm 1/2 661386 2
Watt 5%
D diode LED Uni-Color Red 660nm 2-Pin T-1 333973 2
3/4 Box

JW Jumper wire, #22 solid copper
JW wire JUMPER WIRE SET,M/M,65 PC,4 2237044
LENGHTS,5 COLORS (65 pieces,
male-male)
(Velleman WJW009)


Experiment Photograph
A RC filter is placed between the digital output and the analog input.
Sketch Code Listing 5

//----------------------------------------------------------
// Analog_Voltmeter_2017_0704
// This program generates a clock with 50 percent duty cycle.
// The PWM is the clock source and the builtin analog-to-digital
// converters takes the voltage measurement.
// Connecting the PWM output directly to the A/D input will
// produce 0 and 5 volt readings because the PWM output is
// truely a digital output, with no load going from the
// positive rail to the negative rail. (+5V to 0V)
// test configuration 2 uses a low pass filter to obtain the
// average analog voltage which is 50 percent or 2.5V
// 1 meg ohm resistor and 1 uf capacitor is used
//-----------------------------------------------------------
// global variables
int dutycycle = 0;
float voltage = 99;
int ain0 = 55;

void setup() {
// put your setup code here, to run once:
pinMode (3, OUTPUT); // digital pin 3
Serial.begin(9600); // default baud rate for Serial Monitor
dutycycle = 128; // set up 500HZ clock with 50 percent duty cycle
analogWrite(3, dutycycle); // digital pin 3, bad arduino function name, s/b SetClockDutyCycle
}

void loop() {
// put your main code here, to run repeatedly:



ain0 = analogRead(0); // analog pin 0, warning open pin gives unpredictable value
voltage= ain0/205.0; // warning, requires .0 to yield float
Serial.println(voltage); // Serial Plotter
delayMicroseconds(100);
}

Sketch Code Listing Screen Capture
Screen Capture
Direct Connection D3 to A0
This is the waveform before connecting the filter.
The digital output is connected directly to analog input.
Screen Capture

Short RC Filter Output Waveform


Digital output feeds a RC filter and the output goes to the analog input.
R = 1.2K ohm, C=1 uF
This screen captures show a slightly filtered square-wave signal now looking
more like a triangular waveform. Notice the center of the waveform or the DC
level is near 2.5V.
Screen Capture
Long RC Filter Output Waveform
Digital output feed a RC filter and the output goes to the analog input.
R = 1 Meg ohm, C=1 uF
The square-wave signal has been completely filtered out with only the DC
component remaining. For a square-wave or 50 percent duty cycle the DC
average is one-half of the peak-to-peak voltage.
Oscilloscope 3 Project
The Oscilloscope 3 project adds an A/D converter to the Arduino Uno Rev 3
board and the A/D digital outputs are read by the Uno board. The Uno board
generates the sample clock for the A/D converter. Although this demonstration is
made using a Uno board just about any microcontroller can be used for this
project.
ADC0820 Analog-to-Digital Converter
This experiment demonstrates the benefit of using an external analog-to-digital
converter. The internal A/D inputs are very slow compared to using the
ADC0820 device.
Building this experiment is slightly more complex that the previous experiment
only because there are more connections to be made.
The code on the other hand is much more complex.
This program requires using more complex programming structures and
techniques.
A separate function is called to perform the burst capture of 500 samples and
store the data into an array. The data is in the form of a parallel bus of 8-bits
from the analog-to-digital converter. Only 6-bits are used for this experiment.
Unfortunately the data bus must be read in one-bit at a time which is an Arduino
predefined function limitation. The digital weight for each bit must be converted
into the decimal value to produce an integer value of the data bus. This process
of reading and converting the bits takes precious execution cycles but ends up
being much faster than using the internal A/D.
Once the acquisition burst is done the output can be sent to the slow serial port
and the waveform plotter shows the acquired waveform.
For this experiment I used an external ramp generator to demonstrate the
capturing of the signal from a signal generator. Since only 6 bits are used, the
steps in the plotter waveform show the 6-bit resolution of the signal. The stair-
step in the captured waveform would disappear using all 8 bits of resolution of
the A/D converter.
In the loop function there is a delay(2000) statement which produces a 2 second
delay which is long even to see the captured waveform on the serial plotter.
Program Enhancements and Functionality
The serial data can be sent through the USB/serial port to a PC computer for
further processing of the waveform.
A separate PC could be used to issue commands to the Uno code for more
sophisticated control. The sketch code could be enhanced to sample at specified
time intervals. The Uno board could use another digital pin for external
triggering of the acquisition process.
Adding these capabilities turns the experiment into a useful digital oscilloscope
project.
Schematic
Pin one on ICs usually are identified by an indentation or dot near pin one.
Components Required
Designator Category Description Part# Qty
MCU Micro- MCU,ARDUINO UNO SMD,REV3 2163840 1
controller 32K FLASH,1K EEPROM,USB,14
I/O
BB-small breadboard BREADBOARD,3.25"x2.125",400pnt 20601 1

R resistor Resistor Carbon Film 1.2K Ohm 1/2 2
Watt 5%
U ADC Analog to Digital Converter Single 10225 1
Semi-Fash 667K SPS 8-Bit Parallel
20-Pin MDIP Rail
ADC0820CCN

JW Jumper wire, #22 solid copper
JW wire JUMPER WIRE SET,M/M,65 PC,4 2237044
LENGHTS,5 COLORS (65 pieces,
male-male)
(Velleman WJW009)


Sketch Code Listing – Oscilloscope 3
void setup() {
// put your setup code here, to run once:
Serial.begin (9600);
}

void loop() {
// put your main code here, to run repeatedly:
unsigned int delaynum;
const int MAX = 500;
read_data_block ( delaynum, MAX);
delay(2000);
}

// ----------------------------------------------------------------
void read_data_block ( unsigned int delaynum, int MAX)
{
// int value;
byte bytearray[MAX];
unsigned char value;
char chvalue;
int i;
//---------------------
pinMode ( 9, OUTPUT); // strobe
pinMode ( 2, INPUT);
pinMode ( 3, INPUT);
pinMode ( 4, INPUT);
pinMode ( 5, INPUT);
pinMode ( 6, INPUT);
pinMode ( 7, INPUT);
for (i = 0; i < MAX; i++) {
digitalWrite ( 9, HIGH); // strobe
// may need delay
value=0;
if (digitalRead(2) == HIGH)
{
value=value+1;
}
if (digitalRead(3) == HIGH)
{
value=value+2;
}
if (digitalRead(4) == HIGH)
{
value=value+4;
}
if (digitalRead(5) == HIGH)
{
value=value+8;
}

if (digitalRead(6) == HIGH)
{
value=value+16;
}
if (digitalRead(7) == HIGH)
{
value=value+32;
}
bytearray[i]=value;
//delay(delaynum);
delayMicroseconds(delaynum);
digitalWrite(9,LOW); // strobe
//delay(delaynum);
delayMicroseconds(delaynum);
//send_serial_byte(value);
} // for loop 1
for (i = 0; i < MAX; i++) {
chvalue=char(bytearray[i]);
//Serial.print (chvalue);
Serial.println (bytearray[i]);
delay(10);
} // for loop 2
//---------------------
}
//----------------------------------------------------------------------------------
Screen Capture
This is a screen capture of the serial plotter. The signal captured is a ramp signal
from an external signal generator. The stair-step of the waveform shows the low
resolution of using only 6-bits for the analog to digital conversion. The
waveform gets updated about every two seconds.
Definitions
AC – alternating current
A/D – short for analog to digital converter, D/A is the opposite conversion
Application Note – a manufacturer’s published document showing the design use of a component, usually
with theory, formulas, calculations and component values for a specific use.
Av – voltage amplification usually in reference to amplifiers, G may also be used for gain
Avalanche breakdown – a high reverse voltage causes a device such as a MOSFET to run away due to the
high electric fields in the reverse biased P-N junction. The run-away condition is heat generated from the
reverse voltage increases the resistance in the device resulting in higher power losses which in turn
generates more heat. Once the voltage drop across the junction reaches a limit, the device no longer behaves
properly and fails. In some cases it literally burns up.
CMOS - Complementary metal–oxide–semiconductor, only one transistor of the pair is always on, the
series combination draws significant power only during switching between the on and off states.
Component – in the electronics industry they are generic devices such as resistors, capacitors, ICs,
transistors which are the basic devices connected together to build specific functions for a product.
Data Book – the manufacturer publishes a data sheet for each component which is the specification of
maximum ratings and typical performance of products such as a transistor, integrated circuit (IC), etc. A
data book is a collection of these individual data sheets organized by category for easy look up of technical
information. The internet has made data books obsolete and pretty much nobody prints data books anymore.
Data Sheet – the manufacturer published document specifying the capabilities of an electronic component.
Detailed Design – there are different levels of design where the detailed design phase is making the circuits
and selecting the components to be used in a unit. The pin connections and component values are all
determine during the detailed design phase. The detailed design phase may be known as the implementation
portion of a project.
DIP – dual inline package, it may be referred to as a through-hole component as opposed to a surface-
mount
Efficient or efficiency – is generally the inverse of amount of wasted energy or power in a system. A 60%
efficient power supply wasted 40% of the energy in the form of heat.
FIFO – first-in first-out memory is a sequential memory where access is made one byte at a time in
sequence so to read the 5th byte the first four must be read first.
Fire – trigger, energize, start event
Harmonic – a frequency that is a multiple of the fundamental frequency
High Level Design – is where the design is made independent of specific components and only the
functionality is place on the drawing. A rectangular box for each complex or basic function is suitable for a
high level design although the author usually draws out logic symbols for gate functions or a generic op-
amp symbol where an op-amp device is going to be used.
IC - integrated circuit, a chip, a device with multiple components such as transistors, resistors built into a
single monolithic package with leads for access to the circuitry.
Impedance – AC resistance as opposed to DC resistance
Invention - An invention is a unique or novel device, method, composition or process.
IR – infra-red wavelength, it is also used as part of ohms law, E = I R
KIS – Keep It Simple or KISS for keep it simple stupid
LSB & MSB – is the least significant bit and most significant bit. A binary number or bus consists of
weighted bits, each having twice the value of the next lower bit.
MSPS – mega samples per second, mega being 10 raised to the sixth power (1,000,000)
Noise – in electronics is spurious voltages of random amplitude and duration although usually small
amounts
Old-School – usually means the use of methods or technologies prior to the digital revolution and
microprocessors.
Patent - is a set of exclusive rights, granted by a sovereign state to an inventor or assignee for a limited
period of time in exchange for detailed public disclosure of a new invention.
Patent Law – invention or the discovery or production of some new or improved process or machine that is
both useful and is not obvious to persons skilled in the particular field
PCB – a board with copper traces and holes for connecting and holding individual components making a
circuit.
PC Computer – PC means personal computer but to emphasize the specific type of computer I identify it
as PC Computer, a DOS based and now a Microsoft Windows based computer operating system.
PLL – phased locked loop
Reference Design – published by the manufacturer, a schematic showing a specific use for a component
usually accompanied by the equations for determining the component values
PI (π) - The number π is a mathematical constant. It is the ratio of a circle's circumference to its diameter. ,
π is approximated as 3.14159.
RF – radio frequency are electromagnetic wave that are wireless or travel normally through the air for
communications purposes such as AM or FM radio. The general frequency range is 3 kHz to 300 GHz. I
question the low end range since it is within the audio frequency range. Obviously RF signals can travel
through a wire, how else you get a TV signal inside the box. The wireless term is to differentiate it from AC
power grids that operate at 60 hertz.
Sampling Frequency – a clock used to store a data sample, an A/D clock for starting a conversion
Signal – a signal can mean many things but simply put it is a voltage level communicating between
components. The communication can be either analog or digital. Not all voltages are signals such as a
power supply voltage. A power supply is used to power the devices and power equals voltage times
current.
SIP – single inline package as opposed to DIP or dual inline package. The lead spacing is 0.1 inches apart.
Slew – the time it takes to make a signal transition usually expressed in volts per time unit
SRAM – static random access memory, a static RAM doesn’t have to be refreshed like dynamic Ram
although the data is volatile and will be lost upon removal of power to the device. Random access means
any address can be written or read directly. Se FIFO for a non-random access memory. SRAM are
asynchronous devices that can be written at anytime as long as setups times are followed. These are some of
the fastest memories available.
Surface Mount - surface-mount technology is a design standard for constructing electronic circuits using
components that are mounted directly onto the surface of the printed circuit board (PCB). The components
have small metal tabs that are soldered directly onto the surface of the printed circuit board. This is unlike
through-hole-technology that uses holes in the PCB for holding the component leads.
Stage – refers to a section of circuitry with a specific function. An example is a preamp, the stage before the
power amplifier which is another stage.
State – is the condition of a circuit. An example is the power switch is turned off so it is in the off-state.
Times – when used as such: times 10 means multiplied by 10. The x symbol means times or multiplication
when between two numbers. A multiplication is implied when two variables are shown next to each other.
Tolerance – is a dimensions, properties, or conditions that may vary. When the tolerance is specified then it
is within certain practical limits without significantly affecting functioning of component, equipment or a
process.
Traditional – the original, long standing, historical, conventional, popular way to do something
TTL – transistor-transistor logic, referring to bipolar transistors
Unit – usually the complete item, such an electronic box although it could be a subassembly item such as a
box that goes inside a bigger box along with other boxes.
UNIX Workstation – is basically a high performance PC Computer using the UNIX operating system
which is a more powerful operating system that is also used on mainframe computers. The original UNIX
Workstations did not use Intel microprocessor chips but used higher performance specialized chips.
VCO – voltage-controlled oscillator where the frequency is control by an input voltage
|| - the two vertical line symbol means: the parallel value such as the value of two resistors connected in
parallel
Datasheet Information
ADC0820 Data Sheet Information
ADC0820
8-Bit High Speed μP Compatible A/D Converter with Track/Hold Function
By using a half-flash conversion technique, the 8-bit ADC0820 CMOS A/D
offers a 1.5 μs conversion time and dissipates only 75 mW of power. The half-
flash technique consists of 32 comparators, a most significant 4-bit ADC and a
least significant 4-bit ADC. The input to the ADC0820 is tracked and held by
the input sampling circuitry eliminating the need for an external sample-and-
hold for signals moving at less than 100 mV/μs. For ease of interface to
microprocessors, the ADC0820 has been designed to appear as a memory
location or I/O port without the need for external interfacing logic.
Features
Built-in track-and-hold function
No missing codes
No external clocking
Single supply—5 VDC
Easy interface to all microprocessors, or operates stand-alone
Latched TRI-STATE® output
Logic inputs and outputs meet both MOS and TTL
voltage level specifications
Operates ratiometrically or with any reference value equal to or less than
VCC
0V to 5V analog input voltage range with single 5V
supply
No zero or full-scale adjust required
Overflow output available for cascading
0.3" standard width 20-pin DIP
20-pin molded chip carrier package
20-pin small outline package
20-pin shrink small outline package (SSOP)
Connection Diagram



Timing Diagrams


FIGURE - RD Mode (Pin 7 is Low)
Note: On power-up the state of INT can be high or low.

FIGURE - WR-RD Mode (Pin 7 is High and tRD<tI)


Timing Diagrams




FIGURE - WR-RD Mode (Pin 7 is High and tRD>tI)


FIGURE - WR-RD Mode (Pin 7 is High) Stand-Alone Operation
Pin Description
Electronic Parts Suppliers
Electronic component suppliers like most sellers change the products that they
have available for sale. Prices also occasionally change so the project builder
needs to be flexible and understand how to substitute parts. The electronic
reference section in the “Electronic Projects for the Test Bench” book explains
the purpose of components and identifies commonly used components for the
projects in the author’s book.
Jameco.com
Jameco.com is my favorite electronic component supplier for hobbyist parts.
Most or all of the project components come from this supplier. They are low
cost, have a wide selection and are a reliable supplier. The Jameco part numbers
in this book are represented by the J# notation. Obviously everything is subject
to change including the part number, price and availability.
Jameco uses a Major Brands notation to indicate there are many manufacturers
of electronic components and some industry standard components are produced
by multiple manufacturers with the exact same specification. These highly
popular components are identified as “Major Brands” and come from different
manufacturers.
Digikey.com
A few of the components for projects by the author were obtained from
distributers or other professional electronic component suppliers. Today most
distributers will sell in small quantities unlike the pre-internet days.
Unfortunately for the hobbyist their selection of through-hole components is
limited since they specialize in surface-mount components. I use digikey.com for
FIFOs since jameco.com stopped carrying them. Digikey.com carries a large
number of FIFO, A/D devices and op-amps and the higher performance devices
that are not usually available from a hobbyist supplier.
Circuitspecialists.com
Circuit Specialist has a good selection of medium size enclosures at a reasonable
price.
Minicircuits.com
Mini-Circuits is a very specialized source for RF and microwave components.
ExpressPCB.com
The author uses ExpressPCB.com to manufacture his hobby PCB boards. They
provide free schematic and layout software.


Trademarks
All trademarks and trade names are the property of their respective owners.
The author was merely a user of most of the mentioned products.
References
Arduino.cc website
Electronic Circuits 2nd Edition by Joseph Berardi
Electronic Projects for the Test Bench by Joseph Berardi
Datasheet information from product manufacturer

You might also like