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

PIC18F46K20 vs CCS

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



Joined: 02 Dec 2005
Posts: 28
Location: Italy, Milan

View user's profile Send private message Send e-mail

PIC18F46K20 vs CCS
PostPosted: Mon Dec 22, 2008 5:13 am     Reply with quote

Hi All,

The PIC in object is not yet test by CCS :( and in fact I am experiencing some problems setting the clock speed. I need to use the internal oscillator.
The setting I use is:

Code:

 #fuses INTRC,NOWDT,NOPROTECT,NOLVP,NODEBUG, noBROWNOUT
 #use delay(clock=8000000)


I use the same configuration (and same code) on PIC 18F2455 and it work. Using clock=8000000 or clock=4000000 I get the right speed (tested brutally with a delay instruction of 4seconds and a stopwatch and tested with serial communication, 9600bps set in program work with 9600bps set in hyperterminal).

On PIC18F46K20 I know a difference using clock=4000000 than clock=8000000 in code speed BUT THE DELAY INSTRUCTION of 4seconds always takes 2 seconds!!!! (both clock=8000000 and clock=4000000). Moreover an rs232 speed of 9600bps set in code work only with a 19200bps in hyper terminal!!

This is the strange behavior, knows someone help me?

Thanks
Alex
PICoHolic



Joined: 04 Jan 2005
Posts: 224

View user's profile Send private message

PostPosted: Mon Dec 22, 2008 6:32 am     Reply with quote

You need to configure the internal osc using "setup_oscillator" function

For ex, to set for 31KHz:
Code:

setup_oscillator(OSC_31KHZ|OSC_INTRC|OSC_IDLE_MODE|OSC_PLL_OFF);
[mAnNaRo]



Joined: 02 Dec 2005
Posts: 28
Location: Italy, Milan

View user's profile Send private message Send e-mail

PostPosted: Mon Dec 22, 2008 8:46 am     Reply with quote

I doesn't work :-(

This is my setup:
Code:

setup_oscillator(OSC_8MHZ|OSC_INTRC|OSC_IDLE_MODE);


the serial comunication set to 9600bps work always with a value of 19200bps in hyperterminal :-(

Alex
PICoHolic



Joined: 04 Jan 2005
Posts: 224

View user's profile Send private message

PostPosted: Mon Dec 22, 2008 9:31 am     Reply with quote

Plz post your code along with compiler version!
[mAnNaRo]



Joined: 02 Dec 2005
Posts: 28
Location: Italy, Milan

View user's profile Send private message Send e-mail

PostPosted: Mon Dec 22, 2008 10:21 am     Reply with quote

Compiler version PCH 4.078.

Code:

 #include <18F46K20.h>   
 #fuses INTRC_IO,NOWDT,NOPROTECT,NOLVP,NODEBUG, noBROWNOUT
 #use delay(clock=8000000)
 #use rs232(baud=9600, xmit=PIN_B7, rcv=PIN_B6)    


and a simple:
Code:

printf("Battery connected!\r\n");


Alex
Ttelmah
Guest







PostPosted: Mon Dec 22, 2008 4:06 pm     Reply with quote

You need a simple program we can compile. As short as possible, but it needs the main, and the basic initialisation.
The problem could come from the layout of your program, hence we need to see this.

Best Wishes
[mAnNaRo]



Joined: 02 Dec 2005
Posts: 28
Location: Italy, Milan

View user's profile Send private message Send e-mail

PostPosted: Tue Dec 23, 2008 3:49 pm     Reply with quote

Code:

#include <18F46K20.h>   
#fuses INTRC_IO,NOWDT,NOPROTECT,NOLVP,NODEBUG, noBROWNOUT
#use delay(clock=8000000)
#use rs232(baud=9600, xmit=PIN_B7, rcv=PIN_B6)    

void main(void)
{
   int16 i;

   delay_ms(2000);
   printf("TEST UART SPEED\r\n");
   i=0;

   delay_ms(10000);
   printf("10 seconds\r\n");

   while(1)
   {
      for(i=0; i<0xFFFF;i++)
      {
         printf("%Lu\r\n", i);
      }      
   }
}


At 8Mhz (clock=8000000):
Hyperterminal work at 19200bps
The delay take about 5 seconds

At 4Mhz (clock=4000000):
Hyperterminal work at 19200bps
The delay take about 5 seconds

The speed of code executed do not change in 8 or 4 MHz.

Using MPLAB SIM the delay of 10 seconds take 4seconds (measured with mplab stopwatch)

Alex
Ttelmah
Guest







PostPosted: Tue Dec 23, 2008 4:03 pm     Reply with quote

OK.
What is happening, is that the compiler is using the 4620 settings, not the 46K20 settings. The clock speed table for the 4620, goes:
31K
125K
250K
500K
1M
2M
4M
8M

While the one for the 46K20, goes:
31K
250K
500K
1M
2M
4M
8M
16M

Note the doubling.
You need to replace the clock setting lines in the include file with:
Code:

// Constants used in setup_oscillator() are:
// First param:
#define OSC_31KHZ   0
#define OSC_250KHZ  0x10
#define OSC_500KHZ  0x20
#define OSC_1MHZ    0x30
#define OSC_2MHZ    0x40
#define OSC_4MHZ    0x50
#define OSC_8MHZ    0x60
#define OSC_16MHZ   0x70
#define OSC_32MHZ   0x4060
#define OSC_64MHZ   0x4070

and add the line:

setup_oscillator(OSC_8MHz);

at the start of the main (leave the delay statement set to 8MHz).

This should fix it.

Best Wishes
[mAnNaRo]



Joined: 02 Dec 2005
Posts: 28
Location: Italy, Milan

View user's profile Send private message Send e-mail

PostPosted: Wed Dec 24, 2008 12:15 pm     Reply with quote

Thanks Ttelmah!!! Fix it! Very Happy

Alex
dyeatman



Joined: 06 Sep 2003
Posts: 1934
Location: Norman, OK

View user's profile Send private message

PostPosted: Wed Dec 24, 2008 1:00 pm     Reply with quote

Now CCS needs to be notified of the error in the H file...
[mAnNaRo]



Joined: 02 Dec 2005
Posts: 28
Location: Italy, Milan

View user's profile Send private message Send e-mail

PostPosted: Wed Dec 24, 2008 2:39 pm     Reply with quote

...and someone with the last version of PCH should notify the bug in the compiler because the "setup_oscillator(OSC_8MHz);" instruction is a
way to get around the problem. Confused

Alex
Mr_T
Guest







problem of clk with pic18f46k20
PostPosted: Wed May 06, 2009 8:31 am     Reply with quote

Hi all !!!

i'm using a PIC18F46K20 and i have a problem with the clock.
i can't see the the CPU frequence. If you can help me plz, i want to know how can i see the FCPU ?

Code:
/** I N C L U D E S **************************************************/
#include "p18f46k20.h"
#include "delays.h"
#include "09 IntOSC.h"  // header file
#include "dhry_v11.h"
/** V A R I A B L E S *************************************************/
#pragma idata   // declare statically allocated initialized variables
unsigned char LED_Count = 0;    // 8-bit variable

IntOSCFreq ClockSpeed = C_125kHz;


/** D E C L A R A T I O N S *******************************************/
#pragma code    // declare executable instructions
//#pragma config FOSC = INTIO67

void SetIntOSC(IntOSCFreq *ClockSet)

{
//{   // This function sets the internal oscillator to the frequency of
//    // the ClockSet argument variable, and then increments ClockSet
//    // to the next supported frequency.
   
         OSCCON = 0b01110000;          // IRCFx = 111 (16 MHz)
            OSCTUNEbits.PLLEN = 1;  // x4 PLL enabled = 64 MHz

            //OSCCON = 0b01110000;          // IRCFx = 111 (16 MHz)
            //OSCTUNEbits.PLLEN = 0;  //       16 MHz
 
          //OSCCON = 0b01100000;          // IRCFx = 110 (8 MHz)
            //OSCTUNEbits.PLLEN = 1;  // x4 PLL enabled = 32 MHz
}

void main (void)
{
  // Init I/O
  //CONFIG1H = 0b00001001;

    TRISA = 0;                        // TRISA outputs
   LATA = 0b00000000;                  // drive PORTA pins low
    TRISD = 0x7F;        // PORTD bits 7:0 are all outputs (0)
 
    SetIntOSC(&ClockSpeed);
    while (1)
    {
       
      LATDbits.LATD7 = ~LATDbits.LATD7; // toggle LATD
        dhry_run();
       // Delay1KTCYx(50);            // delay 32,000 cycles or about 1 sec at 125kHz
    }
   
}


this is my code it's really simple.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Wed May 06, 2009 10:20 am     Reply with quote

This is C18 code. Please ask C18 questions on the Microchip forum:
http://www.microchip.com/forums/tt.aspx?forumid=3
mr_T
Guest







PostPosted: Thu May 07, 2009 1:46 am     Reply with quote

Thank you very much for the link. I have posted my questions on the microchip forum.(sorry for my english i'm not from england )

May be i can ask you some question ?

i'm doing dhristone test on one pic18f46k20 and i have a problem with array size.
Normaly on dhrystone test you use array=[20] and on this pic i use array=[8].
With array=[8] i can build my project but i lost a lot of information and that means the drystone test is totally wrong and means nothing.

May be you have already made a drystone test on one pic 18 ?
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