PIC24F - Oscillator speed verification.

Status
Not open for further replies.

willcharlton

Newbie level 5
Joined
Mar 16, 2011
Messages
8
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Location
St. Paul, MN
Activity points
1,356
I am using a PIC24FJ64GA004 on an explorer 16 dev board.

My config bits are:
Code:
_CONFIG1(JTAGEN_OFF & GCP_OFF & GWRP_OFF & BKBUG_ON & COE_OFF & ICS_PGx1 & FWDTEN_OFF & WINDIS_OFF) 
_CONFIG2( IESO_OFF & SOSCSEL_SOSC & WUTSEL_FST & FNOSC_PRIPLL & FCKSM_CSDCMD & OSCIOFNC_OFF & IOL1WAY_OFF & I2C1SEL_PRI & POSCMOD_XT)

...set up for XT oscillator with 4xPLL on an 8 MHz crystal oscillator.

In order to verify that the device is indeed running at 32MHz, I set up the following experiment to verify the speed:
Code:
   while(1)
   {
      PORTBbits.RB2 = 1;
      PORTBbits.RB2 = 0;
   }

When I put my oscilloscope probe on the RB2, the measurement was at 4MHz. I viewed the disassembly break-down and found that the compiler executed the code in the following fashion:
Code:
  444A  A842CA     bset.b 0x02ca,#2
  444C  A942CA     bclr.b 0x02ca,#2
125:                  }   
  444E  37FFFD     bra 0x00444a

According to the Datasheet, a bset.b, a bclr.b and a bra takes 4 instr cycles - 2 cycles for the bset.b and bclr.b and 2 cycles for the bra.

Since, FOSC = 32MHz, FCY = FOSC/2 = 16MHz and the reading on the pin should be FCY/(#cycles for operation). So the output frequency on PORTBbits.RB2 should be 4 MHz.

It appears as though everything is working, but only if I've done my math and config bits correctly.

Does this seem right to you? Thoughts?

Thanks!
 

PORTBbits.RB2 = 1;
PORTBbits.RB2 = 0;

is not safe and probably don't work properly (specialy if speed is high),
instead use :

LATBbits.LATB2 = 1;
LATBbits.LATB2 = 0;
 
Last edited:
Status
Not open for further replies.

Similar threads

Cookies are required to use this site. You must accept them to continue using the site. Learn more…