|
|
View previous topic :: View next topic |
Author |
Message |
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Fri Jan 20, 2006 9:34 pm |
|
|
Start with a very simple program, just to get the RS-232 serial port
working. Example:
Code: | #include <18F4550.H>
#fuses XT, NOWDT, NOPROTECT, BROWNOUT, PUT, NOLVP
#use delay(clock=4000000)
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7, ERRORS)
void main()
{
printf("Hello World\n\r");
while(1);
} |
|
|
|
dbrown
Joined: 24 Jul 2004 Posts: 20
|
18F4550 |
Posted: Fri Jan 20, 2006 10:05 pm |
|
|
I tried the simple program as listed above, and the serial interface works fine. If I want to use the usb with a 4 mhz crystal then I need to set pll/1 and cpudiv0.
Thanks for your help PCM.
Dave |
|
|
arys
Joined: 09 Mar 2007 Posts: 31
|
|
Posted: Fri Jan 11, 2008 2:20 am |
|
|
sorry for interrupt but where can I see the "hello world" sentence? |
|
|
Ttelmah Guest
|
|
Posted: Fri Jan 11, 2008 3:56 am |
|
|
Going back to the first question, a 48MHz crystal, is not legitimate. You can use a 48Mhz external _oscillator_, but not a crystal. The internal oscillator is not specified to run above 25MHz.
Now, the 4MHz crystal, may also give problems. Though 'legitimate', on these PICs, I have seen problems with them. For some reason, the internal USB PLL, can behave 'oddly', with quite a few crystals. The chip works, and is clocking at the right rate, but the USB becomes unreliable.
So, I'd say, use a multiple of 4MHz. The 20MHz crystal (or an 8MHz, 12MHz etc.), would be my choice.
For the 20MHz crystal, you have the choice of running the processor, at 48MHz, 24MHz, 20MHz, 16MHz, 12MHz, 10MHz, 6.66MHz, or 5MHz. The normal fuse settings are:
Code: |
HSPLL PLL5 CPUDIV1 USBDIV - 48MHz CPU
HSPLL PLL5 CPUDIV2 USBDIV - 24MHz CPU
HS PLL5 CPUDIV1 USBDIV - 20MHz CPU
HSPLL PLL5 CPUDIV3 USBDIV - 16MHz CPU
HSPLL PLL5 CPUDIV4 USBDIV - 12MHz CPU
HS PLL5 CPUDIV2 USBDIV - 10MHz CPU
HS PLL5 CPUDIV3 USBDIV - 6.66MHz CPU
HS PLL5 CPUDIV4 USBDIV - 5MHz CPU
|
The 'key' is that the USB PLL, is _always_ used, provided the 'USBDIV' fuse is selected. If 'HS' is selected, the CPU clock comes from the crystal, while if 'HSPLL' is selected, the CPU clock comes from the USB PLL. PLL5, says divide the master clock by 5, to get the required 4MHz to feed the USB PLL. Then the 'CPUDIV' numbers, give the division used from the clock source (either the external crystal, or the USBPLL/2), to feed the CPU.
If the 'USBDIV' fuse is not selected, the USB clock comes directly from the external clock.
Start by getting the oscillators 'right'. Setup whichever one you want, set the 'clock' statement to match the CPU frequency, and run a simple 'output one pin high for one second, then low for one second' type program, to verify that the CPU _is_ running at the selected frequency. Once this is running, substitute these clock fuse settings, and clock statement, into the UB example, and try this.
As another 'caveat', add more smoothing to the regulator pin, than is specified in the data sheet. I have had problems with some batches of these chips not giving reliable operation. My standard setup now, is a 1uF electrolytic capacitor, in parallel with a 0.1uF ceramic capacitor on the regulator pin, and this (seems) to be reliable.
Yes, VREGEN, enables the internal regulator.
Best Wishes |
|
|
Ttelmah Guest
|
|
Posted: Fri Jan 11, 2008 3:56 am |
|
|
Going back to the first question, a 48MHz crystal, is not legitimate. You can use a 48Mhz external _oscillator_, but not a crystal. The internal oscillator is not specified to run above 25MHz.
Now, the 4MHz crystal, may also give problems. Though 'legitimate', on these PICs, I have seen problems with them. For some reason, the internal USB PLL, can behave 'oddly', with quite a few crystals. The chip works, and is clocking at the right rate, but the USB becomes unreliable.
So, I'd say, use a multiple of 4MHz. The 20MHz crystal (or an 8MHz, 12MHz etc.), would be my choice.
For the 20MHz crystal, you have the choice of running the processor, at 48MHz, 24MHz, 20MHz, 16MHz, 12MHz, 10MHz, 6.66MHz, or 5MHz. The normal fuse settings are:
Code: |
HSPLL PLL5 CPUDIV1 USBDIV - 48MHz CPU
HSPLL PLL5 CPUDIV2 USBDIV - 24MHz CPU
HS PLL5 CPUDIV1 USBDIV - 20MHz CPU
HSPLL PLL5 CPUDIV3 USBDIV - 16MHz CPU
HSPLL PLL5 CPUDIV4 USBDIV - 12MHz CPU
HS PLL5 CPUDIV2 USBDIV - 10MHz CPU
HS PLL5 CPUDIV3 USBDIV - 6.66MHz CPU
HS PLL5 CPUDIV4 USBDIV - 5MHz CPU
|
The 'key' is that the USB PLL, is _always_ used, provided the 'USBDIV' fuse is selected. If 'HS' is selected, the CPU clock comes from the crystal, while if 'HSPLL' is selected, the CPU clock comes from the USB PLL. PLL5, says divide the master clock by 5, to get the required 4MHz to feed the USB PLL. Then the 'CPUDIV' numbers, give the division used from the clock source (either the external crystal, or the USBPLL/2), to feed the CPU.
If the 'USBDIV' fuse is not selected, the USB clock comes directly from the external clock.
Start by getting the oscillators 'right'. Setup whichever one you want, set the 'clock' statement to match the CPU frequency, and run a simple 'output one pin high for one second, then low for one second' type program, to verify that the CPU _is_ running at the selected frequency. Once this is running, substitute these clock fuse settings, and clock statement, into the UB example, and try this.
As another 'caveat', add more smoothing to the regulator pin, than is specified in the data sheet. I have had problems with some batches of these chips not giving reliable operation. My standard setup now, is a 1uF electrolytic capacitor, in parallel with a 0.1uF ceramic capacitor on the regulator pin, and this (seems) to be reliable.
Yes, VREGEN, enables the internal regulator.
Best Wishes |
|
|
|
|
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
|