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

PIC18LF46K22 clk problem !

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



Joined: 21 Dec 2012
Posts: 5

View user's profile Send private message

PIC18LF46K22 clk problem !
PostPosted: Fri Dec 21, 2012 8:01 am     Reply with quote

Hi,
I designed a low voltage system based on 18LF46K22 micro which is working with 2v.
I am using 14.7456 MHz crystal to drive it, and run a very simple program just to test it as below:

#INCLUDE <18LF46K22.H>
#FUSES HSH , NOPROTECT , NOWDT
#USE delay ( clock=14745600 )
void main( void ) {
while ( true ) {
output_bit(PIN_B2,0);
output_bit(PIN_B2,1);
}
}

The result is a square wave with nearly 8 micro sec. "0" and 16 micro sec. "1".
But normally it should work much faster than this, isn't it ? Question
asmallri



Joined: 12 Aug 2004
Posts: 1634
Location: Perth, Australia

View user's profile Send private message Send e-mail Visit poster's website

Re: PIC18LF46K22 clk problem !
PostPosted: Fri Dec 21, 2012 9:43 am     Reply with quote

jsafaie wrote:
Hi,
I designed a low voltage system based on 18LF46K22 micro which is working with 2v.
I am using 14.7456 MHz crystal to drive it, and run a very simple program just to test it as below:

#INCLUDE <18LF46K22.H>
#FUSES HSH , NOPROTECT , NOWDT
#USE delay ( clock=14745600 )
void main( void ) {
while ( true ) {
output_bit(PIN_B2,0);
output_bit(PIN_B2,1);
}
}

The result is a square wave with nearly 8 micro sec. "0" and 16 micro sec. "1".
But normally it should work much faster than this, isn't it ? Question


Look at the LST file and see how many instructions it executes to pass through the while loop. 14MHz will give you roughly 3.5 million instructions per second.

Also strictly speaking you do not have a square wave - if you did then the "0" and "1" periods would be the same - that is where the square in square wave comes from.
_________________
Regards, Andrew

http://www.brushelectronics.com/software
Home of Ethernet, SD card and Encrypted Serial Bootloaders for PICs!!
Ttelmah



Joined: 11 Mar 2010
Posts: 19346

View user's profile Send private message

PostPosted: Fri Dec 21, 2012 10:00 am     Reply with quote

The two output instructions, using fixed bit values, and levels, each take two machine cycles. The loop also takes two. So to get 8uSec, and 16uSec, for a total of six machine cycles, implies you are clocking at 1MHz (250K instructions per second, 6 instructions).
By default, the chip will wake up with FSCM enabled, so will 'fall back' to the internal oscillator if it can't start the main oscillator, or something is wrong.
The default speed of this is 1MHz.
First thing I note, again by default the PLL will be enabled. You don't want this, so need NOPLLEN. HSH, is designed for crystals over 16MHz, so you really want HSM. You should have PRIMARY_ON selected.

So:
#FUSES HSM , NOPROTECT , NOWDT, NOPLLEN, PRIMARY_ON, PUT, NOIESO, NOFCMEN

Now, the last two fuses, now mean it won't start at all, if the crystal doesn't work, makes testing easier!. If it doesn't start, then there is a problem with the crystal circuit.

Best Wishes
jsafaie



Joined: 21 Dec 2012
Posts: 5

View user's profile Send private message

PostPosted: Fri Dec 21, 2012 10:27 am     Reply with quote

Very Happy
Thanks a lot guys, it is solved by your proposition.
#FUSES HSM , NOPROTECT , NOWDT, NOPLLEN, PRIMARY_ON, PUT, NOIESO, NOFCMEN
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