How to output analog voltage (+/-10V ) using usb port ?
Show older comments
Hi,
I have a matlab program that communicates with an instrument to measure the strain of a material under test. It is a real time measurement. The strain values are stored in a vector, in Matlab workspace (R2015b). Of course, the vector grows in size as function of time. Until here, no problem.
I need to send the strain values to another instrument, in real time also. This instrument has an +/- 10V analog input. I would like Matlab to use a USB port for the data transfer. The connection would be something like:
MATLAB ----> USB ----> Digital/Analog Converter ----> +/- 10V signal
What I don't know is:
1) Is there an easier solution to create a +/- 10V signal with Matlab?
2) How to send data (a vector or matrice) to a USB port? What are the basics functions for that?
3) Is there USB Digital/Analog Converters that can communicates with Matlab?
4) How the Digital/Analog Converters and MATLAB can understand each other?
Many thanks!
9 Comments
Walter Roberson
on 15 Feb 2019
what current do you need on output ? Which operating system ? Is your r2015b matlab 32 bit or 64 bit?
Valentin Segouin
on 15 Feb 2019
Walter Roberson
on 15 Feb 2019
R2015b was the last release that supported 32 bit MATLAB (which could be executed on 32 bit or 64 bit Windows.) The difference between 32 bit and 64 bit MATLAB is important for this purpose as 32 bit MATLAB was able to use the legacy Data Acquisition Toolbox, but 64 bit MATLAB needed the newer session-based Data Acquisition Toolbox. The legacy toolbox supported a number of different vendors, but back in R2015b, the newer session based interface supported only some National Instruments (NI) devices.
I suppose I should also ask whether you even have the Data Acquisition Toolbox, since it is probably tool late to purchase it now against R2015b.
If you do not have Data Acquisition Toolbox, then do you have Instrument Control Toolbox?
What is acceptable latency, and what sampling rate do you need for taking the measurements for your situation? If you do not use the Data Acquisition Toolbox then some of the most natural approaches involve adding in an Arduino or Raspberry Pi, which are inexpensive but not especially fast, and communications with either one of those is rate restricted. (If you are not using Data Acquisition Toolbox then communication to anything USB based is rate restricted to at most 1000 packets per second.)
Walter Roberson
on 15 Feb 2019
Edited: Walter Roberson
on 15 Feb 2019
What device are you communicating with at the moment, with what toolbox?
What sample rate do you need?
The NI USB-6001 is 2 channels of output, +/- 10V, but only 5 mA. None of their USB-6xxx series appears to handle more than 5 mA.
Walter Roberson
on 15 Feb 2019
See the discussion at https://www.maximintegrated.com/en/app-notes/index.mvp/id/2398 about circuits for +/-10V at 10 mA, built with components and a 0-3.3V DAQ.
Valentin Segouin
on 16 Feb 2019
Walter Roberson
on 16 Feb 2019
Ah, I misread the micro-amp . 10 micro-amp should be easy to do with the voltage being more of a problem.
Walter Roberson
on 16 Feb 2019
Edited: Walter Roberson
on 16 Feb 2019
The age of your MATLAB leads to complications. In R2015b, the Data Acquisition Toolbox for 64 bit MATLAB supported only some National Instruments devices, and the Digilent Analog Discovery device.
The Digilent device is interesting, but would require a voltage doubler (it is +/- 5V). However it is no longer sold by Digilent, replaced by the Analog Discover 2, which requires R2018b or later.
The National Instruments boards are rarely the fastest or least expensive boards on the market, but support for them is pretty well developed. In R2015b, the 64 bit MATLAB "session based" interface did support the USB-6001 device I mentioned before, which directly supports +/- 10V.
For the data rates that you need, Arduino or Raspberry Pi would do fine for rate. However neither of them is as "plug and play" for analog output. For both of them, the built-in analog outputs are fixed voltage with PWM, and the voltage range is not very high (0-5V) . There is discussion at https://www.instructables.com/id/Arduino-RC-Circuit-PWM-to-analog-DC/ showing how to smooth out a PWM to a flatter continuous response using an RC circuit, but that in itself will not get you negative voltage. https://www.amazon.ca/Digital-Analog-Signal-Tranformer-Konverter/dp/B00UIZKYAS has an inexpensive device to convert PWM to 0-10V, but again no negative voltage.
Direct negative voltage on Arduino or Raspberry Pi would probably involve installing a small I2C based chip -- though finding one that handles negative voltage is not easy. https://store.ncd.io/product/1-channel-0-10v-dac-digital-analog-converter-i%c2%b2c/ has a 0-10V I2C chip.
Someone crowdsourced a +/-10V device but was not successful; https://www.kickstarter.com/projects/660498803/extended-dac-shield-for-arduino-eight-10v-analog-o
Ti has a circuit suggestion for converting a 0-2.5V DAQ into +/- 10V; see http://www.ti.com/tool/TIPD125
Ah it looks like https://www.maximintegrated.com/en/products/analog/data-converters/digital-to-analog-converters/MAX5322.html/tb_tab0 might be an SPI based output of +/-10V . The documentaiton of https://www.mathworks.com/help/supportpkg/arduinoio/examples/communicate-with-spi-device-on-arduino-hardware.html shows communicating with an SPI device from Arduino.
... As a quick summary then, if you follow the examples about communicating with I2C or SPI devices for Arduino or Raspberry Pi, then for the rates you need, the software should not be difficult. Finding an appropriate hardware device to handle the range you need might be more of a problem. Still, if you have not worked with Arduino or Raspberry Pi before, you would have to allocate some time to working through the kinks. If you had needed significantly higher rates then Arduino and Raspberry could involve higher learning curve.
The NI USB-6001 will do +/-10V for sure, if you have the Data Acquisition Toolbox. If you do not have that, then getting it now would be expensive, as you would have to update your MATLAB to the current release in order to be eligible to purchase the Data Acquisition Toolbox. Update to the current release for purchasing purposes, that is: if you had reasons to stick with R2015b then buying a current license would permit you to continue to use any older release.
Valentin Segouin
on 20 Feb 2019
Edited: Valentin Segouin
on 21 Feb 2019
Answers (0)
Categories
Find more on Arduino Hardware in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!