View previous topic :: View next topic |
Author |
Message |
picprogrammer12345
Joined: 27 Jun 2013 Posts: 22
|
PIC18F25K22 clock problem |
Posted: Thu Mar 06, 2014 9:09 am |
|
|
I am using a PIC18F25K22 chip.
I am using a 20MHz external oscillator.
The fuse setup is as follows:
#fuses HSH,NOPLLEN,NOMCLR,NOWDT,NOLVP,PROTECT,DEBUG //Fuses configuration
#use delay(clock=20000000) //Clock Used is 20 MHz
The software works perfectly fine. But after sometime the code starts to work very slowly.
There is a delay of 3sec in the code before printing information on the LCD. It starts to become a delay of around 15 to 20 second but the software is still working but it is very very slow.
Can someone guide me to right direction on what is happening? |
|
![](templates/subSilver/images/spacer.gif) |
newguy
Joined: 24 Jun 2004 Posts: 1903
|
|
Posted: Thu Mar 06, 2014 9:33 am |
|
|
The HSH and HSM fuses are for crystals. For an external oscillator, you need either ECH (external clock, high power) or ECH_IO (same as ECH but your PIC's OSC2 line becomes available for program IO control). |
|
![](templates/subSilver/images/spacer.gif) |
temtronic
Joined: 01 Jul 2010 Posts: 9174 Location: Greensville,Ontario
|
|
Posted: Thu Mar 06, 2014 10:04 am |
|
|
One possible problem is that the fuse 'debug' is enabled. When enabled, it'll set fuses to what IT wants, not necessarily what YOU need.
Also if using MPLAB, be sure the compile is done in .release' mode not the factory default of 'debug'. Again, that can cause 'fun'.
I also set fuse 'PUT' to enable the 'Power Up Timer' just to help the PIC do 'housekeeping'..
hth
jay |
|
![](templates/subSilver/images/spacer.gif) |
picprogrammer12345
Joined: 27 Jun 2013 Posts: 22
|
|
Posted: Thu Mar 06, 2014 12:39 pm |
|
|
The clock I am using is ECS-200-20-46X
Datasheet
http://www.ecsxtal.com/store/pdf/HC-46X.pdf
I think EC would be for a clock that doesnt use both CLKIN pin and LCKOUT pin. But for this I am using both.
Also software is working at first sometimes works for hours. It randomly starts to delay the entire code.
I am using PIC compiler version 4.129 not MPLAB. |
|
![](templates/subSilver/images/spacer.gif) |
picprogrammer12345
Joined: 27 Jun 2013 Posts: 22
|
|
Posted: Thu Mar 06, 2014 12:44 pm |
|
|
On the datasheet of PIC18F25K22 for the oscillator and clock it say on page 35:
HS Oscillator mode offers a Medium Power (MP) and a
High Power (HP) option selectable by the FOSC<3:0>
bits. The MP selections are best suited for oscillator
frequencies between 4 MHz and 16 MHz. The HP
selection has the highest gain setting of the internal
inverter-amplifier and is best suited for frequencies
above 16 MHz. HS mode is best suited for resonators
that require a high drive setting.
FIGURE 2-6: QUARTZ CRYSTAL
OPERATION (LP, XT OR
HS MODE)
Note 1: A series resistor (RS) may be required for
quartz crystals with low drive level.
2: The value of RF varies with the Oscillator mode
selected (typically between 2 Mohm to 10 Mohm
If you want to look at the figure please download datasheet. Could it be cause of the resistance? Right now the clock is connected directly to the PIC chip with 22pF caps. |
|
![](templates/subSilver/images/spacer.gif) |
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Thu Mar 06, 2014 12:48 pm |
|
|
Quote: | I am using a 20MHz external oscillator. |
It's the terminology. In the electronics world, a "cystal" is what you
show in your data sheet. The package contains the crystal only.
An "oscillator" is a package which contains both a crystal and the
oscillator circuit inside it. It requires power and ground to run it.
http://www.ecsxtal.com/store/pdf/ecs-5725-5718r.pdf |
|
![](templates/subSilver/images/spacer.gif) |
picprogrammer12345
Joined: 27 Jun 2013 Posts: 22
|
|
Posted: Thu Mar 06, 2014 12:50 pm |
|
|
PCM programmer wrote: | Quote: | I am using a 20MHz external oscillator. |
It's the terminology. In the electronics world, a "cystal" is what you
show in your data sheet. The package contains the crystal only.
An "oscillator" is a package which contains both a crystal and the
oscillator circuit inside it. It requires power and ground to run it.
http://www.ecsxtal.com/store/pdf/ecs-5725-5718r.pdf |
Thanks for the clarification. I know my datasheet says for sure the clock is a quartz crystal. So i believe my fuses are set right. Could it be because the reistance is not there, the clock fails randomly? Or is it something else I am not seeing?
Thanks all for the replies |
|
![](templates/subSilver/images/spacer.gif) |
newguy
Joined: 24 Jun 2004 Posts: 1903
|
|
Posted: Thu Mar 06, 2014 12:50 pm |
|
|
For future reference, an oscillator is taken to mean a self contained unit that generates a high stability clock signal on its own. A crystal does not.
Your crystal is a series crystal. That's a problem. |
|
![](templates/subSilver/images/spacer.gif) |
Ttelmah
Joined: 11 Mar 2010 Posts: 19368
|
|
Posted: Thu Mar 06, 2014 12:51 pm |
|
|
What you have is a crystal, not an oscillator.
A crystal is a 'resonant' device.
A crystal makes an oscillator, when driven by a circuit that amplifies and inverts the signal coming from it's output, and feeds it back to the input.
Yes it uses HSH.
An oscillator is a module that contains the amplifier as well, and just gives a clock output.
You only have an 'oscillator', when connected to the amplifier in the PIC.
I don't think your problem is clock related.
Without seeing your code, it is difficult to have any idea. However something internal in the code, that is sitting waiting for something to happen, and an event (floating pin, or specific signal pattern for example), that changes the wait. |
|
![](templates/subSilver/images/spacer.gif) |
picprogrammer12345
Joined: 27 Jun 2013 Posts: 22
|
|
Posted: Thu Mar 06, 2014 12:56 pm |
|
|
Alll the program does is checks analog pin for high voltage. When the adc pin detects high voltage , the code enters a loop and stays there until the pin is high.
What happens is sometimes when i am constantly supplying high and low to the ADC pin, at certain point it gets stuck at high detected and gets stuck there even after i remove the high voltage line.
After around 10-20 seconds it says high not detected. Then if I give the high again, it says high detected after another 10-20 seconds or so.
How can it happen when its going through the same loop which worked for an hour? |
|
![](templates/subSilver/images/spacer.gif) |
Ttelmah
Joined: 11 Mar 2010 Posts: 19368
|
|
Posted: Thu Mar 06, 2014 12:58 pm |
|
|
What is driving the pin?.
What ensures the signal does not go outside the range Vss to Vdd?. |
|
![](templates/subSilver/images/spacer.gif) |
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
![](templates/subSilver/images/spacer.gif) |
newguy
Joined: 24 Jun 2004 Posts: 1903
|
|
Posted: Thu Mar 06, 2014 1:10 pm |
|
|
The datasheet he linked to mentioned it was a series crystal. That was as far as I dug.
As Ttelmah has said, he probably has a much different issue masquerading as a clock problem. |
|
![](templates/subSilver/images/spacer.gif) |
Ttelmah
Joined: 11 Mar 2010 Posts: 19368
|
|
Posted: Thu Mar 06, 2014 1:21 pm |
|
|
I too only looked at the sheet he linked to.
However it going wrong after a time, to me suggests something else is 'afoot'.
Best Wishes |
|
![](templates/subSilver/images/spacer.gif) |
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Thu Mar 06, 2014 1:22 pm |
|
|
Quote: | The software works perfectly fine. But after sometime the code starts to work very slowly. |
What's your CCS compiler version ? |
|
![](templates/subSilver/images/spacer.gif) |
|