Page 1 of 1
ARRAYS in supplementary code
Posted: Tue Sep 15, 2020 4:03 pm
by Kisen
Hi,
I would like to create some Arrays in C code that can be called as required.
I am very conscious of the RAM that i am using so i dont want to have all of the arrays stored in RAM.
When adding arrays in supplementary code are these stored in the RAM or in the FLASH memory?
If they arent stored in the FLASH is there a way to define them in the chart but only have them used in the RAM when they are written into an array?
Re: ARRAYS in supplementary code
Posted: Tue Sep 15, 2020 4:05 pm
by Benj
Hello,
Can you use the LUT component available under storage, this effectively creates a ROM based array you can call directly within the flow chart.
Re: ARRAYS in supplementary code
Posted: Tue Sep 15, 2020 6:30 pm
by Kisen
It has just started coming back to me. I have done this before on PIC.
So i just added this to supplementary code
Code: Select all
//LED BATTERY PROFILE 4
rom char* BATTERY4 = {0xFF , 0x8F , 0x00, //LED 1 ORANGE
0xFF , 0x8F , 0x00, //LED 2 ORANGE
0xFF , 0x8F , 0x00, //LED 3 ORANGE
0x00 , 0x00 , 0x00, //LED 4 OFF
0x00 , 0x00 , 0x00}; //LED 5 OFF
I thought this would compile OK. But i get this error.
Q1 TEST.c:344:5: error: expected '=', ',', ';', 'asm' or '__attribute__' before 'char'
rom char* BATTERY4 = {0xFF , 0x8F , 0x00, //LED 1 ORANGE
I cant see anything wrong, no missing commas etc. Any ideas?
Re: ARRAYS in supplementary code
Posted: Tue Sep 15, 2020 7:28 pm
by Bachman
Maybe:
Code: Select all
const rom unsigned char BATTERY4[]={
0xFF , 0x8F , 0x00, //LED 1 ORANGE
0xFF , 0x8F , 0x00, //LED 2 ORANGE
0xFF , 0x8F , 0x00, //LED 3 ORANGE
0x00 , 0x00 , 0x00, //LED 4 OFF
0x00 , 0x00 , 0x00}; //LED 5 OFF
Re: ARRAYS in supplementary code
Posted: Tue Sep 15, 2020 7:39 pm
by Kisen
Hi Bachman,
I tried your code. I get the same error, unfortunatly.
Re: ARRAYS in supplementary code
Posted: Tue Sep 15, 2020 11:07 pm
by Benj
This should work, It's what the Lookup table component generates.
Code: Select all
const unsigned char BATTERY4 [] =
{
0xFF , 0x8F , 0x00, //LED 1 ORANGE
0xFF , 0x8F , 0x00, //LED 2 ORANGE
0xFF , 0x8F , 0x00, //LED 3 ORANGE
0x00 , 0x00 , 0x00, //LED 4 OFF
0x00 , 0x00 , 0x00 //LED 5 OFF
};
Re: ARRAYS in supplementary code
Posted: Wed Sep 16, 2020 12:27 am
by medelec35
I'm using 47K of bytes within supplementary code as loading images
The only way all 47K could be loaded was by using the format:
Code: Select all
char const unsigned BATTERY4[] ={0xFF , 0x8F , 0x00, //LED 1 ORANGE
0xFF , 0x8F , 0x00, //LED 2 ORANGE
0xFF , 0x8F , 0x00, //LED 3 ORANGE
0x00 , 0x00 , 0x00, //LED 4 OFF
0x00 , 0x00 , 0x00 //LED 5 OFF
};
Any other way would cause a ran out of memory issue.
For example if you have lots of data then:
Does not place data in ROM, it places it in RAM instead.
Funny how it all works.
Re: ARRAYS in supplementary code
Posted: Wed Sep 16, 2020 7:30 am
by Kisen
medelec35 wrote: ↑Wed Sep 16, 2020 12:27 am
I'm using 47K of bytes within supplementary code as loading images
The only way all 47K could be loaded was by using the format:
Code: Select all
char const unsigned BATTERY4[] ={0xFF , 0x8F , 0x00, //LED 1 ORANGE
0xFF , 0x8F , 0x00, //LED 2 ORANGE
0xFF , 0x8F , 0x00, //LED 3 ORANGE
0x00 , 0x00 , 0x00, //LED 4 OFF
0x00 , 0x00 , 0x00 //LED 5 OFF
};
Any other way would cause a ran out of memory issue.
For example if you have lots of data then:
Does not place data in ROM, it places it in RAM instead.
Funny how it all works.
Hi,
I tried Bens example and this compiles fine now.
I have just seem your post this morning, medelec35.
so i have this correct....
Your example, puts the data in the ROM
Bens example, puts the data in the RAM
How do i know for sure where its being placed? Can i check this sort of thing somehow?
Re: ARRAYS in supplementary code
Posted: Wed Sep 16, 2020 2:47 pm
by medelec35
I'm not sure in the answer.
It was LeighM that said to use
Since I was requiring lots of data.
He will know far more than me.
The topic is in a hidden section of the forum for staff and VC members.
I have moved it to the public section for other people to learn from.
Here is the
link
Rereading the topic.
The other way the data is not stored in RAM, but is treated as a RAM variable.
Note: Started out with AVR and ended up with PIC, so both are covered in the topic.
Hope you find the reading useful?