Question

I'm writing a code for 2 minutes delay. I used Mikro C pro for PIC compiler. I'm Using PIC18F4550

To calculate the timer delay I used the Timer-Calculator

Now, my doubt is which Clock frequency to use for the delay? Internal clock or should I provide an external clock?

void InitTimer0(){   
  T0CON  = 0x86;
  TMR0H  = 0x67;
  TMR0L  = 0x69;
  GIE_bit    = 1;
  TMR0IE_bit     = 1;
}

void Interrupt(){  //1 Second delay
  if (TMR0IF_bit){ 
    TMR0IF_bit = 0;
    TMR0H    = 0x67;
    TMR0L    = 0x69;
    //Enter your code here
    count++;
  }
}
...
void main() { 
     if(count == 120) {      //120 Seconds
         //My Code
     }
}

Here in this code, I calculated for 20 MHz MCU Clock Frequency. Is there an internal clock for PIC18F4550?

I'm going to implement this on a PIC Development board that contains 20 MHz Oscillator built on the board?

Was it helpful?

Solution

The PIC18F4550's internal oscillator pegs out a 8 MHz. To use a delay routine calibrated for 20 MHz, you'll have to use an external oscillator. So you will either have to write a routine for 8 MHz or setup an external oscillator.

Section 2 of the datasheet describes the function and setup of the clock, including how to configure the chip for an external oscillator.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top