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 CCS Technical Support

PIC18F46K22 for 20Mhz

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



Joined: 30 Jan 2008
Posts: 197

View user's profile Send private message

PIC18F46K22 for 20Mhz
PostPosted: Mon Jul 17, 2017 2:36 pm     Reply with quote

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

View user's profile Send private message

PostPosted: Mon Jul 17, 2017 3:33 pm     Reply with quote

Add the NOPLLEN fuse.
temtronic



Joined: 01 Jul 2010
Posts: 9222
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Tue Jul 18, 2017 10:21 am     Reply with quote

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: 19500

View user's profile Send private message

PostPosted: Tue Jul 18, 2017 12:10 pm     Reply with quote

I didn't say anything!.... Very Happy

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

View user's profile Send private message

PostPosted: Tue Jul 18, 2017 2:04 pm     Reply with quote

sorry it was PCMP.... Crying or Very sad
pilar



Joined: 30 Jan 2008
Posts: 197

View user's profile Send private message

PostPosted: Thu Jul 20, 2017 7:03 pm     Reply with quote

Embarassed 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: 19500

View user's profile Send private message

PostPosted: Thu Jul 20, 2017 11:19 pm     Reply with quote

So, use the setup:

(crystal=20MHz, clock=20MHz)

This will work on both chips the same.
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