Hi. I usually write with your basic compiler, but now it gave me an error like this:
Error: The array xxx is too large
I don't think the dimension is a lot expensive for the microchip microcontroller and I believe that it could be a compiler error. At least for an array like this
It's strange that for an other array (into same code) more expensive about elements, the compiler doesn't report the same error instead for the second, one on the top, it crashes with an error!
What do you think about?
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Copying the array define into another program, and it compiles fine. Have you tried commenting the larger array out, and tried compiling that?
How many variables do you have?
Is the program space nearly maxed out? Check for it in places like the Pickit "Program Window", the compiled.lst file if using MPASM or possibly gputils for the assembler. Could be you need a device with more program memory.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
;Variables
Dim UnoA(94)
Dim UnoB(94)
Dim UnoC(94)
Dim UnoD(94)
The compiler give me an error for the last 3 arrays (B C D). I have to write more than one for my software and the compiler not allow me to do it. But the memory of microcontroller isn't over, I don't understand because this compiler give me all this problems!
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Unfortunately, you will need to use a different PIC chip, or use smaller arrays!
Each array has 94 elements, or 95 once you include the 0 element. Each array will take 95 bytes of RAM to store, so for 4 arrays you will need 380 bytes of RAM. But on the 12F683, there are only 128 bytes of RAM, so there is no way that this will work. Another problem is that arrays in GCBASIC must not be larger than one "bank" of data memory. On the 12F683, there is a bank of 96 bytes, and a bank of 32. But GCBASIC uses 16 bytes from the first bank for temporary variables, so you can only have an array of 80 elements on a 12F683.
The 8 pin PIC with the largest data memory is the 12F1840, which has 256 bytes of RAM. Maybe this will work, but if you need more memory you will need to use a larger PIC, like the PIC18F14K22 which has 20 pins and 512 bytes of RAM.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
The 12f683 has 128 bytes of ram, you are asking for minimum 376 plus overhead.
I'll attempt to explain myself a little better on variables. When using arrays, general purpose ram is addressed indirectly (INDF) through the file select (FSR) addressing scheme. So my mistake, even though UnoA, UnoB, etc. show as only one variable in the compiler output, there is much more to it. This is best shown by an example using the following arrays:
#chip 12f683,4
Dim UnoA(25)
Dim UnoB(25)
Dim UnoC(25)
Dim UnoD(25)
Main:
For number = 1 to 25
UnoA(number) = number
UnoB(number) = number
UnoC(number) = number
UnoD(number) = number
Next
goto Main
Then looking at the absolute or EQU locations from the compiled.asm:
The 12f683 has 128 bytes of static ram. The memory map location for general purpose ram runs out at location BFh or dec 191. As you can see from the UNOA EQU we are pointed at 164, then add the size of the array of 25 which makes it top out at 189. Still room for more ram to be placed, here and there.
If by chance you are trying to run bitmaps on a glcd, then definitely go with a much larger device, like a 18f45k22.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
1. Yes, you can write you code to save/retrieve to/from eeprom. You may ask 'why does the array handler not do this anyway?' Because, the use of RAM is the norm for array handling. I know a lot of compilers and this is the general case. You can write you own code to save/retrieve to eeprom this would work, but, be aware this will be a slower process than using RAM for storage.
2. What are trying to achieve? What is your goal? This may help us to help you. :-)
Depends
Last edit: Anobium 2013-09-18
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
What is the goal? I have to write on output a series of data contained in these arrays. That's all, but I want to do it without other memory devices connected if possible.
I hoped that with all the program memory available this couldn't be a true problem.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
First, the table must be created. The code to create a lookup table is simple - a line that has "Table" and then the name of the table, a list of numbers (up to 254), and then "End Table".'
So, 254 elements.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Ok, the Tables are just great! But... is it possible to set a Table temporary? I need it to optimize my code, there are many subroutines that make the same sub-code and it's a waste in this way.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Tables are for constants. Use the 80 element array per Hugh.
A 8 pin 12f1840 can give you 256 ram. A 14 pin 16f1825 can give you 1024 ram. Too big? use a tssop pkg.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I read that 12f1840 can't be wrote the with pickit 2, but only with the pickit 3. It's a good microchip, but I would like that my device was programmable with the first version of pickit, even though I have both! Thanks for the tips!
I try in every possible way to put inside the 12f683 my software, even if it's complicated.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I am the same way about the Pickit 2, the Pickit 3 is just a pretender. I can only hope that they continue periodic updates of the Pickit 2. Speaking of which, the device file version 1.62.14 does indeed have the 12f1840, along with many other of the enhanced midrange devices. Good luck either way.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Only a question that seem off topic but it isn't. About math with this basic compiler, is it possible to separate the module from the decimal part of a floating point number?
Which are the commands?
I have opened with "not off topic" because it could be a good solution to apply a compression over data if there is some command code to do it.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I tried to use the 'remainder' with the command that you have suggested "SysCalcTempX", but it doesn't seem to work. This is the example code:
;Chip Settings
#chip 12F683,8
#config FCMEN=OFF, IESO=OFF, BOD=OFF, CPD=OFF, CP=OFF, MCLRE=ON, PWRTE=OFF, WDT=OFF, OSC=INTRC_OSC_NOCLKOUT
;Variables
Dim i As integer
Dim GenOut As integer
Dim ones As integer
Dim zeros As integer
Dim SysCalcTempX As integer
;Data tables
Table U
302
303
...
301
705
End Table
Table No
203
604
....
101
503
101
502
End Table
uu = 61
noo = 145
Main:
one
Wait 1000 ms
Goto Main
Sub one
check = 1
For i = 1 To uu
ReadTable U, i, GenOut
generate
Next
check = 1
For i = 1 To noo
ReadTable No, i, GenOut
generate
Next
End Sub
Sub generate
ones = GenOut/100
zeros = SysCalcTempX
If check = 1 Then
Set GPIO.5 On
Wait ones*31 10us
Set GPIO.5 Off
check = 0
Else
Wait zeros*31 10us
check = 1
End If
End Sub
Could you help me?
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I just run up your code. No issues with SysCalctempX.
However, I had to make a number of changes to get the code to run. A few errors in your method.
Changes:
1. Do not use variables with single characters. I now use the following:
ug_variablename - where the ug_... means User Global
ul_variablename - where the ul_... means the variable is local to the SUB or Function
2. Do not redeclare SySCalcTempX. This is already defined as a PUBLIC global. (A good question would be to ask Hugh..... is what is the complete list of PUBLIC globals).
3. I am not sure why use define variables as Integers. I think you need Words.
I hope this helps. My code and output (this is the debug screen, see my code)
' Define the switch port
#define SwitchIn1 PORTD.2
Dir SwitchIn1 In
'address of switch - required by method
#define check_switch RD2
'initial state of the switch - required by method
#define state_switch OFF
;Variables
Dim GenOut As word
Dim ones As word
Dim zeros As word
'Dim SysCalcTempX As integer
Dim tempvar as word
;Data tables
Table MyTable1
302
303
301
705
End Table
Table No
203
604
101
503
101
502
End Table
uu = 4
noo = 6
Wait 1000 ms
ANSIERASECREEN
ANSI(0,0)
Main:
one
Wait 1000 ms
end
Sub one
check = 0
For myLoop = 1 To uu
ReadTable MyTable1, myLoop, GenOut
HSerPrint myLoop: HSerPrint ": GenoutU = ": hserprint GenOut:HSerSend 9
generate
Next
check = 0
For myLoop = 1 To noo
ReadTable No, myLoop, GenOut
HSerPrint myLoop: HSerPrint ": GenoutNo = ": hserprint GenOut:HSerSend 9
generate
Next
End Sub
Sub generate
ones = GenOut/100
zeros = SysCalcTempX
HSerPrint "Sx = ": hserprint zeros: HSerSend 9
If check = 1 Then
' Set GPIO.5 On
Wait ones*31 10us
' Set GPIO.5 Off
check = 0
Else
tempvar = zeros * 31
Wait tempvar 10us
HSerPrint "tempvar = ": hserprint tempvar:crlf(1)
check = 0
End If
End Sub
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Hi. I usually write with your basic compiler, but now it gave me an error like this:
I don't think the dimension is a lot expensive for the microchip microcontroller and I believe that it could be a compiler error. At least for an array like this
It's strange that for an other array (into same code) more expensive about elements, the compiler doesn't report the same error instead for the second, one on the top, it crashes with an error!
What do you think about?
Copying the array define into another program, and it compiles fine. Have you tried commenting the larger array out, and tried compiling that?
How many variables do you have?
Is the program space nearly maxed out? Check for it in places like the Pickit "Program Window", the compiled.lst file if using MPASM or possibly gputils for the assembler. Could be you need a device with more program memory.
If I write something like this:
The compiler give me an error for the last 3 arrays (B C D). I have to write more than one for my software and the compiler not allow me to do it. But the memory of microcontroller isn't over, I don't understand because this compiler give me all this problems!
Unfortunately, you will need to use a different PIC chip, or use smaller arrays!
Each array has 94 elements, or 95 once you include the 0 element. Each array will take 95 bytes of RAM to store, so for 4 arrays you will need 380 bytes of RAM. But on the 12F683, there are only 128 bytes of RAM, so there is no way that this will work. Another problem is that arrays in GCBASIC must not be larger than one "bank" of data memory. On the 12F683, there is a bank of 96 bytes, and a bank of 32. But GCBASIC uses 16 bytes from the first bank for temporary variables, so you can only have an array of 80 elements on a 12F683.
The 8 pin PIC with the largest data memory is the 12F1840, which has 256 bytes of RAM. Maybe this will work, but if you need more memory you will need to use a larger PIC, like the PIC18F14K22 which has 20 pins and 512 bytes of RAM.
The 12f683 has 128 bytes of ram, you are asking for minimum 376 plus overhead.
I'll attempt to explain myself a little better on variables. When using arrays, general purpose ram is addressed indirectly (INDF) through the file select (FSR) addressing scheme. So my mistake, even though UnoA, UnoB, etc. show as only one variable in the compiler output, there is much more to it. This is best shown by an example using the following arrays:
Then looking at the absolute or EQU locations from the compiled.asm:
The 12f683 has 128 bytes of static ram. The memory map location for general purpose ram runs out at location BFh or dec 191. As you can see from the UNOA EQU we are pointed at 164, then add the size of the array of 25 which makes it top out at 189. Still room for more ram to be placed, here and there.
If by chance you are trying to run bitmaps on a glcd, then definitely go with a much larger device, like a 18f45k22.
Oops, Hugh beat me to it.
Is it possible to store this arrays on eeprom of chip? Or on program memory? Any solutions?
Just another question. Why all variables have to be loaded into RAM of 12f683?
It would be easier to load all the necessary step by step...
The answer is simple, 'it depends'.
1. Yes, you can write you code to save/retrieve to/from eeprom. You may ask 'why does the array handler not do this anyway?' Because, the use of RAM is the norm for array handling. I know a lot of compilers and this is the general case. You can write you own code to save/retrieve to eeprom this would work, but, be aware this will be a slower process than using RAM for storage.
2. What are trying to achieve? What is your goal? This may help us to help you. :-)
Depends
Last edit: Anobium 2013-09-18
What is the goal? I have to write on output a series of data contained in these arrays. That's all, but I want to do it without other memory devices connected if possible.
I hoped that with all the program memory available this couldn't be a true problem.
Could use the ReadTable command (see Help file) to store data sets in program memory, but it also takes the speed hit that Anobium alludes to.
How much could be long a Table?
Just pulled this from the help file.
'Using Lookup Tables
First, the table must be created. The code to create a lookup table is simple - a line that has "Table" and then the name of the table, a list of numbers (up to 254), and then "End Table".'
So, 254 elements.
Ok, the Tables are just great! But... is it possible to set a Table temporary? I need it to optimize my code, there are many subroutines that make the same sub-code and it's a waste in this way.
Tables are for constants. Use the 80 element array per Hugh.
A 8 pin 12f1840 can give you 256 ram. A 14 pin 16f1825 can give you 1024 ram. Too big? use a tssop pkg.
I read that 12f1840 can't be wrote the with pickit 2, but only with the pickit 3. It's a good microchip, but I would like that my device was programmable with the first version of pickit, even though I have both! Thanks for the tips!
I try in every possible way to put inside the 12f683 my software, even if it's complicated.
I am the same way about the Pickit 2, the Pickit 3 is just a pretender. I can only hope that they continue periodic updates of the Pickit 2. Speaking of which, the device file version 1.62.14 does indeed have the 12f1840, along with many other of the enhanced midrange devices. Good luck either way.
I've been using the Pickit 2 to program 12f1840. What is the problem supposed to be?
I have created a new posting for the Pickit debate. See https://sourceforge.net/p/gcbasic/discussion/579125/thread/fbb69eae/#171f
Only a question that seem off topic but it isn't. About math with this basic compiler, is it possible to separate the module from the decimal part of a floating point number?
Which are the commands?
I have opened with "not off topic" because it could be a good solution to apply a compression over data if there is some command code to do it.
I did a search for 'remainder'. there is lots more info.
In Help forum : _ http://sourceforge.net/projects/gcbasic/forums/forum/579126/topic/1827101?message=4526599_
W_Cholmondeley writes :
"SysCalcTempX stores the remainder after a division, and using it saves some calculations.)"
I tried to use the 'remainder' with the command that you have suggested "SysCalcTempX", but it doesn't seem to work. This is the example code:
Could you help me?
I just run up your code. No issues with SysCalctempX.
However, I had to make a number of changes to get the code to run. A few errors in your method.
Changes:
1. Do not use variables with single characters. I now use the following:
ug_variablename - where the ug_... means User Global
ul_variablename - where the ul_... means the variable is local to the SUB or Function
2. Do not redeclare SySCalcTempX. This is already defined as a PUBLIC global. (A good question would be to ask Hugh..... is what is the complete list of PUBLIC globals).
3. I am not sure why use define variables as Integers. I think you need Words.
I hope this helps. My code and output (this is the debug screen, see my code)
OUTPUT:
1: GenoutU = 302 Sx = 2 tempvar = 62
2: GenoutU = 303 Sx = 3 tempvar = 93
3: GenoutU = 301 Sx = 1 tempvar = 31
4: GenoutU = 705 Sx = 5 tempvar = 155
1: GenoutNo = 203 Sx = 3 tempvar = 93
2: GenoutNo = 604 Sx = 4 tempvar = 124
3: GenoutNo = 101 Sx = 1 tempvar = 31
4: GenoutNo = 503 Sx = 3 tempvar = 93
5: GenoutNo = 101 Sx = 1 tempvar = 31
6: GenoutNo = 502 Sx = 2 tempvar = 62
CODE:
~~~~~
#chip 16F1937, 32
#config Osc = intOSC, MCLRE_OFF, PLLEN_ON, VCAPEN_OFF
#include "D:\Microchip\Projects\Great Cow Basic\DC Motor Controller\input.gcb"
#include "D:\Microchip\Projects\Great Cow Basic\DC Motor Controller\outputserial.gcb"
#include "D:\MicroChip\Projects\Great Cow Basic\DC Motor Controller\outputdevices_009.gcb"
#define ANSITERMINAL
' Define the LED ports
#define LED1 LATD1
#define LED2 LATE2
#define LED3 LATE1
#define LED4 LATE0
' Define the ADC port
Dir PORTB.2 In
#define ADCPort AN8
dim ADCreading as word
' Define the switch port
#define SwitchIn1 PORTD.2
Dir SwitchIn1 In
'address of switch - required by method
#define check_switch RD2
'initial state of the switch - required by method
#define state_switch OFF
;Variables
Dim GenOut As word
Dim ones As word
Dim zeros As word
'Dim SysCalcTempX As integer
Dim tempvar as word
;Data tables
Table MyTable1
302
303
301
705
End Table
Table No
203
604
101
503
101
502
End Table
uu = 4
noo = 6
Wait 1000 ms
ANSIERASECREEN
ANSI(0,0)
Main:
one
Wait 1000 ms
end
Sub one
check = 0
For myLoop = 1 To uu
ReadTable MyTable1, myLoop, GenOut
HSerPrint myLoop: HSerPrint ": GenoutU = ": hserprint GenOut:HSerSend 9
generate
Next
End Sub
Sub generate
' Set GPIO.5 On
Wait ones*31 10us
' Set GPIO.5 Off
check = 0
Else
tempvar = zeros * 31
Wait tempvar 10us
HSerPrint "tempvar = ": hserprint tempvar:crlf(1)
check = 0
End If
End Sub