View previous topic :: View next topic |
Author |
Message |
respected
Joined: 16 May 2006 Posts: 95
|
18F26J50 doesn't work usb! |
Posted: Thu Mar 22, 2012 3:57 pm |
|
|
Code: |
#include <18F26J50.h>
#fuses INTRC_PLL,PLL2,CPUDIV6
#use delay(clock=8M)
|
Where is mistake?
Led blinking is working but usb doesn't work. I want to execute the internal oscillator. |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19553
|
|
Posted: Thu Mar 22, 2012 4:23 pm |
|
|
Study section 3.4.
The internal oscillator, _only_ supports the USB in low speed mode, not full speed mode. CPUDIV1, is the only supported divider. The CPU, then runs at 24MHz. You also need to make the changes in the USB code you are using to select low speed mode. Table 3-5, the second entry from the bottom, line in black, is the only one that is supported. Paragraph 3.3.1, gives this.
Best Wishes |
|
|
respected
Joined: 16 May 2006 Posts: 95
|
|
Posted: Thu Mar 22, 2012 5:15 pm |
|
|
Code: | #include <18F26J50.h>
#fuses INTRC_PLL,PLL2,CPUDIV2
#use delay(clock=24M)
|
I changed but it doesn't work yet. |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19553
|
|
Posted: Fri Mar 23, 2012 4:12 am |
|
|
Have you changed the USB code?.
You need:
#define USB_USE_FULL_SPEED FALSE
before you load the USB libraries.
Also have you got 3.3v fed into Vusb?. Required on these chips (no internal regulator).
Best Wishes |
|
|
respected
Joined: 16 May 2006 Posts: 95
|
|
Posted: Fri Mar 23, 2012 6:03 am |
|
|
Code: |
#include <18F26J50.h>
#fuses INTRC_PLL,PLL2,CPUDIV2
#use delay(clock=24M)
#define USB_USE_FULL_SPEED FALSE
#define USB_CONFIG_HID_TX_SIZE 2
#define USB_CONFIG_HID_RX_SIZE 2
#include <pic18_usb.h>
#include <usb_j50_hid.h>
#include <usb.c>
void usb_debug_task(void)
{
int8 new_connected;
int8 new_enumerated;
new_connected=usb_attached();
new_enumerated=usb_enumerated();
if (new_enumerated)
output_high(PIN_B0);
else
output_low(PIN_B0);
}
void main(void)
{
int8 out_data[USB_CONFIG_HID_TX_SIZE];
int8 in_data[USB_CONFIG_HID_RX_SIZE];
usb_init_cs();
while (TRUE)
{
usb_task();
usb_debug_task();
if (usb_enumerated())
{
if (usb_kbhit(1))
{
usb_get_packet(1, in_data, 1);
switch(in_data[0])
{
case 1:output_high(PIN_B1);
break;
case 2:output_low(PIN_B1);
break;
case 5: out_data[0]=77; out_data[1]=78;
usb_put_packet(1,out_data,1,USB_DTS_TOGGLE);
break;
}
}
}
}
} |
This is full code. It worked with 18F4550. Same code only changed fuses settigs. I don't understand. |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19553
|
|
Posted: Fri Mar 23, 2012 8:42 am |
|
|
Obvious thing is hardware.
You do realise that the 26J50, is a low voltage device. Needs a supply between 2.35, and 3.6v fed to the chip, and Vusb, needs a supply between the Vdd level, and 3.6v max - normally simplest setup, is 3.3v for the whole chip. Also you are using init_cs, which implies you must have the sense connection setup to detect when USB is connected.
Have you 'stepped back', and verified the chip is actually running, and can toggle a pin at the expected speed (will show any oscillator setup errors)?. This should always be the starting point.
I'd also add NOXINST (should be the default, but worth being sure). Also, on these chips the PLL, is software controllable, so add:
setup_oscillator(OSC_PLL_ON);
as the first line of your main code.
Best Wishes |
|
|
respected
Joined: 16 May 2006 Posts: 95
|
|
Posted: Fri Mar 23, 2012 11:34 am |
|
|
Circuit has 1,4v diode (BAS31). Therefore 5V-1,4V= 3,6V power supply.
Also this circuit was work. It doesn't new circuit. I try on mplabx and it work.
I guess settings problem. Thanks Ttelmah. |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19553
|
|
Posted: Fri Mar 23, 2012 4:08 pm |
|
|
Seriously, check the stability, and voltage on the supply. 3.6v, is _pushing it_ for USB. It is the _absolute maximum voltage allowed by the bus_, for the Vusb pin. If you are even 0.05v above this, USB is not going to work. You really need to be aiming for 3.3v. It is also the absolute maximum for the chip. You should be aiming for a supply voltage below this. A zener dropper is not really a safe way to do this, since if supply current falls, so will the drop.
Bit puzzled, since the BAS31, is a double avalanche diode, not a zener, and as such is absolutely unsuitable as a dropper. The Vf of each diode potentially will be about 0.7v, if you are drawing 50mA or more from it, but at typical PIC operating current, can easily be closer to 0.6v....
Use a proper regulator.
Remember also good decoupling is needed at the Vusb pin, and the Vdd pin.
Best Wishes |
|
|
respected
Joined: 16 May 2006 Posts: 95
|
|
|
respected
Joined: 16 May 2006 Posts: 95
|
|
Posted: Fri Mar 23, 2012 4:52 pm |
|
|
Code: |
#include <18F26J50.h>
#fuses INTRC_PLL,PLL2,CPUDIV2
#use delay(clock=6M)
// or clock=8M
#define USB_CONFIG_HID_TX_SIZE 2
#define USB_CONFIG_HID_RX_SIZE 2
#include <pic18_usb.h>
#include <usb_j50_hid.h>
#include <usb.c>
void usb_debug_task(void)
{
int8 new_connected;
int8 new_enumerated;
new_connected=usb_attached();
new_enumerated=usb_enumerated();
if (new_enumerated)
output_high(PIN_B0);
else
output_low(PIN_B0);
}
void main(void)
{
int8 out_data[USB_CONFIG_HID_TX_SIZE];
int8 in_data[USB_CONFIG_HID_RX_SIZE];
setup_oscillator(OSC_PLL_ON);
usb_init_cs();
while (TRUE)
{
usb_task();
usb_debug_task();
if (usb_enumerated())
{
if (usb_kbhit(1))
{
usb_get_packet(1, in_data, 1);
switch(in_data[0])
{
case 1:output_high(PIN_B1);
break;
case 2:output_low(PIN_B1);
break;
case 5: out_data[0]=77; out_data[1]=78;
usb_put_packet(1,out_data,2,USB_DTS_TOGGLE);
break;
}
}
}
}
} |
It is working now. |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19553
|
|
Posted: Sat Mar 24, 2012 3:39 pm |
|
|
With the same fuses, and clock line, do a simple 'flash an LED to 10 seconds' routine (no USB). What speed does the LED flash....
It won't be right.
Best Wishes |
|
|
respected
Joined: 16 May 2006 Posts: 95
|
|
Posted: Sat Mar 24, 2012 3:49 pm |
|
|
ttelmah;
can you write basic routine? i try only USB working. maybe it doesn't led flash |
|
|
|