• AVR Freaks

Hot!#PRAGMA Definitions Location

Author
rontaylor
Starting Member
  • Total Posts : 32
  • Reward points : 0
  • Joined: 2009/07/31 08:22:53
  • Location: 0
  • Status: offline
2019/03/20 02:06:05 (permalink)
0

#PRAGMA Definitions Location

Hi,
 
I had a problem setting up the configuration of a dsPIC33FJ128GP804 where I could not get the OSC1/CLKI pin to behave as I/O. I eventually traced the cause to the #PRAGMA POSCMD and OSCIOFCN statements. Using;
 
#pragma config POSCMD = 3         // Primary Oscillator Source (Primary Oscillator Disabled)
#pragma config OSCIOFNC = 0       // OSC2 Pin Function (OSC2 pin has clock out function)
 
works, whereas;
 
#pragma config POSCMD = NONE   // Primary Oscillator Source (Primary Oscillator Disabled)
#pragma config OSCIOFNC = OFF   // OSC2 Pin Function (OSC2 pin has clock out function)
 
does not. Where are the #PRAGMA tokens located? I know that the CONFIG bit definitions are held in the device header but these are a different format - but are the tokens extracted from these?
 
Regards
 
Ron Taylor
Penrith, Cumbria
post edited by rontaylor - 2019/03/20 02:12:46
#1

11 Replies Related Threads

    crosland
    Super Member
    • Total Posts : 1584
    • Reward points : 0
    • Joined: 2005/05/10 10:55:05
    • Location: Bucks, UK
    • Status: offline
    Re: #PRAGMA Definitions Location 2019/03/20 02:33:08 (permalink)
    0

    whereas #pragma config POSCMD = 3 did. Out of curiosity I'm trying to understand why this is.

     
    Have you searched the device data sheet for 'POSCMD'?
     
    That's a polite way of saying RTFM.
    #2
    rontaylor
    Starting Member
    • Total Posts : 32
    • Reward points : 0
    • Joined: 2009/07/31 08:22:53
    • Location: 0
    • Status: offline
    Re: #PRAGMA Definitions Location 2019/03/20 02:55:56 (permalink)
    0
    Yes, indeed I have as well as the #pragma sections of the tools help file, that's why I tried the numerical substitution which worked. However, I'm trying to find out why the text substitution code (NONE and OFF) doesn't work. Hence my curiosity as to where the #pragma token definitions are held. If they are taken from the device header;
     
    #define POSCMD_NONE          0x00E7
     
    then that point to an error here (POSCMD=0x00E7) and my curiosity is answered. I'll try reverting to the original config format to see if this is it.
     
    Ron
    post edited by rontaylor - 2019/03/20 03:45:55
    #3
    rontaylor
    Starting Member
    • Total Posts : 32
    • Reward points : 0
    • Joined: 2009/07/31 08:22:53
    • Location: 0
    • Status: offline
    Re: #PRAGMA Definitions Location 2019/03/20 03:10:14 (permalink)
    0
    Looks like it's an error in the header using;
     _FOSC(FCKSM_CSECMD & 0x00E3 & 0x00E3); works,
     
    whereas
     
     _FOSC(FCKSM_CSECMD & OSCIOFCN_OFF & POSCMD_NONE); does not.
     
    The OSCIOFCN_OFF and POSCMD_NONE are both defined in the header as 0x00E7. From this I presume that #pragma must use the same definitions.
     
    Ron
     
    #4
    crosland
    Super Member
    • Total Posts : 1584
    • Reward points : 0
    • Joined: 2005/05/10 10:55:05
    • Location: Bucks, UK
    • Status: offline
    Re: #PRAGMA Definitions Location 2019/03/20 07:12:37 (permalink)
    0
    Hmm, I would say the header definitions are for SFR access and different to what's used in #pragmas, but I could be wrong. As such, it's quite possible that two macros could have the same value but are not intended to be used the way you are using them.
    #5
    du00000001
    Just Some Member
    • Total Posts : 2792
    • Reward points : 0
    • Joined: 2016/05/03 13:52:42
    • Location: Germany
    • Status: offline
    Re: #PRAGMA Definitions Location 2019/03/20 07:34:46 (permalink)
    0
    Could it be a siple typo? (OSCIOFCN_OFF where OSCIOFNC_OFF would be correct?)

    PEBKAC / EBKAC / POBCAK / PICNIC (eventually see en.wikipedia.org)
    #6
    aschen0866
    Super Member
    • Total Posts : 4469
    • Reward points : 0
    • Joined: 2006/01/08 22:18:32
    • Location: San Diego
    • Status: offline
    Re: #PRAGMA Definitions Location 2019/03/20 10:36:23 (permalink)
    4 (1)
    rontaylor
    Hi,
     
    I had a problem setting up the configuration of a dsPIC33FJ128GP804 ...
    ...
    Where are the #PRAGMA tokens located? I know that the CONFIG bit definitions are held in the device header but these are a different format - but are the tokens extracted from these?
    ...

    I think the Microchip recommended method is to do it from MPLABX IDE. If you go to Window->Target Memory Views->Configuration Bits, you can set up all the Configuration Bits from the GUI, then hit "Generate Source Code to Output". Once that is done, you can copy/paste whatever in the Output window to a .c file.
    #7
    rontaylor
    Starting Member
    • Total Posts : 32
    • Reward points : 0
    • Joined: 2009/07/31 08:22:53
    • Location: 0
    • Status: offline
    Re: #PRAGMA Definitions Location 2019/03/20 11:14:58 (permalink)
    0
    Found the cause. By declaring;
     
    #pragma config OSCIOFNC = OFF       // OSC2 Pin Function (OSC2 pin has clock out function)
     
    I'm clearing the bit from a definition of OFF in my main.h, however, this bit has an inverted logic (depending how you look at it!). From the header file;
     
    #define OSCIOFNC_ON          0x00E3 Clears the bit and
    #define OSCIOFNC_OFF         0x00E7 sets the bit
     
    When used with the #pragma statements ON and OFF are being picked up from my main.h and are the reverse logic in the ON=1 and OFF=0. There is vague a warning about this in the clock document section 48.
     
    I presume that #pragma is using he device header file even though the aliases differ, but I would need to edit a config entry to verify that.
     
    Thanks all,
     
    Ron
    #8
    aschen0866
    Super Member
    • Total Posts : 4469
    • Reward points : 0
    • Joined: 2006/01/08 22:18:32
    • Location: San Diego
    • Status: offline
    Re: #PRAGMA Definitions Location 2019/03/20 11:34:58 (permalink)
    0
    Put all #pragma config's in a C source file (.c) not a header file (.h), and add this .c file to your project. That's all you have to do.
    #9
    qhb
    Superb Member
    • Total Posts : 9998
    • Reward points : 0
    • Joined: 2016/06/05 14:55:32
    • Location: One step ahead...
    • Status: offline
    Re: #PRAGMA Definitions Location 2019/03/20 12:21:24 (permalink)
    0
    Microchip recommend that ALL #includes are placed after the "#pragma config" lines for this very reason.

    Nearly there...
    #10
    rontaylor
    Starting Member
    • Total Posts : 32
    • Reward points : 0
    • Joined: 2009/07/31 08:22:53
    • Location: 0
    • Status: offline
    Re: #PRAGMA Definitions Location 2019/03/20 12:56:41 (permalink)
    0
    All my #pragmas are and were in main.c in front of the #includes as recommended in the Compiler User's Guide.
     
    But... it looks the problem is one of interpretation on my part! In this instance ON=0 and OFF=1, hence for I/O functionality it should be;
     
    #pragma config POSCMD = NONE   // Primary Oscillator Disabled
    #pragma config OSCIOFNC = ON   // OSC2 Pin has digital I/O
     
    and in old money;
     
     _FOSC(FCKSM_CSECMD & OSCIOFCN_ON & POSCMD_NONE); 
     
    Obvious once you step back and take another look at it. Sorry for talking up your time!
     
    Regards
     
    Ron Taylor
     
     
     
    #11
    Aussie Susan
    Super Member
    • Total Posts : 3591
    • Reward points : 0
    • Joined: 2008/08/18 22:20:40
    • Location: Melbourne, Australia
    • Status: offline
    Re: #PRAGMA Definitions Location 2019/03/20 18:14:19 (permalink)
    0
    Which is why the recommendation is to do one (or more) of:
    - not define values such as ON and OFF in the same file that contains the CONFIG settings
    - put the config settings into a separate source file
    - only put in the CONFIG settings that are different to the default settings
    The 'inversion' comes about because the FLASH is erased to all '1's. Therefore the default setting is typically OFF or '1'. FLASH memory can only be written from '1' to '0'. This means that any item you want to set to 'ON' needs to to have a numerical value of '0'.
    Susan
    #12
    Jump to:
    © 2019 APG vNext Commercial Version 4.5