PIC programming for computer to PIC

Thread Starter

thisdabest

Joined Feb 16, 2014
4
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?
 

takao21203

Joined Apr 28, 2012
3,702
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
 

ErnieM

Joined Apr 24, 2011
8,377
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:

Brownout

Joined Jan 10, 2012
2,390
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.
 

THE_RB

Joined Feb 11, 2008
5,438
Alternatively, you can use a USB-serial adapter for your computer. I use the FTDI 4232 mini-module. ...

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.

Sparkfun has the modules for the FT232 for around 15 bucks.
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.
 

takao21203

Joined Apr 28, 2012
3,702
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.
 

shteii01

Joined Feb 19, 2010
4,644
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.
When girls buy accessories, they buy earrings, hand bags, shoes.

When boys buy accessories, they buy... stuff for their 3 dollar microcontrollers.
 

takao21203

Joined Apr 28, 2012
3,702
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.
 

Brownout

Joined Jan 10, 2012
2,390
takao21203 said:
what sense does it make to pay $15 for USB module for a $3 microcontroller with USB?
Because of this:

Use the USB stack.
Download from the website (Microchip).

you have to copy the project and then modify it.
I don't need to modify anything. And, to say "modify it" without any specifics wouldn't be enough information to get me started.

Also you can't communicate properly through a converter like via USB.
I can, no problem at all.
 

ErnieM

Joined Apr 24, 2011
8,377
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.
 

takao21203

Joined Apr 28, 2012
3,702
I can, no problem at all.
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).
 

Brownout

Joined Jan 10, 2012
2,390
Fullduplex with serial port is a bit of an effort, or isn't it
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:

takao21203

Joined Apr 28, 2012
3,702
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.
 

ErnieM

Joined Apr 24, 2011
8,377
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.
Here's his post:
PIC programming for computer to PIC
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?
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?
 

Brownout

Joined Jan 10, 2012
2,390
The USB/serial converters are offered on the market because people repeatedly buy them.

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.
 

Brownout

Joined Jan 10, 2012
2,390
I see a question concerning (and I quote) "getting my PIC(18f2550) to read its USB input."
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:

takao21203

Joined Apr 28, 2012
3,702
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).
 

Brownout

Joined Jan 10, 2012
2,390
Why not discuss the technology a bit.
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.
 

takao21203

Joined Apr 28, 2012
3,702
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.
 
Top