A couple of days ago Ben in The Ben Heck show made a oscilloscope using raspberry pi and bitscope, now I want to show you how I made my personal oscilloscope using arduino and LabView.
Let's start!
First of all we have to know the speed limitation of analogRead, infact this instruction takes a bit more than 0.1 ms to execute, so the theoretical max speed that we can reach is lower than 10Khz. Umm..... it doesn't sound good! So the first step is to speed up analogRead, to do this we have to find the atmega328 datasheet and then study the chapter that explain how the adc works.Great, I just have to set a couple of registers to increase the conversion's speed (it seems easy but this was the first time that I changed the default settings so I spent few hours of "study" for it).Basically the adc take the system clock and divide its frequency with a certain factor specified into a register before using it for timing, so decreasing this number we can increase the speed.We also need to set the voltage reference, the input pin and the "format" of the adc output.
The next step is to create a fast data flow from arduino to pc, this is really easy because we have only to find the maximum speed using "standard" arduino communication, after a bit of try I found that the max speed is about 4000000 baud/s (500KByte/s, not bad!).
Beware! You can't use this speed to display data with the standard serial monitor, you have to made a specific program that can read data at those speed.
Below here you can see the program running on arduino:
byte mask=B01000000;//mask for start of conversion & state of conversion char t=' '; void setup() { Serial.begin(4000000);//500kByte/s, super speed! ADMUX=B01100000;//I'm using input A0,result is left adjusted DIDR0=0x01;//shut off digital input for A0 ADCSRA=B11000011;//I'm using 8 as division factor,with 4 I obtain quite noisy measurements ADCSRB=0x00;//free running, default setting } void loop() { startofconversion();//start a new conversion Serial.print(t);//send old data t=waitandget();//obtain new data, it will be send next cicle } void startofconversion() { ADCSRA=ADCSRA|mask;//let's start a conversion! } byte waitandget() { while((ADCSRA&mask)==mask)//wait { } return ADCH; }
With this I reach a sample rate of about 85/90 Khz(It's an estimate, i can't measure it because I haven't an oscilloscope),of course it isn't comparable with a real oscilloscope but it's enough if you have to display for example an audio waveform or if you have to check the pwm for a motor.
The precision is 8 bit.
Pc program
To make the pc interface I used LabView, the program still have some little problems but it works, with it I can see in real time the signal and the current value:
Of course I can zoom in to see it better
You can also freeze current measurements to see it in the "Static graph" and then take data using windows on the upper right.
In this image I'm visualizing the voltage on a capacitor and below the old measurements of the square wave, as you can see the measured frequency is 1129 Hz, the calculated one is 1300 Hz so it isn't perfect but it can give you a quite accurate idea of what your circuit is doing (I was checking an oscillator made with a 555).
I will work to make it better, more precise and stable and probably I will create a small circuit to increase the range (0-5V is a quite poor range).
Top Comments