Skip to main content
2 of 3
edited tags
user avatar
user avatar

How to configure PIC24H for 20MHz external oscillator?

The basic addition of a 20MHz external oscillator is becoming much more painful that I thought. I've got a breadboard setup with a DIP package of a PIC24HJ128GP502. Nothing fancy, and it has been able to blink an LED with the internal FRC for the clock. My configuration bits are set in code as follows:

// General Segment code-protection configuration: // leave code protection off, GSS_OFF // disable code protection, GCP_OFF // disable write protection, GWRP_OFF _FGS(GSS_OFF & GCP_OFF & GWRP_OFF) // OSCillator SELection: // Primary oscillator (XT, HS, EC) w/ PLL FNOSC_PRIPLL // enable two-speed oscillator startup IESO_ON _FOSCSEL(FNOSC_PRIPLL & IESO_ON) // OSCillator configuration: // enable clock switching but not monitoring, FCKSM_CSECMD // allow the RPn pins to be continually remapped, IOL1WAY_OFF // leave OSC2 pin as clock pin (not digital I/O) OSCIOFNC_OFF // High-Speed (10-32MHz crystal) Oscillator, POSCMD_HS _FOSC(FCKSM_CSECMD & IOL1WAY_OFF & OSCIOFNC_OFF & POSCMD_HS) // WatchDog Timer configuration: // disable the watchdog timer, FWDTEN_OFF _FWDT(FWDTEN_OFF) // Power-On-Reset configuration: // map I2C pins to SDA1/SCL1, ALTI2C_OFF // use the smallest power-on-reset value of 2ms, FPWRT_PWR2 _FPOR(ALTI2C_OFF & FPWRT_PWR2) // Debugger configuration: // JTAG is enabled, JTAGEN_ON // communicate on PGC1/EMUC1 and PGD1/EMUD1, ICS_PGD1 _FICD(JTAGEN_ON & ICS_PGD1) int main(void) { // STAYS HERE FOREVER, NEVER LOCKS! while (!OSCCONbits.LOCK); // wait for the PLL to lock ... 

The only knobs (or places I can go wrong that I know of) are in _FOSCSEL() and _FOSC(). I've tried nearly every iteration of those configuration bits that made any bit of sense (even just a wee bit..ok even the ones that made no sense). I've also tried programming it in debug mode as well as release mode.

Environment: MPLab v8.88.00.00, C30 compiler

Relevant Research:

Circuit: 3.3V power supply the middle pin of the crystal goes to GND, the outer two pins go to OSC1 and OSC2, there is a 1MOhm resistor connecting each of the outer two pins for the 3-pin oscillator (for stability)

tarabyte
  • 3.2k
  • 10
  • 50
  • 74