Rich D.
Active Member
It appears config bits are not being set or followed on my PIC. Is there some thing disabling this feature?
I have been struggling with programming this PIC, even though I have much experience with dsPIC30s. First, I haven't been able to get it to switch clock speeds from the FRC /4 which is default, no matter what I tried. Next, I haven't been able to get the timers to time correctly. Now, I find that I can't control the watchdog timer period. All my problems seem to be related to the config bits. The only thing that seemed to work was turning off the JTAG.
I have a UART working and sending debug messages to a LCD, so the baud rate generator is working (though it had to be programmed for 1/4 speed to match the slow clock). As a result I can clearly see that the COSC bits are 111, but the NOSC bits are 001, indicating it is not performing a clock switch to the FRCPLL. I also have interrupts working reliably from the timers, but the time periods are seemingly random and out of control. In short, everything that is giving me a problem is related to the config bits and/or clock timing in some way, and they seem to not affect any changes to the programming.
Specifically, I am using a PIC24FJ128GA406, programming it with MPLAB-X and a PICkit 3. I am writing in assembly. Here is the beginning of my code which has the PRAGMA stuff (generated via MPLAB-X by the way).
;..............................................................................
; CONFIGURATION BITS:
;..............................................................................
;// PIC24FJ128GA406 Configuration Bit Settings
#include <xc.h>
;// FSEC
#pragma config BWRP = OFF // Boot Segment Write Protect (Boot segment may be written)
#pragma config BSS = OFF // Boot segment Protect (No Protection (other than BWRP))
#pragma config BSEN = OFF // Boot Segment Control bit (No Boot Segment)
#pragma config GWRP = OFF // General Segment Write Protect (Writes to program memory are allowed)
#pragma config GSS = OFF // General Segment Code Protect (Code protection is disabled)
#pragma config CWRP = OFF // Configuration Segment Program Write Protection bit (Configuration Segment may be written)
#pragma config CSS = DIS // Configuration Segment Code Protection Level bits (No Protection (other than CWRP))
#pragma config AIVTDIS = DISABLE // Alternate Interrupt Vector Table Disable bit (Disable AIVT)
;// FBSLIM
#pragma config BSLIM = 0x1FFF // Boot Segment Code Flash Page Address Limit bits (Boot Segment Flash page address limit)
;// FSIGN
;// FOSCSEL
#pragma config FNOSC = FRCPLL // Oscillator Select (Fast RC Oscillator with PLL module (FRCPLL))
#pragma config PLLMODE = PLL4X // Frequency Multiplier Select Bits (4x PLL selected)
#pragma config IESO = ON // Internal External Switchover (Start up with user-selected oscillator source)
;// FOSC
#pragma config POSCMOD = NONE // Primary Oscillator Select (Primary Oscillator disabled)
#pragma config OSCIOFCN = ON // OSCO Pin Configuration (OSCO/CLKO/RC15 functions as port I/O (RC15))
#pragma config SOSCSEL = OFF // SOSC Power Selection Configuration bits (Digital (SCLKI) mode)
#pragma config PLLSS = PLL_FRC // PLL Secondary Selection Configuration bit (PLL is fed by the on-chip Fast RC (FRC) oscillator)
#pragma config IOL1WAY = OFF // IOLOCK One-Way Set Enable (The IOLOCK bit can be set and cleared using the unlock sequence)
#pragma config FCKSM = CSECME // Clock Switching and Monitor Selection (Clock switching is enabled, Fail-Safe Clock Monitor is enabled)
;// FWDT
#pragma config WDTPS = PS32 // Watchdog Timer Postscaler (1:32) PRODUCES ABOUT 4 SECONDS TIMEOUT?
#pragma config FWPSA = PR32 // WDT Prescaler (Prescaler ratio of 1:32), OTHER OPTION IS 1:128
#pragma config FWDTEN = ON // Watchdog Timer Enable (Watchdog Timer is enabled)
#pragma config WINDIS = OFF // Windowed Watchdog Timer Disable bit (Standard Watchdog Timer enabled (Windowed-mode is disabled))
#pragma config WDTWIN = PS75_0 // Watchdog Window Select bits (Watch Dog Timer Window Width is 75 percent)
#pragma config WDTCMX = LPRC // WDT Clock Source Select bits (WDT always uses LPRC as its clock source)
#pragma config WDTCLK = LPRC // WDT Clock Source Select bits (WDT uses LPRC)
;// FPOR
#pragma config BOREN = ON // Brown-out Reset Enable bits (Brown-out Reset Enable)
#pragma config LPCFG = OFF // Low power regulator control (Disabled)
;// FICD
#pragma config ICS = PGx3 // Emulator Pin Placement Select bits (Emulator functions are shared with PGEC3/PGED3)
#pragma config JTAGEN = OFF // JTAG Port Enable (JTAG port is disabled)
#pragma config BTSWP = OFF // BOOTSWP Instruction Enable bit (BOOTSWP instruction is disabled)
;// FDS
#pragma config DSWDTPS = DSWDTPS0B // Deep Sleep Watchdog Timer Postscale Select bits (1:65,536 (2.114s))
#pragma config DSWDTOSC = LPRC // DSWDT Reference Clock Select bit (DSWDT uses Low Power RC Oscillator (LPRC))
#pragma config DSBOREN = ON // Deep Sleep Zero-Power BOR Enable bit (Deep Sleep BOR enabled in Deep Sleep)
#pragma config DSWDTEN = ON // Deep Sleep Watchdog Timer Enable bit (DSWDT enabled)
#pragma config DSSWEN = OFF // Deep Sleep Software Control Select Bit (Deep Sleep disabled)
;// FDEVOPT1
#pragma config ALTCMPI = DISABLE // Alternate Comparator Input Enable bit (C1INC, C2INC, and C3INC are on their standard pin locations)
#pragma config TMPRPIN = OFF // Tamper Pin Enable bit (TMPRN pin function is disabled)
#pragma config TMPRWIPE = OFF // RAM Based Entryption Key Wipe Enable bit (Cryptographic Engine Key RAM is not erased onTMPR pin events)
#pragma config ALTVREF = ALTVREFDIS // Alternate VREF location Enable (VREF is on a default pin (VREF+ on RA10 and VREF- on RA9))
;// #pragma config statements should precede project file includes.
.include "p24Fxxxx.inc"
...and so on....
Is there some reason the config bits are being ignored? They are the first lines of code in the main '.s' assembly file.
I have been struggling with programming this PIC, even though I have much experience with dsPIC30s. First, I haven't been able to get it to switch clock speeds from the FRC /4 which is default, no matter what I tried. Next, I haven't been able to get the timers to time correctly. Now, I find that I can't control the watchdog timer period. All my problems seem to be related to the config bits. The only thing that seemed to work was turning off the JTAG.
I have a UART working and sending debug messages to a LCD, so the baud rate generator is working (though it had to be programmed for 1/4 speed to match the slow clock). As a result I can clearly see that the COSC bits are 111, but the NOSC bits are 001, indicating it is not performing a clock switch to the FRCPLL. I also have interrupts working reliably from the timers, but the time periods are seemingly random and out of control. In short, everything that is giving me a problem is related to the config bits and/or clock timing in some way, and they seem to not affect any changes to the programming.
Specifically, I am using a PIC24FJ128GA406, programming it with MPLAB-X and a PICkit 3. I am writing in assembly. Here is the beginning of my code which has the PRAGMA stuff (generated via MPLAB-X by the way).
;..............................................................................
; CONFIGURATION BITS:
;..............................................................................
;// PIC24FJ128GA406 Configuration Bit Settings
#include <xc.h>
;// FSEC
#pragma config BWRP = OFF // Boot Segment Write Protect (Boot segment may be written)
#pragma config BSS = OFF // Boot segment Protect (No Protection (other than BWRP))
#pragma config BSEN = OFF // Boot Segment Control bit (No Boot Segment)
#pragma config GWRP = OFF // General Segment Write Protect (Writes to program memory are allowed)
#pragma config GSS = OFF // General Segment Code Protect (Code protection is disabled)
#pragma config CWRP = OFF // Configuration Segment Program Write Protection bit (Configuration Segment may be written)
#pragma config CSS = DIS // Configuration Segment Code Protection Level bits (No Protection (other than CWRP))
#pragma config AIVTDIS = DISABLE // Alternate Interrupt Vector Table Disable bit (Disable AIVT)
;// FBSLIM
#pragma config BSLIM = 0x1FFF // Boot Segment Code Flash Page Address Limit bits (Boot Segment Flash page address limit)
;// FSIGN
;// FOSCSEL
#pragma config FNOSC = FRCPLL // Oscillator Select (Fast RC Oscillator with PLL module (FRCPLL))
#pragma config PLLMODE = PLL4X // Frequency Multiplier Select Bits (4x PLL selected)
#pragma config IESO = ON // Internal External Switchover (Start up with user-selected oscillator source)
;// FOSC
#pragma config POSCMOD = NONE // Primary Oscillator Select (Primary Oscillator disabled)
#pragma config OSCIOFCN = ON // OSCO Pin Configuration (OSCO/CLKO/RC15 functions as port I/O (RC15))
#pragma config SOSCSEL = OFF // SOSC Power Selection Configuration bits (Digital (SCLKI) mode)
#pragma config PLLSS = PLL_FRC // PLL Secondary Selection Configuration bit (PLL is fed by the on-chip Fast RC (FRC) oscillator)
#pragma config IOL1WAY = OFF // IOLOCK One-Way Set Enable (The IOLOCK bit can be set and cleared using the unlock sequence)
#pragma config FCKSM = CSECME // Clock Switching and Monitor Selection (Clock switching is enabled, Fail-Safe Clock Monitor is enabled)
;// FWDT
#pragma config WDTPS = PS32 // Watchdog Timer Postscaler (1:32) PRODUCES ABOUT 4 SECONDS TIMEOUT?
#pragma config FWPSA = PR32 // WDT Prescaler (Prescaler ratio of 1:32), OTHER OPTION IS 1:128
#pragma config FWDTEN = ON // Watchdog Timer Enable (Watchdog Timer is enabled)
#pragma config WINDIS = OFF // Windowed Watchdog Timer Disable bit (Standard Watchdog Timer enabled (Windowed-mode is disabled))
#pragma config WDTWIN = PS75_0 // Watchdog Window Select bits (Watch Dog Timer Window Width is 75 percent)
#pragma config WDTCMX = LPRC // WDT Clock Source Select bits (WDT always uses LPRC as its clock source)
#pragma config WDTCLK = LPRC // WDT Clock Source Select bits (WDT uses LPRC)
;// FPOR
#pragma config BOREN = ON // Brown-out Reset Enable bits (Brown-out Reset Enable)
#pragma config LPCFG = OFF // Low power regulator control (Disabled)
;// FICD
#pragma config ICS = PGx3 // Emulator Pin Placement Select bits (Emulator functions are shared with PGEC3/PGED3)
#pragma config JTAGEN = OFF // JTAG Port Enable (JTAG port is disabled)
#pragma config BTSWP = OFF // BOOTSWP Instruction Enable bit (BOOTSWP instruction is disabled)
;// FDS
#pragma config DSWDTPS = DSWDTPS0B // Deep Sleep Watchdog Timer Postscale Select bits (1:65,536 (2.114s))
#pragma config DSWDTOSC = LPRC // DSWDT Reference Clock Select bit (DSWDT uses Low Power RC Oscillator (LPRC))
#pragma config DSBOREN = ON // Deep Sleep Zero-Power BOR Enable bit (Deep Sleep BOR enabled in Deep Sleep)
#pragma config DSWDTEN = ON // Deep Sleep Watchdog Timer Enable bit (DSWDT enabled)
#pragma config DSSWEN = OFF // Deep Sleep Software Control Select Bit (Deep Sleep disabled)
;// FDEVOPT1
#pragma config ALTCMPI = DISABLE // Alternate Comparator Input Enable bit (C1INC, C2INC, and C3INC are on their standard pin locations)
#pragma config TMPRPIN = OFF // Tamper Pin Enable bit (TMPRN pin function is disabled)
#pragma config TMPRWIPE = OFF // RAM Based Entryption Key Wipe Enable bit (Cryptographic Engine Key RAM is not erased onTMPR pin events)
#pragma config ALTVREF = ALTVREFDIS // Alternate VREF location Enable (VREF is on a default pin (VREF+ on RA10 and VREF- on RA9))
;// #pragma config statements should precede project file includes.
.include "p24Fxxxx.inc"
...and so on....
Is there some reason the config bits are being ignored? They are the first lines of code in the main '.s' assembly file.