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

how running 18F26K22 to 64MHZ internal?

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



Joined: 17 Feb 2015
Posts: 134

View user's profile Send private message

how running 18F26K22 to 64MHZ internal?
PostPosted: Sat Apr 04, 2015 9:46 pm     Reply with quote

Someone can help me with this doubt:
I want to have the max speed
Code:

#FUSES NOWDT                    //No Watch Dog Timer
#FUSES WDT128                   //Watch Dog Timer uses 1:128 Postscale
#FUSES INTRC_IO                 //Internal RC Osc, no CLKOUT
#FUSES NOPLLEN                  //4X HW PLL disabled, 4X PLL enabled in software
#FUSES NOFCMEN                  //Fail-safe clock monitor disabled
#FUSES NOIESO                   //Internal External Switch Over mode disabled
#FUSES NOBROWNOUT               //No brownout reset
#FUSES WDT_SW                   //No Watch Dog Timer, enabled in Software
#FUSES NOPBADEN                 //PORTB pins are configured as digital I/O on RESET
#FUSES NOMCLR                   //Master Clear pin used for I/O
#FUSES NOSTVREN                 //Stack full/underflow will not cause reset
#FUSES NOLVP                    //No low voltage prgming, B3(PIC16) or B5(PIC18) used for I/O
#FUSES NOXINST                  //Extended set extension and Indexed Addressing mode disabled (Legacy mode)

#use delay(clock=64M)

main(){
 setup_oscillator(OSC_64MHZ|OSC_INTRC|OSC_PLL_OFF);
}

But no work the timer1, i think that no runnig to 64M
Code:

#int_TIMER1                           
void TIMER1_isr(void){                         //                         
   cont++;                                          //                                   
   if(cont == 2){                                 // 0,5*1=1 seg
        ban_1seg = 1;cont = 0;                                                     
     
   }                                               
   set_timer1(-934464);                               // 0.5=4/64000000*8(65536-x),x=-934464
}

Thank!
Ttelmah



Joined: 11 Mar 2010
Posts: 19499

View user's profile Send private message

PostPosted: Sun Apr 05, 2015 2:28 am     Reply with quote

First, you are turning it off......
There is not a 64MHz 'oscillator' internally. The fastest is the 16Mhz oscillator, _which you can then run with the PLL, to give 64MHz_...
You are deliberately turning the PLL off!....

What does OSC_PLL_OFF do?.

Then, your 'main' code will run off the end, and stop the chip.

Then you are not enabling the interrupt.

Then you are not setting up/starting the timer.

Then the timer is a 16bit timer. What makes you think it can be set to a value like -934464?.

You have a lot of problems.....

Code:

#include <18F26K22.h>

#FUSES NOWDT                    //No Watch Dog Timer
#FUSES INTRC_IO                 //Internal RC Osc, no CLKOUT
#FUSES NOPLLEN                  //4X HW PLL disabled, 4X PLL enabled in software
#FUSES NOFCMEN                  //Fail-safe clock monitor disabled
#FUSES NOIESO                   //Internal External Switch Over mode disabled
#FUSES NOBROWNOUT               //No brownout reset
#FUSES WDT_SW                   //No Watch Dog Timer, enabled in Software
#FUSES NOPBADEN                 //PORTB pins are configured as digital I/O on RESET
#FUSES NOMCLR                   //Master Clear pin used for I/O
#FUSES STVREN                   //Stack full/underflow will cause reset
#FUSES NOLVP                    //No low voltage prgming, B3(PIC16) or B5(PIC18) used for I/O
#FUSES NOXINST                  //Extended set extension and Indexed Addressing mode disabled (Legacy mode)

#use delay(clock=64M, internal=16MHz)
int8 cont=0;
int8 ban_1seg=0;
#define TICKS 15 //interrupt ticks for 0.5 seconds

#int_TIMER1                           
void TIMER1_isr(void)
{
   static int8 internal=TICKS-1;
   if (internal)
      --internal;
   else
   {
      //Now this will be approximately 0.5 seconds
      internal=TICKS-1; //reset counter
      cont++;                                          //                                   
      if(cont == 2)
      {                                 // 0,5*1=1 seg
         ban_1seg = 1;
         cont = 0;
      }                                               
   }
}

void main(void)
{
   setup_oscillator(OSC_64MHZ | OSC_INTRC);
   //Now the _slowest_ timer1 can run from a 64MHz clock, is 64000000/(4*8*65536) = 30.5 interrupts/second...
   setup_timer1(T1_INTERNAL | T1_DIV_BY_8);
   enable_interrupts(INT_TIMER1);
   enable_interrupts(GLOBAL); //enable the interrupt
   
   do
   {
   } while (TRUE); //and leave the chip running waiting for interrupts
}
cvargcal



Joined: 17 Feb 2015
Posts: 134

View user's profile Send private message

PostPosted: Sun Apr 05, 2015 9:59 am     Reply with quote

Ttelmah wrote:
First, you are turning it off......
There is not a 64MHz 'oscillator' internally. The fastest is the 16Mhz oscillator, _which you can then run with the PLL, to give 64MHz_...
You are deliberately turning the PLL off!....

What does OSC_PLL_OFF do?.

Then, your 'main' code will run off the end, and stop the chip.

Then you are not enabling the interrupt.

Then you are not setting up/starting the timer.

Then the timer is a 16bit timer. What makes you think it can be set to a value like -934464?.

You have a lot of problems.....

Code:

#include <18F26K22.h>

#FUSES NOWDT                    //No Watch Dog Timer
#FUSES INTRC_IO                 //Internal RC Osc, no CLKOUT
#FUSES NOPLLEN                  //4X HW PLL disabled, 4X PLL enabled in software
#FUSES NOFCMEN                  //Fail-safe clock monitor disabled
#FUSES NOIESO                   //Internal External Switch Over mode disabled
#FUSES NOBROWNOUT               //No brownout reset
#FUSES WDT_SW                   //No Watch Dog Timer, enabled in Software
#FUSES NOPBADEN                 //PORTB pins are configured as digital I/O on RESET
#FUSES NOMCLR                   //Master Clear pin used for I/O
#FUSES STVREN                   //Stack full/underflow will cause reset
#FUSES NOLVP                    //No low voltage prgming, B3(PIC16) or B5(PIC18) used for I/O
#FUSES NOXINST                  //Extended set extension and Indexed Addressing mode disabled (Legacy mode)

#use delay(clock=64M, internal=16MHz)
int8 cont=0;
int8 ban_1seg=0;
#define TICKS 15 //interrupt ticks for 0.5 seconds

#int_TIMER1                           
void TIMER1_isr(void)
{
   static int8 internal=TICKS-1;
   if (internal)
      --internal;
   else
   {
      //Now this will be approximately 0.5 seconds
      internal=TICKS-1; //reset counter
      cont++;                                          //                                   
      if(cont == 2)
      {                                 // 0,5*1=1 seg
         ban_1seg = 1;
         cont = 0;
      }                                               
   }
}

void main(void)
{
   setup_oscillator(OSC_64MHZ | OSC_INTRC);
   //Now the _slowest_ timer1 can run from a 64MHz clock, is 64000000/(4*8*65536) = 30.5 interrupts/second...
   setup_timer1(T1_INTERNAL | T1_DIV_BY_8);
   enable_interrupts(INT_TIMER1);
   enable_interrupts(GLOBAL); //enable the interrupt
   
   do
   {
   } while (TRUE); //and leave the chip running waiting for interrupts
}


Yes, i have many problems xD
Ok, Thank

I say 64MH because in PIC18F26K22.h
is:
Code:
#define OSC_PLL_ON  0x4000
#define OSC_PLL_OFF 0
#define OSC_31250   0x8000
#define OSC_31KHZ   0x00
#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 the timer is with this formule :0.5=4/64000000*8(65536-x),x=-934464

;) Thank! my my knowledge is little.

The code work, but please do you can say how work?
Why #define TICKS 15?
why you no used set_timer1()?
Ttelmah



Joined: 11 Mar 2010
Posts: 19499

View user's profile Send private message

PostPosted: Sun Apr 05, 2015 10:56 am     Reply with quote

Yes, I'm being a 'pedant'. Smile

However it is important to understand that you run with a 16MHz oscillator, and a 64MHz clock.
Little details like this are vital when dealing with chips.

Being pedantic, several of the standard CCS nomenclatures are 'dubious'. It's like "#use RS232", which actually controls the generation of TTL async serial, _not_ 'RS232'. This can be used with a whole variety of different signalling standards (RS232, RS485 etc..), but can't actually generate 'RS232' without external hardware. It's little details like this that encourage getting 'the wrong idea' about what chips can actually do!....
cvargcal



Joined: 17 Feb 2015
Posts: 134

View user's profile Send private message

PostPosted: Sun Apr 05, 2015 11:13 am     Reply with quote

Ttelmah wrote:
Yes, I'm being a 'pedant'. Smile

However it is important to understand that you run with a 16MHz oscillator, and a 64MHz clock.
Little details like this are vital when dealing with chips.

Being pedantic, several of the standard CCS nomenclatures are 'dubious'. It's like "#use RS232", which actually controls the generation of TTL async serial, _not_ 'RS232'. This can be used with a whole variety of different signalling standards (RS232, RS485 etc..), but can't actually generate 'RS232' without external hardware. It's little details like this that encourage getting 'the wrong idea' about what chips can actually do!....


Thank master, now undertand that on thing is oscillador and other is clock.
Do you think that is better used external oscillator to internal?


My other questions is.

I used this for timer1 (with 4MHZ work perfect)

Code:
#int_TIMER1                           
void TIMER1_isr(void){                        //                         
   cont++;                                          //                                   
   if(cont == 2){                                  // 0,5*2=1 segundo
        ban_1seg = 1;cont = 0;              //                                     
     
   }                                                  //
   set_timer1(3036);                     // 0.5=4/4000000*8(65536-x),x=3036 >> Tiempo de desbordamiento es 0.5 segundos
}


and

Code:
void main(){   
//-------------- Configuración ----------           //
     setup_timer_1 (T1_INTERNAL | T1_DIV_BY_8);     // Configuración  Timer1
     set_timer1 (3036);                             // 0.5=4/4000000*8(65536-x),x=3036 >> Tiempo de desbordamiento es 0.5 segundos
     enable_interrupts(int_timer1);                // Deshabilitar Interrupción timer1
     enable_interrupts(GLOBAL);                     // Habilitar Interrupción Global
     Reset();
     enable_interrupts(int_timer1);                 // Habilitar Interrupción Timer1       
//--------------- Subprograma ---------------                                     
   while(true){
                if(ban_1seg){                                    //
                  ban_1seg = 0; seg++;                     //
                  if(seg == 60){                                 // Si ya van 60 seg
                      seg=0;min++;                            //
                      if (min==6){                              //
                        min=0;                                    //
                        disable_interrupts(int_timer1); Reset(); //   
                      }                                                                                                               
                    }               
                 }   
           }
}


I no undertand your code

Code:

int8 cont=0;
int8 ban_1seg=0;
#define TICKS 15 //interrupt ticks for 0.5 seconds

#int_TIMER1                           
void TIMER1_isr(void)
{
   static int8 internal=TICKS-1;
   if (internal)
      --internal;
   else
   {
      //Now this will be approximately 0.5 seconds
      internal=TICKS-1; //reset counter
      cont++;                                          //                                   
      if(cont == 2)
      {                                 // 0,5*2=1 seg
         ban_1seg = 1;
         cont = 0;
      }                                               
   }
}


Why 15?
Thank so much!
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