Hi I am compiling a program on a 16f1783 in GCBasic.
My program was working fine until I created a new variable.
The program compiles fine with the variable defined or commented out, but when defined other variables become corrupted and unpredictable. When commented out the program is stable. if I change the variable name it makes no difference (i.e I am not using a system variable name etc.)
The variable is not used anywhere in the program. I was about to add new code all I literally did was add the variable.
I have changed to a larger capacity chip 16f1788. But it makes no difference.
Is there a point where variables run out of space, and the stack overflows into the variable memory area, or is there a code boundary limit beyond which GCbasic cannot exceed.
Thanks
Adrian
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
But, I haven't a compilation problem. As said "Adrian" (the creator of this post): "The program compiles fine with the variable defined or commented out, but when defined other variables become corrupted and unpredictable."
Anyway, I'll try with the latest build. I'll send you a private message.
Best regards,
Edorul
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Sorry but with this new "hex" file I have the same problem :-(
About weird behaviour, I've made some experiments and it seems that the problem comes from SWITCH_UP (=PortA.1): it is always detected as PRESSED (=1) even when the switch is released.
So it's not a variable problem but a port problem...
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
You've found the problem!!! It's just the misspell of "RELEASED" in the code which causes all my troubles (furthermore I've made the same misspelling when I've tested all my variables and ports) :-(
But it's weird that my code doesn't work as soon as I create a new variable... perhaps "REALEASED" was defined as 0x00 by default (as "RELEASED" is defined as 0x00, but on purpose) until the memory was rearanged when new variables were created ? And then it's default value has became something else than 0x00?????
Anyway thanks a lot for you help and I'm sorry to have wasted your time because of a misspelling error!!!!!
(Isn't it possible to add to "Great Cow Basic" an option to force the declaration of variables before their use? Something like in FreeBasic where you can place 'Option Explicit' at the program beginning in order to avoid implicit variables declaration)
Best regards,
Edorul
Last edit: edorul 2016-05-26
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
There is an #Option Explicit in the new compiler that Evan sent you. However it is "experimental" at this time and may return errors depending upon the source code.
To avoid implicit declarations, sometimes it may be a good practice to use DIM on all user variables and then to then write a value of zero to the variable. (Before the main loop runs).
Something like:
DIM Var1 as Byte : Var1 = 0
DIM Var2 as Word : Var2 = 0
Using DIM also enables the IDE to list the variables in the "Tree" pane. This helps to keep track of variables in user code.
William
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
If you use a variable in a statement, I thought GCB automatically set it up as a byte variable so no declaration was required. Only variables other than a byte needed to be declared. Or did that change?
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
While GCB will automatically set up a byte variable without DIM, I sometimes prefer to declare variables with "DIM as" at the beginning of code, or at the begining of a sub, so that I can look at the tree pane in the IDE and see what variables have been declared. I find that this makes it it easier to keep track of variables and to manage code, especially with large programs that use lots of variables.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Hi I am compiling a program on a 16f1783 in GCBasic.
My program was working fine until I created a new variable.
The program compiles fine with the variable defined or commented out, but when defined other variables become corrupted and unpredictable. When commented out the program is stable. if I change the variable name it makes no difference (i.e I am not using a system variable name etc.)
The variable is not used anywhere in the program. I was about to add new code all I literally did was add the variable.
I have changed to a larger capacity chip 16f1788. But it makes no difference.
Is there a point where variables run out of space, and the stack overflows into the variable memory area, or is there a code boundary limit beyond which GCbasic cannot exceed.
Thanks
Adrian
We can help.
I have seen this a long time ago. I mean two years ago.
Please post your code.
What version of the compiler? Date of gbasic.exe.
Hello,
I've exactly the same problem.
To answer to your previous questions :
date of "gbasic.exe" = 2016-02-24
my code is the following (note: the problem occurs when I add "DefinedCounterValue" and/or "ActualCounterValue"):
Best regards,
Edorul
Please send me a personal message. THis is is fixed in the current build. I will send you the pre-release version.
I have just test compiled, as follows.
20:46:41 G+Stool-COMPILE/ASSEMBLE, processing C:\GCB@Syn\G+Stools\makeHEX.bat
Source-File = C:\TEMP\memissue.gcb
Target-File = C:\TEMP\memissue.hex
6.3 Sec. Compiler Version: 0.95 2016-05-23 Program Memory: 352/4096 words (8.59%) RAM: 37/256 bytes (14.45%) Chip: 18F1330
Anobium
Hello,
Thanks for your reply.
But, I haven't a compilation problem. As said "Adrian" (the creator of this post): "The program compiles fine with the variable defined or commented out, but when defined other variables become corrupted and unpredictable."
Anyway, I'll try with the latest build. I'll send you a private message.
Best regards,
Edorul
Hi edorul ,
As a test to help isolate the problem, please try changing all bit variables to byte variables and let us know if anything changes.
Also, please attach your ASM code so that we can analyze.
Thanks
William
Last edit: William Roth 2016-05-25
Hello William,
I've tested with "Byte" variables instead of "Bit" ones, and I've the same strange behaviour.
As asked I join the ASM files (one with the "Bit" variables, the other with the "Byte" variables and the "gbc" file too).
Thanks :-)
Edorul
Edorul,
Thank you, We will analyze these
Attached is a HEX file of your program for testing. Please program the PIC with this HEX and let us know the results. - William
Are only certain variables or variable types corrupted? if so, which ones?
Sorry but with this new "hex" file I have the same problem :-(
About weird behaviour, I've made some experiments and it seems that the problem comes from SWITCH_UP (=PortA.1): it is always detected as PRESSED (=1) even when the switch is released.
So it's not a variable problem but a port problem...
I tested on 18F25K22 and PortA.1 works ok. I suspect that this is not a compiler problem but let's make sure other stuff is ok first.
Defined Constant "Released" is misspelled as REALEASED. Need to correct this first.
Check wiring. Make sure there is a 10K pulldown resistor on all switch pins that are active high.
Measure Voltage at PORTA.1. (Pin3) Does it change from 0V to 5V when button is pressed?
Review the use of braces in your code. Many are unnecessary
Example1: " If timer0 () > "
These braces are not necessary and should be simply "If timer 0 >"
William
Edit. Corrected spelling of "misspelled" :)
Last edit: William Roth 2016-05-25
Hello William,
You've found the problem!!! It's just the misspell of "RELEASED" in the code which causes all my troubles (furthermore I've made the same misspelling when I've tested all my variables and ports) :-(
But it's weird that my code doesn't work as soon as I create a new variable... perhaps "REALEASED" was defined as 0x00 by default (as "RELEASED" is defined as 0x00, but on purpose) until the memory was rearanged when new variables were created ? And then it's default value has became something else than 0x00?????
Anyway thanks a lot for you help and I'm sorry to have wasted your time because of a misspelling error!!!!!
(Isn't it possible to add to "Great Cow Basic" an option to force the declaration of variables before their use? Something like in FreeBasic where you can place 'Option Explicit' at the program beginning in order to avoid implicit variables declaration)
Best regards,
Edorul
Last edit: edorul 2016-05-26
Glad we have a resolution.
There is an #Option Explicit in the new compiler that Evan sent you. However it is "experimental" at this time and may return errors depending upon the source code.
To avoid implicit declarations, sometimes it may be a good practice to use DIM on all user variables and then to then write a value of zero to the variable. (Before the main loop runs).
Something like:
DIM Var1 as Byte : Var1 = 0
DIM Var2 as Word : Var2 = 0
Using DIM also enables the IDE to list the variables in the "Tree" pane. This helps to keep track of variables in user code.
William
If you use a variable in a statement, I thought GCB automatically set it up as a byte variable so no declaration was required. Only variables other than a byte needed to be declared. Or did that change?
No change. We are working on new capability. #option explicit. Do not use till we announce it is supported. As of May 2016 it is not supported.
While GCB will automatically set up a byte variable without DIM, I sometimes prefer to declare variables with "DIM as" at the beginning of code, or at the begining of a sub, so that I can look at the tree pane in the IDE and see what variables have been declared. I find that this makes it it easier to keep track of variables and to manage code, especially with large programs that use lots of variables.