|
|
View previous topic :: View next topic |
Author |
Message |
jsafaie
Joined: 21 Dec 2012 Posts: 5
|
PIC18LF46K22 clk problem ! |
Posted: Fri Dec 21, 2012 8:01 am |
|
|
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 ? |
|
|
asmallri
Joined: 12 Aug 2004 Posts: 1635 Location: Perth, Australia
|
Re: PIC18LF46K22 clk problem ! |
Posted: Fri Dec 21, 2012 9:43 am |
|
|
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 ? |
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: 19536
|
|
Posted: Fri Dec 21, 2012 10:00 am |
|
|
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
|
|
Posted: Fri Dec 21, 2012 10:27 am |
|
|
Thanks a lot guys, it is solved by your proposition.
#FUSES HSM , NOPROTECT , NOWDT, NOPLLEN, PRIMARY_ON, PUT, NOIESO, NOFCMEN |
|
|
|
|
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
|