Oscilloscopes are common place in electronics workshops and laboratories. However they can be expensive and in a lot of cases they are bulky and more than is needed for the job in hand. Oscilloscopes also come in the form of storage scopes, which can record an output trace over a much longer period of time.
Using an ECIO combined with the Flowcode USB and Analogue components it is possible to create a very low cost basic scope that will replicate most of the functionality from an oscilloscope. As the scope data is also going into a PC it is also possible to take this further. For example you could measure the ambient light level outside and then when it gets dark you could automatically shut your curtains.
The demonstration program uses the Flowcode USB Slave component to transfer the voltage data from the ECIO to the PC. The ECIO device sits in a loop waiting for communications from the PC. At the same time, the analogue channel is being sampled as part of a timer interrupt service routine. Each sample is placed into a data buffer consisting of an array of byte variables. When the request from the PC comes into the ECIO device the data buffer is copied to the outgoing USB buffer and the ECIO then starts again from the beginning of the buffer. It is therefore possible to change the timer interrupt rate and directly control the analogue sample rate.
The PC software was created using the free VB 2008 Express Edition and simply outputs the incoming data by plotting points on an x y graph. Each time the PC requests data from the ECIO it receives the complete buffer and straight away plots the buffer onto the graph. The graph can hold 600 values so the time frame for this is 600 multiplied by the ECIO timer interrupt period. The example comes with a timer interrupt rate of 732.4hz which corresponds to an interrupt period of 1/f = 1.365ms or a sample window of 600 x 0.00136 = 0.82 seconds.
The output buffer for the USB slave component is 32 bytes in length by default. I have used the custom code feature of Flowcode to modify the USB Slave component to allow for a much larger array size of 128 bytes. The USB Slave component uses the Defines section of code to define the USB buffer sizes. I have modified the default settings by finding the line shown below:
#define USB_EP1_IN_SIZE 32
And changing it to this.
#define USB_EP1_IN_SIZE 128
You will also need to rearrange the in and out buffers for endpoint 1 to allow the increased buffer to fit in with the other USB buffers.
Eg
#define USB_EP0_OUT_ADDR 0x0500
#define USB_EP0_IN_ADDR 0x0508
#define USB_EP1_OUT_ADDR 0x0510
#define USB_EP1_IN_ADDR 0x0530
The maximum buffer size that can be used on a PIC is 256 so if you want a really fast scope then you could possibly double the buffer size again to give even more data throughput. This has to be balanced with how fast the VB can collect and process the data so as to avoid gaps in the output signal trace. In an attempt to try and speed up the VB.net code I have used a technique called double buffering where the output data is plotted onto a hidden image. Once the data has been plotted onto the image the image is then loaded onto the screen. This is much faster then trying to plot the signals directly onto the screen.
To provide the analogue sources I have connected an EB003 sensor board to Port A of the ECIO and used the onboard LDR and potentiometer. Alternatively you could connect the analogue inputs to just about anything to read the voltage. You may want to put a 10K series resistor between the analogue input pin and the analogue voltage source to avoid any potential damage to the ECIO microcontroller. Here is a good example circuit that will suit most types of analogue resistive sensor.
It is also good practise to add a ceramic capacitor between the analogue voltage source and ground to filter out any frequencies too high to be detected by the microcontroller. Here we can see the effects of a high frequency signal the output is aliased and instead of a nice single trace we seem to get multiple traces occurring simultaneously.
Here is a picture of the finished project. As you can see the two analogue traces are being plotted onto the screen, one in red and the other in green. The oscillations seen in the red line are from the LDR sensor picking up 50hz mains interference via the strip lights in the Matrix development office.
To take this project further a trigger value could be used to try to replicate the signal triggering function of an oscilloscope. This would allow for recurring signals to be analysed or for precise events to be captured onto the screen. Another use would be to take the values and output them to a log file allowing for future plotting or long term signal analysis such as sunlight levels measured over several years.
Using an ECIO as a USB analogue oscilloscope
- Benj
- Matrix Staff
- Posts: 15312
- Joined: Mon Oct 16, 2006 10:48 am
- Location: Matrix TS Ltd
- Has thanked: 4803 times
- Been thanked: 4314 times
- Contact:
Using an ECIO as a USB analogue oscilloscope
- Attachments
-
- USB Scope.zip
- (280.92 KiB) Downloaded 658 times
Regards Ben Rowland - MatrixTSL
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
-
- Posts: 41
- Joined: Thu Oct 16, 2008 11:01 am
- Has thanked: 21 times
- Been thanked: 7 times
- Contact:
Re: Using an ECIO as a USB analogue oscilloscope
I would rate this article as high, if only it was possible...
-
- Posts: 114
- Joined: Fri Jul 27, 2007 10:50 am
- Been thanked: 1 time
- Contact:
Re: Using an ECIO as a USB analogue oscilloscope
Am I correct that I would need the following hardware?
EB061 Β£27.00
ECIO028P Β£16.50
EB003 Β£17.00
Also any idea what sort of bandwidth the resulting oscilloscope is. I have an old Picoscope ADC-40 that only manages 10Khz
and it plugs into a printer port To buy a more modern Picoscope that uses the USB and has a bandwidth of 25Mhz would
cost me Β£125
EB061 Β£27.00
ECIO028P Β£16.50
EB003 Β£17.00
Also any idea what sort of bandwidth the resulting oscilloscope is. I have an old Picoscope ADC-40 that only manages 10Khz
and it plugs into a printer port To buy a more modern Picoscope that uses the USB and has a bandwidth of 25Mhz would
cost me Β£125
-
- Posts: 114
- Joined: Fri Jul 27, 2007 10:50 am
- Been thanked: 1 time
- Contact:
Re: Using an ECIO as a USB analogue oscilloscope
"Also any idea what sort of bandwidth the resulting oscilloscope is"
Should have read the article more carefully I see the Sample rate is 732.4hz so the bandwidth would be about 1/2 of this i.e. about 360Hz. That is should be okay for measuring signals up to about 360Hz but not more
Should have read the article more carefully I see the Sample rate is 732.4hz so the bandwidth would be about 1/2 of this i.e. about 360Hz. That is should be okay for measuring signals up to about 360Hz but not more
- Benj
- Matrix Staff
- Posts: 15312
- Joined: Mon Oct 16, 2006 10:48 am
- Location: Matrix TS Ltd
- Has thanked: 4803 times
- Been thanked: 4314 times
- Contact:
Re: Using an ECIO as a USB analogue oscilloscope
Hello
Sorry I just noticed I did not attach the actual VB code or Flowcode examples, I am not in work today but I will attach these files first thing tomorrow.
As for the predicted throughput I think you should be able to achieve around about 10KHz + at constant sampling via the analogue and USB components though I have not tried to push this to the limit. If anyone wants to give this a go then it would be interesting...
Sorry I just noticed I did not attach the actual VB code or Flowcode examples, I am not in work today but I will attach these files first thing tomorrow.
As for the predicted throughput I think you should be able to achieve around about 10KHz + at constant sampling via the analogue and USB components though I have not tried to push this to the limit. If anyone wants to give this a go then it would be interesting...
Regards Ben Rowland - MatrixTSL
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
- Steve
- Matrix Staff
- Posts: 3424
- Joined: Tue Jan 03, 2006 3:59 pm
- Has thanked: 114 times
- Been thanked: 422 times
- Contact:
Re: Using an ECIO as a USB analogue oscilloscope
You don't even need the EB-003 sensors board . We are only using this here because we are using it's onboard LDR and potentiometer to provide analogue signals to measure. In practice you would likely connect your own sensors to the ECIO device, so perhaps a terminal board (EB-002), proto board (EB-016) or patch board (EB-017) would be more appropriate.KeithSloan wrote:Am I correct that I would need the following hardware?
EB061 Β£27.00
ECIO028P Β£16.50
EB003 Β£17.00
- Benj
- Matrix Staff
- Posts: 15312
- Joined: Mon Oct 16, 2006 10:48 am
- Location: Matrix TS Ltd
- Has thanked: 4803 times
- Been thanked: 4314 times
- Contact:
Re: Using an ECIO as a USB analogue oscilloscope
Hello
The files are now included in the article.
Richard
Are you still unable to use the rating system? I will look into this for you.
The files are now included in the article.
Richard
Are you still unable to use the rating system? I will look into this for you.
Regards Ben Rowland - MatrixTSL
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
- Benj
- Matrix Staff
- Posts: 15312
- Joined: Mon Oct 16, 2006 10:48 am
- Location: Matrix TS Ltd
- Has thanked: 4803 times
- Been thanked: 4314 times
- Contact:
Re: Using an ECIO as a USB analogue oscilloscope
Hello
I noticed that I increased the wrong buffer size in the example I put up before. I was increasing the size of the OUT buffer but this is from the PC's point of view and therefore the size of my outgoing buffer from the PIC device was actually 32 bytes.
I have now fixed this in the example files above so that the size of the IN buffer has been increased rather then the OUT buffer. This is allowing for a much better scope operation with the ability to go to much higher sample speeds.
I noticed that I increased the wrong buffer size in the example I put up before. I was increasing the size of the OUT buffer but this is from the PC's point of view and therefore the size of my outgoing buffer from the PIC device was actually 32 bytes.
I have now fixed this in the example files above so that the size of the IN buffer has been increased rather then the OUT buffer. This is allowing for a much better scope operation with the ability to go to much higher sample speeds.
Regards Ben Rowland - MatrixTSL
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel