View previous topic :: View next topic |
Author |
Message |
pilar
Joined: 30 Jan 2008 Posts: 197
|
PIC18F46K22 for 20Mhz |
Posted: Mon Jul 17, 2017 2:36 pm |
|
|
Hi, I have been working without any problem with the pic18f4620 at 20Mhz with frequency setting to HS, but now I have had to change controller and I am trying to use the PIC18F46K22, but all my time calculations have varied and I do not get my code to work correctly.
I would like to know which is the correct configuration to work at 20 Mhz, so I do not have to change my code.
Here is part of my code...
Code: | #include <18F46K22.h>
#fuses HSH,NOWDT,PUT,BROWNOUT
#use delay(clock=20M)
#use rs232(baud=9600, UART1, stream=USER, errors)
#use rs232(baud=9600, UART2, stream=ISAT, errors)
char Keypress1=' ';
char Keypress2=' ';
#int_rda
void serial_isr1() {
Keypress1=0x00;
if(kbhit(USER)){
Keypress1=fgetc(USER);
if(Keypress1!=0x00){
fputc(keypress1,ISAT);
keypress1=0x00;
}
}
}
#int_rda2
void serial_isr2() {
Keypress2=0x00;
if(kbhit(ISAT)){
Keypress2=fgetc(ISAT);
if(Keypress2!=0x00){
fputc(keypress2,USER);
keypress2=0x00;
}
}
}
void main() {
enable_interrupts(global);
enable_interrupts(int_rda);
enable_interrupts(int_rda2);
fprintf(USER,"Listen on RS232\r\n");
fprintf(ISAT,"Listen on RS232\r\n");
while (TRUE);
} |
|
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Mon Jul 17, 2017 3:33 pm |
|
|
Add the NOPLLEN fuse. |
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9222 Location: Greensville,Ontario
|
|
Posted: Tue Jul 18, 2017 10:21 am |
|
|
One problem is you don't say what your xtal freq is. I'm making a huge assumption you've got a 20MHz xtal and a couple of caps on the primary OSC, so what Mr T says is true though I don't know what the compiler defaults to.
I usually use the internal OSC at 16Megs and the PLL to get 64MHz operation.
The 46K22 has a LOT of clock options, so it's best to 'spell out' to the compiler( and us) what you have and what you want.
Jay |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19503
|
|
Posted: Tue Jul 18, 2017 12:10 pm |
|
|
I didn't say anything!....
However the key is the number of extra options, and you not giving the compiler any data on how to set them.
NOPLLEN, and/or (crystal=20MHz, clock=20MHz)
either tells the compiler how to set the PLL. By default the PLL is enabled, so with just 'clock=20MHz', the chip is trying to run at 80MHz.... |
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9222 Location: Greensville,Ontario
|
|
Posted: Tue Jul 18, 2017 2:04 pm |
|
|
sorry it was PCMP.... |
|
|
pilar
Joined: 30 Jan 2008 Posts: 197
|
|
Posted: Thu Jul 20, 2017 7:03 pm |
|
|
Sorry for the omission,
I am using the CCS V5.015 and a crystal of 20Mhz...
I have developed an application for the PIC18F4620 at 20 MHz, and this has many timings with the different timer and I do not want to do more variations, I simply want to change the microcontroller but do not change the configuration of the timer... for that is my query ... |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19503
|
|
Posted: Thu Jul 20, 2017 11:19 pm |
|
|
So, use the setup:
(crystal=20MHz, clock=20MHz)
This will work on both chips the same. |
|
|
|