PIC32MX795F Oscillator Configuration Bit Assistance

Status
Not open for further replies.

micro9000

New Member
Hi everyone, I finally made the jump to a PIC32MX795F512H (64pin .5mm pitch LQFP) uC. I purchased this board from proto-advantage.com so I can prototype with a touch screen that I also purchased. I am also using MPLAB X 1.6 and C32.

The main problem I am experiencing is with the oscillator. Now before I go into detail, I rechecked the connections and I am confident I have them correct. However, upon programming the uC I get an error message stating that my configuration bits are incorrect.

Here is a picture of the error and circuit:

**broken link removed**
**broken link removed**

Code:
// DEVCFG3
// USERID = No Setting
#pragma config FSRSSEL = PRIORITY_7     // SRS Select (SRS Priority 7)
#pragma config FMIIEN = OFF             // Ethernet RMII/MII Enable (RMII Enabled)
#pragma config FETHIO = OFF             // Ethernet I/O Pin Select (Alternate Ethernet I/O)
#pragma config FCANIO = OFF             // CAN I/O Pin Select (Alternate CAN I/O)
#pragma config FUSBIDIO = ON            // USB USID Selection (Controlled by the USB Module)
#pragma config FVBUSONIO = ON           // USB VBUS ON Selection (Controlled by USB Module)

// DEVCFG2
#pragma config FPLLIDIV = DIV_2         // PLL Input Divider (4x Divider) Using 20MHz/4 = 5MHz
#pragma config FPLLMUL = MUL_16         // PLL Multiplier (16x Multiplier) 5MHz * 16 = 80Mhz
#pragma config UPLLIDIV = DIV_5         // USB PLL Input Divider (5x Divider)
#pragma config UPLLEN = OFF             // USB PLL Enable (Disabled and Bypassed)
#pragma config FPLLODIV = DIV_2         // System PLL Output Clock Divider (PLL Divide by 1) => 80Mhz/1 => 80MHz


// DEVCFG1
#pragma config FNOSC = PRIPLL           // Oscillator Selection Bits (Primary Osc w/PLL (XT+,HS+,EC+PLL))
#pragma config FSOSCEN = OFF            // Secondary Oscillator Enable (Disabled)
#pragma config IESO = OFF                // Internal/External Switch Over (Disabled)
#pragma config POSCMOD = HS             // Primary Oscillator Configuration (HS osc mode)
#pragma config OSCIOFNC = OFF           // CLKO Output Signal Active on the OSCO Pin (Disabled)
#pragma config FPBDIV = DIV_1           // Peripheral Clock Divisor (Pb_Clk is Sys_Clk/1)
#pragma config FCKSM = CSDCMD           // Clock Switching and Monitor Selection (Clock Switch Disable, FSCM Disabled)
#pragma config WDTPS = PS1              // Watchdog Timer Postscaler (1:1)
#pragma config FWDTEN = OFF              // Watchdog Timer Enable (WDT Enabled)

// DEVCFG0
#pragma config DEBUG = OFF              // Background Debugger Enable (Debugger is disabled)
#pragma config ICESEL = ICS_PGx1        // ICE/ICD Comm Channel Select (ICE EMUC1/EMUD1 pins shared with PGC1/PGD1)
#pragma config PWP = OFF                // Program Flash Write Protect (Disable)
#pragma config BWP = OFF                // Boot Flash Write Protect bit (Protection Disabled)
#pragma config CP = OFF                 // Code Protect (Protection Disabled)

I've done some research and narrowed down which configuration bit is causing the issue:

"Programming/Verify complete
The target device is not ready for debugging. Please check your configuration bit settings and program the device before proceeding.".

This line of code is causing the issue.
Code:
#pragma config FNOSC = PRIPLL           // Oscillator Selection Bits (Primary Osc w/PLL (XT+,HS+,EC+PLL))

This most likely means this is a problem with my resonator. I hope it isn't placed too far from the pins. The data sheet recommends 12mm distance. I tried putting it closer and soldering short wires to another resonator, but it still didn't work.
_______________________________________

So my questions are as follows:

1. Is it the resonator causing the issue?
2. If I have to use the internal oscillator for the PIC32, is it really that much worse compared to and external part?
3. What other actions should I take? What suggestions can you make? What issues do you see? etc..

Thanks for anyone taking the time to reply and assist me with this matter.

Note: The PIC32 does blink the LED I have and operates properly when using the internal oscillator and not the PRIPLL config (albeit slower than expected since I don't have the proper configuration for the internal oscillator setup).
 
Last edited:
The internal osc should work just fine. Of of the few things it will not work for is generating TV video signals.

I am not using 32 bitters but you have

#pragma config DEBUG = OFF

It seem logical that you want this to ON for debugging?
 
I actually had that turned off when I prototyped with a PIC32MX250F128B using a 20MHz resonator and I received no errors and everything worked just fine at 40MHz. The PIC32MX795F config settings are a bit different, but 90% of it is the same, including that debug line. Also, just to be sure, I tried with it "ON" with the PIC32MX795F and the problem still persists. The project does run successfully without the PRIPLL config set (FNOSC is changed), so I believe I am good to use the internal oscillator.

I plan to use UART with my project. I've read that an external oscillator is better suited for it, but then again, I think I've read that the internal oscillator of 32bit uC's may be a bit better then with other uCs. I'm not 100% on that.

Anyway, thank you for the response. I really wish it were something simple I overlooked (it probably still is). I have looked at a bunch of forum posts on a bunch of sites with similar issues and there really hasn't been a clear and cut fix for this issue (that I am aware of). I just don't want something like requiring an external oscillator to hold me back in anyway when I start to implementing my project. If you see anything else or find anything else out please let me know as I greatly appreciate the fact that you are taking the time to help me troubleshoot my project.
 
Last edited:
Probably just 9600 baud, maybe a bit faster. I only intend to send temperature information wirelessly, maybe also control a multi-color LED. I'm not sure about sending graphics information just yet (which I'm sure I'll need a much faster baud rate for). What do think the cutoff is for using an internal oscillator?
 
Last edited:
I figured it out! The cause of the PRIPLL bit raising a flag was caused by the ordering of this configuration:

Code:
#pragma config IESO = ON                // Internal/External Switch Over (Disabled)

The order matters! The code generator for MPLAB X places this below the oscillator bits. In the oscillator reference manual it mentions that you must set the internal switch over before configuring the oscillator control register.

Here is the final working configuration:

Code:
#pragma config IESO = ON                // Internal/External Switch Over (Disabled) <-- !!!! Must come first
// DEVCFG3
// USERID = No Setting
#pragma config FSRSSEL = PRIORITY_7     // SRS Select (SRS Priority 7)
#pragma config FMIIEN = OFF             // Ethernet RMII/MII Enable (RMII Enabled)
#pragma config FETHIO = OFF             // Ethernet I/O Pin Select (Alternate Ethernet I/O)
#pragma config FCANIO = OFF             // CAN I/O Pin Select (Alternate CAN I/O)
#pragma config FUSBIDIO = OFF            // USB USID Selection (Controlled by the USB Module)
#pragma config FVBUSONIO = OFF          // USB VBUS ON Selection (Controlled by Port Function)

// DEVCFG2
// Internal Oscillator uses base 8MHz oscillator
#pragma config FPLLIDIV = DIV_4         // PLL Input Divider (4x Divider) Using 8MHz/2 = 4MHz
#pragma config FPLLMUL = MUL_16         // PLL Multiplier (20x Multiplier) 4MHz * 20 = 80Mhz
//#pragma config UPLLIDIV = DIV_5         // USB PLL Input Divider (5x Divider)
#pragma config UPLLEN = ON            // USB PLL Enable (Disabled and Bypassed)
#pragma config FPLLODIV = DIV_1         // System PLL Output Clock Divider (PLL Divide by 1) => 80Mhz/1 => 80MHz


// DEVCFG1
#pragma config FNOSC = PRIPLL           // Oscillator Selection Bits (Primary Osc w/PLL (XT+,HS+,EC+PLL))
#pragma config FSOSCEN = OFF            // Secondary Oscillator Enable (Disabled)

#pragma config POSCMOD = HS             // Primary Oscillator Configuration (HS osc mode)
#pragma config OSCIOFNC = OFF           // CLKO Output Signal Active on the OSCO Pin (Disabled)
#pragma config FPBDIV = DIV_2           // Peripheral Clock Divisor (Pb_Clk is Sys_Clk/1)
#pragma config FCKSM = CSDCMD           // Clock Switching and Monitor Selection (Clock Switch Disable, FSCM Disabled)
#pragma config WDTPS = PS1              // Watchdog Timer Postscaler (1:1)
#pragma config FWDTEN = OFF              // Watchdog Timer Enable (WDT Enabled)

// DEVCFG0
#pragma config DEBUG = OFF              // Background Debugger Enable (Debugger is disabled)
#pragma config ICESEL = ICS_PGx1        // ICE/ICD Comm Channel Select (ICE EMUC1/EMUD1 pins shared with PGC1/PGD1)
#pragma config PWP = OFF                // Program Flash Write Protect (Disable)
#pragma config BWP = OFF                // Boot Flash Write Protect bit (Protection Disabled)
#pragma config CP = OFF                 // Code Protect (Protection Disabled)

Additionally, these USB configuration bits caused an issue was well. As you can see I changed the following:

Code:
#pragma config FUSBIDIO = OFF            // USB USID Selection (Controlled by the USB Module)
#pragma config FVBUSONIO = OFF          // USB VBUS ON Selection (Controlled by Port Function)
...
#pragma config UPLLIDIV = DIV_5         // USB PLL Input Divider (5x Divider)
#pragma config UPLLEN = ON            // USB PLL Enable (Disabled and Bypassed)

Woohoo! I'm going to look into the USB configuration bits a bit more, but at leas I am on the right track.

EDIT: Another interesting note is the PBCLK config:

Code:
#pragma config FPBDIV = DIV_2           // Peripheral Clock Divisor (Pb_Clk is Sys_Clk/1)

If I change it to "DIV_1" I get the same error message as above, but it works with DIV_2. I wonder why that is happening...

Also, when I try running the project while I have "delay.h" open it also throws the same error message as above.

EDIT2:

Unfortunately, the problem still persists, but now it seems that it is a bit random. Sometimes it runs and other times it doesn't. This is getting a bit more confusing now.
 
Last edited:
You should not see any problems with the internal clock at speeds normally used for RS232. The receiving UART resnycs on the start bit of each char.
 
Update:

I not longer get the error ""Programming/Verify complete
The target device is not ready for debugging. Please check your configuration bit settings and program the device before proceeding."

Also, the order of #pragma config IESO = ON // Internal/External Switch Over (Disabled) does not matter and does not necessarily need to be "ON"

The real issue was the VCORE pin. It requires an ESR of 1ohm and a 10uF capacitor. I managed to find a schematic showing the connections:

https://www.electro-tech-online.com/custompdfs/2013/01/UBW32_MX795_schematic_v2621.pdf

As you can see, the Vcore/Vcap pin is tied to a 10uF cap in parallel with a .1uF cap to get 10.1uF. I assume that this is to get the correct ESR. So, I used a 100nF cap in parallel with a 10uF capacitor. In addition, I also disconnected the VUSB pin since I'm not going to be using USB anytime soon (I have it working on a pic18F, but I'm not sure if I want to incorporate it just yet). Also, the configuration bits for VUSB and VUSBID should be off if you are not using USB just yet and there are no connections. The PBCLK now also works using DIV_1, which is a 1:1 ratio between the SYSCLK. So, now the project builds and debugs successfully with the external resonator. Here are the configurations:

Code:
// DEVCFG3
// USERID = No Setting
#pragma config FSRSSEL = PRIORITY_7     // SRS Select (SRS Priority 7)
#pragma config FMIIEN = OFF             // Ethernet RMII/MII Enable (RMII Enabled)
#pragma config FETHIO = OFF             // Ethernet I/O Pin Select (Alternate Ethernet I/O)
#pragma config FCANIO = OFF             // CAN I/O Pin Select (Alternate CAN I/O)
#pragma config FUSBIDIO = OFF           // USB USID Selection (Controlled by the USB Module)
#pragma config FVBUSONIO = OFF          // USB VBUS ON Selection (Controlled by Port Function)
// DEVCFG2
// External Oscillator uses base 20MHz oscillator
#pragma config FPLLIDIV = DIV_5         // PLL Input Divider (4x Divider) Using 20MHz/5 = 4MHz
#pragma config FPLLMUL = MUL_20         // PLL Multiplier (20x Multiplier) 4MHz * 20 = 80Mhz
#pragma config UPLLIDIV = DIV_5         // USB PLL Input Divider (5x Divider) (USB module must have an input of 4MHz to multiply by 24 (96) and divide by 2 to get 48MHz for FS)
#pragma config UPLLEN = ON            // USB PLL Enable (Disabled and Bypassed)
#pragma config FPLLODIV = DIV_1         // System PLL Output Clock Divider (PLL Divide by 1) => 80Mhz/1 => 80MHz


// DEVCFG1
#pragma config FNOSC = PRIPLL           // Oscillator Selection Bits (Primary Osc w/PLL (XT+,HS+,EC+PLL))
#pragma config FSOSCEN = OFF            // Secondary Oscillator Enable (Disabled)
#pragma config IESO = OFF                // Internal/External Switch Over (Disabled)
#pragma config POSCMOD = XT             // Primary Oscillator Configuration (XT osc mode)
#pragma config OSCIOFNC = OFF           // CLKO Output Signal Active on the OSCO Pin (Disabled)
#pragma config FPBDIV = DIV_1           // Peripheral Clock Divisor (Pb_Clk is Sys_Clk/1)
#pragma config FCKSM = CSDCMD           // Clock Switching and Monitor Selection (Clock Switch Disable, FSCM Disabled)
#pragma config WDTPS = PS1              // Watchdog Timer Postscaler (1:1)
#pragma config FWDTEN = OFF              // Watchdog Timer Enable (WDT Enabled)

// DEVCFG0
#pragma config DEBUG = OFF              // Background Debugger Enable (Debugger is disabled)
#pragma config ICESEL = ICS_PGx1        // ICE/ICD Comm Channel Select (ICE EMUC1/EMUD1 pins shared with PGC1/PGD1)
#pragma config PWP = OFF                // Program Flash Write Protect (Disable)
#pragma config BWP = OFF                // Boot Flash Write Protect bit (Protection Disabled)
#pragma config CP = OFF                 // Code Protect (Protection Disabled)

However, I cannot power and operate the microcontroller without the pickit 3 for some reason. I tried using 2 AA batteries, then I tried using 4 AA batteries with a 3V low drop out linear voltage regulator (the MCP1702) with 1uF capacitors as shown in the diagram from the datasheet (https://www.electro-tech-online.com/custompdfs/2013/01/22008E.pdf). Using a DMM I measured 3.016V coming out of the voltage regulator and 3.1V coming out of the pickit 3, so I am sort of stumped as to why the uC doesn't blink the LED when the pickit 3 is not being used. Does anyone have any ideas as to why this is happening?

Interesting Note: I meaured the voltage across the LED when being powered by AA batteries and it was between ~300mV and then to 1.3V and it went from ~300mV to 3.8V when using the pickit 3 (I'm using a 100 ohm resistor). So, that could be why I'm not seeing anything, but at 1.2V shouldn't I at least see a dimmed LED?
 
Last edited:
Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…