Need Larger Array

For Flowcode users to discuss projects, flowcharts, and any other issues related to Flowcode 4.
To post in this forum you must have a registered copy of Flowcode 4 or higher. To sign up for this forum topic please use the "Online Resources" link in the Flowcode Help Menu.

Moderator: Benj

Post Reply
MarkW
Flowcode v5 User
Posts: 118
Joined: Thu Sep 17, 2009 1:30 pm
Has thanked: 3 times
Been thanked: 11 times
Contact:

Need Larger Array

Post by MarkW »

Hello

Using 18F2620 which has about 4k static memory. I need about 2k size array , but the variable can only
hold 256 members (error at compile time). Is there any way to extend the array size declared?
I imagine the array is managed in FC with 8bit value.....16bit would have been ideal :(

Thanx in advance

Mark

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: Need Larger Array

Post by Benj »

Hi Mark,

Standard 8-bit PICs have an inbuilt paging mechanism in memory which is all arranged into blocks of 256 bytes. The compilers should be able to allow for bigger array sizes by doing the legwork for you but for some reason they do not allow this. I have not come across a 8-bit PIC compiler that allows this yet.

One workaround is to create multiple arrays and then use a index variable to switch between arrays.

array0[256]
array1[256]
array2[256]
array3[256]

Create a macro to read or write from your array at a specific address.

Code: Select all

if (address < 256)
{
   return = array0[address]
}
else
{
   address = address - 256
   if (address < 256)
   {
      return = array1[address]
   }
   else
   {
      ...
   }
}
16-bit PICs, AVRs and ARMs do not have this limitation.

MarkW
Flowcode v5 User
Posts: 118
Joined: Thu Sep 17, 2009 1:30 pm
Has thanked: 3 times
Been thanked: 11 times
Contact:

Re: Need Larger Array

Post by MarkW »

Hi Ben

looking at datasheet now, i realise this to be the case. Your suggestion will fit the bill :D
Thanx for your advice once again!

Mark

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: Need Larger Array

Post by Benj »

Cheers Mark,

From this topic I found it looks like BoostC may be on their way to supporting larger arrays in the future :D

http://forum.sourceboost.com/index.php?showtopic=4003

C18 and MikroC can apparently already do it but I bet it's not as simple as declaring and referencing the variable.

Code: Select all

char buff1[512];
buff1[511] = 5;
For example here is the C18 workaround,
changing the size of a memory section in the linker file and then using the #pragma udata directive
It sounds a bit painful to me but then I don't particularly like the way the pragma's etc work in C18 anyway. Seems very easy to get things wrong and for it not to work at all with no warnings as to why.

MarkW
Flowcode v5 User
Posts: 118
Joined: Thu Sep 17, 2009 1:30 pm
Has thanked: 3 times
Been thanked: 11 times
Contact:

Re: Need Larger Array

Post by MarkW »

Hi Ben

Actually from what i can see, the Mikro compilers allow it to be that easy :)

Another mate of mine uses the CCS pic compiler and he says that the compiler
automatically handles the memory paging.
Does FC V5 have the same constraints? I am considering going to V5........

In the meantime, i setup a memory page handler using the switch icon. Its a bit
clumsy but does the job.

Flowcode/BoostC will hopefully "upgrade" this function, that will be really handy.

Cheers for the advice and looking into this!

Mark

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: Need Larger Array

Post by Benj »

Hi Mark,

It seems we may have some updates already present in v5.

Compiling an array of 512 bytes currently gives this error message.
PIC ArraySize.c(103): error: total number of array elements can not exceed 0x100 (use -idx 2 compiler command line argument to remove this restriction)
Adding "-idx 2" to both the compiler and linker parameters lines in the compiler option window removes this error but I start getting other errors related to other boostc functions.
Error: Unresolved external function:'__div_16_16(unsigned short,unsigned short)'
I will have a play and see if this is something that can be made to work correctly.

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: Need Larger Array

Post by Benj »

Right I can confirm that this works in v5 :)

First you have to go into the compiler options window and change the compiler parameters to look like this.
-v -t PIC%p "%f.c" -idx 2
Then in the linker tab change the parameters to look like this. Remove the " (x86)" from the path on a 32-bit computer.
-ld "C:\Program Files (x86)\Flowcode\v5\Tools\BoostC\lib" large\libc.pic16.lib large\rand.pic16.lib large\float.pic16.lib "%f.obj" -t PIC%p -d "%d" -p "%f" -idx 2
And that's that, arrays larger then 256 bytes now compiling correctly :D

MarkW
Flowcode v5 User
Posts: 118
Joined: Thu Sep 17, 2009 1:30 pm
Has thanked: 3 times
Been thanked: 11 times
Contact:

Re: Need Larger Array

Post by MarkW »

Nice one Ben,

I tried changing the parameters on FC4...does not work. Would it work on FC4?
Is FC5 using same BoostC revision?

Anyway, drinks on the house to ya :D

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: Need Larger Array

Post by Benj »

No problem :) Just happy it works.

For reference Flowcode V5.4 for PIC comes packaged with boostc version v7.04 and I think the change was brought in for v7.0. The compiler messages window should show you what version of the compiler you are currently using.

MarkW
Flowcode v5 User
Posts: 118
Joined: Thu Sep 17, 2009 1:30 pm
Has thanked: 3 times
Been thanked: 11 times
Contact:

Re: Need Larger Array

Post by MarkW »

Thanx Ben

Is it possible for you to test / look into, the possibility of this method working
with FC V4?

I am going to go FC V5 soon, just wanted to know if V4 can do this in the meantime?
( I tried the - idx 2 setting and not working on V4 it seems)

Thanx for the gr8 support

Mark

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: Need Larger Array

Post by Benj »

Hi Mark,

V4.5 of Flowcode looks like it can handle it too :)

Looks like you have to use a 18F target device for the -idx 2 message to appear correctly. Not sure if the 10F/12F/16F devices can handle the 2 byte array mechanism? Certainly all the lib files in the large (2 byte index) directory are 18F only.
Generated by: Flowcode v4.5.18.74
...
BoostC Optimizing C Compiler Version 7.04 (for PIC18 architecture)
...
Flowcode1.c(62): error: total number of array elements can not exceed 0x100 (use -idx 2 compiler command line argument to remove this restriction)
Here are the modified v4 compiler options.

Compiler Parameters
-v -t PIC%p "%f.c" -idx 2
Linker Parameters. Remove the " (x86)" from the path on a 32-bit computer.
-ld "C:\Program Files (x86)\Matrix Multimedia\Flowcode V4\BoostC\lib" large\libc.pic16.lib flowcode.pic16.lib large\rand.pic16.lib large\float.pic16.lib "%f.obj" -t PIC%p -d "%d" -p "%f" -idx 2

MarkW
Flowcode v5 User
Posts: 118
Joined: Thu Sep 17, 2009 1:30 pm
Has thanked: 3 times
Been thanked: 11 times
Contact:

Re: Need Larger Array

Post by MarkW »

Hi Ben,

Great information there thanx. I have declared the one array as having 300 members, and with the
new compiler options it gets so far as correctly doing the pre-processor part successfully, but when it
gets to the linker part things fall apart. It seems to have an error reference to some I_String function
(not even using that function).

See output i copy/paste:
Launching the compiler...
c:\program files\matrix multimedia\flowcode v4\boostc\boostc_pic18_flowcode.exe -v -t PIC18F2620 "C4_USB_FC4_2.c" -idx 2
BoostC Optimizing C Compiler Version 7.04 (for PIC18 architecture)
http://www.sourceboost.com
Copyright(C) 2004-2011 Pavel Baranov
Copyright(C) 2004-2011 David Hobday

Licensed to FlowCode User under Single user Pro License for 1 node(s)
Limitations: PIC18 max code size:Unlimited, max RAM banks:Unlimited


C4_USB_FC4_2.c
Starting preprocessor: c:\PROGRA~1\MATRIX~1\FLOWCO~2\boostc\pp.exe C4_USB_FC4_2.c -i c:\PROGRA~1\MATRIX~1\FLOWCO~2\boostc\include -d _PIC18F2620 -la -c2 -o C4_USB_FC4_2.pp -v -d _BOOSTC -d _PIC18 -d _SHORT_INDEX


..................

C4_USB_FC4_2.c success

success

Return code = 0

Launching the linker/assembler...
c:\program files\matrix multimedia\flowcode v4\boostc\boostlink_pic.exe -ld "C:\Program Files\Matrix Multimedia\Flowcode V4\BoostC\lib" large\libc.pic18.lib flowcode.pic18.lib large\rand.pic18.lib large\float.pic18.lib "C4_USB_FC4_2.obj" -t PIC18F2620 -d "C:\Backup2\Newco\Electronic_Projects\Titler_VSI200\VSI_Shrink\NewC4_XML_Data\C4_USB_MOD\Code" -p "C4_USB_FC4_2" -idx 2
BoostLink Optimizing Linker Version 7.03
http://www.sourceboost.com
Copyright(C) 2004-2011 Pavel Baranov
Copyright(C) 2004-2011 David Hobday


Error: Unresolved external function:'FCI_TOSTRING(signed short,unsigned char*,unsigned char)'
Error: Unresolved external function:'FCI_TOSTRING(signed short,unsigned char*,unsigned char)'
Error: Unresolved external function:'FCI_TOSTRING(signed short,unsigned char*,unsigned char)'
Error: Unresolved external function:'FCI_TOSTRING(signed short,unsigned char*,unsigned char)'
Error: Unresolved external function:'FCI_TOSTRING(signed short,unsigned char*,unsigned char)'
Error: Unresolved external function:'FCI_TOSTRING(signed short,unsigned char*,unsigned char)'
Error: Unresolved external function:'FCI_TOSTRING(signed short,unsigned char*,unsigned char)'
Error: Unresolved external function:'FCI_TOSTRING(signed short,unsigned char*,unsigned char)'
Error: Unresolved external function:'FCI_TOSTRING(signed short,unsigned char*,unsigned char)'
Error: Unresolved external symbol, function:FCI_TOSTRING


failure

Return code = -2

Flowcode was unable to assemble the ASM file due to the following errors:


FINISHED
Any ideas whats going on? I did copy/paste your compiler options as is from your prev answer.

Cheers

Mark

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: Need Larger Array

Post by Benj »

Hi Mark,

Copy and paste the following into the functions section of the supplementary code window, available via the project options window.

Code: Select all

	char FCI_TOSTRING(int iSrc1, char* sDst, char iDst_len)
	{
		char tmp1;
		short tmp2;
		char idx = 0;

		//copy source 1 into destination:
		//minus sign
		if (iSrc1 < 0)
		{
			sDst[0] = '-';
			idx++;
			iSrc1 = 0 - iSrc1;
		}

		tmp2 = iSrc1;
		if (iSrc1 >= 10000)
		{
			if (idx < iDst_len)
			{
				tmp1 = tmp2 / 10000;
				sDst[idx] = '0' + tmp1;
				idx++;
			}

			while (tmp1 > 0)
			{
				tmp2 = tmp2 - 10000;
				tmp1--;
			}
		}

		if (iSrc1 >= 1000)
		{
			if (idx < iDst_len)
			{
				tmp1 = tmp2 / 1000;
				sDst[idx] = '0' + tmp1;
				idx++;
			}

			while (tmp1 > 0)
			{
				tmp2 = tmp2 - 1000;
				tmp1--;
			}
		}

		if (iSrc1 >= 100)
		{
			if (idx < iDst_len)
			{
				tmp1 = tmp2 / 100;
				sDst[idx] = '0' + tmp1;
				idx++;
			}

			while (tmp1 > 0)
			{
				tmp2 = tmp2 - 100;
				tmp1--;
			}
		}

		if (iSrc1 >= 10)
		{
			if (idx < iDst_len)
			{
				tmp1 = tmp2 / 10;
				sDst[idx] = '0' + tmp1;
				idx++;
			}

			while (tmp1 > 0)
			{
				tmp2 = tmp2 - 10;
				tmp1--;
			}
		}

		if (idx < iDst_len)
		{
			sDst[idx] = '0' + tmp2;
			idx++;
		}

		//add terminating null (if we can)
		if (idx < iDst_len)
		{
			sDst[idx] = 0;
		}

		return (idx);
	}
In v4 the Flowcode string library for BoostC is pre-compiled with the -idx setting set to 1, however for HiTech the functions are available in the internals.h source file. If you have any further problems simply find the internals.h file and copy the function code out and paste into the supp code window and this should fix the issue.

MarkW
Flowcode v5 User
Posts: 118
Joined: Thu Sep 17, 2009 1:30 pm
Has thanked: 3 times
Been thanked: 11 times
Contact:

Re: Need Larger Array

Post by MarkW »

Hi Ben,

That did the trick thanx!

Much appreciated.

Mark

MarkW
Flowcode v5 User
Posts: 118
Joined: Thu Sep 17, 2009 1:30 pm
Has thanked: 3 times
Been thanked: 11 times
Contact:

Re: Need Larger Array

Post by MarkW »

Hi Ben

Considering your last answer on this subject, i have a few more questions pls:

1. In FC V4 i got the idx2 etc working with larger arrays no problem...however i am now using string
functions etc in the program and as you mentioned in the previous post these are compiled for idx1.
So therefore i am now getting compile errors....
Question is where/how do i get the Hitech compiler to do string functions using idx2? In other words
how do i realise using string functions yet retain the idx2 functionality of larger arrays?
The FC folder on the my PC has no reference to any Hitech compiler....where/how does one get it?
What version Hitech compiler must one use?
2. Does FC V5 resolve all of these issues and is it the same story in the compiler options for larger arrays?
Does FC V5 have large array capability with string functions working as well?

Thanx!

Mark

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: Need Larger Array

Post by Benj »

Hello Mark,

I don't think the issue is HiTech related. You are currenty using the BoostC compiler but it is the inbuilt v4 Flowcode library that is not supporting idx2.

For version 5 the string functions library is not pre-compiled allowing idx2 support out the box.

I may be able to alter the v4 pre-compiled library for idx2 so I will look into this for you.

MarkW
Flowcode v5 User
Posts: 118
Joined: Thu Sep 17, 2009 1:30 pm
Has thanked: 3 times
Been thanked: 11 times
Contact:

Re: Need Larger Array

Post by MarkW »

Hi Ben

OK...so it seems we are heading to get V5 :)

In the meanwhile, if you got something for string functions to work with V4 then great.

Thanx for the support

Mark

Post Reply