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 support@ccsinfo.com

Need help to correctly setup USB on PIC18F67J50
Goto page 1, 2  Next
 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
Diego_Garcia
Guest







Need help to correctly setup USB on PIC18F67J50
PostPosted: Sat Mar 01, 2008 7:13 am     Reply with quote

Hi guys I've changed somethings in my project and now the pc detects de device but it doesnt reconize, i'm using the ex_usb_hid.c sample, and my project should work with the internal oscilator.

Here is the follow link to the schematic

(I've registered to the board but I dont receive my activation link so please remove the spaces from the link and change the dots)

www dot unitone dot com dot br / arquivos / esqusb01.jpg

I'm using the follow header on my program:

#include <18F67J50.h>
//The i dont know yet how to correct setup the PLL and the CPUDIV.
#fuses INTRC_PLL,NOWDT,NOPROTECT,NODEBUG,PLL2,NOCPUDIV, IESO
#use delay(clock=48000000)


//Tells the CCS PIC USB firmware to include HID handling code.
#DEFINE USB_HID_DEVICE TRUE
#define USB_EP1_TX_ENABLE USB_ENABLE_INTERRUPT //turn on EP1 for IN bulk/interrupt transfers
#define USB_EP1_TX_SIZE 64 //allocate 8 bytes in the hardware for transmission
#define USB_EP1_RX_ENABLE USB_ENABLE_INTERRUPT //turn on EP1 for OUT bulk/interrupt transfers
#define USB_EP1_RX_SIZE 64 //allocate 8 bytes in the hardware for reception

//Commented or uncomented doesnt seens to change anything
#define USB_CON_SENSE_PIN PIN_D7

#include <pic18_usb.h> //Microchip 18Fxx5x hardware layer for usb.c
#include <usb_desc_new.h> //USB Configuration and Device descriptors for this UBS device
#include <usb.c> //handles usb setup tokens and get descriptor reports



Thanks a lote guys, please just give me some tips, I'm new to the usb world.
Regards,
Diego Garcia
DiegoGarcia



Joined: 01 Mar 2008
Posts: 48

View user's profile Send private message

PostPosted: Sat Mar 01, 2008 7:47 am     Reply with quote

My Confirmation link arrived now so here is the correct link to the schematic

http://www.unitone.com.br/arquivos/esqusb01.jpg

Thanks a lote guys,
Regards,
Diego
Ttelmah
Guest







PostPosted: Sat Mar 01, 2008 7:51 am     Reply with quote

First big hint, is that you _cannot_ use the internal oscillator for USB. It's accuracy is at least a couple of orders of magnitude _below_ the level required for USB operation. This is why if you look at the chip's daa sheet, at the section regarding the oscillator, there is no routing from this internal oscillator, to the USB circuitry....

Best Wishes
DiegoGarcia



Joined: 01 Mar 2008
Posts: 48

View user's profile Send private message

PostPosted: Sat Mar 01, 2008 8:06 am     Reply with quote

O i didnt noted that.

I was lokin at the page 36 of the datasheet

http://ww1.microchip.com/downloads/en/DeviceDoc/39775b.pdf

and I've saw an connection from the internal osc to the FOSC2 so I was wondering that it could use the Internal osc to acomplish the task.

Is it my idea rigth ? (I think not but just to confirm) .

So should I add an external osc ? and if yes what value do you recomend ?

Thanks a lote for the great help Ttelmah
Regards,
Diego M. Garcia
DiegoGarcia



Joined: 01 Mar 2008
Posts: 48

View user's profile Send private message

PostPosted: Sat Mar 01, 2008 10:00 am     Reply with quote

I would know if it is necessary to connect the ENVREG pin or if it could be with no connection. I 've readed the especification about it but I've not understand for what purpose it is used. Can you guys explain it to me if possible ?

Very much Thanks and kindly regards,
Diego Garcia
Ttelmah
Guest







PostPosted: Sat Mar 01, 2008 10:06 am     Reply with quote

Er.
FOSC2, is an internal _configuration bit_, not something you can 'connect' to. The diagram, shows this bit _controlling_ what the internal oscillator can connect to. Assuming you are looking at Fig 2-1, look at the very last line in the 'notes'. This is the 'critical' line for USB. You can feed the internal oscillator a whole raft of ways to get different frequency options, but this is the one that stops you actually 'using' the USB.
Personally, I'd suggest using an 8MHz crystal. This is simply because the system can work off any crystal from 4Mhz, to 24Mhz (and higher at 5v, or with an external oscillator), and use USB, from any one that is integer divisible by 4. 4MHz itself, is slightly more 'fussy' to get working than 8MHz, and this is then the lowest frequency crystal, to offer most options.
If you then select PLLDIV2, you get the 4MHz master clock to fed the USB PLL.
You can run the CPU, off 48, 24, 16, or 8MHz, by selecting PLLEN, and CPUDIV1, 2, 3 or 6.

Best Wishes
DiegoGarcia



Joined: 01 Mar 2008
Posts: 48

View user's profile Send private message

PostPosted: Sat Mar 01, 2008 10:55 am     Reply with quote

Thanks a lote Ttelmah I doesnt seen this note, thanks a lote you rely light my mind ;)

Kindly Regards,
Diego Garcia
DiegoGarcia



Joined: 01 Mar 2008
Posts: 48

View user's profile Send private message

PostPosted: Tue Mar 04, 2008 4:40 pm     Reply with quote

Hi Ttelmah sorry to bother again, but I'm going nuts :/.

I've connected an 20 Mhz Xtal in my project but It still doesnt work ... but now the problem changes, when I connect the usb on my pc it stucks so when I remove it get back to work ...

I'm using the follow #fuses and config to setup the pic mcu:

#define __USB_PIC_PERIF__ 1

#include <18F67J50.h>
#fuses HS, NOWDT, NOPROTECT, NODEBUG, PLL5, CPUDIV2, IESO
#use delay(clock=24000000)


//Tells the CCS PIC USB firmware to include HID handling code.
#DEFINE USB_HID_DEVICE TRUE
#define USB_EP1_TX_ENABLE USB_ENABLE_INTERRUPT //turn on EP1 for IN bulk/interrupt transfers
#define USB_EP1_TX_SIZE 64 //allocate 64 bytes in the hardware for transmission
#define USB_EP1_RX_ENABLE USB_ENABLE_INTERRUPT //turn on EP1 for OUT bulk/interrupt transfers
#define USB_EP1_RX_SIZE 64 //allocate 64 bytes in the hardware for reception

#define USB_CON_SENSE_PIN PIN_D7

#include <pic18_usb.h> //Microchip 18Fxx5x hardware layer for usb.c
#include <usb_desc_new.h> //USB Configuration and Device descriptors for this UBS device
#include <usb.c> //handles usb setup tokens and get descriptor reports

Thanks a lote for the big hand you are givin to me ;) and once again sorry to bother you :/

Regards,
Diego Garcia
DiegoGarcia



Joined: 01 Mar 2008
Posts: 48

View user's profile Send private message

PostPosted: Wed Mar 05, 2008 9:17 am     Reply with quote

Ok after searching and reading the datasheet I just think it could be that ENVREG pin that is an internal regulator.

Its documented in the page 360 of datasheet so the think I should change my hardware to the first one of the fig 25-2...

I dont know more what to do ...

Maybe some of you guys could give me an light.

Thanks for the great people that uses this forum ;)

Regards,
Diego Garcia
DiegoGarcia



Joined: 01 Mar 2008
Posts: 48

View user's profile Send private message

PostPosted: Wed Mar 05, 2008 10:42 am     Reply with quote

Ok I've done the changes like the datasheet sayed but I still get the Unknow Device message ...

Dont know what to do any more ....

Here comes the full code of my project

#define __USB_PIC_PERIF__ 1

#include <18F67J50.h>

#fuses HS
#fuses PLL5
#fuses CPUDIV2
#fuses NOWDT
#fuses NOIESO
#fuses NOXINST
#fuses NOSTVREN
#fuses NOFCMEN
#fuses NOPROTECT
#fuses NODEBUG

#use delay(clock=24000000)


//Tells the CCS PIC USB firmware to include HID handling code.
#DEFINE USB_HID_DEVICE TRUE

#define USB_EP1_TX_ENABLE USB_ENABLE_INTERRUPT //turn on EP1 for IN bulk/interrupt transfers
#define USB_EP1_TX_SIZE 8 //allocate 8 bytes in the hardware for transmission
#define USB_EP1_RX_ENABLE USB_ENABLE_INTERRUPT //turn on EP1 for OUT bulk/interrupt transfers
#define USB_EP1_RX_SIZE 8 //allocate 8 bytes in the hardware for reception

#define USB_CON_SENSE_PIN PIN_D7

#include <pic18_usb.h> //Microchip 18Fxx5x hardware layer for usb.c
#include <usb_desc_hid.h> //USB Configuration and Device descriptors for this UBS device
#include <usb.c> //handles usb setup tokens and get descriptor reports


#define LED1 PIN_F2
#define LED_ON output_high
#define LED_OFF output_low

void main()
{
int8 out_data[20];
int8 in_data[2];
int8 send_timer=0;

LED_ON(LED1);
delay_ms(5000);

usb_init_cs();

while (TRUE)
{
usb_task();

if (usb_enumerated()) {
if (!send_timer) {
send_timer=250;
out_data[0]=0x21;
out_data[1]=0x22;
usb_put_packet(1, out_data, 2, USB_DTS_TOGGLE);
}
if (usb_kbhit(1)) {
usb_get_packet(1, in_data, 2);
}
send_timer--;
delay_ms(1);
}
}
}


Any tips ???

Thanks a lote,
Regards,
Diego Garcia
DiegoGarcia



Joined: 01 Mar 2008
Posts: 48

View user's profile Send private message

PostPosted: Fri Mar 07, 2008 7:11 am     Reply with quote

Ok after setup the Envreg my pc stop to stuck when using HS or H4_SW but it stills doesnt reconize my device ... ('Unknow Device')

Maybe one of you guys could give me a hand if possible :/

I dont know more what to do, I'm using the CCS C 4.057.

I've readed the datasheet lots of times, but dont now more what to do..
I'm using internal pullups to select speed, should I setup something from program to use it ? becuse I dont se anything related to it in the sample of hid that comes with ccs samples.

Thanks a lote guys,
Regards,
Diego Garcia
Ttelmah
Guest







PostPosted: Fri Mar 07, 2008 8:36 am     Reply with quote

What crystal have you got fitted (20MHz?).
What is developing Vusb?.

Best Wishes
DiegoGarcia



Joined: 01 Mar 2008
Posts: 48

View user's profile Send private message

PostPosted: Fri Mar 07, 2008 9:06 am     Reply with quote

Hi Ttelmah,
Yes I'm using the 20Mhz, and th Vusb is geting the source power from a external power supply 3.3v.

Here is the link to the updated schematic: http://www.unitone.com.br/arquivos/esqusb02.jpg

Thanks for the helping me !

Regards,
Diego Garcia
Ttelmah
Guest







PostPosted: Fri Mar 07, 2008 3:25 pm     Reply with quote

You are aware that you must have the line:
setup_oscillator(OSC_PLL_ON);
at the start of the 'main', before the PLL will turn on?....

Best Wishes
DiegoGarcia



Joined: 01 Mar 2008
Posts: 48

View user's profile Send private message

PostPosted: Fri Mar 07, 2008 3:40 pm     Reply with quote

Hi Ttelma
There is no OSC_PLL_ON on the header of this device.

So what should I done ?

The defines available for setup_oscillator are:

// Constants used in setup_oscillator() are:
#define OSC_31KHZ 0
#define OSC_125KHZ 0x10
#define OSC_250KHZ 0x20
#define OSC_500KHZ 0x30
#define OSC_1MHZ 0x40
#define OSC_2MHZ 0x50
#define OSC_4MHZ 0x60
#define OSC_8MHZ 0x70
// The following may be OR'ed in with the above using |
#define OSC_TIMER1 1
#define OSC_INTRC 2
#define OSC_NORMAL 0
// The following may be OR'ed in with the above using |
#define OSC_IDLE_MODE 0x80
// A second optional parameter may be used with this part to fine
// tune the speed (signed int,0-63)
// Result may be (ignore all other bits)
#define OSC_STATE_STABLE 4
#define OSC_STATE_EXT_RUNNING 8

Thanks !

Regards,
Diego Garcia
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Goto page 1, 2  Next
Page 1 of 2

 
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