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

Pic18F4520 Osc questions ~OR~ Brain farts! HELP!

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







Pic18F4520 Osc questions ~OR~ Brain farts! HELP!
PostPosted: Thu Aug 03, 2006 5:36 pm     Reply with quote

Hi all,

I've got the major case of brain farts here. Question about osc fuses...

Setup: CCS Software Proto Board w/20Mhz crystal, pic18f4520

My WORKING fuses etc for 20mhz is

#fuses HS

This says to me, "High Speed Crystal/Resonator" or 20mhz

~NOW~

I want to go faster!

#1. I could use the internal 8mhz osc with 4x PLL = 32Mhz. What fuses would I need? All I can find is the INTRC_IO for 8mhz, how do I apply the 4x?

Thanks in advance!

~Kam (^8*
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Thu Aug 03, 2006 5:40 pm     Reply with quote

Quote:
What fuses would I need? All I can find is the INTRC_IO for 8mhz.

Scroll down in the 18F4520.h file until you get to the setup_oscillator()
section.
Guest








PostPosted: Thu Aug 03, 2006 6:30 pm     Reply with quote

PCM programmer wrote:

Scroll down in the 18F4520.h file until you get to the setup_oscillator()
section.


Thanks for the pointer! Makes more sense...

NOW I still have an issue!

Here is my code:

Code:

#include <18F4520.h>

#device adc=10
#FUSES NOWDT                    //No Watch Dog Timer
#FUSES NOPROTECT                //Code not protected from reading
#FUSES BROWNOUT                 //Reset when brownout detected
#FUSES BORV25                   //Brownout reset at 2.5V
#FUSES NOPUT                    //No Power Up Timer
#FUSES NOCPD                    //No EE protection
#FUSES STVREN                   //Stack full/underflow will cause reset
#FUSES NODEBUG                  //No Debug mode for ICD
#FUSES NOLVP                    //No low voltage prgming, B3(PIC16) or B5(PIC18) used for I/O
#FUSES NOWRT                    //Program memory not write protected
#FUSES NOWRTD                   //Data EEPROM not write protected
#FUSES IESO                     //Internal External Switch Over mode enabled
#FUSES FCMEN                    //Fail-safe clock monitor enabled
#FUSES PBADEN                   //PORTB pins are configured as analog input channels on RESET
#FUSES NOWRTC                   //configuration not registers write protected
#FUSES NOWRTB                   //Boot block not write protected
#FUSES NOEBTR                   //Memory not protected from table reads
#FUSES NOEBTRB                  //Boot block not protected from table reads
#FUSES NOCPB                    //No Boot Block code protection
#FUSES LPT1OSC                  //Timer1 configured for low-power operation
#FUSES MCLR                     //Master Clear pin enabled
#FUSES NOXINST                  //Extended set extension and Indexed Addressing mode disabled (Legacy mode)

//#FUSES HS                       //20mhz mode
#fuses  INTRC_IO                // internal 8mhz osc

#use delay(clock=32000000)
//#use delay(clock=8000000)

void main()
{
    setup_oscillator(OSC_8MHZ|OSC_INTRC|OSC_PLL_ON);

    output_low(PIN_B0);

    while(1)
    {
        delay_ms(500);
        output_toggle(PIN_B0);
    }
}


I think I have the settings correct(?) The delay is not working correctly.
Also, I'm assuming in the #use delay I enter the NEW speed(32000000), yes?

Also, the manual (CCS) says that using a #fuses INTRC_IO with a valid #use delay, this step (setup_osc) is done automagically...

Well, thanks again for the help!

~Kam (^8*
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Thu Aug 03, 2006 7:59 pm     Reply with quote

What is your version of the compiler ? Here is the oscillator setup code
generated by PCH vs. 3.249 for your program. It looks like it should
work.
Code:

...  setup_oscillator(OSC_8MHZ|OSC_INTRC|OSC_PLL_ON); 
0048:  MOVLW  72  // Setup for 8 MHz with internal oscillator
004A:  MOVWF  FD3   // OSCCON register

004C:  MOVLW  40  // Enable PLL for IntOsc
004E:  MOVWF  F9B   // OSCTUNE register
0050:  MOVF   FD3,W  // Read OSCCON register
Guest








PostPosted: Thu Aug 03, 2006 9:11 pm     Reply with quote

PCM Progammer,

Here is my listing:

Code:

....................     setup_oscillator(OSC_8MHZ|OSC_INTRC|OSC_PLL_ON); 
0044:  MOVLW  72
0046:  MOVWF  FD3
0048:  CLRF   F9B
004A:  MOVF   FD3,W


Here's yours

Code:

...  setup_oscillator(OSC_8MHZ|OSC_INTRC|OSC_PLL_ON);
0048:  MOVLW  72  // Setup for 8 MHz with internal oscillator
004A:  MOVWF  FD3   // OSCCON register

004C:  MOVLW  40  // Enable PLL for IntOsc  <---- MISSING FROM MINE!

004E:  MOVWF  F9B   // OSCTUNE register
0050:  MOVF   FD3,W  // Read OSCCON register


I'm missing a line!

My compiler(s) version is 3.234.

I'm starting to feel sad now... Sad Sad

~Kam
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Thu Aug 03, 2006 10:33 pm     Reply with quote

Fix it by adding the two lines shown below.
Code:

#byte OSCTUNE = 0xF9B    // Add this line

void main()
{
setup_oscillator(OSC_8MHZ|OSC_INTRC|OSC_PLL_ON);

OSCTUNE = 0x40;   // PLL ON      Add this line

Guest








PostPosted: Fri Aug 04, 2006 9:53 am     Reply with quote

PCM programmer wrote:
Fix it by adding the two lines shown below.
Code:

#byte OSCTUNE = 0xF9B    // Add this line

void main()
{
setup_oscillator(OSC_8MHZ|OSC_INTRC|OSC_PLL_ON);

OSCTUNE = 0x40;   // PLL ON      Add this line



PCM Programmer,

I added the lines your suggested, and the asm looks right, but there is still an issue with the time! It's still taking approx 2 sec for the "delay_ms(500)" command!

Any Thoughts?

BTW, thanks for all your help!

~Kam (^8*

Code:

0000:  GOTO   002C
....................  #include <18F4520.h>
....................  //////// Standard Header file for the PIC18F4520 device //////////////// 
.................... #device PIC18F4520 
.................... #list 
.................... 
....................   
.................... #device adc=10 
.................... #FUSES NOWDT                    //No Watch Dog Timer 
.................... #FUSES NOPROTECT                //Code not protected from reading 
.................... #FUSES BROWNOUT                 //Reset when brownout detected 
.................... #FUSES BORV25                   //Brownout reset at 2.5V 
.................... #FUSES NOPUT                    //No Power Up Timer 
.................... #FUSES NOCPD                    //No EE protection 
.................... #FUSES STVREN                   //Stack full/underflow will cause reset 
.................... #FUSES NODEBUG                  //No Debug mode for ICD 
.................... #FUSES NOLVP                    //No low voltage prgming, B3(PIC16) or B5(PIC18) used for I/O 
.................... #FUSES NOWRT                    //Program memory not write protected 
.................... #FUSES NOWRTD                   //Data EEPROM not write protected 
.................... #FUSES IESO                     //Internal External Switch Over mode enabled 
.................... #FUSES FCMEN                    //Fail-safe clock monitor enabled 
.................... #FUSES PBADEN                   //PORTB pins are configured as analog input channels on RESET 
.................... #FUSES NOWRTC                   //configuration not registers write protected 
.................... #FUSES NOWRTB                   //Boot block not write protected 
.................... #FUSES NOEBTR                   //Memory not protected from table reads 
.................... #FUSES NOEBTRB                  //Boot block not protected from table reads 
.................... #FUSES NOCPB                    //No Boot Block code protection 
.................... #FUSES LPT1OSC                  //Timer1 configured for low-power operation 
.................... #FUSES MCLR                     //Master Clear pin enabled 
.................... #FUSES NOXINST                  //Extended set extension and Indexed Addressing mode disabled (Legacy mode) 
....................   
.................... //#FUSES HS                       //20mhz mode 
.................... #fuses  INTRC_IO                // internal 8mhz osc 
....................   
.................... #use delay(clock=32000000) 
0004:  CLRF   FEA
0006:  MOVLW  07
0008:  MOVWF  FE9
000A:  MOVF   FEF,W
000C:  BZ    0028
000E:  MOVLW  0A
0010:  MOVWF  01
0012:  CLRF   00
0014:  DECFSZ 00,F
0016:  BRA    0014
0018:  DECFSZ 01,F
001A:  BRA    0012
001C:  MOVLW  5F
001E:  MOVWF  00
0020:  DECFSZ 00,F
0022:  BRA    0020
0024:  DECFSZ FEF,F
0026:  BRA    000E
0028:  GOTO   005E (RETURN)
.................... //#use delay(clock=8000000) 
....................   
.................... #byte OSCTUNE = 0xF9B 
....................   
.................... void main() 
.................... { 
002C:  CLRF   FF8
002E:  BCF    FD0.7
0030:  CLRF   FEA
0032:  CLRF   FE9
0034:  MOVF   FC1,W
0036:  ANDLW  C0
0038:  IORLW  0F
003A:  MOVWF  FC1
003C:  MOVLW  07
003E:  MOVWF  FB4
0040:  MOVF   FB4,W
0042:  BCF    FA1.6
....................     setup_oscillator(OSC_8MHZ|OSC_INTRC|OSC_PLL_ON); 
0044:  MOVLW  72
0046:  MOVWF  FD3
0048:  CLRF   F9B
004A:  MOVF   FD3,W
....................     OSCTUNE = 0x40;   // PLL ON 
004C:  MOVLW  40
004E:  MOVWF  F9B
....................   
....................     output_low(PIN_B0); 
0050:  BCF    F93.0
0052:  BCF    F8A.0
....................   
....................     while(1) 
....................     { 
....................         delay_ms(500); 
0054:  MOVLW  02
0056:  MOVWF  06
0058:  MOVLW  FA
005A:  MOVWF  07
005C:  BRA    0004
005E:  DECFSZ 06,F
0060:  BRA    0058
....................         output_toggle(PIN_B0); 
0062:  BCF    F93.0
0064:  BTG    F8A.0
....................     } 
0066:  BRA    0054
.................... } 
.................... 
0068:  SLEEP

Configuration Fuses:
   Word  1: C800   IESO FCMEN INTRC_IO
   Word  2: 1E1F   BROWNOUT NOWDT BORV25 NOPUT WDT32768
   Word  3: 8700   PBADEN CCP2C1 LPT1OSC MCLR
   Word  4: 0081   STVREN NODEBUG NOLVP NOXINST RESERVED
   Word  5: C00F   NOPROTECT NOCPD NOCPB
   Word  6: E00F   NOWRT NOWRTD NOWRTC NOWRTB
   Word  7: 400F   NOEBTR NOEBTRB
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Fri Aug 04, 2006 2:41 pm     Reply with quote

This thread on the Microchip forum offers some help:
http://forum.microchip.com/tm.aspx?m=145909&mpage=1

Based on that advice, try the following setup code. See if it works.
Code:

#byte OSCCON = 0xFD3 
#byte OSCTUNE = 0xF9B

void main()
{
//    setup_oscillator(OSC_8MHZ|OSC_INTRC|OSC_PLL_ON);

OSCCON = 0x70;   // 8 MHz, Primary Oscillator
OSCTUNE = 0x40;  // PLL ON


Guest








Success!
PostPosted: Sat Aug 05, 2006 11:53 am     Reply with quote

PCM Programmer,

Thanks for all the help! I came across the SAME thread this morning (did not read your message), changed the 0x72 to 0x70, and with your earlier suggestions, it works!

Code:
#fuses  INTRC_IO                // internal 8mhz osc
#use delay(clock=32000000)

#byte OSCTUNE = 0xF9B

void main()
{
    setup_oscillator(OSC_8MHZ|OSC_NORMAL|OSC_PLL_ON);
    OSCTUNE = 0x40;   // PLL ON

    output_low(PIN_B0);

    while(1)
    {
        delay_ms(500);
        output_toggle(PIN_B0);
    }
}


All I changed in the OR's was the OSC_NORMAL (0x00 vs. 0x02).

I was coming to report my new findings to the board, but alas, you beat me to it!

Again, thanks for all your help.

~Kam (^8*
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