Professional Documents
Culture Documents
Table of Contents
Step 1: Requirements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2
File Downloads . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3
File Downloads . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6
File Downloads . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16
Related Instructables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16
Advertisements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17
Comments . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17
http://www.instructables.com/id/Arduino-High-speed-Oscilloscope-with-PC-interface/
Intro: Arduino High speed Oscilloscope with PC interface
Use your Arduino and PC as a fast Storage Oscilloscope.
The Arduino can reliably gather voltage readings at a frequency of between 141 and 153 KiloHertz.
I have written a PC interface to display the data and control the arduino. My PC program is presented as is - it would take a very long instructable to explain it!
The data output from the Arduino is not complex. I am sure others will write interfaces for the operating system of their choosing ....
I have written two slightly different versions for the Arduino data capture. One utilizes software triggering for when an accurate change in voltage is required, before the
oscilloscope triggers. The second, uses hardware edge triggering based on an interrupt on Arduino pin 2. The hardware version runs a little faster at the highest
frequency.
Step 1: Requirements
Arduino Mega 2560 (Let me know if other arduino types work)
.
The following component works- alternatives may be viable (with program tweaking- I leave that to you!)
Simple Buffer box to accept analogue voltages: (Only required if you don't already have voltage buffers)
NE5534P op amp
A multimeter
Balanced +-9V supply (At least +-6V is needed to allow the NE5534P to produce 5V at the output)
A PC with a windows operating system. I have tested my interface on XP, Windows 7 and windows 8.
http://www.instructables.com/id/Arduino-High-speed-Oscilloscope-with-PC-interface/
File Downloads
winpcInterface.zip (1 MB)
[NOTE: When saving, if you see .tmp as the file ext, rename it to 'winpcInterface.zip']
hardOscilloscope.ZIP (5 KB)
[NOTE: When saving, if you see .tmp as the file ext, rename it to 'hardOscilloscope.ZIP']
SoftOscilloscope.ZIP (5 KB)
[NOTE: When saving, if you see .tmp as the file ext, rename it to 'SoftOscilloscope.ZIP']
Step 2: The Specifications
The Arduino program:
Some text information is sent to the serial port and lcd screen.
The lcd screen buttons control trigger slope, sample period and sampling.
1) Oscilloscope.ino
The trigger level can be specified in mV. Sampling commences when the voltage climbs above (or falls below) by more than the trigger value, between two subsequent
sampled readings.
The trig level is a best fit, limited by the resolution of the a/d port.
2) OscilloscopeExt.ino
http://www.instructables.com/id/Arduino-High-speed-Oscilloscope-with-PC-interface/
Hardware trigger version.
Common Specifications
Lcd button support. (The Lcd adc port is specified by the variable lcdport)
Serial Monitor set at 115200 baud.
Data is written to a 1000 byte buffer, which when full is written to the Serial port.
In a fast run the arduino will wait for a serial response of any character for 1500 milli seconds after outputting data. If a character is received (a handshake), the Arduino
will immediately gather more data. If 1500 mS is up more data is recorded, regardless.
The buttons on the LCD Keypad Shield will produce the following result:
Note that the LCD screen requires Analogue port 0 to allow the buttons to work.
'trig' Trigger level set. If 0 is sent triggering is cancelled. Non zero trigger levels produce triggering. The lcd screen buttons control whether the trigger is on a posive or
negative slope.
'run' Repeated sampling- a fast run. No serial port text is sent during a run- only raw data.
During a fast run the sample period and edge select can be altered. A fast run is stopped using the lcd select key.
The PC Interface:
Available scales:
raw 0-255
0V to 5V
-2.5 to +2.5V
-5 to +5V
-9 to +9V
1) positive edges around the average of the data maximum and data minimum voltage
this ensures that the interrupts that would occur can not slow down the sampling.
http://www.instructables.com/id/Arduino-High-speed-Oscilloscope-with-PC-interface/
File Downloads
I use the variable prescalar to control the frequency of the sampling interrupt.
If triggering is on, data is not transferred to the buffer until the triggering condition is met.
The frequency is defined using a prescalar. (ADCSRA register: bits ADPS2, ADPS1 and ADPS0. )
These bits determine the division factor between the system clock frequency and the input clock to the ADC.
Set the number of bits used in the analogue port capture. For speed 8 bits are read. The ADLAR bit controls the presentation of the ADC conversion Write one to
ADLAR to left adjust. Otherwise, the value is right adjusted. This has an Immediate effect on the ADC Data Register.
Set the bits in ADCSRA for the frequency prescalar. (ADPS0, ADPS1, ADPS2 bits)
Set the interrupt to repeatedly Auto Trigger when the analogue port is read. (The ADATE and ADIE bit)
Note the use of the sbi function. This and the cbi function are very useful for setting and clearing data register bits.
//
cli(); // disable interrupts so that we can change registers without being interrupted
ADCSRA = 0;
ADCSRB = 0;
ADMUX |= (1 << ADLAR); // left align the ADC value- so we can read highest 8 bits from ADCH register only
http://www.instructables.com/id/Arduino-High-speed-Oscilloscope-with-PC-interface/
if(prescalar==64) ADCSRA |= (1 << ADPS2) | (1 << ADPS1);
// 128 prescalar - 9.4 Khz sampling if (prescalar==128) ADCSRA |= (1 << ADPS2) | (1 << ADPS1) | (1 << ADPS0);
sei();
Variable bufcount is the position in the buffer, whose size is BUF_SIZE (=1000).
When the buffer is full flag writeit is set true and the adc is disabled. ( cbi(ADCSRA,ADEN); )
To trigger the interrupt either triggered is set to true in setup and the data starts recoding immediately.
If the difference is greater than the trigger, triggered is set to true and the data is stored in the buffer.
The variable trigcount is used to count the number of data items read during triggering.
This number is added to the buffer size during the frequency calculation to maintain the accuracy of the observed frequency.
if (triggered){
bufa[bufcount]=ADCH;
if (bufcount==BUF_SIZE) {
} else {
newval=ADCH;
trigcount++;
trip = newval-oldval;
triggered=true;
}else{
oldval=newval;
http://www.instructables.com/id/Arduino-High-speed-Oscilloscope-with-PC-interface/
http://www.instructables.com/id/Arduino-High-speed-Oscilloscope-with-PC-interface/
Step 4: Setting up the Interrupt for the hardware triggered version
This method is very similar to the software version.
Digital Port two must be connected to analogue input 1, for this to work.
Essentially if no triggering is selected, the adc interrupt is enabled and data is captured immediately. If triggering is selected an interrupt on digital port 2 is used to enable
the interrupt on the adc port 1.
Digital port 2 can be configured to read analogue signals and generate an interrupt on rising or falling data edges. It is very fast.
My interrupt routine is called gotinterrupt and as I am using digital port 2 the interrupt id is 0.
pinMode(ExtInterrupt,INPUT);
The flag triggered controls whether the digital port 2 interrupt starts the analogue port 1 interrupt . When triggered is false the interrupt starts the adc interrupt when it
detects an edge in the analogue input.
// then ..
if (trigger==0) {
starttime=micros();
}else{
triggered=false;
void gotinterrupt() {
if (!triggered){
triggered=true;
Variable bufcount stores the position in the buffer, whose size is BUF_SIZE (=1000)
When the buffer is full flag writeit is set true and the adc is disabled. ( cbi(ADCSRA,ADEN); )
http://www.instructables.com/id/Arduino-High-speed-Oscilloscope-with-PC-interface/
ISR(ADC_vect) {
bufa[bufcount]=ADCH;
if (bufcount==BUF_SIZE) {
1) If writeit is true:
calculates the observed time period, correcting for micro time rollover
outputs the buffer bufa
calculates frequency in KiloHertz
outputs buffer bufinfo, with a handshke zero byte and the frequency in milliHertz
enables the lcd port so that the buttons can be read
Switches off the test pulse on pw3
Outputs text details to the serial port if showdetails is true (set false by a fast run)
sets flag writeit to false and hasdata to true
2) If hasdata is true
LCD Buttons
The left button, for instance lies in the range 400 to 599
'test' toggles a square wave on testpin (= digital port 3), using the flag pwtoggle.
pinMode(testpin,OUTPUT);
if (pwtoggle==false) analogWrite(testpin, 0);
if (pwtoggle) analogWrite(testpin,127);
'trig' sets the trigger level. In the software triggered version the trigger variable is used mathematically to set the triggering level. In the hardware version it simply toggles
triggering.
http://www.instructables.com/id/Arduino-High-speed-Oscilloscope-with-PC-interface/
http://www.instructables.com/id/Arduino-High-speed-Oscilloscope-with-PC-interface/
Step 6: Setting up the windows PC Interface
Open winpcInterface.zip and extract to a folder of your choice.
1) The graph support 'rm chart setup.exe' . I found this very useful package on the Internet. VB programmers will find this interesting!
2) For windows 7/8 copy the address of the folder in which you extracted the application. If you right click on the address in the bar at the top of windows file explorer you
will find the option to copy the folder address.
XP - 'ocxXP.bat'
Ready to test!
Install one of the two arduino oscilloscope programs. (Hard or soft triggering version)
http://www.instructables.com/id/Arduino-High-speed-Oscilloscope-with-PC-interface/
Exit any serial interface used to do this.
Click capture.
A square wave is available on the digital port. Select again and you will see it plotted by the oscilloscope.
Select frequency and you will get the square wave frequency. The first estimate is based on the rising edges at the midpoint of the voltage range. The second is based on
a technique outlined in an excellent article at:
http://www.instructables.com/id/Reliable-Frequency...
The graph can be 'zoomed' using a mouse left click and drag, or un- zoomed with a right click.
fast 'run'
freeze a fast run
freeze the x-scale during fast run for data comparison.
print or copy the graph
output the data as a text file
alter triggering levels
alter y scale
apply an offset for bi-polar y axis
1. Voltage follower
2. Bipolar +-9V to 0-5V converter
3. A.C. coupler
It has a simple dc offset circuit- make sure you trim the 100K pot to set the output voltage to zero for an input of zero.
I used a balanced +-9V supply. However +-6V would give enough headroom to provide an output of 5V. The absolute maximum is +- 22V.
The bipolar converter allows for a signal which is below zero to be measured by the analogue port, which can not be taken below zero.
This bipolar converter is interesting. In the past I have designed these with an op amp, precision voltage reference and lots of trim pots. This design was inspired by an
article which was supported by Ronald Michallick of Linear Applications. He suggested using a three resistor bridge and supplied an excel spreadsheet to design it.
If you need a different range of input voltages use the spreadsheet to get your own resistor values.
Setup the two 1k trim pots with an accurate resistance meter so that the upper and lower resistors meet the design specification.
a) The arduino "5V" level may not be accurate. Alter the spreadsheet b2-b3 values if you want strict accuracy.
That is 70.6mV. So relatively coarse voltage changes are observed (with 71mV jumps).
The A.C. coupler is very straightforward. The DC bias is set at the midpoint of our analogue port voltage (5V).
No external DC will transfer across the 10uF capacitor. This circuit works well with a microphone pre-amp.
To setup this circuit connect to the arduino, Use the raw data scale on the pc software. Grab the port data and trim the 100K pot so that the input is 127. Or use a
voltmeter and set to "5V"/2.
The circuits are all straight forward to build on one piece of Copper stripboard.
Putting the circuits in a box is useful, The separate outputs can be inter-connected as needs arise.
Note the 0.1inch connectors on the side of my box so that standard Arduino header leads can be used.
Check your circuits before testing. All responsibility for the use of this article rests with you.
http://www.instructables.com/id/Arduino-High-speed-Oscilloscope-with-PC-interface/
File Downloads
Related Instructables
ROBOTIC ARM
How to make an Building a
with USB PC Oscilloscope Oscilloscope
Interface (plus Arduino Digital
Oscilloscope Display (Photos) clock by Oscilloscope
how to oscilloscope
How To by by Samartist neelandan from a DIY Kit
assemble) probe by
amandaghassaei by Josehf
(video) by NeoRecasata
Murchison
theseventhsage
http://www.instructables.com/id/Arduino-High-speed-Oscilloscope-with-PC-interface/
Advertisements
Comments
1 comments Add Comment
http://www.instructables.com/id/Arduino-High-speed-Oscilloscope-with-PC-interface/