Arduino Due to PC High Speed USB communication - embedded

I am working on a project that uses the Arduino Due (microcontroller ATSAM3X8E). My goal is to be able to track the values of some of the key variables I am using in my firmware in real time. The fact is that I need to plot the change in the values of the variables over time.
In order to do this, I have decided to send the data to my PC through the native USB port. The real time constraint I am having is that I need to send the values of 20 variables (each of them 8 bytes long) within 0.1 ms. There is a native USB port available on the Arduino Due, which is connected to the USB peripheral of the chip. I have tried using UART over USB by setting up the Due in USB device mode. I can only get up to speeds of 115200 baud using Serial (UART) communication (any higher speeds don't allow the Due or my host PC to send the data correctly).
So, I did some home work and found that USB based devices have different classifications based on what they do. I want to know if there is a high speed protocol with a speed of at least 2 M bits/sec I can use on top of USB to data across to my PC from the Due, and, if there is an equivalent driver I can use on my Windows PC to successfully capture that high speed data - any recommendations would be greatly helpful.
Thanks in advance!
Subramanian

The Arduino Due's native USB port is capable of high-speed USB (480 Mbps), and by default it will appear to the computer a USB virtual COM port. This is a virtual serial port, so you can send data as fast as the USB drivers will allow, and you are not limited by the virtual "baud rate" of the COM port, which is an irrelevant setting. I think the virtual COM port will be fast enough for you and you should try it before doing something more complicated.
To use this port, use the SerialUSB in your Arduino program. The object has the same interface as Serial. You should already have a drivers for it if you installed the Arduino IDE or you are running Windows 10.
Please note that USB virtual COM ports usually use USB bulk endpoints, which don't guarantee any paritcular latency or throughput. If your computer is busy talking to other devices on the bus, you might get less throughput then you were hoping for, but you have a lot of margin of error here so I don't think it will be a problem in practice. If you want to be safe, just make sure that you can buffer up a few milliseconds of data on the device side so you aren't losing any data. You might have to look at the internals of the Arduino core code to see how big its buffers are.

Related

Directly Control USB Output?? (any language)

So I know that for a USB port type A there is 2 ouputs/inputs. I'm working on a simple electronic circuit and I would like to ouput datas on to my computer so a program could work with it. How (without it getting too complicated on the circuit side) can I just choose the output of the USB port and read the input just on the on/off level?
Thanks
What you want is the www.Nusbio.net device.
it is an USB device that give any .NET programming languages access to 8 gpios and also SPI and I2c bus.
USB is more complicated than what you are describing. It sounds like what you really want is a serial port, where you can use the TX and RX lines as your output and input to the PC, or manually control the modem control or GPIO pins. You can still do this with USB via a USB to UART Bridge device.
If you are simply looking to toggle an I/O pin, some of these devices also have general purpose I/O pins for this type of thing. You can set it to low/high from the PC if it is set to be an output and read the I/O value if it is an input.
You can talk to it as a serial device from your computer using normal serial communications such as POSIX method for Linux or OSX or the Commuincations API for Windows. In this case you can also set the flow control to manual and use the RTS/CTS pins as GPIOs.
You cannot directly control the USB inputs and outputs like you want to do. However, there are various solutions that involve connecting a USB device to your computer and sending commands to it that use its inputs and outputs. One such solution is called Firmata.

embedded target to host communication

I have the following problem:
A micro controller with the possibility to talk with PC via several communication interfaces: RS232, USB are present. Ethernet is not available. The software is bare metal with optional embedded OS.
The hardware is not important as this is applicable to any microcontroller and physical communication interface.
Several communication channels are needed simultaneously:
1 for a simple console - debug purpose: uC <-> PC
1 for getting real time samples from the ADC to PC: uC -> PC
1 for sending real time samples from PC to DAC: PC -> uC
1 setting different parameters of the acquisition/conversion, start/stop, etc: uC <-> PC
Ideally only one physical interface should be used RS232 or USB (preferable).
Is there something already available to multiplex different channels on a single physical one ? message passing, remote procedure call.
If you have an IP stack on the uC, then you can probably use SLIP or PPP to communicate through a serial link. On the other extreme, if you have a barebones system take a look at those protocols and things like HDLC because you will end up implementing something similar.
An obvious choice would be to use a TCP/IP stack. Each open "socket" is independent of any other and a link can support multiple simultaneous connections.
TCP/IP can be transported over Ethernet or over a serial connection via PPP or SLIP. A an asynchronous serial connection (COM port) can be emulated over USB by implementing a CDC/ACM class device, however if your device is to be released commercially you will need a USB vendor ID.
Some sort of multi-threading kernel may make handling multiple connections simpler, but is by no means necessary.
RS232
Almost nobody still ships RS232 on a PC/Notebook.
Is there something already available to multiplex different channels on a single physical one?
You aleady mentioned that you wanted to use USB, which supports multiple pipes on a device, called endpoints. The USB standard allows up to 32, but a specific micro controller may have implemented less endpoints, or has restrictions on endpoint types.
On the PC (Host) side you can use WinUSB or LibUSB to access these pipes.
Edit:
I use USB-to-RS232 converters personally, they can work but I must advise rather strongly against them for new designs:
Different USB Port can result in different COM port number
Unplugging a USB2COM while the port is "in use" results in COM port not working when replugging
Many driver issues on cheaper converters
Good luck trying to find Win8 drivers for older adapters
The 1ms USB frame time can negatively impact some RS232 protocols
All problems are minor, but you can avoid them when using USB directly.
real time samples
This raises the question of available bandwidth, where USB ususally has 12 MBit/s (or even 480 on some high-end micros). Most USB-2-RS232 adapters max out at 460800 or 921600 Baud.

USB to COM, how does the RS-232 interperate data?

If I had a RFID reader that sends a bunch of keystrokes through USB like a HID, how would the COM port interperate that if I used a USB to COM converter? What would the COM port see?
You should see the "keystrokes" from the rfid device.
At the link level, the converter should take care of speed mismatch issues. It does this via an internal buffer or by throttling the sender.
But the HID protocol is more than simple keystrokes. So either the additional information will be suppressed by the USB-COM converter or it won't be. This issue may also be converter-dependent.
In this sort of HW mashup, the best thing is to try it and see. (And then write a blog post about what you discovered.)
What is your overall goal? What sw are you trying to connect the RFID reader to?
Added I agree with #Turbo J's point: most every USB-COM converter acts as a USB device. As such, if you connect them to another USB device, nothing will happen since you're using them "the wrong way around."
You'll need to find a USB/Host to COM converter. The usual name for such things is "computer" -- a used laptop may be your best bet if you want to continue down this road.
On USB, a device can only talk to the host.
The RFID reader is a device. The USB->COM converter is a device. They cannot talk to each other wihout a host.
Conclusion: If you want the RFID data going out of the COM port, write a program which does that - by reading the HID data from RFID device and writing to the USB COM port.
Probably nothing. COM ports are usually very low speed things (you can usually tweak them up to about 115kbps. USB ports are (by comparison) incredibly high speed ports. I think the lowest speed USB is like 1.5mbps.
The more important question is how you are going to make the physical conversion.
You have an RFID reader that has a usb plug on it. Are you going to chop this off and solder a db9 connector on the end, which you are then going to plug into an USB to COM adapter and try to read serial data off the com port?
You are adding in one more step into it that you don't need to (you're taking up an usb port anyway).

Provide input data to FPGA using USB

I am working on Xilinx Spartan 3E platform, using this development board:
http://www.xilinx.com/products/boards-and-kits/HW-SPAR3E-SK-US-G.htm
My program operates on certain data and then provides output. I wish to transfer the input signals externally. The input data is a stream of 8-bit signals.
So, how do I send the input signals from my laptop to the FPGA via USB? Does Xilinx support this or is there standard software to do this?
Thanks.
It sounds like you are describing a uart more than a native USB interface. You can get a USB to logic level serial adapter that will let you easily transfer data to and from a Pc at up to 921.6k baud. A uart/serial port is easy to implement in the Fpga and PCs are easy to use with serial ports.
Here is the cable:
http://www.ftdichip.com/Products/Cables/USBTTLSerial.htm
If you have a development card it is very possible this type of interface is present.
On the software side you can use your programming language of choice as if it was interfacing with a seal port or use a terminal program like hyper terminal or Download teraterm http://ttssh2.sourceforge.jp/
Updated response:
100Hz is not a hard interface to make. At that rate you should use the serial interface if at all possible. The board you referenced has 2 full RS-232 connections. At that point you only need a way to connect that to your computer. If you have a PC with RS-232 connectors you only need a cable if you have a newer computer without you need a RS-232 to USB translator cable (like this one: http://search.digikey.com/scripts/DkSearch/dksus.dll?Detail&name=768-1014-ND or google rs232 usb). This will give you a virtual com port on the pc to interface with the previously mentioned terminal programs or your custom software.
Update 2:
on the resource tab of the development board page you linked to there are several UART based fpga designs that you should be able to use as a starting point.
i.e. the "PicoBlaze Processor SPI Flash Programmer".
That board doesn't provide easy access to the USB interface from the FPGA as far as I can tell. It's just for configuration and debug.
Some of the newer boards and tools do allow something called hardware-in-the-loop testing where the simulator can upload data to the FPGA, wait it to calculate the results and then pull the data back. This is relatively common when using Xilinx's System Generator product as the simulations can be really long.
But I think with that board you'd be better off using the on board RS232 port to get data to and from the board. You will have to build the infrastructure to do it yourself though.
This may also give you some ideas:
http://www.1pin-interface.com/

Is USB power always enabled ? And if not, how to write a driver

I have a device that came with an AC power adapter where the connector is a mini USB plug. The device however doesn't seem to power itself from a computer's USB port (using a standard USB-mini USB cable) unless a specific driver is installed. The driver is only available for Windows. I would like to charge the device from USB plugs on different platforms.
My question is: why isn't power getting to the device without the driver? Is a driver always required for a USB port to start giving power? Or is it this device that's specifically made not to take a charge unless some software routine triggers it to do so?
I guess my question can be summarized as: Is power not present on the USB cable or is it present but the device ignoring it. If the answer is the former, I'll be trying to figure out how to write software that will enable the voltage to always be present.
Thanks
Why isn't power getting to the device without the driver?
USB ports are always powered when the computer is on and the USB control software hasn't detected current overdraw.
Is a driver always required for a USB port to start giving power?
No, the USB port is always required to start off providing power to the device, otherwise the device could never initiate a connection.
Or is it this device that's specifically made not to take a charge unless some software routine triggers it to do so?
This can be complex. To meet the USB spec a device cannot pull more than a few mA until it's registered with the computer.
However, nearly every computer allows the USB port to pull the full 500mA (and more) before it'll shut the power off.
The device you're charging is being nice by not pulling any significant power until the computer gives permission.
Writing software won't help, the device has to register with the USB bus, which will best be done with the driver.
However, the plug in charger doesn't do that. It likely has shorted the two data lines of the USB plug together, which signals the USB device that it's not connected to a computer and can pull the full 500mA without waiting.
Take a USB extension cable, cut off the jacket, and short the data lines (green and yellow, sometimes) together on the end going to the USB device, and leave them cut without touching anything on the end going to the PC, and leave the read and black power wires connected through.
It might work. If not, take the wall charger apart and find out what it's doing with each of the four USB wires, and see if you can duplicate that.
This might be helpful if you are targeting a linux system.
This seems to be platform-specific. In Linux, USB ports are always energized, while on Windows they don't. Thumbdrives with LEDs turn off when unmounted in windows, but in Linux they stay lit. My cellphone's manual says that it can't be charged by a PC, but I regularly do on my linux machine, I guess that's because they don't have a driver and windows won't power up without one.
Have you tried plugging it into a 'dumb' USB port - like the one on a car charger? Those ports are pure power and don't create a USB network. I think.
Unless you have the hardware specs from the manufacturer, I think you are out of luck. You could try reverse engineering the driver to see what it does, but I'd expect it would be cheaper and easier just to buy one with cross platform drivers or charges without the driver.