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

Pic18f2520 INTRC setting

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



Joined: 03 Jun 2011
Posts: 7

View user's profile Send private message

Pic18f2520 INTRC setting
PostPosted: Thu May 10, 2012 7:46 am     Reply with quote

Hello,

I would like to use the internal oscillator of the chip running at 32 MHz.
I wasn't able to set it.
Here is my code:

Code:

#include <18F2520.h>
#device HIGH_INTS=TRUE adc=8

//#FUSES INTRC_IO                 //Internal RC Osc, no CLKOUT
#FUSES INTRC                 //Internal RC Osc


#FUSES NOWDT                    //No Watch Dog Timer
#FUSES WDT128                   //Watch Dog Timer uses 1:128 Postscale
#FUSES NOIESO                   //Internal External Switch Over mode disabled
#FUSES PUT                      //Power Up Timer
#FUSES NOBROWNOUT               //No brownout reset
#FUSES NOPBADEN                 //PORTB pins are configured as digital I/O on RESET
#FUSES NOLPT1OSC                //Timer1 configured for higher power operation
#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=32000000)

#use fast_io(A)
#use fast_io(B)
#use fast_io(C)


#define LED    PIN_A0

#define X0   PIN_B3
#define X1   PIN_B2
#define Y0   PIN_B1
#define Y1   PIN_B0

#define X_dir   PIN_B4      // X motor lépésének iránya
#define X_step   PIN_B5      // X motor lépése
#define Y_dir   PIN_B6      // Y motor lépésének iránya
#define Y_step   PIN_B7      // Y motor lépése



#define SPI_MODE_0  (SPI_L_TO_H | SPI_XMIT_L_TO_H)
#define SPI_MODE_1  (SPI_L_TO_H)
#define SPI_MODE_2  (SPI_H_TO_L)
#define SPI_MODE_3  (SPI_H_TO_L | SPI_XMIT_L_TO_H)


int n;

//------------------------------------------------------------------------------
#int_SSP HIGH
void  SSP_isr(void){
   
}
//------------------------------------------------------------------------------
#int_TIMER1
void  TIMER1_isr(void)    //
{
   //disable_interrupts(INT_TIMER1);
   
   //életjel
//   n++;
//   if(n>=0){
      output_toggle(LED);
//      n=0;
//   }
   //enable_interrupts(INT_TIMER1);   
}
//-----------------------------------------------------------------
void main() {
   
   
   setup_oscillator(OSC_32MHZ|OSC_INTRC);
   
   setup_timer_1(T1_INTERNAL|T1_DIV_BY_1);      //
   
   setup_timer_3(T3_DISABLED | T3_DIV_BY_1);
   
   setup_spi(SPI_SLAVE|SPI_MODE_0);

   setup_ccp1(CCP_COMPARE_INT);
   setup_comparator(NC_NC_NC_NC);
   
   set_tris_a(0b100000);    // 0:életjel, 5:_SS
   set_tris_b(0b00001111);   // B0-B3: Y1,Y0,X1,X0   B4-B7: XD,XS,YD,YS
   set_tris_c(0b00011000);   // 2:interrupt ki, 3:SCK, 4:SDI, 5:SDO

   output_b(0);
   n=0;
   //enable_interrupts(INT_SSP);
   //enable_interrupts(INT_TIMER1);
   //enable_interrupts(GLOBAL);
   
   while(TRUE){
      output_toggle(LED);
   }

}


I measured the output pin with scope, and the led is on for 1,5us.
There is 2 instruction in the main loop, which need 8 clock.


What's wrong?

Please help me.

Regards, István
Mike Walne



Joined: 19 Feb 2004
Posts: 1785
Location: Boston Spa UK

View user's profile Send private message

PostPosted: Thu May 10, 2012 11:24 am     Reply with quote

Have you looked at the assembly listing to see how many instructions are in your loop?

Have you counted two machine cycles for the jump?

Have you checked the OSCTUNE register to see if the PLLEN bit is actually being set?

To me, it looks like you are not actually setting the PLL.

Mike
pisti66



Joined: 03 Jun 2011
Posts: 7

View user's profile Send private message

PostPosted: Fri May 11, 2012 2:17 am     Reply with quote

Hello,

You are right. I counted the jump only with 1 instruction cycle.
Anyway, the chip operates at 8 MHz.

Regards, István
Ttelmah



Joined: 11 Mar 2010
Posts: 19552

View user's profile Send private message

PostPosted: Fri May 11, 2012 3:02 am     Reply with quote

Critical question - compiler version?.

CCS, have two different 'routes' to setting the PLL, on chips with software setup like this. The first is:
Code:

#use delay(clock=32MHz, internal=8MHz)

and the second is using the 'setup_oscillator' function as you show.

Annoyingly, which one works, changes with compiler version.... :(

My 'system', is simple. Try each, and just look at the first few lines of the listing file, to see if the bit does get set.

So, try the #use delay version, and see if it works for your compiler (get rid of the setup_oscillator version).

Best Wishes
pisti66



Joined: 03 Jun 2011
Posts: 7

View user's profile Send private message

PostPosted: Fri May 11, 2012 4:01 am     Reply with quote

Hello,

My compiler version is 4.130 .
I removed the setup_oscillator function and changed the "#use delay" line to the suggested, and it works.

Many thanks.

Regards, István
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