I have been working on a PIC24FJ128GA310 development board for for some time now and recently got a PCB made. If I try to move my code into the new board all timing related math and functions are failing on HS oscillator even the UART lines wont work at the desired baud rate. The device does not run when I put it to XT oscillator.
After some debugging, I found out that the PLL module wasn't getting locked. I have a 8 MHz oscillator with PRIPLL config bit on. So, instead of having FCY of ((8*4)/2) I have (8/2). The case is true if I have POSCMD as HS. But if I put POSCMD as XT, the controller just wont work at all. I am unable to debug the code with POSCMD as XT, IDE says device is not ready for debugging as some config bit is incorrect or the emulator is not wired properly. I know for sure the pickit3 connections are fine because when I change the POSCMD to HS or put the device to work on internal oscillator I am able to get into debug mode.
I tried doing a while(OSCCONbits.LOCK == 0); at the starting to check if the PLL module start-up timer is satisfied. But it never out of that loop. I also tried to start up with internal oscillator and then switch to external oscillator and PLL without much luck.
After some research online I got to this thread, which says the capacitor on Vcore pin should be causing the problem. I changed that capacitor to a through hole 10uF tantalum. But still the issue remains unresolved.
Here is the schematic and layout of relevant sections.
Oscillator Circuit
Vcore pin
Layout of both. Bottom Layer
I have run out of options and need some help. Please suggest any other course of action. Thanks for any help.