View previous topic :: View next topic |
Author |
Message |
Diego_Garcia Guest
|
Need help to correctly setup USB on PIC18F67J50 |
Posted: Sat Mar 01, 2008 7:13 am |
|
|
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
|
|
|
Ttelmah Guest
|
|
Posted: Sat Mar 01, 2008 7:51 am |
|
|
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
|
|
Posted: Sat Mar 01, 2008 8:06 am |
|
|
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
|
|
Posted: Sat Mar 01, 2008 10:00 am |
|
|
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
|
|
Posted: Sat Mar 01, 2008 10:06 am |
|
|
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
|
|
Posted: Sat Mar 01, 2008 10:55 am |
|
|
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
|
|
Posted: Tue Mar 04, 2008 4:40 pm |
|
|
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
|
|
Posted: Wed Mar 05, 2008 9:17 am |
|
|
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
|
|
Posted: Wed Mar 05, 2008 10:42 am |
|
|
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
|
|
Posted: Fri Mar 07, 2008 7:11 am |
|
|
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
|
|
Posted: Fri Mar 07, 2008 8:36 am |
|
|
What crystal have you got fitted (20MHz?).
What is developing Vusb?.
Best Wishes |
|
|
DiegoGarcia
Joined: 01 Mar 2008 Posts: 48
|
|
Posted: Fri Mar 07, 2008 9:06 am |
|
|
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
|
|
Posted: Fri Mar 07, 2008 3:25 pm |
|
|
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
|
|
Posted: Fri Mar 07, 2008 3:40 pm |
|
|
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 |
|
|
|