Hello,
I am trying to learn and also correctly set up the configuration settings for my project. I am using an 18LF2550 since I have a supply of them, but my project is not going to use the USB capabilities of the PIC.
I have attached a one second LED flashing program (to test configuration settings for my main program) which works dead on for the delays, but to get the correct timing, I had to set the clock speed for only 1MHz despite using a 20MHz crystal.
In looking at the 18LF2550 data sheet at page 287, it seems to indicate that the system clock can run at the 96MHz PLL divided by 2 to derive the system clock, which would be 48 MHz. This is how i configured the project settings in the attached file, but I have to use 1MHz for the clock speed to get the LED to flash correctly.
I have read extensively in the forums and tried to interpret the data sheet, but I still have not been able to figure out why I have to set the clock speed to only 1MHz.
Am I missing something or do I have an incorrect setting?
Thanks!
Clock Speed of 1MHz?
-
- Posts: 17
- http://meble-kuchenne.info.pl
- Joined: Tue Jul 05, 2022 8:54 am
- Has thanked: 9 times
- Been thanked: 3 times
Clock Speed of 1MHz?
- Attachments
-
- One Second LED Flasher.fcfx
- (7.87 KiB) Downloaded 452 times
Last edited by Tortilla on Mon Aug 22, 2022 8:56 am, edited 4 times in total.
Re: Clock Speed of 1MHz?
Hi, if you need just 1 second generator, I can recommend use second MCU with crystal 32768 Hz and connect output one second to your master MCU. 6 or 8 pin low cost like pic12f683 or other and then use timer in interapt. If this helps I hope.
-
- Valued Contributor
- Posts: 1528
- Joined: Thu Dec 03, 2020 10:57 am
- Has thanked: 353 times
- Been thanked: 549 times
Re: Clock Speed of 1MHz?
Hi
That chip has a more complex oscillator structure compared to other PICs to run the USB, so it would be quite easy to overlook something (and I probably have). The chip needs an external oscillator / crystal to run the USB but if you are not intending to use it you might want to consider using the internal oscillator.
In your config you have the clock (Oscillator) set at HS: HS+PLL,USB-HS which will be looking for an external clock. Do you have one connected and if so what frequency is it running at? With the PLL enabled it should only be a 4MHz crystal (I think). Clock Speed should match your Oscillator setup.
With HS: USB-HS selected I think you can use any crystal from 4MHz to 48MHz (must be a multiple of 4MHz).
It might be easier to use the Internal Oscillator (note it still looks for an external oscillator for USB use). Set the Oscillator to any of the INTOSC options. When using an Internal Oscillator you also need to use a "C-Block" at the beginning of your Main chart to set the frequency. You can use the IntOsc Helper to assist. Open it and choose from the available frequencies (you have chosen 4000000). It will then show you what code to use in the C-Block (OSCCON = 0x60;). Copy this and paste it into a C-Block. Remember to set your clock speed to 4MHz too (or whatever you have chosen).
Hope this helps, and I hope I've not overlooked anything either
Regards
That chip has a more complex oscillator structure compared to other PICs to run the USB, so it would be quite easy to overlook something (and I probably have). The chip needs an external oscillator / crystal to run the USB but if you are not intending to use it you might want to consider using the internal oscillator.
In your config you have the clock (Oscillator) set at HS: HS+PLL,USB-HS which will be looking for an external clock. Do you have one connected and if so what frequency is it running at? With the PLL enabled it should only be a 4MHz crystal (I think). Clock Speed should match your Oscillator setup.
With HS: USB-HS selected I think you can use any crystal from 4MHz to 48MHz (must be a multiple of 4MHz).
It might be easier to use the Internal Oscillator (note it still looks for an external oscillator for USB use). Set the Oscillator to any of the INTOSC options. When using an Internal Oscillator you also need to use a "C-Block" at the beginning of your Main chart to set the frequency. You can use the IntOsc Helper to assist. Open it and choose from the available frequencies (you have chosen 4000000). It will then show you what code to use in the C-Block (OSCCON = 0x60;). Copy this and paste it into a C-Block. Remember to set your clock speed to 4MHz too (or whatever you have chosen).
Hope this helps, and I hope I've not overlooked anything either

Regards
- Attachments
-
- One Second LED Flasher_IntOsc.fcfx
- (8.07 KiB) Downloaded 432 times
Re: Clock Speed of 1MHz?
Hi,chipfryer27 wrote: ↑Mon Aug 22, 2022 9:06 amHi
That chip has a more complex oscillator structure compared to other PICs to run the USB, so it would be quite easy to overlook something (and I probably have). The chip needs an external oscillator / crystal to run the USB but if you are not intending to use it you might want to consider using the internal oscillator.
In your config you have the clock (Oscillator) set at HS: HS+PLL,USB-HS which will be looking for an external clock. Do you have one connected and if so what frequency is it running at? With the PLL enabled it should only be a 4MHz crystal (I think). Clock Speed should match your Oscillator setup.
With HS: USB-HS selected I think you can use any crystal from 4MHz to 48MHz (must be a multiple of 4MHz).
It might be easier to use the Internal Oscillator (note it still looks for an external oscillator for USB use). Set the Oscillator to any of the INTOSC options. When using an Internal Oscillator you also need to use a "C-Block" at the beginning of your Main chart to set the frequency. You can use the IntOsc Helper to assist. Open it and choose from the available frequencies (you have chosen 4000000). It will then show you what code to use in the C-Block (OSCCON = 0x60;). Copy this and paste it into a C-Block. Remember to set your clock speed to 4MHz too (or whatever you have chosen).
Hope this helps, and I hope I've not overlooked anything either
Regards
Thanks for the reply. Much appreciated.
I am using a 20MHz crystal with appropriate caps. I understand how to use the internal oscillator by setting OSCCON at the beginning of the program, this exercise is more for me to determine how to set up an external crystal with this PIC (18LF2550 without using the USB function) and it would be nice to use it with the program I am developing.
I never really used the one second flasher test before, but after reading a lot of the recommendations to use it, I finally did and now I can't seem to get it to work correctly for the 18LF2550 with any other clock setting except 1MHz when I use the 20 MHz external crystal.
Hope that makes sense.
-
- Valued Contributor
- Posts: 1528
- Joined: Thu Dec 03, 2020 10:57 am
- Has thanked: 353 times
- Been thanked: 549 times
Re: Clock Speed of 1MHz?
Hi
Not very familiar with the chip but my thoughts are with the Oscillator set at HS:HS+PLL and OSC Select set at divide by 5, then your 20MHx crystal is fed to the 96MHz PLL at the correct 4MHz, giving a 96MHz output. All would seem to be good so far.
This then feeds into the Postscaller which you have set as OSC/1 or PLL/2 which gives a clock of 48MHz (96/2) which seems good.
Clock Speed sets the delays used by Flowcode and must match actual clock speed, so try it using 48MHz.
If you change Oscillator to HS:USB-HS then your clock would now be 20MHz (using same settings) so Clock Speed should be 20MHz
I would disable Internal / external changeover until I know I have external working.
With the above settings, do you have a scope or logic analyser that can confirm what is happening on the Outputs?
Regards
Not very familiar with the chip but my thoughts are with the Oscillator set at HS:HS+PLL and OSC Select set at divide by 5, then your 20MHx crystal is fed to the 96MHz PLL at the correct 4MHz, giving a 96MHz output. All would seem to be good so far.
This then feeds into the Postscaller which you have set as OSC/1 or PLL/2 which gives a clock of 48MHz (96/2) which seems good.
Clock Speed sets the delays used by Flowcode and must match actual clock speed, so try it using 48MHz.
If you change Oscillator to HS:USB-HS then your clock would now be 20MHz (using same settings) so Clock Speed should be 20MHz
I would disable Internal / external changeover until I know I have external working.
With the above settings, do you have a scope or logic analyser that can confirm what is happening on the Outputs?
Regards
Re: Clock Speed of 1MHz?
Hi,
Yes, I tried all of the various clock speeds, 48 Mhz, 20 MHz, 10 MHz, etc. but the delays ran way too long. Also, I disabled the internal external changeover. It was only with 1 Mhz that the flasher worked correctly. I know that sounds odd, but that's what I found.
I will take a look at it with my scope and see what it is generating.
Thanks,
Dan
Yes, I tried all of the various clock speeds, 48 Mhz, 20 MHz, 10 MHz, etc. but the delays ran way too long. Also, I disabled the internal external changeover. It was only with 1 Mhz that the flasher worked correctly. I know that sounds odd, but that's what I found.
I will take a look at it with my scope and see what it is generating.
Thanks,
Dan
-
- Valued Contributor
- Posts: 1528
- Joined: Thu Dec 03, 2020 10:57 am
- Has thanked: 353 times
- Been thanked: 549 times
Re: Clock Speed of 1MHz?
Hi
As the default Internal Oscillator speed is 1MHz I think that for whatever reason the chip is not using the correct source and is therefore using the internal.
Time to get the manual out
As the default Internal Oscillator speed is 1MHz I think that for whatever reason the chip is not using the correct source and is therefore using the internal.
Time to get the manual out
