PIC programming for computer to PIC

Discussion in 'Embedded Systems and Microcontrollers' started by thisdabest, Feb 16, 2014.

  1. thisdabest

    Thread Starter New Member

    Feb 16, 2014
    4
    0
    I am creating a project in which you control your lights via a computer. However I have no experience in getting my PIC(18f2550) to read its USB input. Can anyone help me?
     
  2. takao21203

    Distinguished Member

    Apr 28, 2012
    3,577
    463
    Use the USB stack.
    Download from the website (Microchip).

    you have to copy the project and then modify it.

    If the PIC is supported directly, it is easy, if not, you need to use one close to that type, and patch it
     
    absf likes this.
  3. ErnieM

    AAC Fanatic!

    Apr 24, 2011
    7,386
    1,605
    I agree with takao on this. My choice would be a CDC class (communications device class) that makes your device appear as a serial COM port to the PC. There is lots of support for this on a PC, even Hyperterminal can use it, so you don't need any custom drivers.

    The Microchip application library have several examples for several PICs on different development platforms. The platform is described in a file called "HardwareProfile.h"

    I would suggest for a first time you make as few changes as possible: if you can afford the development platform do so, if not at least choose the same PIC as a supported board.

    Once you get used to these USB sample programs they get very useful to reuse in your own projects.
     
    Last edited: Feb 16, 2014
    absf likes this.
  4. Brownout

    Well-Known Member

    Jan 10, 2012
    2,375
    998
    Alternatively, you can use a USB-serial adapter for your computer. I use the FTDI 4232 mini-module. You can download drivers form FTDI's website. I think Windows 7/8 already have the drivers, so you do nothing more than just plug and play. No RS232 translator is needed, as the output is 3.3V CMOS. Sparkfun has the modules for the FT232 for around 15 bucks.
     
  5. THE_RB

    AAC Fanatic!

    Feb 11, 2008
    5,435
    1,305

    Agreed, a much easier way to do it, and if the USB part blows up from static or any other reason you can just replace that module.

    Or you can get 10 from China direct for $15. ;)

    Or better still get the ones built into the USB lead, 10 are about $23 if I remember right.
     
  6. takao21203

    Distinguished Member

    Apr 28, 2012
    3,577
    463
    what sense does it make to pay $15 for USB module for a $3 microcontroller with USB?

    Also you can't communicate properly through a converter like via USB. You can only use the USB interface of the converter.
     
  7. shteii01

    AAC Fanatic!

    Feb 19, 2010
    3,383
    495
    When girls buy accessories, they buy earrings, hand bags, shoes.

    When boys buy accessories, they buy... stuff for their 3 dollar microcontrollers.
     
    spinnaker likes this.
  8. takao21203

    Distinguished Member

    Apr 28, 2012
    3,577
    463
    so you claim buying metal made pendants is a domain of the female gender?

    OP did not make a claim of searching for some extra stuff.
     
  9. Brownout

    Well-Known Member

    Jan 10, 2012
    2,375
    998
    Because of this:

    I don't need to modify anything. And, to say "modify it" without any specifics wouldn't be enough information to get me started.

    I can, no problem at all.
     
  10. ErnieM

    AAC Fanatic!

    Apr 24, 2011
    7,386
    1,605
    So I guess the choice is to spend a short bit of time (for me it's literally under half an hour but I've done it a few times) modifying the USB example code to accept and transmit data from an application instead of it's default method of sending data to the serial module, which happens to answer the question the OP was asking... or you can do something else which is not what the OP was asking.

    I've still never seen any advantage to using the FTDI when you also have a PIC in the project.
     
  11. Brownout

    Well-Known Member

    Jan 10, 2012
    2,375
    998
    The OP asked for help controlling lights via a computer. This is a way to do it, and do it simply. I disagree it wasn't what he asked.
     
  12. takao21203

    Distinguished Member

    Apr 28, 2012
    3,577
    463
    Sure, I don't doubt that.

    Fullduplex with serial port is a bit of an effort, or isn't it?

    With USB you get 3 different modes- control (slow), normal (data packets), and bulk (fastest but bits might be incorrect).

    With serial port, you cant transfer as fast as with USB, sure it is OK for a control string, but what if you want to program a FLASH chip with a few megabytes?

    that will take longer with serial port.

    What I wanted to say is you don't necessary can fully control the USB converter on the PCB side in a C++ software, like you could do it with the USB PIC, since you have the specification.

    You can only use it in some way, like a serial port.

    Instead of probing for the identification of your USB device, you have to select a COM port from a listview.

    Control signals are very slow, since USB has minimum latency of 1mS
    (in the DOS age you were able to react much faster by hogging the timer interrupt for instance).
     
  13. Brownout

    Well-Known Member

    Jan 10, 2012
    2,375
    998
    None at all. Serial is full-duplex. In the simple case of a PC and microcontroller, the goal is usually to communicate, and not to probe the depths of the specification. If the goal is to use all of USB's features, then that's a horse of a different color.
     
    Last edited: Feb 17, 2014
  14. takao21203

    Distinguished Member

    Apr 28, 2012
    3,577
    463
    Sure. Both technologies have their justifications to prefer them for an application (a circuit).

    The USB/serial converters are offered on the market because people repeatedly buy them.

    That said, why would you want to if you can get a 14pin USB chip for a dollar w/o crystal?

    Maybe for communications to something different than a PC, longer distance, etc.

    There are justifications to use RS232 in some cases for sure.
     
  15. ErnieM

    AAC Fanatic!

    Apr 24, 2011
    7,386
    1,605
    Here's his post:
    I see a question concerning (and I quote) "getting my PIC(18f2550) to read its USB input."

    Can you point me to the spot where he asks to redesign his circuit?
     
  16. Brownout

    Well-Known Member

    Jan 10, 2012
    2,375
    998

    Everything that is offered on the market is because people buy them. What's your point? I would chose to use a USB/Serial chip because not all projects require USB. For most PC to UC communication, serial is ideal.
     
  17. Brownout

    Well-Known Member

    Jan 10, 2012
    2,375
    998
    I see the question as, and I quote, "a project in which you control your lights via a computer.", so I offered an alternative. Did someone die and leave you the post police?
     
    Last edited: Feb 17, 2014
  18. takao21203

    Distinguished Member

    Apr 28, 2012
    3,577
    463
    have you ever seen a RS232 device containing a small FLASH drive containing the software + drivers? I haven't. You have to set the com port at least and adjust the protocol parameters. For USB you don't need to do this.

    I don't say better or not, both may have justifications. It's true OP was wondering how to get along with a USB PIC. Why not discuss the technology a bit.

    Same for inter chip, it's not necessary to use USB all the time, often a simple serial protocol is not just enough, it is the appreciate thing.

    Sometimes you'd want the automatic configuration capabilities (for instance recognize the node on the trunk, enumerate more than one of the same device, and look up the device capabilities. Even if you could do it with serial, USB is the standard for that).
     
  19. Brownout

    Well-Known Member

    Jan 10, 2012
    2,375
    998
    You are free to discuss the technology all you want. I won't stop you. I have an alternative method which is much simpler, although you need to set 4 parameters (takes about 4 seconds). But, please proceed to discuss any technology you like.
     
  20. takao21203

    Distinguished Member

    Apr 28, 2012
    3,577
    463
    maybe use both systems- just in case the USB fails due to a software issue or cable failure.

    It's nice to have complex installation and even if one subsystem breaks down, you still can issue some control over it and you'd still be able to use it somehow.

    think the Stuxnet issue for instance.

    So if I'd be asked to work out some installation, I'd consider not only to rely on one brand of modules and one way of wiring.

    Add some local displays and options of interaction, even if they are not so comfortable.
     
Loading...