CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to support@ccsinfo.com

18F2680 H4 External Clock Help

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
gling8313



Joined: 18 Jul 2012
Posts: 8

View user's profile Send private message

18F2680 H4 External Clock Help
PostPosted: Wed Jul 18, 2012 12:43 pm     Reply with quote

I am currently developing using a PIC18F2680 and I wanted to increase the clock speed via an external crystal. I fabricated the external crystal circuit according to the datasheet with (2)15pf capacitors and a series resistor.

I'm currently using the H4 fuse in my code to multiply my clock signal to 32Mhz. I need to know for sure that the external crystal is driving the board so I tested it with and without the circuit attached. They both worked.


Why does the board still run even without the external clock circuit?
And how can I be sure that the board is indeed running off my external clock circuit?

Note: I disabled the clock fail safe as well.


Here is a list of the fuses I am using:
Code:

#fuses H4, NOLVP, NOMCLR, BROWNOUT, BORV43, NOWDT,NOPBADEN, PROTECT, CPB, WRTC, EBTRB, EBTR, CPD, NOIESO, WRTB, WRT

#use delay(clock=32000000, restart_wdt)
Ttelmah



Joined: 11 Mar 2010
Posts: 19430

View user's profile Send private message

PostPosted: Wed Jul 18, 2012 2:37 pm     Reply with quote

You don't show the fail safe as disabled.
Code:

#fuses H4, NOLVP, NOMCLR, BROWNOUT, BORV43, NOWDT,NOPBADEN, PROTECT, CPB, WRTC, EBTRB, EBTR, CPD, NOIESO, WRTB, WRT, NOFCMEN


NOIESO, turns off _software_ switching of the clock. NOFCMEN, turns off the failsafe clock monitor.

You should find the chip stops working now, if there is no crystal present.

Best Wishes
gling8313



Joined: 18 Jul 2012
Posts: 8

View user's profile Send private message

PostPosted: Wed Jul 18, 2012 2:51 pm     Reply with quote

Thanks for your reply! I double checked my code and the reason I didn't use NOFCMEN is because when I check the configuration bits in MPLAB, the fail-safe is disabled by default.

Does the chip somehow override this unless i specify it in the fuses as you have shown?
gling8313



Joined: 18 Jul 2012
Posts: 8

View user's profile Send private message

PostPosted: Wed Jul 18, 2012 3:02 pm     Reply with quote

Update: I tried the NOFCMEN fuse anyways and disconnected the clock circuit. My board, however, still ran. :confused:
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Wed Jul 18, 2012 3:09 pm     Reply with quote

Post a short but compilable program that blinks an led, so we can test it.
http://www.ccsinfo.com/forum/viewtopic.php?t=46286&start=5
Also post your compiler version. It's given at the top of the .LST file,
which will be in your project directory after a successful compile.
Example of version numbers:
http://www.ccsinfo.com/devices.php?page=versioninfo
gling8313



Joined: 18 Jul 2012
Posts: 8

View user's profile Send private message

PostPosted: Wed Jul 18, 2012 3:17 pm     Reply with quote

The compiler version is 3.224

And here is an LED loop I wrote to debug some code in another project. So hopefully you meant something like this:
Code:

   #define LED_Debug PIN_A5
   
   
   while(1){
      
      output_high(LED_Debug);
      delay_ms(1000);
      output_low(LED_Debug);
      delay_ms(1000);   
   }
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Wed Jul 18, 2012 4:33 pm     Reply with quote

I wanted you to post a full test program, similar to this, so I wouldn't
have to assume anything:
Code:

#include <18F2680.h>
#fuses H4, NOLVP, NOMCLR, BROWNOUT, BORV43, NOWDT,NOPBADEN, PROTECT, CPB, WRTC, EBTRB, EBTR, CPD, NOIESO, WRTB, WRT, NOFCMEN
#use delay(clock=32000000, restart_wdt)
#define LED_Debug PIN_A5

//=========================
void main()
{   
   
while(1){
  output_high(LED_Debug);
  delay_ms(1000);
  output_low(LED_Debug);
  delay_ms(1000);   
  }

}

I don't have your exact version. The closest I have is vs. 3.230.
To help us find the problem, compile the program above, or post
whatever test program you are using, and post the fuses which
are given at the end of the .LST file. For example, with vs. 3.230,
I get these fuses:
Code:

Configuration Fuses:
   Word  1: 0600   H4 NOIESO NOFCMEN RESERVED
   Word  2: 1E0F   BROWNOUT NOWDT BORV43 NOPUT WDT32768
   Word  3: 0000   NOPBADEN NOLPT1OSC NOMCLR RESERVED
   Word  4: 0081   STVREN NODEBUG NOLVP BBSIZ1K NOXINST RESERVED
   Word  5: 0000   PROTECT CPD CPB
   Word  6: 8008   WRT NOWRTD WRTC WRTB
   Word  7: 0008   EBTR EBTRB
gling8313



Joined: 18 Jul 2012
Posts: 8

View user's profile Send private message

PostPosted: Wed Jul 18, 2012 4:54 pm     Reply with quote

Oh my bad! Here is what I compiled:

Code:
#include"18f2680.h"
#include <can-18xxx8.c>

#fuses H4, NOLVP, NOMCLR, BROWNOUT, BORV43, NOWDT,NOPBADEN, PROTECT, CPB, WRTC, EBTRB, EBTR, CPD, NOFCMEN,IESO, WRTB, WRT
#use delay(clock=32000000, restart_wdt)

   while(1){
      
      output_high(LED_Debug);
      delay_ms(100);
      output_low(LED_Debug);
      delay_ms(100);
      
      
   }   




Here is the .LST file
Code:
Configuration Fuses:
   Word  1: 8200   H4 IESO NOFCMEN
   Word  2: 1E0F   BROWNOUT NOWDT BORV43 NOPUT WDT32768
   Word  3: 0000   NOPBADEN NOLPT1OSC NOMCLR RESERVED
   Word  4: 0081   STVREN NODEBUG NOLVP BBSIZ1K NOXINST RESERVED
   Word  5: 0000   PROTECT CPD CPB
   Word  6: 8008   WRT NOWRTD WRTC WRTB
   Word  7: 0008   EBTR EBTRB
Ttelmah



Joined: 11 Mar 2010
Posts: 19430

View user's profile Send private message

PostPosted: Thu Jul 19, 2012 1:14 am     Reply with quote

MPLAB, should not be changing the fuse itself. That it is, suggests something else is going on.
1) Obviously the tick box in MPLAB to set fuses from the code is made?.
2) You are compiling for run mode, not debug mode?.
MPLAB in certain versions, defaults to debug mode, and this will override several fuses.
3) For development, get rid of the code protect fuses. Setting these means the chip _has_ to perform a full erase every time, increasing the 'wear and tear' on the flash memory. Pointless.
4) What are you actually running this on?. Off the shelf board? Home made?. etc..

Best Wishes
gling8313



Joined: 18 Jul 2012
Posts: 8

View user's profile Send private message

PostPosted: Thu Jul 19, 2012 12:03 pm     Reply with quote

Yeah I have the "Configuration Bits set in code" box ticked.
I will double check that I am indeed compiling for run and not debug.
I am running this on a custom homemade board.

Thank you for your help!
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Thu Jul 19, 2012 1:11 pm     Reply with quote

Quote:
Why does the board still run even without the external clock circuit?

I edited the Config Bits in MPLAB before I programmed the PIC, so that
Word 1 = 0x82 just like in your posted .LST file values. Then I got your
symptoms. You have IESO enabled. So when you pull the crystal the
PIC will switch to the internal oscillator and it keeps running.

Also, your compiler version is not compiling the H4 fuse correctly.
It's actually compiling it for the HS fuse. Because of that, your PIC
will run at 1/4 of the desired speed. It's a bug in your version.
gling8313



Joined: 18 Jul 2012
Posts: 8

View user's profile Send private message

PostPosted: Mon Jul 23, 2012 11:55 am     Reply with quote

Quote:
Also, your compiler version is not compiling the H4 fuse correctly.
It's actually compiling it for the HS fuse. Because of that, your PIC
will run at 1/4 of the desired speed. It's a bug in your version.


Oh wow, I didn't realize that! I'll update the version, re-compile it and report back. Is there any way to enable the PLL x4 multiplier for the crystal other than the fuse?
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Mon Jul 23, 2012 12:31 pm     Reply with quote

One quick way is to use the Configure Menu in MPLAB (after you compile)
and select Configuration Bits, and change it from "HS" to "HS oscillator,
PLL enabled". Then program the PIC.

You can also do it with a #rom statement. The #rom statement will
override the Oscillator settings (and the IESO and FCMEN settings)
in Config Word 1. You can see this in the Configuration bits in MPLAB
after you compile the program:
Code:


#include <18F2680.h>
#fuses H4, NOLVP, NOMCLR, BROWNOUT, BORV43, NOWDT,NOPBADEN, PROTECT, CPB, WRTC, EBTRB, EBTR, CPD, NOIESO, WRTB, WRT, NOFCMEN
#rom 0x300001 = {0x06}
#use delay(clock=32000000, restart_wdt)

#define LED_Debug PIN_A5

//=========================
void main()
{   
   
while(1){
  output_high(LED_Debug);
  delay_ms(1000);
  output_low(LED_Debug);
  delay_ms(1000);   
  }

}
 
gling8313



Joined: 18 Jul 2012
Posts: 8

View user's profile Send private message

PostPosted: Mon Jul 23, 2012 2:48 pm     Reply with quote

Quote:
One quick way is to use the Configure Menu in MPLAB (after you compile)
and select Configuration Bits, and change it from "HS" to "HS oscillator,
PLL enabled". Then program the PIC.

You can also do it with a #rom statement. The #rom statement will
override the Oscillator settings (and the IESO and FCMEN settings)
in Config Word 1. You can see this in the Configuration bits in MPLAB
after you compile the program:



I don't think I am able to apply the first method you suggested as I would need to re-compile the project after I change the bits in the Configuration Bits menu. Whenever I re-compile, MPLAB overrides the choice I just selected.

(I should clarify that I'm not programming the PIC directly through MPLAB, but I am using the HEX file generated by the program.)

However, I tried the #rom statement you suggested and it indeed changed the OSC field to run with HSPLL. So I will try programming the PIC with this option and report back.

Thank you for all of your help so far.
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
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