Configure PIC24E to run at 70 MIPS


In this article we give an example on how to configure a PIC24EP to run at its maximum performance of 70 MIPS, using internal FRC or external 8 MHz crystal. Using FRC is advantageous in case you want to minimize circuit components, or want to use the two pins RA2, RA3, which are consumed by the external crystal otherwise. It is not quite suitable when more precise timing is needed (though some tuning is possible) such as when using asynchronous communication. Using an external oscillator might be a better choice.

In this simple example, we verify the clock swtich visually via the LED blink speed. In case you are curious whether the PIC24EP is running at 70 MIPS as advertised, one way to verify is to set up a timer that sends out a toggle output. Then you can measure the period using an oscilloscope.

If a scope is not available, a crude way is to toggle an LED with timer output. You can set the blink speed that can be measured visually, say, 1 Hz. Then compare it with the second count on your watch. The code below shows how to set up timer1 for such purpose.

// global variables
volatile unsigned int msc;
// -------- timer functions ----------------
void initT1() // Initialize Timer 1 to interrupt every 1 ms
    T1CON = 0x8020 ; 		// Internal Clock (FOSC/2)=70MHZ, 1:64 prescale
    PR1   = 1094;        //0.001/(tcy*64) where tcy = 1/70M
    TMR1  = 0x0000 ;
     msc = 0;
    _T1IF = 0;
    _T1IE = 1;  


void __attribute__((interrupt, auto_psv)) _T1Interrupt(void)
// Timer 1 interrupt every 1 mS
    if (msc>1000)   {  // blink LED each second
        LEDB = !LEDB;  
        msc = 0;

    _T1IF = 0;

Note that we actually set interrupt period of timer1 to 1 milliseconds, and toggle LED every 1000 interrupts. Do not forget to put initT1() function into main().

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s