View previous topic :: View next topic |
Author |
Message |
hemnath
Joined: 03 Oct 2012 Posts: 242 Location: chennai
|
blink led program in pic18F8722 |
Posted: Fri Dec 12, 2014 9:00 am |
|
|
I have a very strange problem.
I have bought a 18F8722 development board. It has 18F8722, 20Mhz crystal, MAX232, RS232, I/O pins and 5V regulator.
Blink led code:
Code: | #include "18F8722.h"
#fuses HS, NOWDT, NOLVP
#use delay(clock=20000000)
void main()
{
while(1)
{
output_high(PIN_D0);
delay_ms(500);
output_low(PIN_D0);
delay_ms(500);
}
} |
LED should blink for every 500ms. But the led is ON for 10 sec and OFF for 10 sec approximately.
What could be the problem?
Please help. |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19536
|
|
Posted: Fri Dec 12, 2014 9:13 am |
|
|
For some reason the crystal is not running.
This chip (in common with a lot of later ones), has a thing called 'fail safe clock monitor'. If the selected primary oscillator isn't running, it drops 'back' to a default internal oscillator. 1MHz.
Could be a faulty crystal, bad connection, etc. etc.. |
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9241 Location: Greensville,Ontario
|
|
Posted: Fri Dec 12, 2014 9:19 am |
|
|
Another potential problem is if your program was compile in 'debug' mode and not 'release' mode.
For the PIC to run correctly you need to compile in 'release' mode.
and... be sure ICD=true is NOT used ! as it'll setup the PIC differently than you want as well....
Jay |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19536
|
|
Posted: Fri Dec 12, 2014 10:03 am |
|
|
and (of course), could then be compiling through MPLAB, which defaults to debug mode..... |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Fri Dec 12, 2014 11:27 am |
|
|
Quote: | I have bought a 18F8722 development board. |
Post a link to the website for your board. Post your compiler version. |
|
|
hemnath
Joined: 03 Oct 2012 Posts: 242 Location: chennai
|
|
Posted: Fri Dec 12, 2014 9:12 pm |
|
|
Thanks for the help. I modified the program for internal oscillator. It blinks for every 500ms.
I'll change the crystal and post the results. |
|
|
hemnath
Joined: 03 Oct 2012 Posts: 242 Location: chennai
|
|
Posted: Sat Dec 13, 2014 7:25 am |
|
|
Even when I changed the crystal., Problem remains the same.
I bought the development board from local market. |
|
|
dyeatman
Joined: 06 Sep 2003 Posts: 1934 Location: Norman, OK
|
|
Posted: Sat Dec 13, 2014 7:36 am |
|
|
You still didn't post the compiler version... _________________ Google and Forum Search are some of your best tools!!!! |
|
|
hemnath
Joined: 03 Oct 2012 Posts: 242 Location: chennai
|
|
Posted: Sun Dec 14, 2014 12:18 am |
|
|
Compiler version CCS 4.114 |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19536
|
|
Posted: Sun Dec 14, 2014 1:40 am |
|
|
A relatively old compiler, but the 8722, had been supported for a long time. There was something wrong with the include file back in the late 4.0xx's, but you are after this. Anyway the compiler version wouldn't affect this unless it was setting the fuses incorrectly. A quick compile of the code, shows one thing wrong. It is defaulting to XINST. You need to NOXINST fuse. This though should not cause problems on the simple code posted (only causes problems with things like table accesses etc..). However correct this for the future.
Can you check the capacitors used to load the crystal?. Could be something silly like these being 22nF, instead of 22pF for example....
Do you know anything 'about' the crystals you have?. What cut they are, what load capacitance they want, etc..
Triple check around the connections with a magnifying glass. A simple whisker, if the board has not been electrical tested, could easily be the problem.
The 8722, is a chip that I have had problems with in the past, getting the oscillator to always start. Quite a few crystals do need a series resistor on this chip (though lacking this tends to result in the frequency being 'out of spec', rather than stopping the oscillator working). Microchip recommend 330R. I've also though found that the internal resistor across the crystal terminals may not be enough to ensure all crystals start reliably, especially if the power rise time is slow. Something like 1.5MR between the oscillator terminals solves this. |
|
|
hemnath
Joined: 03 Oct 2012 Posts: 242 Location: chennai
|
|
Posted: Sun Dec 14, 2014 4:27 am |
|
|
I have changed a new crystal and capacitors. Still no blinking.
Also double checked the connections from crystal to micro-controller pins.
Also, added a resistor with a value of 1Mohm(i dont have 1.5Mohm right now) across crystal. Still no blinking on led.
my code:
Code: | #include "18F8722.h"
#fuses HS, NOWDT, NOLVP, NOXINST, NOFCMEN, NOIESO, NOPUT
#use delay(clock=20000000)
void main()
{
while(1)
{
output_high(PIN_D0);
delay_ms(500);
output_low(PIN_D0);
delay_ms(500);
}
} |
Please help. whether my fuses are right? Do i have to add anyother fuses? |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Sun Dec 14, 2014 4:15 pm |
|
|
Quote: | I have changed a new crystal and capacitors. Still no blinking.
I bought the development board from local market. |
Post an in-focus, HD-quality photo of your board.
How to post an image on the CCS forum:
Post it on a free image hosting website. Examples:
http://postimage.org
http://tinypic.com
https://imageshack.com
Then post a link to it here. |
|
|
hemnath
Joined: 03 Oct 2012 Posts: 242 Location: chennai
|
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Mon Dec 15, 2014 11:12 am |
|
|
The board has 9 header connectors for i/o ports. The crystal pins, A6
and A7, are connected to one of the headers.
Have you added any wires or connections to pins RA6 or RA7 on the
header connector ? This could certainly affect the crystal circuit.
I don't like the fact that they put long traces between the crystal circuit
and the header pins. The crystal circuit should have been left alone,
with only the required connections to the capacitors and the PIC.
It's possible that the long traces to the header are affecting the circuit.
I suggest that you use an Ohmmeter, and carefully check for continuity
of the traces between the PIC pins and the crystal circuit, and all traces
within the crystal circuit. Also check for shorts between traces.
Look at PIC pins A6 and A7 with a magnifier and check for bad solder
joints. Using an X-Acto knife with a magnifier, carefully nudge pins A6
and A7 to check if they are really soldered to the PCB, or if they are loose. |
|
|
gpsmikey
Joined: 16 Nov 2010 Posts: 588 Location: Kirkland, WA
|
|
Posted: Mon Dec 15, 2014 1:03 pm |
|
|
As PCM suggests, be sure an use an ohmmeter - even if there is nothing visible under a magnifying glass, there still may be an issue. I had one a few years ago where we absolutely could not find the problem until we checked continuity - turns out an internal void between vias in the board had allowed the "thru-hole" plating they use for the vias to bridge between two pins on the board and that was NOT visible - even when we knew where it was.
mikey _________________ mikey
-- you can't have too many gadgets or too much disk space !
old engineering saying: 1+1 = 3 for sufficiently large values of 1 or small values of 3 |
|
|
|