3
\$\begingroup\$

I'm prototyping a board which has a USB connector, in Spice or any other circuit simulation technology. The production board will plug into the PC and there will be some software which talks to it through USB. I'd like to do a lot of the prototyping in software before I mess around with meat-space, because speed.

Is it / how is it possible to connect the software to a simulation of the board? What simulation software does this?

In other words, it would be cool to get the simulation happening and have it act like it's plugged into one of the USB ports on the computer (a real one or a virtual one), so I can test the interaction with my PC-side code.

\$\endgroup\$
  • 3
    \$\begingroup\$ Assuming you are not trying to model the analog electrical behavior of the USB interface, perhaps what would be most useful would be to find a programming interface to the simulator which can let an external program control sources on nodes which correspond to the I/O pins of the USB interface device. \$\endgroup\$ – Chris Stratton Aug 23 '13 at 16:37
  • \$\begingroup\$ @ChrisStratton that's along the lines of what I was thinking. Do you happen to know of any simulator that provides interfaces like that? \$\endgroup\$ – Purrell Aug 23 '13 at 21:21
  • \$\begingroup\$ Have a look at the specifications and videos of Proteus simulation: It does a fair job of simulating multiple analog and digital parts and interfaces, though it does require hefty computing power. The simulator can even simulate firmware for several microcontrollers while taking simulated input signal from simulated interfaces such as USB. It's not SPICE, but it's pretty powerful stuff. \$\endgroup\$ – Anindo Ghosh Aug 26 '13 at 4:09
2
\$\begingroup\$

I'm afraid the answer to your question is that this is most likely not possible.

If you describe your system and goals in more detail, someone may suggest a possible alternative. A few doubts and questions that come to my mind are (sorry if I've totally misunderstood your situation):

  • What simulator are you using?
  • Do you really have a working model for the USB controller? USB devices are usually a microcontroller running a nontrivial amount of code, which is very complicated to simulate at the level of Spice, or even Verilog.
  • If you do have a working simulation, how fast does it run? PC USB drivers are time-sensitive and will expect quick responses from the USB device. I would expect a behavioral simulation of a microcontroller running code from a ROM to run on the order of 10 minutes real time per 1 millisecond simulation time.
\$\endgroup\$
  • \$\begingroup\$ I think there's a possibility no one has written software to do it (or made it freely available anyway). Although I bet there is something out there. For an example I'm thinking of something like sparkfun.com/tutorials/108 there are spice models for all of these components. I'm just looking to plug a 'virtual usb cable' into the USB adapter into the simulation, as if one end were plugged into my PC usb port, and the other end into the circuit. \$\endgroup\$ – Purrell Aug 23 '13 at 21:17
  • \$\begingroup\$ The timing issue is a good consideration, since if it is too slow it could possibly cause USB exceptions \$\endgroup\$ – Purrell Aug 23 '13 at 21:28
2
\$\begingroup\$

You are well beyond the system-complexity level where SPICE is a meaningful tool.

SPICE is a analog simulator. It can scale to a few thousands of transistors. The ICs you want to simulate have many tens or hundreds of thousands of transistors in them.

Also, SPICE does sparse evaluation when it can determine it's resolving the dV/dT with sufficient precision. Since your micro/other-complex-logic-IC is likely going to have a fast internal clock, SPICE will have to simulate the device with considerable precision, which would render the simulation even slower then simple analog circuits.

Additionally, SPICE is not a real-time tool. Simple models can run at ~ \$\frac{1}{1,000}\$ - \$\frac{1}{1,000,000}\$ realtime. This is acceptable for most simple simulations, where you can properly set initial conditions, and run the sim for a short duration to evaluate it's behavior.

If you combine the above factors and the fact that you will need many hundreds of milliseconds of in-simulation-time for your MCU to properly start up and connect, you will probably need several real-time days (!) for your simulation to even enumerate! Additionally, something will have to properly implement the USB-host the device is connected to. You cannot simply forward a USB connection running at one millionth (or more) of realtime to the host and expect it to work.

The way simulations like the one @Purrell links in his answer is they have simplified models of the various devices. The MCU is simulated as something along the lines of a VHDL or Verilog soft-core MCU, purely in the digital domain (note: this is not SPICE), and the interfaces are buffered into the analog simulation (and that assuming they're doing any analog simulation at all. I think it's pretty unlikely).

Obviously, this is also constrained by the accuracy of the models. Even SPICE is not a perfect tool, and the further you abstract away from the actual nature of the devices, the more likely simulation imprecisions are likely to affect your simulated result.


Really, it seems like you're overthinking this. Even simulators such as SPICE are generally rather poorly regarded, as they tend to be very susceptible to corner-cases, and are really only worth-wile as a analog design verification tool.

There are really no tools for this sort of thing, as they would be more-or-less useless. The depth of knowledge of a specific device required to write a useable, if not perfect model of said device would render the simulation unneeded, and the simulation would still not always perfectly model the real hardware.

The reason there isn't much interest or products that do what you want is cause it's kind of useless. Until we can simulate the entire chip with a resolution of of a few atoms, it will remain useless outside of a few specific applications.

Really, you just have to get over it, and build the actual hardware.

\$\endgroup\$
  • \$\begingroup\$ I might be using the wrong term with SPICE. Any sort of simulation or emulation is what I'm after. The microcontroller and the USB don't have to be SPICE in a simulation, understand? Your answer is right for full SPICE, and geared toward a complex board. For a simple board, simulating it in software to get the schematic and interface software down first is a fine idea. real-time simulation is not a requirement, if it were, that would be different. \$\endgroup\$ – Purrell Aug 25 '13 at 21:38
1
\$\begingroup\$

Here's a simulator that does it:

http://www.labcenter.com/products/usb.cfm

They claim to be the only one that does it, which is unfortunate because the software is expensive and the UI is dated IMO, and it's such a nice idea. It works for PICs and AT90s which is what I'm up to.


I'm surprised by the no-you-can't answers. Folks - it's 2013 :) . We can can simulate entire computers, including their USB interfaces in software. I'm writing this inside of a windows VM running on a Macbook Pro. The USBs inside the VM are completely simulated, "real-time", and they hook through to the host machine as if they were local.

In fact, in addition to the Lab Center software working beautifully and simulating the USB interface, I'm running a VM because this software only runs on windows. So I've got code on my host OSX machine connecting to a virtual USB port on the VM windows machine, which is connected a virtual USB interface from the circuit simulation. That's a whole 'nother layer of virtualization on top of the one you're telling me I'm not supposed to be able to do. Beer me!

\$\endgroup\$
  • \$\begingroup\$ I'm not sure this software really does what you asked for. It simulates USB transactions down to the driver level, but there's no indication you can connect your own software to that driver. \$\endgroup\$ – Joe Hass Aug 24 '13 at 19:09
  • \$\begingroup\$ Sorry, I meant that it's not clear you can run your own software in anything close to real time along with a SPICE simulation of your board. Also note that it only works with a specified set of USB-capable microcontrollers. I'm skeptical and I don't want to spend ~$1,000 to try it, so let us know how it works for you. \$\endgroup\$ – Joe Hass Aug 24 '13 at 19:18
  • \$\begingroup\$ Nah, you can connect it. It works. Let's just say I "borrowed" the software. It's cool. UI not so great. It connects just as if the device was plugged in to the USB port on the machine. The circuit is not full-speed but I have no trouble connecting to it via libusb-win32. It was a bit of a pain but meh. \$\endgroup\$ – Purrell Aug 25 '13 at 22:08
  • \$\begingroup\$ VMs are NOT a simulation. You are confusing terms a lot here. Also, you're missing one of the key-points in that no one in the industry really wants the kind of simulation you're talking about, as it's more or less useless for anything but extremely simple implementations, which you shouldn't really need to simulate anyways. \$\endgroup\$ – Connor Wolf Aug 26 '13 at 0:27
  • \$\begingroup\$ VMs are quite obviously a simulation, Connor. You have a poor attitude I must say. By simulating this I must have saved at least a few hours if not more. My parts are in the mail, and I've already proved my circuit in theory, along with my code. Check your attitude and your ego, please. \$\endgroup\$ – Purrell Aug 26 '13 at 15:26

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.