Author Topic: can a usb port be used as a counter?  (Read 9356 times)

0 Members and 1 Guest are viewing this topic.

Offline sarepairman2Topic starter

  • Frequent Contributor
  • **
  • Posts: 480
  • Country: 00
can a usb port be used as a counter?
« on: August 17, 2015, 03:27:03 am »
Is it possible to use a USB ports signal lines to count pulses from an "analog" device that does not really make any kind of packets or anything like that (so long voltage levels are right)? or does there need to be handshaking/etc going on?
 

Offline exmadscientist

  • Frequent Contributor
  • **
  • Posts: 404
  • Country: us
  • Technically A Professional
Re: can a usb port be used as a counter?
« Reply #1 on: August 17, 2015, 03:35:27 am »
Is it possible to use a USB ports signal lines to count pulses from an "analog" device that does not really make any kind of packets or anything like that (so long voltage levels are right)?
No.
or does there need to be handshaking/etc going on?
Yes.

USB is not a simple protocol. It is extremely unfriendly to improper or buggy implementations. It is also quite challenging to get right, and because it is a shared bus, if your device is flaky, you can take down other devices on the same root port.
 

Offline rs20

  • Super Contributor
  • ***
  • Posts: 2322
  • Country: au
Re: can a usb port be used as a counter?
« Reply #2 on: August 17, 2015, 03:36:32 am »
No.

Not with normal device drivers at least; I suppose I can't rule out certain USB chips having a debug mode built in that you could abuse, or maybe you can hack the device-present detection mechanism somehow. But it's absolutely not normal to do things this way, and how you'd negotiate past the USB hubs built onto your motherboard is beyond me.
 

Offline jeroen79

  • Frequent Contributor
  • **
  • Posts: 529
Re: can a usb port be used as a counter?
« Reply #3 on: August 17, 2015, 10:34:56 am »
What do you want to use this for?
At what frequency will these pulses come in?

You could use a USB to serial adapter, a USB I/O board or perhaps a gamecontroller board if it is only for low frequencies and timing isn't critical.

Otherwise you should program a suitable microcontroller to do the counting and report the result over USB.
 

Offline compet17

  • Regular Contributor
  • *
  • Posts: 100
  • Country: ch
    • Youtube - Play with Junk
Re: can a usb port be used as a counter?
« Reply #4 on: August 17, 2015, 06:59:25 pm »
If the frequency is low, take an old USB keyboard and rewire one of the keys. Then count the key presses....

I once modified an USB mouse for a "who clicks most in one minute" competition with a relais on the mouse button. If I remember right I came up to 150Hz and broke all records  >:D
 

Offline Jeroen3

  • Super Contributor
  • ***
  • Posts: 4286
  • Country: nl
  • Embedded Engineer
    • jeroen3.nl
Re: can a usb port be used as a counter?
« Reply #5 on: August 17, 2015, 08:02:40 pm »
Well, you could theoretically abuse the cable detect mechanism.
 

Offline electr_peter

  • Supporter
  • ****
  • Posts: 1458
  • Country: lt
Re: can a usb port be used as a counter?
« Reply #6 on: August 17, 2015, 08:14:05 pm »
Answer to original question - no, no way. Accomplishing something like this requires either massive SW and HW modifications to USB bus (which would not be USB any longer) or dedicated MCU serving as an USB device and doing intended function.

If only I could get a € for everytime I hear such question... It is very common to ask such thing amongst beginners. Some people think that if you have a PC, you should be able to anything on USB lines via means of software...

However, all you get from USB is 5V rail at limited current and D+/D- communication lines. Communication protocol is specific and cannot be changed or directly accessed from PC side. D+/D- is only for USB protocol and nothing else (well, except USB abuse with chargers that is).
 

Offline sarepairman2Topic starter

  • Frequent Contributor
  • **
  • Posts: 480
  • Country: 00
Re: can a usb port be used as a counter?
« Reply #7 on: August 19, 2015, 12:37:28 am »
Well, you could theoretically abuse the cable detect mechanism.

i would like to know more
 

Offline rs20

  • Super Contributor
  • ***
  • Posts: 2322
  • Country: au
Re: can a usb port be used as a counter?
« Reply #8 on: August 19, 2015, 03:28:17 am »
i would like to know more

Here is how USB speed and device detection works:

http://www.beyondlogic.org/usbnutshell/usb2.shtml

Theoretically, you could poll the state of the host chip and "infer" something about the voltages on the D-/D+ lines. But there's no guarantee on speed (could only check 10 times a second and the user experience would be perfectly fine) or whether the hardware actually exposes any of this knowledge to the PC (it may just keep dead silent until it successfully establishes a proper USB protocol link). Hence why this is being described as a "theoretical" approach. trying to exploit this for a real application is undoubtedly a terrible idea. I'd be surprised if it were actually possible on a typical PC.
 

Offline Jeroen3

  • Super Contributor
  • ***
  • Posts: 4286
  • Country: nl
  • Embedded Engineer
    • jeroen3.nl
Re: can a usb port be used as a counter?
« Reply #9 on: August 19, 2015, 06:27:09 pm »
I'd assume that such a thing is most viable for Linux. You'd be limited to probalbe less than 1 plugin events per 10 seconds or so. Due to the many layers involved.
For windows, don't.

It's more reliable to get an mbed and create a simple tool to send some data over usb hid or usb uart.
 

Offline ChristofferB

  • Frequent Contributor
  • **
  • Posts: 929
  • Country: dk
  • Chemistry phd student!
    • My channel:
Re: can a usb port be used as a counter?
« Reply #10 on: August 20, 2015, 01:28:28 am »
If it's not for the sake of seeing if it can be done (if you need it, for something) - You could probably get a long way with either one of those little USB->serial or USB->parallel adapters. One of the handshaking inputs on either device could presumably do the trick, while keeping it "dumb" -no µcontroller.

If you do get it to work on pure USB-please do tell how!

-Christoffer
--Christoffer //IG:Chromatogiraffery
Check out my scientific instruments diy (GC, HPLC, NMR, etc) Channel: https://www.youtube.com/channel/UCZ8l6SdZuRuoSdze1dIpzAQ
 

Offline sarepairman2Topic starter

  • Frequent Contributor
  • **
  • Posts: 480
  • Country: 00
Re: can a usb port be used as a counter?
« Reply #11 on: August 20, 2015, 02:10:39 am »
Well I wanted like 100 KHz max counter on a regular USB port without the need for a microcontroller on the hardware side.
 

Offline kc8apf

  • Regular Contributor
  • *
  • Posts: 103
  • Country: us
Re: can a usb port be used as a counter?
« Reply #12 on: August 20, 2015, 02:50:57 am »
Well I wanted like 100 KHz max counter on a regular USB port without the need for a microcontroller on the hardware side.
A soundcard line in is much better suited for this. If your signals voltage level is too high, add a voltage divider.
 

Offline Richard Crowley

  • Super Contributor
  • ***
  • Posts: 4319
  • Country: us
  • KJ7YLK
Re: can a usb port be used as a counter?
« Reply #13 on: August 20, 2015, 03:30:58 am »
Well I wanted like 100 KHz max counter on a regular USB port without the need for a microcontroller on the hardware side.
You cannot talk to USB without a microcontroller.

A soundcard line in is much better suited for this. If your signals voltage level is too high, add a voltage divider.
It seems unlikely that your average sound card would respond decently up to 100 KHz.

OTOH, it is cheap and relatively simple to use one of the little boards that interfaces between USB and several raw I/O ports.
For example, this SparkFun USB to FIFO Breakout - FT245RL  $17.95
https://www.sparkfun.com/products/7841

 

Offline kc8apf

  • Regular Contributor
  • *
  • Posts: 103
  • Country: us
Re: can a usb port be used as a counter?
« Reply #14 on: August 20, 2015, 04:22:22 am »


OTOH, it is cheap and relatively simple to use one of the little boards that interfaces between USB and several raw I/O ports.
For example, this SparkFun USB to FIFO Breakout - FT245RL  $17.95
https://www.sparkfun.com/products/7841


I'm not finding any info on interrupt on change capabilities for an FTDI. Polling over USB is going to be CPU intensive and slow. Hitting 1kHZ would surprise me.
 

Offline sarepairman2Topic starter

  • Frequent Contributor
  • **
  • Posts: 480
  • Country: 00
Re: can a usb port be used as a counter?
« Reply #15 on: August 20, 2015, 05:14:15 am »
its more size related then $ related
 

Offline c4757p

  • Super Contributor
  • ***
  • Posts: 7799
  • Country: us
  • adieu
Re: can a usb port be used as a counter?
« Reply #16 on: August 20, 2015, 05:15:47 am »
MCP2210 and other related parts have an interrupt counter that you can read out over USB.
No longer active here - try the IRC channel if you just can't be without me :)
 

Offline matseng

  • Frequent Contributor
  • **
  • Posts: 563
  • Country: se
    • My Github
Re: can a usb port be used as a counter?
« Reply #17 on: August 20, 2015, 05:57:01 am »
MCP2210 and other related parts have an interrupt counter that you can read out over USB.
That's a cool function, I didn't know that it had that.  I'm filing that fact away in the might-be-handy-someday drawer in my brain :-)  Thanks.
 

Offline Richard Crowley

  • Super Contributor
  • ***
  • Posts: 4319
  • Country: us
  • KJ7YLK
Re: can a usb port be used as a counter?
« Reply #18 on: August 21, 2015, 11:43:10 pm »
its more size related then $ related
You can't hardly get much smaller than this...



Espruino Pico  PRODUCT ID: 2621  $24.95
http://www.adafruit.com/product/2621
 

Offline rs20

  • Super Contributor
  • ***
  • Posts: 2322
  • Country: au
Re: can a usb port be used as a counter?
« Reply #19 on: August 22, 2015, 12:18:56 am »
You can't hardly get much smaller than this...
What? That's MASSIVE:P



Yeah, to be fair that thing can't count pulses. But what it does do is far more complex!
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf