CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

PIC18LF2550 + USB connection

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
planmas



Joined: 18 Aug 2011
Posts: 8

View user's profile Send private message

PIC18LF2550 + USB connection
PostPosted: Wed Sep 14, 2011 4:12 am     Reply with quote

Hello

I'm going to develop a small project where I want to use a usb connection and a PIC 18LF2550. USB has a VBUS value of 5V and I want to power the PIC with 3.3V.

My question is: how do I make the connection between the USB socket and the PIC? I have read many things online including the datasheet of the PIC but I'm a little confused. I have reached to this result:

D+ and D- will be connected directly from the PIC to the USB socket as well the ground:


PIC side -------------- USB side
D+ ---------------------D+
D- ----------------------D-
GND --------------------GND

Also the Vusb on the PIC will be connected to the 3.3V that power the PIC, right?

My only doubt is the VBUS pin of the USB socket, because I have read several theories:

-Leave the pin floating, not connected to anything.
-Bring down the voltage with 2 diodes in series and then connect to the 3.3V

VBUS---|>---|>---3.3V

-Connect the VBUS in the entry to the input of the 3.3V regulator (did not mention this above - the 3.3V are obtained with a regulator).


Could anyone help because I don't know what to do with VBUS. I'm confused.

Tank you.

note: I do not want the pic power via USB, this is just for communication.

Planmas
ezflyr



Joined: 25 Oct 2010
Posts: 1019
Location: Tewksbury, MA

View user's profile Send private message

PostPosted: Wed Sep 14, 2011 7:03 am     Reply with quote

Hi,

If your project will not be powered from the USB bus, simply leave Vusb unconnected. Grounds (PC & PIC), of course, will be common. Your external power source, and +3.3V regulator, will supply power to your project.

Depending on your project, you may want to allow your PIC to sense the Vusb connection to determine when it's connected to the USB bus. In this case, connect Vusb to ground thru a resistive divider made up of two 100K resistors. The center tap of the divider is then connected to an I/O pin of the PIC. By reading the state of this pin, your PIC can easily determine whether it's connected to the USB bus or not.

John
Ttelmah



Joined: 11 Mar 2010
Posts: 19537

View user's profile Send private message

PostPosted: Wed Sep 14, 2011 9:36 am     Reply with quote

No.
Powering Vusb, has nothing to do with whether the project is powered off the USB bus.

Start by looking at the diagram. Figure 17-1.
VUSB, is both an output - from the 3.3V regulator, and potentially an input from a 3.3v source. You can operate in multiple ways:
1) Disable the Vregen bit in the fuses. Then the internal regulator is turned off. Connect a 3.3v input to the Vusb pin, and enable the internal pull-ups.
2) Disable Vregen as above, don't make a connection to Vusb at all, and use external pull-ups, _and an external transceiver_.
3) Disable Vregen as above, make the connection to Vusb to power just the transceiver, and use external pull-ups.

The Vusb pin _powers the internal transceiver_ unless 3.3v is on this pin, you have to use an external transceiver. So it is easiest if you have 3.3v feeding the chip to just connect this supply to this point. It also potentially powers the internal pull up resistors, so if you have made this connection, you may as well use these!. Option-1, much the easiest. However key thing is that Vregen, must be turned off in the fuses, otherwise the internal regulator tries to go 'on', and if you have some capacitance at the Vusb pin, though it won't be able to do anything, when the chip goes 'off', if Vusb stays high after The Vdd drops, you can get the regulator reverse biased, and potentially damage it...

So you can operate with no connection to Vusb, but if you do so, you have to use an external transceiver. Some people also 'get away' with this, without making the connection, because the regulator only drops a minimum of about 0.3v, and things do 'sort of' work with the 3v, that then appears on the Vusb pin.

Best Wishes
ezflyr



Joined: 25 Oct 2010
Posts: 1019
Location: Tewksbury, MA

View user's profile Send private message

PostPosted: Wed Sep 14, 2011 10:43 am     Reply with quote

Hi,

I used the term 'Vusb' indiscriminately. What I meant was pin #1 of the USB connector from the PC which will be at +5V. That pin can be left unconnected, or it can be used to signal your USB device that it's connected to the USB bus using the resistor divider as I described previously. This assumes that your project is "internally" powered.

Sorry for the confusion!

John
Ttelmah



Joined: 11 Mar 2010
Posts: 19537

View user's profile Send private message

PostPosted: Wed Sep 14, 2011 2:39 pm     Reply with quote

Yes. Makes sense.
Vusb, has a very specific meaning on the PIC, this is as you say 'distinct' from the USB power pin. USBVCC.
This also probably tends to explain the multiple connection advice the original poster has seen.

Best Wishes
planmas



Joined: 18 Aug 2011
Posts: 8

View user's profile Send private message

PostPosted: Thu Sep 15, 2011 8:12 am     Reply with quote

Hello,

Thank you for your reply.

I'm try to use the ex_usb_serial.c example with the resistive divider for the VBUS pin. Did not look with much attention for the code, but does it has the fuse to disable the internal regulator and enable the internal pull ups?


Tank you again.

Planmas
Ttelmah



Joined: 11 Mar 2010
Posts: 19537

View user's profile Send private message

PostPosted: Thu Sep 15, 2011 9:48 am     Reply with quote

No.
Has the fuse to enable the internal pull-ups, but also enables the internal regulator, since normally this is run on a unit at 5v. Change the VREGEN fuze to NOVREGEN. It is in ex_usb_common.h.
You will need to tweak several other fuse settings anyway, since the examples all assume clocking at 48MHz, and the LF chip at 3.3v, supports 18.7MHz max. I'd suggest running with an 8MHz crystal, HSPLL, and USBDIV2 to give the required 4MHz for the USB PLL, then CPUDIV4 (which in this configuration gives /6....), and clock=16MHZ.

Best Wishes
planmas



Joined: 18 Aug 2011
Posts: 8

View user's profile Send private message

PostPosted: Thu Sep 15, 2011 11:12 am     Reply with quote

It works nicely.

I'm able to send and receive strings trough the usb aka virtual COM on my pc.

Now its time for the tweaks.

Thank you for your help.

planmas
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group