PDA

View Full Version : Are my variable counts too high?



csantex
- 17th February 2020, 18:31
Hello everyone,

My question is if using over 5K bytes as multiple arrays, variables and cons within a PIC18F67K40 would cause PBP not to be able to fit more.
This PIC has a capacity of 128K bytes available.

I have mulple arrays that vary in size such as examples:

Array1 [540] var byte
Array2 [132] var byte
Array3 [132] var byte
Array4 [528] var byte
Array5 [132] var byte
Array6 [540] var byte
Array7 [6] var byte
.
.
.
Array18 [512] var byte
Array19 [512] var byte
Array20 [32] var word
Array21 [32] var word

Word1 var word
.
.
.
Word34 var word

byte1 var byte
.
.
.
byte27 var byte

con1 con 255 (byte value)
.
.
.
con33 con 255 (byte value)

con34 con 512 (word value)
.
.
.
con42 con 512 (word value)

This is just an example of how my variables, arrays and cons are listed in my code.
At compile, PBP states that only 33116 bytes are used. If I try to increase the size of my arrays, it states that it is unable to fit them in.
Do the 33116 bytes used include the 5K+ bytes listed as variables, arrays and cons?

Or am I missing something?

All feedback is appreciated,

csantex.

HenrikOlsson
- 17th February 2020, 20:24
You're mixing stuff a bit.
Variables (BIT, BYTE, WORD, LONG and arrays of these) are stored in RAM. Constants are replaced with there numeric value at compile time and are stored, together with the rest of the compiled program in program memory (FLASH). When you compile your code the reported size is how much room the program takes in FLASH - it's got nothing to do with how many variables you've declared.

The 18F67K40 has 128kB of program memory (where the compiled code is stored) and 3562 bytes of RAM (where you variables are held during runtime). PBP itself uses some of that RAM, the rest is free for you to use.

/Henrik

csantex
- 17th February 2020, 21:41
Thanks for your feedback HenrikOlsson!

I knew something was off when I made this post. It was my mind! Thanks for clearing this up for me.

csantex