News:

PROTON pic BASIC Compilers for PIC, PIC24, dsPIC33

Main Menu

Error assigning value to SDWORD array

Started by gtvpic, Jun 20, 2021, 04:00 PM

Previous topic - Next topic

gtvpic

Good,
I am using prositron version 4.0.0.2 with a PIC18F47K42
When assigning a value to an SDWORD variable of an array the assigned value is not correct, if I assign the value to a variable that is not from an array it works correctly.

I send example code to better explain the problem
Device       = 18F47K42
Declare Xtal = 64
Include "PIC18F47K42.INC"               ' Configuracion del Micro y Perifericos.
Declare Optimiser_Level  = 0
Configura_ES()                     ' Asigna los Pines

Dim Max_B_T[15]         As SDword       ' Calibracion Fondo Escala Bruto   T.
Dim Min_B_T[15]         As SDword       ' Calibracion Inicio Escala Bruto  T.
Dim Aux_SPS             As Byte         ' Auxiliar Telegramas de SPS Calibracion
Dim G0 As SDword
Dim G1 As SDword

Do
  Aux_SPS = 0
  Max_B_T[Aux_SPS] = -8388607
  Min_B_T[Aux_SPS] = -8388606

  Print At 1,1,"Max= " ,SDec Max_B_T[Aux_SPS] ,"             "
  Print At 2,1,"Min= " ,SDec Min_B_T[Aux_SPS] ,"             "

Loop

Assign the values:
Aux_SPS = 0
Max_B_T [Aux_SPS] = -8388607
Min_B_T [Aux_SPS] = -8388606
Outcome
Max_B_T [Aux_SPS] ---> 8388609
Min_B_T [Aux_SPS] ---> 8388610

Can you help me?
Thank you

IMG20210620175707.jpg


RGV250

Hi,
I think the issue is with the print command, if you create it for a 18F452 you can simulate it in the VSM and the variables table show the correct values.

Bob

RGV250

Hi,
A bit more info, if you use # for the array if shows the correct value, could not get it to compile with the value as Aux_SPS.
  Print At 1,1,"Max= " ,SDec Max_B_T#0 ,"             "
  Print At 2,1,"Min= " ,SDec Min_B_T#0 ,"             "

Bob

RGV250

Also, if you move the value into variable and print that it works.
Dim Max_B_T[15]         As SDword       ' Calibracion Fondo Escala Bruto   T.
Dim Min_B_T[15]         As SDword       ' Calibracion Inicio Escala Bruto  T.
Dim Aux_SPS             As Byte         ' Auxiliar Telegramas de SPS Calibracion
Dim G0 As SDword
Dim G1 As SDword

Dim Max_B_T_Print As SDword
Dim Min_B_T_Print As SDword

Do

  Aux_SPS = 0
  Max_B_T[Aux_SPS] = -8388607
  Min_B_T[Aux_SPS] = -8388606 
 
  Max_B_T_Print = Max_B_T[Aux_SPS]
  Min_B_T_Print = Min_B_T[Aux_SPS]
 
  Print At 1,1,"Max= " ,SDec Max_B_T_Print ,"             "
  Print At 2,1,"Min= " ,SDec Min_B_T_Print ,"             "

Loop   

Bob

gtvpic

As I comment in the original message "if I assign the value to a variable that is not from an array, it works correctly.". The problem arises with the assignment to matrices only.
I don't understand the use of "#".
I always assign the value to the arrays indicating the index between brackets
Min_B_T [Aux_SPS] = -8388606
it doesn't work either
Min_B_T
  • = -8388606

Any suggestion

Thank you very much for the help

gtvpic

Buenas RGV250

This code doesn't work either, so I understand that the problem is one of assignment to the matrix.

Device       = 18F47K42
Declare Xtal = 64
Include "PIC18F47K42.INC"               ' Configuracion del Micro y Perifericos.
Declare Optimiser_Level  = 0
Configura_ES()                     ' Asigna los Pines

Dim Max_B_T[15]         As SDword       ' Calibracion Fondo Escala Bruto   T.
Dim Min_B_T[15]         As SDword       ' Calibracion Inicio Escala Bruto  T.
Dim Aux_SPS             As Byte         ' Auxiliar Telegramas de SPS Calibracion
Dim G0 As SDword
Dim G1 As SDword

Do
  Aux_SPS = 0
  Max_B_T[Aux_SPS] = -8388607
  Min_B_T[Aux_SPS] = -8388606
  G0 = Max_B_T[Aux_SPS]
  G1 = Min_B_T[Aux_SPS]

  Print At 1,1,"G0= " ,SDec Max_B_T[Aux_SPS] ,"             "
  Print At 2,1,"G1= " ,SDec Min_B_T[Aux_SPS] ,"             "

Loop

Attached photograph of the result
IMG20210620175707.jpg

RGV250

Hi,
In your second example if you actually printed G0/G1 instead of Max_B_T[Aux_SPS] it comes out correct.

# is another way of addressing the array but I do not know how it can be used with an index, I cannot find it in the manual either.

I thought in your original post it was that the variable was being stored as an incorrect value so it messed up calculations.

Bob

gtvpic

This does not work
Do
  Aux_SPS = 0
  Max_B_T[Aux_SPS] = -8388607
  Min_B_T[Aux_SPS] = -8388606
  G0 = Max_B_T[Aux_SPS]
  G1 = Min_B_T[Aux_SPS]

  Print At 1,1,"G0= " ,SDec Max_B_T[Aux_SPS] ,"             "
  Print At 2,1,"G1= " ,SDec Min_B_T[Aux_SPS] ,"             "

Loop

This works fine
Do
  Aux_SPS = 0
  Max_B_T[Aux_SPS] = -8388607
  Min_B_T[Aux_SPS] = -8388606
  G0 = -8388607      ' Max_B_T[Aux_SPS]
  G1 = -8388606      ' Min_B_T[Aux_SPS]

  Print At 1,1,"G0= " ,SDec Max_B_T[Aux_SPS] ,"             "
  Print At 2,1,"G1= " ,SDec Min_B_T[Aux_SPS] ,"             "

Loop

So I think the problem is in the assignment of the value to the matrix.

I will have to check the code directly in the assembler to see where the problem comes from, which means a little more time.
This code is an example, the problem is detected in the program I am making, which is quite large and it already cost me all day to get to this point and generate the example to be able to ask for help in the forum.
Let's see if someone contributes any ideas before I go crazy  ;D  ;D  ;D
Thank you
A great forum


trastikata

Hi,

Did you use "Declare Auto_Heap_Arrays" ? Try with it ON and OFF

Also for test purposes instead of variable index try using a number directly, like:

Max_B_T[0] = -8388607
Min_B_T[0] = -8388606

Print At 1,1,"G0= " ,SDec Max_B_T[0] ,"             "
Print At 2,1,"G1= " ,SDec Min_B_T[0] ,"             "

And when you print, instead of using array, pass it first to a variable:

Dim TempSDword as SDword

Max_B_T[0] = -8388607
Min_B_T[0] = -8388606

TempSDword = Max_B_T[0]
Print At 1,1,"G0= " ,SDec TempSDword ,"             "
TempSDword = Min_B_T[0]
Print At 2,1,"G1= " ,SDec TempSDword ,"             "


I think I noticed some anomalies with Auto_Heap_Arrays and sometimes using arrays and index variables (not related anomalies), but did not have time to investigate and report something certain. If you can, try and see if any of the above resolves the problem.

Pepe


top204

#10
I have examined the compiler's assembler code it produces from your snippet, and I can see the problem happening.

It is loading the array correctly, but is not converting the Signed Dword array to ASCII correctly for transmitting or displaying on an LCD. For some reason, it is seeing a Long variable type array instead of a Dword type in a particular function within the compiler. Maybe recursion anomalies happening again within the C++ code.

I'll get on to it ASAP and upload a free anomaly fixing update.

Many thanks for spotting the anomaly and posting a good snippet of code to examine.

top204

I have found and corrected the anomaly, and an update is available from here:

Positron Compilers corrections update 4.0.0.3

Thanks for spotting the anomaly. It was a typo mistake made by me when I was first adding Long variable type arrays, so it has been with the compiler for quite a while now. The compiler was calling the function to read a Long array instead of a Dword array when the SDec modifier was used.

gtvpic

Thanks to You, Les, for the great work and patience you have to keep going with this great compiler. I encourage you to keep moving forward and never stop trusting yourself.

Also thank you very much to the Forum for how well it works and with the desire that they put to solve the problems

Thank you

gtvpic

Good again
Download version 4.0.0.3 and install it, so I'm on the latest version.
The previous problem was solved but now another appears with the assignment of matrices with the index. If the index I assign it with a number directly, the matrix takes the value and it works correctly, on the other hand, if the index I assign it with a BYTE variable, the matrix apparently does not take the value.
I present two example, This one works correctly:
Device       = 18F47K42
Declare Xtal = 64
Include "PIC18F47K42.INC"               ' Configuracion del Micro y Perifericos.
Declare Optimiser_Level  = 0
Configura_ES()                          ' Asigna los Pines

Dim Aux_SPS             As Byte         ' Auxiliar Telegramas de SPS Calibracion
Dim Max_V_T[15]         As Float        ' Calibracion Fondo  Escala Medida T.
Dim Min_V_T[15]         As Float        ' Calibracion Inicio Escala Medida T.

Do
  Aux_SPS = 0
  Max_V_T[7] =  1000.0
  Min_V_T[7] = -1000.0

  Print At 1,1,"Max= " ,Dec Max_V_T[7] ,"             "
  Print At 2,1,"Min= " ,Dec Min_V_T[7] ,"             "

Loop

On the other hand, this code does not assign the value to the arrays:

Device       = 18F47K42
Declare Xtal = 64
Include "PIC18F47K42.INC"               ' Configuracion del Micro y Perifericos.
Declare Optimiser_Level  = 0
Configura_ES()                          ' Asigna los Pines

Dim Aux_SPS             As Byte         ' Auxiliar Telegramas de SPS Calibracion
Dim Max_V_T[15]         As Float        ' Calibracion Fondo  Escala Medida T.
Dim Min_V_T[15]         As Float        ' Calibracion Inicio Escala Medida T.

Do
  Aux_SPS = 0
  Max_V_T[Aux_SPS] =  1000.0
  Min_V_T[Aux_SPS] = -1000.0

  Print At 1,1,"Max= " ,Dec Max_V_T[Aux_SPS] ,"             "
  Print At 2,1,"Min= " ,Dec Min_V_T[Aux_SPS] ,"             "

Loop

It seems that this week I have it complicated.  :PAG  :PAG  :PAG

Thank you

top204

#14
I missed this thread because it had the same title as the SDword anomaly. Please open a new thread for any different questions in future. :-)

Yes... I've ran a test, and the floating point constant value is being placed in the float array in the reverse order. So the value is correct, just reversed within the Float Array's RAM. :-)

This anomaly appears to have been with the compiler for quite a few years, so many thanks for spotting it and giving code that allow it to be examined.

To counteract this anomaly until I get a fix, use a temporary Float variable to store the constant in, then load the Float Array with the temporary Float variable.

I'm on it now, so should have a free update ASAP to download.

top204

An update to correct the constant value assigned to a Float array which has a variable as its index is available here:

Positron Compilers corrections update 4.0.0.4

gtvpic

Thanks TOP204.
Today All day working and I could not respond to emails or connect to the forum. I see that you located the thread and as always the solution very fast.
As always a great pleasure to have a great compiler service and a very good support forum.
This great "POSITRON" compiler continues to advance and many thanks to all of you for the great work you have done.
All the best.

top204

Many thanks.

I try my hardest to keep the compilers as trustworthy as possible, but sometimes, anomalies creep in because I am only human, and the compiler source code is huge and inter-woven. :-)

I have always prided myself as being a person that will admit I was wrong, unlike some people I have known in the past, who are always right, even when it is obvious they are/were wrong, so they make excuses up to put the blame on others and not themselves. :-)