Using 16F87 Internal oscillator

General discussion on mikroC.
Post Reply
Author
Message
Jimbotnik
Posts: 42
Joined: 20 Jan 2010 14:27

Using 16F87 Internal oscillator

#1 Post by Jimbotnik » 09 Dec 2010 22:42

Hello,

I have a project which toggles the state of PORTB every ~0.9ms by using the CCP1 feature of the 16F87 chip.

The project was making use of the external 8Mhz oscillator (on the EasyPic 5 developement board) but recently I tried to adapt the program to use the internal oscillator.

Now PORTB toggles state every ~3.5ms.

What am I missing?

Here are the settings I used originally:

Code: Select all

Oscillator:  HS 8 MHz  (HS_OSC config bit set)

T1CON = 0x01;

PIE1.TMR1IE = 0;
PIR1.TMR1IF = 0;       

TMR1H = 0x00;               // Initialize Timer1 register
TMR1L = 0x00;

PIE1.CCP1IE  = 0;           // enable CCP1 interrupt

CCP1CON = 0x08;            
CCPR1H = 0x06;             // Times to match to
CCPR1L = 0xF2;

And this is how I tried to update the settings:

Code: Select all

INTRC_IO Config bit set
HS_OSC config bit  NOT set

OSCCON = 0x7C;   // Set to select 8MHz internal RC Oscillator
                         // Device running primary system clock
                         // Stable frequency
                         // Oscillator mode 

T1CON = 0x25;    //  Set to prescale 1:4 (as clock will be FOsc / 4)
                        // Timer 1 oscillator shut off (as not used)
                        // Do not synchronise external clock input
                        // Internal Clock (FOsc / 4)
                        // Enable Timer1

PIE1.TMR1IE = 0;
PIR1.TMR1IF = 0;           // clear TMR1IF

TMR1H = 0x00;               // Initialize Timer1 register
TMR1L = 0x00;

CCP1CON = 0x08;            
CCPR1H = 0x06;             // Times to match to
CCPR1L = 0xF2;

Any guidance is greatly appreciated!

Jimbo

Jimbotnik
Posts: 42
Joined: 20 Jan 2010 14:27

Re: Using 16F87 Internal oscillator

#2 Post by Jimbotnik » 11 Dec 2010 21:35

Hello again,

I've sorted it - I was just a mistake with my scaling factor (it didn't need one as I had already accomodated the scaling previously)

Lesson learned: Read my own notes! :)

So if anyone is interested, the code above is the correct way of using the internal oscillator instead of the external oscillator.

Jimbo

Post Reply

Return to “mikroC General”