Discovering PIC 16F18446 - TOGGLE "ASM WARNING - Invalid RAM location"


+ Reply to Thread
Results 1 to 11 of 11
  1. #1
    Join Date
    Aug 2006
    Location
    SWITZERLAND (french speaking)
    Posts
    921

    Default Discovering PIC 16F18446 - TOGGLE "ASM WARNING - Invalid RAM location"

    Hi there,

    I'm playing around the 16F18446.

    I just noticed the following:
    Name:  2024-02-17 22_02_55-PBP3 - Post New Thread.jpg
Views: 963
Size:  23.9 KB

    I have used 73 words.


    Now I'm trying to go for TOGGLE so:
    Name:  2024-02-17 22_04_57-Clipboard.jpg
Views: 953
Size:  36.2 KB

    I "spared" 4 words and the blinker still works.

    Do I have to care about this warning?
    Roger

  2. #2
    Join Date
    May 2013
    Location
    australia
    Posts
    2,515


    Did you find this post helpful? Yes | No

    Default Re: Discovering PIC 16F18446 - TOGGLE "ASM WARNING - Invalid RAM location"

    substituting LATx registers for PORTx registers in pbp high level command statements will not work as you might hope
    it can introduce subtle and difficult to diagnose bugs, it also will never set the TRISx registers in the manner those statements expect

    Do I have to care about this warning?
    only if you want your code to work correctly

    see this
    https://www.picbasic.co.uk/forum/sho...1-OWOUT-Glitch
    Last edited by richard; - 18th February 2024 at 11:04.
    Warning I'm not a teacher

  3. #3
    Join Date
    Nov 2003
    Location
    Greece
    Posts
    3,993


    Did you find this post helpful? Yes | No

    Default Re: Discovering PIC 16F18446 - TOGGLE "ASM WARNING - Invalid RAM location"

    Since the introduction of LAT registers, I cannot remember where I read it, maybe it was in Melabs either help file or this forum, we had to use LAT instead of PORT registers.

    Οn some PIC it will not work properly.

    But I have not found an explanation on this matter.

    Ioannis
    Last edited by Ioannis; - 18th February 2024 at 20:55.

  4. #4
    Join Date
    Aug 2006
    Location
    SWITZERLAND (french speaking)
    Posts
    921


    Did you find this post helpful? Yes | No

    Default Discovering PIC 16F18446 - TOGGLE "ASM WARNING - Invalid RAM location"

    Quote Originally Posted by richard View Post
    ...only if you want your code to work correctly
    Who wouldn't?

    At this point, it's just about blinking that LED.

    But after that, how will I be able to avoid any such kind of "mistakes"?

    Please, please don't answer "Easy! Just rfm!!!"

    For week-ends hobbyist like me, is it better to stay with more "modest" PICs and/or always use workarounds like instead of:
    Code:
    TOGGLE LATB.6
    PAUSE 500
    ...I should choose to stay with:
    Code:
    LATB.6 = 1
    PAUSE 500
    LATB.6 = 0
    PAUSE 500
    Roger

  5. #5
    Join Date
    May 2013
    Location
    australia
    Posts
    2,515


    Did you find this post helpful? Yes | No

    Default Re: Discovering PIC 16F18446 - TOGGLE "ASM WARNING - Invalid RAM location"

    For week-ends hobbyist like me, is it better to stay with more "modest" PICs and/or always use workarounds like instead
    it has nothing to do with with the pic chip at all. its simply incorrect usage of the pbp high level commands

    Please, please don't answer "Easy! Just rfm!!!
    did you even look at the link i suggested ? i don't know why i bother



    all pbp "high level" commands that set a pin direction use a fixed offset to get to the tris reg
    it simply will not work correctly from a LATx offset [serout , serout2, toggle,high,low,i2cread........................... ....... ie all of them

    PORTx + offset always equals the TRISx register, LATx + offset does not equal the TRISx register ever

    if you don't believe my then look at the lst file generated by your code

    Code:
    TOGGLE LATB.6
    PAUSE 500
    is improper use

    Code:
    TOGGLE PORTB.6
    PAUSE 500
    is proper use


    Code:
    LATB.6 = 1
    PAUSE 500
    LATB.6 = 0
    PAUSE 500
    is proper use

    Code:
    latb.6=!latb.6
    PAUSE 500
    is proper use
    Warning I'm not a teacher

  6. #6
    Join Date
    May 2013
    Location
    australia
    Posts
    2,515


    Did you find this post helpful? Yes | No

    Default Re: Discovering PIC 16F18446 - TOGGLE "ASM WARNING - Invalid RAM location"

    TRY THIS


    Code:
    ' PIC 16F18446
    #CONFIG
        __config _CONFIG1, _FEXTOSC_OFF & _RSTOSC_HFINT1 & _CLKOUTEN_OFF & _CSWEN_ON & _FCMEN_ON
        __config _CONFIG2, _MCLRE_ON & _PWRTS_PWRT_64 & _LPBOREN_OFF & _BOREN_SBOREN & _BORV_LO & _ZCDDIS_OFF & _PPS1WAY_OFF & _STVREN_ON
        __config _CONFIG3, _WDTCPS_WDTCPS_31 & _WDTE_SWDTEN & _WDTCWS_WDTCWS_7 & _WDTCCS_LFINTOSC
        __config _CONFIG4, _BBSIZE_BB512 & _BBEN_OFF & _SAFEN_OFF & _WRTAPP_OFF & _WRTB_OFF & _WRTC_OFF & _WRTD_OFF & _WRTSAF_OFF & _LVP_OFF
        __config _CONFIG5, _CP_OFF
    #ENDCONFIG
    
    
    ' ====== DEFINES ===================================================================================
        DEFINE OSC 4
        ANSELB = $B0;
        OSCCON1 = $60; // CSWHOLD may proceed; SOSCPWR Low power;
        OSCCON3 = 0;  // MFOEN disabled; LFOEN disabled; ADOEN disabled; SOSCEN disabled; EXTOEN disabled; HFOEN disabled;
        OSCEN = 0 ;    // HFFRQ 4_MHz; 
        OSCFRQ = 2;  // HFTUN 0; 
        OSCTUNE = 0
    
    
    ' ====== TEST PROGRAM ==============================================================================
    TEST:
        TOGGLE PORTB.6
        pause 500
    GOTO TEST
    END
    THEN THIS


    Code:
    ' PIC 16F18446
    #CONFIG
        __config _CONFIG1, _FEXTOSC_OFF & _RSTOSC_HFINT1 & _CLKOUTEN_OFF & _CSWEN_ON & _FCMEN_ON
        __config _CONFIG2, _MCLRE_ON & _PWRTS_PWRT_64 & _LPBOREN_OFF & _BOREN_SBOREN & _BORV_LO & _ZCDDIS_OFF & _PPS1WAY_OFF & _STVREN_ON
        __config _CONFIG3, _WDTCPS_WDTCPS_31 & _WDTE_SWDTEN & _WDTCWS_WDTCWS_7 & _WDTCCS_LFINTOSC
        __config _CONFIG4, _BBSIZE_BB512 & _BBEN_OFF & _SAFEN_OFF & _WRTAPP_OFF & _WRTB_OFF & _WRTC_OFF & _WRTD_OFF & _WRTSAF_OFF & _LVP_OFF
        __config _CONFIG5, _CP_OFF
    #ENDCONFIG
    
    
    ' ====== DEFINES ===================================================================================
        DEFINE OSC 4
        ANSELB = $B0;
        OSCCON1 = $60; // CSWHOLD may proceed; SOSCPWR Low power;
        OSCCON3 = 0;  // MFOEN disabled; LFOEN disabled; ADOEN disabled; SOSCEN disabled; EXTOEN disabled; HFOEN disabled;
        OSCEN = 0 ;    // HFFRQ 4_MHz; 
        OSCFRQ = 2;  // HFTUN 0; 
        OSCTUNE = 0
    
    
    ' ====== TEST PROGRAM ==============================================================================
    TEST:
        TOGGLE LATB.6
        pause 500
    GOTO TEST
    END
    WHICH ONE WORKS ?
    Warning I'm not a teacher

  7. #7
    Join Date
    Aug 2006
    Location
    SWITZERLAND (french speaking)
    Posts
    921


    Did you find this post helpful? Yes | No

    Default Discovering PIC 16F18446 - TOGGLE "ASM WARNING - Invalid RAM location"

    Richard,

    Sorry for my late reply.

    First or upper code in your previous message dosen't work. The LED is steady ON and no warning message.

    Lower or second code doesn't work either; no LED blinking AND I do have the warning message showing up again.

    And "yes", I went to read the post you pointed me at.

    Currently, this is the code that will make the LED blink and have no warnings after compiling:
    Code:
    ' PIC 16F18446
    
    #CONFIG
        __config _CONFIG1, _FEXTOSC_OFF & _RSTOSC_HFINT1 & _CLKOUTEN_OFF & _CSWEN_ON & _FCMEN_ON
        __config _CONFIG2, _MCLRE_ON & _PWRTS_PWRT_64 & _LPBOREN_OFF & _BOREN_SBOREN & _BORV_LO & _ZCDDIS_OFF & _PPS1WAY_OFF & _STVREN_ON
        __config _CONFIG3, _WDTCPS_WDTCPS_31 & _WDTE_SWDTEN & _WDTCWS_WDTCWS_7 & _WDTCCS_LFINTOSC
        __config _CONFIG4, _BBSIZE_BB512 & _BBEN_OFF & _SAFEN_OFF & _WRTAPP_OFF & _WRTB_OFF & _WRTC_OFF & _WRTD_OFF & _WRTSAF_OFF & _LVP_OFF
        __config _CONFIG5, _CP_OFF
    #ENDCONFIG
    
    ' ====== REGISTERS SETTINGS =======================================================================
    TRISB.6 = 0
    
    ' Oscillator Control Register1
    OSCCON1 = %01100000 ' $60
    
    ' HFFRQ - Oscillator's Frequency Selection Register
    OSCFRQ  = %00000010 ' 4MHz
    
    ' ====== TEST PROGRAM =============================================================================
    TEST:
        LATB.6 = 1
        PAUSE 500
        LATB.6 = 0
        PAUSE 500
    GOTO TEST
    END
    Last edited by flotulopex; - 24th February 2024 at 19:16.
    Roger

  8. #8
    Join Date
    Nov 2003
    Location
    Greece
    Posts
    3,993


    Did you find this post helpful? Yes | No

    Default Re: Discovering PIC 16F18446 - TOGGLE "ASM WARNING - Invalid RAM location"

    That is the proper way to do it.

    Ioannis

  9. #9
    Join Date
    May 2013
    Location
    australia
    Posts
    2,515


    Did you find this post helpful? Yes | No

    Default Re: Discovering PIC 16F18446 - TOGGLE "ASM WARNING - Invalid RAM location"

    First or upper code in your previous message dosen't work
    this works perfectly for me, i doubt you implemented it exactly as posted
    i notice you don't set the pins used to digital mode

    another correct way
    Code:
    ' PIC 16F18426
    #CONFIG
        __config _CONFIG1, _FEXTOSC_OFF & _RSTOSC_HFINT1 & _CLKOUTEN_OFF & _CSWEN_ON & _FCMEN_ON
        __config _CONFIG2, _MCLRE_ON & _PWRTS_PWRT_64 & _LPBOREN_OFF & _BOREN_SBOREN & _BORV_LO & _ZCDDIS_OFF & _PPS1WAY_OFF & _STVREN_ON
        __config _CONFIG3, _WDTCPS_WDTCPS_31 & _WDTE_SWDTEN & _WDTCWS_WDTCWS_7 & _WDTCCS_LFINTOSC
        __config _CONFIG4, _BBSIZE_BB512 & _BBEN_OFF & _SAFEN_OFF & _WRTAPP_OFF & _WRTB_OFF & _WRTC_OFF & _WRTD_OFF & _WRTSAF_OFF & _LVP_OFF
        __config _CONFIG5, _CP_OFF
    #ENDCONFIG
    
    
    ' ====== DEFINES ===================================================================================
        DEFINE OSC 4
        ANSELC = $DF;
        OSCCON1 = $60; // CSWHOLD may proceed; SOSCPWR Low power;
        OSCCON3 = 0;  // MFOEN disabled; LFOEN disabled; ADOEN disabled; SOSCEN disabled; EXTOEN disabled; HFOEN disabled;
        OSCEN = 0 ;    // HFFRQ 4_MHz; 
        OSCFRQ = 2;  // HFTUN 0; 
        OSCTUNE = 0
    
    
    ' ====== TEST PROGRAM ==============================================================================
    TEST:
    
    
        TOGGLE PORTC.5
        pause 500
        
    GOTO TEST
    END
    Last edited by richard; - 24th February 2024 at 23:49. Reason: i cant use b6 on a 16f18426 my closest match
    Warning I'm not a teacher

  10. #10
    Join Date
    Aug 2006
    Location
    SWITZERLAND (french speaking)
    Posts
    921


    Did you find this post helpful? Yes | No

    Default Discovering PIC 16F18446 - TOGGLE "ASM WARNING - Invalid RAM location"

    Richard, this is your exact code (no changes at all) and it lights the LED steady ON:
    Code:
    ' PIC 16F18446
    #CONFIG
        __config _CONFIG1, _FEXTOSC_OFF & _RSTOSC_HFINT1 & _CLKOUTEN_OFF & _CSWEN_ON & _FCMEN_ON
        __config _CONFIG2, _MCLRE_ON & _PWRTS_PWRT_64 & _LPBOREN_OFF & _BOREN_SBOREN & _BORV_LO & _ZCDDIS_OFF & _PPS1WAY_OFF & _STVREN_ON
        __config _CONFIG3, _WDTCPS_WDTCPS_31 & _WDTE_SWDTEN & _WDTCWS_WDTCWS_7 & _WDTCCS_LFINTOSC
        __config _CONFIG4, _BBSIZE_BB512 & _BBEN_OFF & _SAFEN_OFF & _WRTAPP_OFF & _WRTB_OFF & _WRTC_OFF & _WRTD_OFF & _WRTSAF_OFF & _LVP_OFF
        __config _CONFIG5, _CP_OFF
    #ENDCONFIG
    
    
    ' ====== DEFINES ===================================================================================
        DEFINE OSC 4
        ANSELB = $B0;
        OSCCON1 = $60; // CSWHOLD may proceed; SOSCPWR Low power;
        OSCCON3 = 0;  // MFOEN disabled; LFOEN disabled; ADOEN disabled; SOSCEN disabled; EXTOEN disabled; HFOEN disabled;
        OSCEN = 0 ;    // HFFRQ 4_MHz; 
        OSCFRQ = 2;  // HFTUN 0; 
        OSCTUNE = 0
    
    
    ' ====== TEST PROGRAM ==============================================================================
    TEST:
        TOGGLE PORTB.6
        pause 500
    GOTO TEST
    END

    Unfortunately, the third example dosen't work either, this one:
    Code:
    ' PIC 16F18426
    #CONFIG
        __config _CONFIG1, _FEXTOSC_OFF & _RSTOSC_HFINT1 & _CLKOUTEN_OFF & _CSWEN_ON & _FCMEN_ON
        __config _CONFIG2, _MCLRE_ON & _PWRTS_PWRT_64 & _LPBOREN_OFF & _BOREN_SBOREN & _BORV_LO & _ZCDDIS_OFF & _PPS1WAY_OFF & _STVREN_ON
        __config _CONFIG3, _WDTCPS_WDTCPS_31 & _WDTE_SWDTEN & _WDTCWS_WDTCWS_7 & _WDTCCS_LFINTOSC
        __config _CONFIG4, _BBSIZE_BB512 & _BBEN_OFF & _SAFEN_OFF & _WRTAPP_OFF & _WRTB_OFF & _WRTC_OFF & _WRTD_OFF & _WRTSAF_OFF & _LVP_OFF
        __config _CONFIG5, _CP_OFF
    #ENDCONFIG
    
    
    ' ====== DEFINES ===================================================================================
        DEFINE OSC 4
        ANSELC = $DF;
        OSCCON1 = $60; // CSWHOLD may proceed; SOSCPWR Low power;
        OSCCON3 = 0;  // MFOEN disabled; LFOEN disabled; ADOEN disabled; SOSCEN disabled; EXTOEN disabled; HFOEN disabled;
        OSCEN = 0 ;    // HFFRQ 4_MHz; 
        OSCFRQ = 2;  // HFTUN 0; 
        OSCTUNE = 0
    
    
    ' ====== TEST PROGRAM ==============================================================================
    TEST:
    
    
        TOGGLE PORTC.5
        pause 500
        
    GOTO TEST
    END

    Maybe this last code doesnt work because you seem to use a 16F8246 not a 16F18446 like I have.

    Honestly, I can have a real good life with LATBs commands instead of TOGGLEs
    Roger

  11. #11
    Join Date
    Nov 2003
    Location
    Greece
    Posts
    3,993


    Did you find this post helpful? Yes | No

    Default Re: Discovering PIC 16F18446 - TOGGLE "ASM WARNING - Invalid RAM location"

    TOGGLE will not work.

    Richard did explain why at post #5.

    So, you have to use either directly PORT or LAT commands. Personally, never liked the TOGGLE command and always preferred to use discrete commands. Bonus that you know the final state of the register. With TOGGLE you only know that it has changed. Not how.

    Ioannis
    Last edited by Ioannis; - 25th February 2024 at 21:38.

Similar Threads

  1. How to do the "SerIN" and "SerOut " for the usb ?
    By vicce67 in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 13th March 2015, 03:01
  2. Replies: 0
    Last Post: - 14th November 2013, 04:32
  3. Replies: 3
    Last Post: - 15th October 2012, 09:06
  4. PBP 2.6/MPLab 8.33 ASM "COD" error message
    By reddog24 in forum mel PIC BASIC Pro
    Replies: 9
    Last Post: - 3rd December 2009, 21:09
  5. Adding data to an "array" in ASM
    By The Master in forum Off Topic
    Replies: 11
    Last Post: - 22nd November 2009, 04:21

Members who have read this thread : 11

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts