• AVR Freaks

Helpful ReplyInternal oscillator for PIC18F4550

Author
stofanel
New Member
  • Total Posts : 22
  • Reward points : 0
  • Joined: 2010/03/19 23:02:25
  • Location: 0
  • Status: offline
2011/04/30 16:01:19 (permalink)
0

Internal oscillator for PIC18F4550

I am trying to use the internal oscillator as the CPU clock.  According to the datasheet, the internal oscillator is accessed through the CONFIG1H register, and the OSSCON register. This is the code:

#include <p18f4550.h>

#pragma config WDT = OFF
#pragma config FOSC = INTOSC_EC    // internal oscillator, RA6 = clock out
#pragma config MCLRE = OFF        // MCLR is disabled



void main(void)
{


    OSCCON = 0xF2; // internal oscillator, 8MHz
    TRISD = 0;
   
    while (1);
       

}

When FOSC = INTOSC_EC, the actual value for FOSC<3:0> = b'1001', which accesses the internal clock and sets RA6 as a Fosc/4 pin.
When OSSCON = b'11110010', the internal clock is driven at 8MHz, with SCS<1:0> = b'10', which activates the internal oscillator.

According to this little program, the output to RA6 should be a square wave driven at Fosc/4, which is 2 MHz.

The actual output that I see on my oscilloscope is a 2 MHz waveform that turns on and off every 8 miliseconds. For 8ms I get a perfectly nice clock signal, but then it shuts off for the next 8ms, and the  process repeats again. I was thinking that perhaps the power supply was erratic, but this is not the case. I have an even 5V power supply. Also, I have connected 1uF capacitors across Vdd and Vss pins to prevent any voltage spikes from forming.

The watchdog timer is disabled, so there should be no reason why the clock stops every 8ms. Is there any other reason why the internal clock behaves like this?
#1
hexreader
Super Member
  • Total Posts : 1039
  • Reward points : 0
  • Joined: 2008/05/04 03:06:55
  • Location: England
  • Status: online
Re:Internal oscillator for PIC18F4550 2011/04/30 16:38:40 (permalink) ☄ Helpful
+2 (1)
You have only specified three of the many config settings.
 
Most importantly, you have not disabled LVP.
 
Try this test program:
 

// test
 
#include <p18f4550.h>
 
//#pragma config FOSC = HSPLL_HS  //10MHz x 4 gives 40MHz clock
#pragma config FOSC = INTOSC_EC    //internal oscillator
#pragma config PLLDIV = 4   //divide by 5 to give 4MHz to PLL
#pragma config FCMEN = OFF   //no fail safe clock monitor
#pragma config IESO = OFF   //oscillator switchover disabled
#pragma config PWRT = ON           //oscillator power up timer enabled (release version only)
#pragma config BOR = OFF      //hardware brown out reset
#pragma config WDT = OFF   //watchdog timer disabled
#pragma config MCLRE = ON    //MCLR pin enabled
#pragma config LPT1OSC = ON  //timer1 low power operation
#pragma config PBADEN = OFF   //portB 0to 4 digital - not analogue
#pragma config LVP = OFF     //low voltage programming disabled
#pragma config CCP2MX = OFF  //portc1 = CCP2
#pragma config XINST = OFF         //do not allow PIC18 extended instructions
#pragma config  STVREN = ON         //stack overflow will cause reset
#pragma config CP0 = OFF      //code protection block 0
#pragma config CP1 = OFF
#pragma config CP2 = OFF
#pragma config CP3 = OFF
#pragma config CPB = OFF      //code protection boot block
#pragma config CPD = OFF      //code protection data EEPROM
#pragma config WRT0 = OFF      //write protection block 0
#pragma config WRT1 = OFF
#pragma config WRT2 = OFF
#pragma config WRT3 = OFF
#pragma config WRTB = OFF      //write protection boot block
#pragma config WRTC = OFF      //write protection configuration register
#pragma config WRTD = OFF      //write protection data EEPROM
#pragma config EBTR0 = OFF      //table read protection block 0
#pragma config EBTR1 = OFF
#pragma config EBTR2 = OFF
#pragma config EBTR3 = OFF
#pragma config EBTRB = OFF      //table read protection boot block
 
void delay1s(void);  //prototype
 
void main(void) {
    TRISA = 0;      // all output (except RA7 not implemented)
    TRISB = 0;      // all output
    TRISC = 0;      // all output (except RC3 not implmented, RC4,5 only input or USB
    TRISD = 0;      // all output
    TRISE = 0;      // all output (only RE0, RE1, RE2 exist)
    OSCCON = 0xF2;  // internal oscillator, 8MHz
 
    while (1)
    {
        delay1s();
        LATA = 0x55;    // test pattern
        LATB = 0x55;    // test pattern
        LATC = 0x55;    // test pattern
        LATD = 0x55;    // test pattern
        LATE = 0x55;    // test pattern
        delay1s();
        LATA = 0xaa;    // test pattern
        LATB = 0xaa;    // test pattern
        LATC = 0xaa;    // test pattern
        LATD = 0xaa;    // test pattern
        LATE = 0xaa;    // test pattern
    }
}
 
// adjust numbers to give about 1 second delay
void delay1s(void)
{
int m,n;
   
    for (m=0;m<200;m++)
    {
        for (n=0;n<200;n++);
    }
}
 

post edited by hexreader - 2011/04/30 16:40:39
#2
stofanel
New Member
  • Total Posts : 22
  • Reward points : 0
  • Joined: 2010/03/19 23:02:25
  • Location: 0
  • Status: offline
Re:Internal oscillator for PIC18F4550 2011/04/30 20:19:37 (permalink)
0
Apparently I need to study the datasheets in more detail ...

turning the LVP = OFF did the trick.
#3
Jump to:
© 2020 APG vNext Commercial Version 4.5