ARRAYS in supplementary code

For Flowcode users to discuss projects, flowcharts, and any other issues related to Flowcode 8.

Moderator: Benj

Post Reply
Kisen
Posts: 73
Joined: Fri Jan 24, 2020 10:38 am
Has thanked: 4 times
Been thanked: 2 times
Contact:

ARRAYS in supplementary code

Post 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?

User avatar
Benj
Matrix Staff
Posts: 15312
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4803 times
Been thanked: 4314 times
Contact:

Re: ARRAYS in supplementary code

Post 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.

Kisen
Posts: 73
Joined: Fri Jan 24, 2020 10:38 am
Has thanked: 4 times
Been thanked: 2 times
Contact:

Re: ARRAYS in supplementary code

Post 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?

User avatar
Bachman
Posts: 116
Joined: Sun Sep 07, 2014 11:37 am
Location: Hungary
Has thanked: 9 times
Been thanked: 53 times
Contact:

Re: ARRAYS in supplementary code

Post 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

Kisen
Posts: 73
Joined: Fri Jan 24, 2020 10:38 am
Has thanked: 4 times
Been thanked: 2 times
Contact:

Re: ARRAYS in supplementary code

Post by Kisen »

Hi Bachman,

I tried your code. I get the same error, unfortunatly.

User avatar
Benj
Matrix Staff
Posts: 15312
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4803 times
Been thanked: 4314 times
Contact:

Re: ARRAYS in supplementary code

Post 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
};

medelec35
Matrix Staff
Posts: 9520
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Has thanked: 2585 times
Been thanked: 3815 times
Contact:

Re: ARRAYS in supplementary code

Post 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:

Code: Select all

const unsigned char BATTERY4[] =
Does not place data in ROM, it places it in RAM instead.
Funny how it all works.
Martin

Kisen
Posts: 73
Joined: Fri Jan 24, 2020 10:38 am
Has thanked: 4 times
Been thanked: 2 times
Contact:

Re: ARRAYS in supplementary code

Post 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:

Code: Select all

const unsigned char BATTERY4[] =
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....

Code: Select all

char const unsigned  BATTERY4[] =
Your example, puts the data in the ROM

Code: Select all

const unsigned char BATTERY4 [] =
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?

medelec35
Matrix Staff
Posts: 9520
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Has thanked: 2585 times
Been thanked: 3815 times
Contact:

Re: ARRAYS in supplementary code

Post by medelec35 »

I'm not sure in the answer.
It was LeighM that said to use

Code: Select all

char const unsigned 
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?
Martin

Post Reply