PIC32MX795F512L doesn't working on my board though it's getting programed

Hello everyone ! 
  
I am trying to program PIC32MX795F512L on by own board using PICKIT3. The schematic of the board is attached.  

schematic.jpg

I am getting the following error when I select the programmer.  
  
PICkit 3 detected 
Connecting to PICkit 3… 
Running self test… 
Self test passed 
Firmware Suite Version… 01.25.10 
Firmware type…PIC32MX 
PICkit 3 Connected. 
Target Detected 
Target Device ID (0000e000) does not match expected Device ID (04307053). 
  
I can see that the PIC is sending out some non-zero bits through oscilloscope on the PGD2 pin, and it is consistent over runs. Still MPLAB is giving the above all zero id error. 
  
Also, if I program in release mode, I am getting success as mentioned below… but the pic is not operational. I have tried in two separate boards but with no luck. 
Programming…Programming/Verify complete 
  
My configuration bits are as follows 
  
#ifndef OVERRIDE_CONFIG_BITS            
#pragma config UPLLEN   = ON            // USB PLL Enabled    
#pragma config FPLLMUL  = MUL_20        // PLL Multiplier    
#pragma config UPLLIDIV = DIV_2         // USB PLL Input Divider    
#pragma config FPLLIDIV = DIV_2         // PLL Input Divider    
#pragma config FPLLODIV = DIV_1         // PLL Output Divider    
#pragma config FPBDIV   = DIV_1         // Peripheral Clock divisor    
#pragma config FWDTEN   = OFF           // Watchdog Timer     
#pragma config WDTPS    = PS1           // Watchdog Timer Postscale    
#pragma config FCKSM    = CSDCMD        // Clock Switching & Fail Safe Clock Monitor    
#pragma config OSCIOFNC = OFF           // CLKO Enable    
#pragma config POSCMOD  = HS            // Primary Oscillator    
#pragma config IESO     = OFF           // Internal/External Switch-over    
#pragma config FSOSCEN  = OFF           // Secondary Oscillator Enable    
#pragma config FNOSC    = PRIPLL        // Oscillator Selection    
#pragma config CP       = OFF           // Code Protect 
#pragma config BWP      = OFF           // Boot Flash Write Protect    
#pragma config PWP      = OFF           // Program Flash Write Protect    
#pragma config ICESEL   = ICS_PGx2      // ICE/ICD Comm Channel Select    
#pragma config DEBUG    = OFF           // Debugger Disabled for Starter Kit             
#endif // OVERRIDE_CONFIG_BITS 
  
Another observation: 
When I check OSC2 pin through oscilloscope, I see an oscillation@7MHz instead of 8MHz. Any idea on why the frequency is decreased will be of great help. I have attached a snapshot of the board too for your reference. 

1.jpg

2.jpg


Thanks in advance.

Much appreciated.

Pickit3

By default the pickit software will not burn the flash memory unless the board ID and the firmware file ID match. Your 2 ID’s are quite different.

I am mostly a PIC24 user and the internal oscillators default to somewhere in the 7.x MHz range. 

mismatched id’s

I know even less then ggallant about those chips.  But it looks to me like the bad id is in the hex file.  I would check the compiler settings for device type,  this could also explain setting the target to a default speed.

Good Luck,

RG