News:

Let's find out together what makes a PIC Tick!

Main Menu

String type variable

Started by Werwolf, Jul 17, 2024, 11:50 AM

Previous topic - Next topic

Werwolf

Hello All

There is a short test program:

Device = 24FJ1024GA606

Config FSEC =       BWRP_OFF, BSS_OFF, BSEN_OFF, GWRP_OFF, GSS_OFF, CWRP_OFF, CSS_DIS, AIVTDIS_DISABLE
Config FBSLIM =     BSLIM_BSLIM
Config FOSCSEL =    FNOSC_FRC, PLLMODE_PLL96DIV3, IESO_ON
Config FOSC =       POSCMD_HS, OSCIOFCN_ON, SOSCSEL_OFF, PLLSS_PLL_PRI, IOL1WAY_ON, FCKSM_CSECME
Config FWDT =       WDTPS_PS32768, FWPSA_PR128, FWDTEN_ON, WINDIS_OFF, PS25_0, WDTCMX_WDTCLK, WDTCLK_LPRC
Config FPOR =       BOREN_ON, LPCFG_OFF, DNVPEN_ENABLE
Config FICD =       ICS_PGX1, JTAGEN_OFF, BTSWP_OFF
Config FDEVOPT1 =   ALTCMPI_DISABLE, TMPRPIN_OFF, SOSCHP_ON, ALTVREF_ALTVREFDIS
Config FBOOT =      BTMODE_SINGLE


Declare Xtal = 32
Declare Reminders = Off
Declare Warnings = On
Declare Watchdog = Off
Declare ACCESS_UPPER_64k = 1
Declare Stack_Size = 256
Declare Stack_Expand = 1
Declare Dead_Code_Remove = On
Declare Create_Coff = False
Declare Optimiser_Level = 2

$define SYSCLK 32000000

Include "GT21_Init.inc"
Include "GT21_HW.inc"
Include "GT21_Debug.inc"



Dim GT21Module_Status As Byte

Dim Test_Str As String * 10
Dim Test_StrL As Byte



MAIN:
    CLOCK_Initialize()
    PIC_Init()
   
    While 1 = 1
        ;Select Case GT21Module_Status
            ;Case $00
                HL11 = ~HL11
               
                ;Test_Str = "Test1\r\n"
               
                Test_Str[0] = "T"
                Test_Str[1] = "e"
                Test_Str[2] = "s"
                Test_Str[3] = "t"
                Test_Str[4] = "2"
                Test_Str[5] = "\r"
                Test_Str[6] = "\n"
                Test_Str[7] = $00
               
                Test_StrL = Len(Test_Str)
               
                HSerOut4["Str_L: ", Dec Test_StrL, 13, 10]
                HSerOut4[Test_Str]
                DelayMS 500
        ;EndSelect
    Wend

Return

If the data of a variable of type String is described as follows:
Test_Str[0] = "T"
Test_Str[1] = "e"
Test_Str[2] = "s"
Test_Str[3] = "t"
Test_Str[4] = "2"
Test_Str[5] = "\r"
Test_Str[6] = "\n"
Test_Str[7] = $00

The result is OK:

Str_L: 7<CR><LF>
Test2<CR><LF>
Str_L: 7<CR><LF>
Test2<CR><LF>
Str_L: 7<CR><LF>
Test2<CR><LF>
Str_L: 7<CR><LF>
Test2<CR><LF>
.........

If the data of a variable of type String is described as follows:
Test_Str = "Test1\r\n"

The resul is bad:

Str_L: 0<CR><LF>
Str_L: 0<CR><LF>
Str_L: 0<CR><LF>
Str_L: 0<CR><LF>
...........

I have been working with PIC24FJ256GB106 controllers for years. Never had this problem. I just tried the PIC24FJ1024GA606 and immediately got a bad result. Maybe somebody can advise me, because I don't want to describe a character string as an array.

Best Regards
Alvydas

Werwolf

Another observation:


......
MAIN:
    While 1 = 1
        Debug_Str("Test\r\n")
        DelayMs 500
    Wend
Return
.......

Proc Debug_Str(ByRef pSTR_Addr As Word)
    Dim Char_None As Byte
       
    While 1 = 1
        Char_None = Ptr8(pStr_Addr++)
        If Char_None = $00 Then Break
        UART4PutChar(Char_None)
    Wend
EndProc

Works perfectly with PIC24FJ256GB106, not working with PIC24FJ1024GA606.

Best Regard
Alvydas

John Lawton

#2
The GA devices only have 2 UARTS and you appear to be referring to UART4 in your code.

EDIT: Oops, I am wrong about this.

Werwolf

PIC24FJ256GB106 has four UARTs, PIC24FJ1024GA606 has six UARTs. UART4 works fine, the problem is not in the number of UARTs, but in the character string formation.

Best Regards
Alvydas

top204

#4
It looks like microchip are at it again with changing names of important SFRs and things on different 16-bit devices.

Initial String variable assignments are stored in flash memory, and with the 16-bit devices, the compiler generates code that uses the PSV mechanism on all of them, so Flash memory can be read as easily as reading from RAM, and using the same mnemonics, but it first has to setup the PSVPAG SFR, and guess what? They have changed the name of the PSVPAG SFR to DSRPAG on the F types as well now... Why? ? ? ? It has been the same name for the F and H types since the PIC24 devices were first created. It doesn't look as though they have changed its mechanism.

I do not have a PIC24FJ1024GA606 device, but try adding the lines of code below near the start of the program listing:

Symbol PSVPAG = DSRPAG

CORCON.2 = 1

Make sure the CORCON bit manipulation is within the run of the program so the PSV bit does get set, and the Symbol will alias the DSRPAG to what the compiler is looking for and load it with the offset before reading flash memory in its assembler code:

    mov.w #MyString,W12
    mov.w #psvpage(str__lb1),W0
    mov.w W0,PSVPAG
    mov.w #psvoffset(str__lb1),W0
    repeat #8
    mov.b [W0++],[W12++]
    clr.b [W12++]

And enable the PSV mechanism.

I'll make sure I alias the PSV name change in the PPI files and make sure the compiler also looks for the DSRPAG as well as PSVPAG on all the 16-bit devices, and the bit name change in CORCON. An update of Positron16 will be forthcoming.

Werwolf

Hello Les

The result of the experiment is positive.

Device = 24FJ1024GA606

Config FSEC =      BWRP_OFF, BSS_OFF, BSEN_OFF, GWRP_OFF, GSS_OFF, CWRP_OFF, CSS_DIS, AIVTDIS_DISABLE
Config FBSLIM =    BSLIM_BSLIM
Config FOSCSEL =    FNOSC_FRC, PLLMODE_PLL96DIV3, IESO_ON
Config FOSC =      POSCMD_HS, OSCIOFCN_ON, SOSCSEL_OFF, PLLSS_PLL_PRI, IOL1WAY_ON, FCKSM_CSECME
Config FWDT =      WDTPS_PS32768, FWPSA_PR128, FWDTEN_ON, WINDIS_OFF, PS25_0, WDTCMX_WDTCLK, WDTCLK_LPRC
Config FPOR =      BOREN_ON, LPCFG_OFF, DNVPEN_ENABLE
Config FICD =      ICS_PGX1, JTAGEN_OFF, BTSWP_OFF
Config FDEVOPT1 =  ALTCMPI_DISABLE, TMPRPIN_OFF, SOSCHP_ON, ALTVREF_ALTVREFDIS
Config FBOOT =      BTMODE_SINGLE


Declare Xtal = 32
Declare Reminders = Off
Declare Warnings = On
Declare Watchdog = Off
Declare ACCESS_UPPER_64k = 1
Declare Stack_Size = 256
Declare Stack_Expand = 1
Declare Dead_Code_Remove = On
Declare Create_Coff = False
Declare Optimiser_Level = 2

$define SYSCLK 32000000

Include "GT21_Init.inc"
Include "GT21_HW.inc"
Include "GT21_Debug.inc"



Dim GT21Module_Status As Byte

Dim Test_Str As String * 10
Dim Test_StrL As Byte

Symbol PSVPAG = DSRPAG
CORCON.2 = 1

MAIN:
    CLOCK_Initialize()
    PIC_Init()
   
    While 1 = 1
        ;Select Case GT21Module_Status
            ;Case $00
                HL11 = ~HL11
               
                Test_Str = "Test1\r\n"
                Test_StrL = Len(Test_Str)
                HSerOut4["Str_L: ", Dec Test_StrL, 13, 10]
                HSerOut4[Test_Str]
               
                Test_Str[0] = "T"
                Test_Str[1] = "e"
                Test_Str[2] = "s"
                Test_Str[3] = "t"
                Test_Str[4] = "2"
                Test_Str[5] = "\r"
                Test_Str[6] = "\n"
                Test_Str[7] = $00
                Test_StrL = Len(Test_Str)
                HSerOut4["Str_L: ", Dec Test_StrL, 13, 10]
                HSerOut4[Test_Str]
                             
                Debug_Str("Test3!\r\n")
                DelayMS 500
        ;EndSelect
    Wend

Return


Result:

Str_L: 7<CR><LF>
Test1<CR><LF>
Str_L: 7<CR><LF>
Test2<CR><LF>
Test3!<CR><LF>

ASM:
; rd_i000014_f001_000064_p000016,0 mkr$ in [gt21_01.bas] Test_Str = "test1\r\n"
    mov.w #Test_Str,W12
    mov.w #psvpage(str__lb1),W0
    mov.w W0,PSVPAG
    mov.w #psvoffset(str__lb1),W0
    repeat #6
    mov.b [W0++],[W12++]
    clr.b [W12++]

This problem was encountered with PIC24FJ128GA306, PIC24FJ1024GA606 and I think it will exist with PIC24FJxxGA70x.

Many thanks. Problem solved.

Best Regards
Alvydas




top204

#6
Thanks for letting me know.

The anomaly correction is already being performed within the Positron16 compiler's source code and an update will be posted ASAP. On looking in more detail on the subtleties of some of the newer PIC24 devices, I have noticed in in a few of them, so the correction will correct the anomaly in all PIC24 devices.