View previous topic :: View next topic |
Author |
Message |
hamid9543
Joined: 31 Jan 2013 Posts: 63
|
pic18f46k22 configure oscillator |
Posted: Sun Aug 30, 2020 4:12 am |
|
|
hi
I want to configure pic18f46k22 in internal oscillator 64 MHz. But rs232 not working !
When change to 16 MHz rs232 working properly.
Code: |
#include <18F46K22.h>
#FUSES NOWDT,NOBROWNOUT,NOPUT,PLLEN,NOMCLR
#use delay(internal=64mhz)
#use rs232(baud=9600,parity=N,xmit=PIN_d6,rcv=PIN_d7,bits=8,stream=BLT)
void main()
{
while(true)
{
printf("hello\r\n");
delay_ms(100);
}
}
|
|
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9225 Location: Greensville,Ontario
|
|
Posted: Sun Aug 30, 2020 5:12 am |
|
|
I did a very quick test to confirm...
these settings work fine for me.
//46k22 fuses
#fuses H4 //uses PLL*4 speed
#fuses INTRC_IO //use internal osc (yes !!)
//
#use delay(clock=64000000,internal)
if they don't work, perhaps it's a compiler 'bug' but 16MHz works, 64 doesn't is 'magically' 4x.... looks like the fuse setting is incorrect.
Jay |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Sun Aug 30, 2020 6:30 am |
|
|
Try this modified version of your program.
Code: | #include <18F46K22.h>
#FUSES INTRC_IO, NOWDT,NOBROWNOUT,NOPUT,NOMCLR
#use delay(clock=64M)
#use rs232(baud=9600,parity=N,xmit=PIN_d6,rcv=PIN_d7,bits=8,stream=BLT)
//=============================
void main()
{
setup_oscillator(OSC_64MHZ, OSC_PLL_ON);
delay_ms(100);
while(TRUE)
{
printf("hello\r\n");
delay_ms(100);
}
} |
|
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19506
|
|
Posted: Sun Aug 30, 2020 6:56 am |
|
|
Critical question, nobody has asked. _What compiler version_. |
|
|
hamid9543
Joined: 31 Jan 2013 Posts: 63
|
|
Posted: Sun Aug 30, 2020 7:32 am |
|
|
Ttelmah wrote: | Critical question, nobody has asked. _What compiler version_. |
5.094 |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19506
|
|
Posted: Sun Aug 30, 2020 9:44 am |
|
|
OK.
In which case the H4 fuse referred to by Jay, doesn't exist.
Your problem is being caused by you trying to enable the PLL, with the
PLLEN fuse. This is not allowed (data sheet PLL in HFINTOSC modes):
Quote: |
The 4x frequency multiplier can be used with the
internal oscillator block to produce faster device clock
speeds than are normally possible with the internal
oscillator. When enabled, the PLL multiplies the
HFINTOSC by 4 to produce clock rates up to 64 MHz.
Unlike external clock modes, the PLL can only be
controlled through software. The PLLEN control bit of
the OSCTUNE register is used to enable or disable the
PLL operation when the HFINTOSC is used.
|
Note what the second paragraph says. You _cannot_ enable the PLL
in the fuses, and use it with the internal oscillator. It has to be enabled
in software.
By turning it on in the fuses, you are preventing it from working.
Simply remove your PLLEN fuse, and it should work.... |
|
|
|