array

For Flowcode users to discuss projects, flowcharts, and any other issues related to Flowcode 5.
To post in this forum you must have a registered copy of Flowcode 5 or higher.

Moderator: Benj

Post Reply
brandonb
Posts: 438
Joined: Mon Aug 29, 2011 12:26 am
Location: arizona
Has thanked: 175 times
Been thanked: 173 times
Contact:

array

Post by brandonb »

was wondering what i can do with an array and what the limitations are, pretty much wanted to use it as a look up table with count+1 scheme if it works that way..i cant seem to link the array as a whole to another variable, .. martin sorry i deleted the last post on this, didnt mean to mess you up on that :oops:
Attachments
trying counting arrays.fcf
(9.5 KiB) Downloaded 247 times

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

Post by medelec35 »

brandonb wrote:, .. martin sorry i deleted the last post on this, didnt mean to mess you up on that :oops:
Did not mess anything up at all bud, I just PM'd you to let you know I was answering your post as it was deleted, just to find out if you still wanted the question answering or not. Did not matter either way :)
I was not sure If you deleted because you have found the answer or not

I have modified your flowchart to work like the LUT

To get you flowchart to work like a look-up-table with arrays:
It uses the format:

Code: Select all

Delay = us[count]
So if Count = 5
Delay = us[5]
= 500

Hope this helps.

Martin
Attachments
trying counting arrays1.fcf
(10.5 KiB) Downloaded 260 times
Martin

brandonb
Posts: 438
Joined: Mon Aug 29, 2011 12:26 am
Location: arizona
Has thanked: 175 times
Been thanked: 173 times
Contact:

Re: array

Post by brandonb »

thanks martin!!! thats awesome... what are my limits using arrays in version5, like how many different arrays can i have, how many different numbers can i have in it, whats the largest number i can use "uint", is there any differences in arrays compared to look up tables other than arrays take longer to create... pretty much i wanted to know my limits which is what i can do and what i cant do with arrays? also where do i generaly put the array?(above the loop"?

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

Post by medelec35 »

Hi Brandon,
Attached is a quick way of generating an array.
This is just an example to look at, and you won't be able to compile to your target device since it takes too much rom up.
Like LUT's array will be limited to 256 (0 - 255) elements, and will be limited to targets available rom.
If you go over the 256 elements then there will be roll-over.

E.g if you assign My_Delay[0] =65
then My_Delay[256] = 80
then that will just reassign My_Delay[0] = 80

I believe the number that can be assigned is limited to only the type of variable.

E.g if Variable is a UInt then max = 65535
My_Delay[0] =65534
My_Delay[1] =65535

Try to limit the type of variable as much as possible.
E.g if maximum number is 250 then you should only use bytes and not integers.

I believe this is correct but not 100% sure.

Hope this helps.

Martin
Attachments
trying counting arrays2.fcf
(11 KiB) Downloaded 278 times
Martin

brandonb
Posts: 438
Joined: Mon Aug 29, 2011 12:26 am
Location: arizona
Has thanked: 175 times
Been thanked: 173 times
Contact:

Re: array

Post by brandonb »

what happened to the memory? :o

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

Post by medelec35 »

medelec35 wrote: This is just an example to look at, and you won't be able to compile to your target device since it takes too much rom up.
Reason being this was just a demo as you wanted to know how many arrays you can have and I just used Uint = 0 to 65535.

The array used up 256 * 16 bits = a lot of rom.
That's why you need to limit if using large numbers.
If using bytes it will take same space as LUT.
Martin

brandonb
Posts: 438
Joined: Mon Aug 29, 2011 12:26 am
Location: arizona
Has thanked: 175 times
Been thanked: 173 times
Contact:

Re: array

Post by brandonb »

ok i was messing with this tonight, i see what you mean ([80] bytes are 10% memory), how would i be able to add 2 or more arrays together to come up with Uint numbers.. thanks for helping me with this!!!

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

Post by medelec35 »

brandonb wrote:how would i be able to add 2 or more arrays together to come up with Uint numbers.. thanks for helping me with this!!!
Your welcome bud.

I believe it would take up the same memory, so may not be worth splitting. Since one UInit = 16 bit and two Bytes = 16 bit

My advice would be use a calculation to derive Delays based on value of count whenever possible, so you can avoid using a high quantity of arrays.

Only for the values which cannot be calculated use arrays.

E.g if for count 1: delay = 100 us
Count 2: delay = 200 us
Ect
then Delay = Count * 100
Delay us

Using UInt for delay then Max delay can be 65535us.
You can also use decision branches for ms.
If count >500:
Delay = Count * 10
Delay ms
Martin

brandonb
Posts: 438
Joined: Mon Aug 29, 2011 12:26 am
Location: arizona
Has thanked: 175 times
Been thanked: 173 times
Contact:

Re: array

Post by brandonb »

hey martin, really what i wanted to do with the array thing is create numbers for pressure and temp sensors, then link adc to it, those kind of sensors arent linier, i was doing the delay examples as just something that was easy to follow, this way with an array with a vaccum sensor i wouldnt have to write a bunch of decisions to get the samw value because i could make a huge array then save it for future use, i would copy it into flowcharts as needed then it would be really easy to create these kind of things in future since really i would only be going through the trouble once.... i'll be playing with this through out the week to see where the limits are, if you think about anything that i should know or ideas of how to use arrays please tell me...thanks

brandonb
Posts: 438
Joined: Mon Aug 29, 2011 12:26 am
Location: arizona
Has thanked: 175 times
Been thanked: 173 times
Contact:

Re: array

Post by brandonb »

martin, im confused on my limits and where they come from... remember this flowchart is concept only not practical in any nature!!! now with 80 values in bytes for the array its happy and it compiles with 10% memory used, if i take it over 100 values in the array i get errors? or if i copy that complete array and change the variable name then paste the old array and name the newly pasted one a different vaiable it give errors.....why? im totally confused!! even when i complile to larger chips it doesnt matter it errors.... the way i figure it there should be 25% memory used with 2 arrays of the same value (right), i thought it had something to do with register size for a single array, thats why i decided to put two of the same arrays with different variable names which didnt work either..... i want to get this concept all figured out since i would like to use a simulatable look up table and this is the closest i can get in flowcode, :idea: maybe matrix could come up with a look up table macro :?:

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

Post by medelec35 »

Hi Brandon,
If you can post flowchart that compiles with errors,
I can take a look at it for you and explain why its going wrong.

Martin
Martin

User avatar
JonnyW
Posts: 1230
Joined: Fri Oct 29, 2010 9:13 am
Location: Matrix Multimedia Ltd
Has thanked: 63 times
Been thanked: 290 times
Contact:

Re: array

Post by JonnyW »

Hi Brandon.
really what i wanted to do with the array thing is create numbers for pressure and temp sensors, then link adc to it, those kind of sensors arent linier
There is a technique called linear interpolation which may be helpful. It saves space in arrays and gives good approximations.

Linear interpolation takes points in your LUT at fixed intervals and gradiates between them.

As an example, here is some code that interpolates between data where you only have 1 in 16 data elements:

Code: Select all

ix = count >> 4
mul = count & 0xF
value = array[ix] * (16 - mul) + array[ix + 1] * mul
value = value >> 4
Assuming 'count' is a byte (0 to 255):
- This makes 'ix' the index into your array (which has 17 elements, 0-16)
- Assigns the remainder of the value to 'mul' (0 to 15)
- Gradiates 'value' between the two possible LUT values
- Reduces 'value' back to an integer, as it is multiplied by 16 (mul) after the calculation
This code requires 1 16th of the size array, but allows for rough curves in your data, such as a logarithm. It is also quite fast as long as you use shifts instead of divisions.

See this Wikipedia article for more info:
http://en.wikipedia.org/wiki/Linear_interpolation

I hope this is useful,

Jonny

brandonb
Posts: 438
Joined: Mon Aug 29, 2011 12:26 am
Location: arizona
Has thanked: 175 times
Been thanked: 173 times
Contact:

Re: array

Post by brandonb »

jonny your making my head smoke :lol: i'll study that to see what i can come up with..... martin, here is the file where i was messing around, remember a quick way to sum myself up is "avalibale time and knowledge are inverslyproportional" unfortunately knowledge is at the low end of the equasion :lol: .... below is file with only one array with 80 values--> notice it only used 10% of chip memory
Attachments
array x80.fcf
single array with 80 values
(13 KiB) Downloaded 189 times

brandonb
Posts: 438
Joined: Mon Aug 29, 2011 12:26 am
Location: arizona
Has thanked: 175 times
Been thanked: 173 times
Contact:

Re: array

Post by brandonb »

continued from last post--> this one is the same one but has two of the same arrays but with different vaiable names, on this one i get code-2 when compile to hex....what gives and what am i missing in understanding this concept?
Attachments
2x array x80.fcf
2 of the same array but with different vaiables
(17.03 KiB) Downloaded 159 times

User avatar
JonnyW
Posts: 1230
Joined: Fri Oct 29, 2010 9:13 am
Location: Matrix Multimedia Ltd
Has thanked: 63 times
Been thanked: 290 times
Contact:

Re: array

Post by JonnyW »

Hi. You only have 256 bytes of RAM available. The line:
RAM available: 256 bytes, used:205 bytes (80.1%), free: 51 bytes (19.9%)
Indicates only 51 bytes are spare, and you need 81.

I wouldn't be put off by the jargon - all linear interpolation is is a kind of averaging - you take a number below your count and a number above it and average them out. I have looked at your arrays and unfortunately they are not a sequence you can interpolate as they jump about, so can not reduce your data set. What you need for this is something like a smooth curve, like your ADC would read.

Still, I have done an example linear interpolation program for you here in case it is of use. 'count' can be 0 to 255, and compiles fine to the chip. You have 64% RAM free.
2x array x80_b.fcf
Interpolation example
(13.48 KiB) Downloaded 212 times
I have added an LCD display so you can see the results in simulation - just disable the 'if' when downloading to chip. The first debug line is the count, the second is the us calculated.

I hope its of use,

Jonny

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

Post by medelec35 »

Hi Brandon,
I believe I know what's going on.

When actual LUT's are used, then the data is stored in ROM. when a LUT is required to be retrieved then the start address is loaded in program counter, then the program counter is incremented by the number that's used to retrieve data.
E.g data 2,4,6,8,10. then if the number is 3 then 8 is retrieved.

Since when using Supplementary code window for data of LUT, it is stored in ROM, then not much RAM will be used.
If however you assign an array variable then for every one array that's assigned, that will take one byte of RAM which is temporary storage.

So if its not possible to use Jonnys idea then LUT maybe the only viable option. Don't forget you can create 16Bit LUT's if required.


Martin
Martin

brandonb
Posts: 438
Joined: Mon Aug 29, 2011 12:26 am
Location: arizona
Has thanked: 175 times
Been thanked: 173 times
Contact:

Re: array

Post by brandonb »

ohh RAM not ROM(i didnt read the code data correctly :oops: )... so the RAM is basicly for strorage of variables? and in the case i had 2 huge variables that wouldnt fit in the allowed space..... in that case what is the heep? and how could i get myself in to trouble,..... martin it does appear LUTs are the way to go after reveiwing the root cause, thats what i get for trying to go the easy route :lol: how do i create 16 bit luts?

Post Reply