News:

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

Main Menu

Error in positron 4.0.0.4

Started by atomix, Jul 19, 2021, 02:19 PM

Previous topic - Next topic

atomix

example code

Device 18F46K22

Declare Xtal = 64
Declare Optimiser_Level = 3

'--------------------------------------
' Use very carefully, since these are the variables for the proton.
Dim PPZ   As Dword System
Dim PP2   As Dword System
Dim PB0   As PP2.Byte0
Dim PB1   As PP2.Byte1
Dim PB2   As PP2.Byte2
Dim PB3   As PP2.Byte3
Dim PZ0   As PPZ.Byte0
Dim PZ1   As PPZ.Byte1
Dim PZ2   As PPZ.Byte2
Dim PZ3   As PPZ.Byte3
'--------------------------------------

Dim link_RxBuf[256] As Byte
Dim link_TxBuf[256] As Byte
Dim cnt As Byte

main:
    For cnt = 0 To 20
        Lfsr 0, (link_RxBuf)
        Lfsr 1, (link_TxBuf)
        WS2812_Send()
    Next
GoTo main


Proc WS2812_Send()
    For PZ2 = 7 To 0 Step -1        ' use this compile ok
    Next
    For PB2 = 7 To 0 Step -1        ' use this compile err
    Next
EndProc

top204

It is not a "compiler" error, it is a misuse of the compiler's internal system variables, so it will screw up the compiler's final parsing because its system variables are always correct as far as it is concerned, because it creates them internally.

A system variable must always be a byte type and cannot be created as any other type without screwing with the compiler's parsing and code generator.

The code below is how to manipulate the compiler's system variables for the code snippet above:

Dim PP2    As Byte System
Dim PP2H   As Byte System
Dim PP2HH  As Byte System
Dim PP2HHH As Byte System

Dim PPZ    As Byte System
Dim PPZH   As Byte System
Dim PPZHH  As Byte System
Dim PPZHHH As Byte System

Dim dPPZ  As PPZ.Dword
Dim dPP2  As PP2.Dword
Dim PB0   As dPP2.Byte0
Dim PB1   As dPP2.Byte1
Dim PB2   As dPP2.Byte2
Dim PB3   As dPP2.Byte3
Dim PZ0   As dPPZ.Byte0
Dim PZ1   As dPPZ.Byte1
Dim PZ2   As dPPZ.Byte2
Dim PZ3   As dPPZ.Byte3

Without knowing how the compiler uses its internal variables with more detail, please do not use them or it will cause problems that the compiler has no control over. This is why I did not add too much about the compiler's innards in the manuals, because if incorrectly altered it will screw it up, and it is not the compiler's fault!

atomix

Thanks for the detailed explanation.

It's just that I'm trying to use proton variables to use more variables in the bank 0 region.

top204

#3
To place a standard variable in lower RAM, use the Access directive:

Dim MyDword As Dword Access

On 18F devices it will place the variable in, Non-Banked, Access RAM, if it can. If Access RAM doesn't have the room for it, it will be placed just after Access RAM and the compiler will give a warning to tell the user that the variable is placed low, but not in Access RAM.

On a 14-bit core device, it will place the variable as low as it can in RAM because they do not have Access RAM in lower memory address'.

The Access directive will not work with arrays, or Bit type variables, but Bit types are automatically placed in low RAM anyway with the Positron8 compiler, so they are extremely efficient in use.

For PIC24 and dsPIC33 devices, the Access directive is ignored because they do have 'true' linear RAM, so it is not required.