How to talk to PIC PLC or any other device thru USB

This is a discussion on How to talk to PIC PLC or any other device thru USB within the Networking/Device Communication forums, part of the General Programming Boards category; Hello,... after a a course in computer design and logic (textbook by Mano). i would like to test my knowlage ...

  1. #1
    Registered User
    Join Date
    Apr 2007
    Posts
    112

    How to talk to PIC PLC or any other device thru USB

    Hello,...

    after a a course in computer design and logic (textbook by Mano).
    i would like to test my knowlage and understandig of the matrieal.
    i thout about using a PIC or PLC to do some simple func and connect it thru usb (Since it is extreamly popular protocol).

    for the example Simple counter (from 0 to 8)

    the actual PIC configuration isn't hard and it can be even created using simple circute (lots of NAND , NOR ,AND, NOT ).

    the comunication between the card will be like the next scrinario:
    Connection on Counter (chip or assembly).

    Code:
     -------------
    |clock         |
    |clear         | 
    |load          |
    |d0       o0  |
    |i1        o1  |
    |i2        o2  |
    |i3        o3  |
     --------------
    the get msg will be
    Clock,Clear,Load,d1,d2,d4
    the post msg will be
    o0,o1,o2,o3
    only if clock = 1 the counter will work
    Code:
    each value,value,... means (binary) value,(binary) value
    how can i conntact this device to a usb port and make an os to talk to it?
    why Gaos didn't had a wife ?
    http://bsh83.blogspot.com

  2. #2
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    You'll need to implement a upper-level USB driver - there may be some user-mode generic versions available too.

    On the other hand, the manufacturer of the PIC chip probably provide suitable drivers that work with the chip, I would expect.

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  3. #3
    Registered User
    Join Date
    Apr 2007
    Posts
    112
    what about the actual pic to usb port connection ?
    how do you set the profuct ID : User ID (that can be shown by lsusb)?
    Last edited by jabka; 09-20-2007 at 11:03 AM. Reason: sorry for the mistake about lspci
    why Gaos didn't had a wife ?
    http://bsh83.blogspot.com

  4. #4
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Quote Originally Posted by jabka View Post
    what about the actual pic to usb port connection ?
    how do you set the profuct ID : User ID (that can be shown by lspci)?
    I presume you mean lsusb, as lspci lists PCI devices, not USB devices.

    I have no idea how that is done in the PIC controller you are using, but I guess it is part of the USB configuration on teh target system. Read the documentation for the specific PIC.

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  5. #5
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Have a look at:
    http://www.linux-usb.org/gadget/

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  6. #6
    Registered User
    Join Date
    Apr 2007
    Posts
    112
    Sorry about lspci ...

    i took a PIC for example .

    as you can see the chip i used in the example isn't a PIC it is just a seqentional circut that is made using AND,NAND,OR etc logical gates.

    im reading now http://www.lrr.in.tum.de/Par/arch/us...sbdoc-1.32.pdf and more (ill post any relevent data {in the feutere ] if i find on http://bsh83.blogspot.com/2007/09/i-...ogram-usb.html)

    so i understand that usb is 4 bit long so i need to use some sort of decoder that will get 4 bit (ill get the maximum of 2^4 instructions)

    the problem is how can i recive the data tru that cable (prevent collisions)
    why Gaos didn't had a wife ?
    http://bsh83.blogspot.com

  7. #7
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    You seem to think that just because USB uses four pins that the protocol is trivial .

    Do you know (roughly) how TCP/IP works? That uses (essentially) two wires. Does that mean that you can make a Network controller with a few NAND, OR, AND-gates? No!

    USB is a serial protocol. It uses these to transfer data from one point to another over a single wire (essentially), but the protocol is fairly complex, including different types of flow control and packet checksums.

    You can get the full specs here:
    http://www.usb.org/developers/docs/

    Here's a description of a "Macrocell" written in VHDL:
    http://www.intel.com/technology/usb/...ocell_1_05.pdf

    Some ready made USB "simple devices" that may suit your project:
    http://www.beyondlogic.org/usb/usbhard2.htm

    There is verilog code to implement USB here:
    http://www.opencores.org/projects.cgi/web/usb/overview

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  8. #8
    Registered User
    Join Date
    Apr 2007
    Posts
    112
    actually i don't know how tcp/ip work (but im learning).
    i didn't new about the two wires (i didn't stumbled on any relevnt data about it in "Computer Networks by Andrew T." ( i guess it some where in the next chapters).

    thnx for the links im reading now (and having some issues with understanding...)

    any way when i said that you have 2^4 instruction it didn't say anything about the comunication abiulty (since USB is serial connection and not parllel).

    for the next explenation i will call the usb pins as ABCD
    for example you can say that after instruction 1100 will start the communication thru the lest segnificit bit)if the third bit from the left (c) becomes 1 the commion will stop so the truth table will be some thing like :


    Code:
    ABCD | Explanation
    0000  | reset the counter (clear)
    0001  | start the counter
    0010  | strart serial load from the second bit.
    0X11  | Loading bits.
    0100  | stop loading
    ....      | something (4 more instructions)
    1100  | start get serial output from counter
    11x0  | actual 4bit data transfer.
    1101  |stop geting serial output
    1111  |get product ID and Vendor Id.
    so here we got a 12 diffrent instructions and 2 data transfer options.


    about the gates (just to clerfay for other that will read this post and maybe not famileor with chips proccesors memory and more ).

    what we call a computer is the sum of many sequantional circutes (they use gates).
    so actually you can using some gates (hundreds ? ) create a router or a firewall or what ever you want (since hardware based router are exatly created in this form) .

    even what we call a "memory bit" is a seqational circute (FF) that is created using logical gates.

    the amount of gates can be calculated very easy (there are some formulas but i don't remmber them).
    why Gaos didn't had a wife ?
    http://bsh83.blogspot.com

  9. #9
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Yes, sure, you can build anything from "gates" - I didn't mean to imply anything else. But building YOUR OWN USB device controller that is compatible with a standard USB host controller is not something you do in a few hundred gates (nor a Network Router).

    Note that the USB protocol is byte oriented, so sending 4 bits at a time is not really possible - you could of course USE only 4 bits out of one byte.

    It is relatively easy to calculate the (minimum) number of gates used to do an add instruction, or something fairly trivial. The number of gates needed for a USB device controller is quite a large number, and the exact number will depend on how much of the work is done in software and how much is done in hardware - the split will in turn depend on what sort of processor you put next to the USB controller. A simpler processor will need more work in the hardware, a more capable processor will require less work in hardware. [It also depends quite a bit on how efficient your VHDL/Verilog/other RTL compiler is at optimizing your gate usage, and how you decide to solve certain types of problems - for any software problem, there is one that uses less memory and more processing power, and another that uses more memory and less processing power - the same applies to logic gates - you can use fewer gates and do more clock-cycles, or more gates and fewer clock-cycles).

    As an example of calculation, one bit of SRAM takes 3 gates, consisting of a total of 6 transistors. On top of that, of course, there is a need to build some addressing logic to fetch the data out of a pariticular memory cell, or set a particular cell to a value. For large memories, these "administrative" gates are not really making up much of the total gate-count, but for small memories, it can notice.

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  10. #10
    Carnivore ('-'v) Hunter2's Avatar
    Join Date
    May 2002
    Posts
    2,879
    There are PIC microcontrollers that have USB peripherals built-in. In a recent project, I used a PIC18F2455, although the PIC18F2550 and PIC18F4550 also support full-speed USB. A couple in the PIC16 family support low-speed USB. Check out Microchip's website, and also google for Microchip Full Speed USB Solutions.

    If you haven't done USB before, then it'll still take a lot of work to figure it all out and get running; there's a fair amount of online resources/examples though. The design is very flexible, and only the lowest level of the USB protocol is done for you so that it will not limit your design options.

    Alternatively, if you just want something that will allow your PC to set some lines high/low in your circuit, check out the FT245RL (USB to parallel converter chip). It isn't the fastest or most efficient method of USB data transfer, but it's by far the easiest, and will give you logic levels compatible with standard 5v circuitry.

    Good luck.

    **EDIT**
    If you're trying to design USB hardware, and not just trying to connect an existing circuit to the computer, forget about it.
    Just Google It. √

    (\ /)
    ( . .)
    c(")(") This is bunny. Copy and paste bunny into your signature to help him gain world domination.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 3
    Last Post: 09-02-2008, 11:51 PM
  2. Interacting with USB device
    By AKalair in forum C Programming
    Replies: 2
    Last Post: 02-20-2008, 02:07 PM
  3. Replies: 4
    Last Post: 06-30-2004, 04:11 PM
  4. Opening a specific USB device.
    By marsface in forum Windows Programming
    Replies: 4
    Last Post: 07-11-2002, 01:02 AM
  5. how can i detect usb device?
    By orcher in forum C++ Programming
    Replies: 2
    Last Post: 06-13-2002, 10:00 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21