Arrays

Hello,
These are some simple programming questions:

Does the Arduino support multidimensional Arrays?

If yes, is it recommended to use multidimensional Arrays?

I am using a Arduino DUE, how big is the maximum array size, for an integer array? – Presumably I am not using the ram for any other things – just for one array, that contains integer values…

Kind Regards,

Andreas

Does the Arduino support multidimensional Arrays?

Yes

If yes, is it recommended to use multidimensional Arrays?

If they are of an appropriate size, yes.

Thx,

is it possible to change the size of an global array during runtime.

Because in my application, the actual arry size is not known right away from the beginning...

is it possible to change the size of an global array during runtime

No.

Use "malloc"

I am using a Arduino DUE, how big is the maximum array size, for an integer array? – Presumably I am not using the ram for any other things – just for one array, that contains integer values…

The Due has 96K of SRAM. There are plenty of other things that need some space there though - stack, constant strings, variables and whatever any libraries you use are consuming - don't for a moment suppose that all of that memory is available for your array.

Hello,

I know that there are many other things that occupy the sram...

I am basically driving two stepping engines with coordinates for a C&C machine.

Currently I have all coordinates saved on an SD-Card... But my problem is, to read and process the coordinates from the SD-Card a lot of processing time is used, which has an negative impact on the performance of the machine...

My thaught to decrease processing time and increase performance during the actual job, was to load the coordinates in arrays before the stepper engines are triggerd...

Therefore a project can encompass just several hundred reference points -> respectively integer values in an arry up to one million...

My thaught to decrease processing time and increase performance during the actual job, was to load the coordinates in arrays before the stepper engines are triggerd...

But motors are slooow.

with coordinates for a C&C machine.

Is that anything like a CNC machine?
If not, what is it?

The Due has 96K of SRAM

In 64 and 32k banks, are that addressable as contiguous memory? I assume so but cannot find anything that explicitly says so.


Rob

Ok, just a thaught experiment:

The Arduino DUE has 96kByte of SRAM.

One Reference Point for the C&C machine may have a 3 digit integer number for the steps of the X stepper, the same for the Y stepper and an additional character that indicates if milling is activ or not.

So in total I have 7 characters per reference point.

1 character is one byte.

So I have 7 Bytes per reference point.

Presumably I can use all 96kByte to store this information, which is not the case, I could store 96000 Bytes / 7 Bytes = 13714 reference points....

If this is the case, I can forget the idea of buffering the reference points in arrays, because many projects overshoot this ammount of reference points....

Thx.

You can try some buffering - no need to load all the data (G-code?) at once. IIRC, the SD card library loads 512 bytes at a time, the only time I can see it causing you any grief is at the time it has to read another block and even then, I'm doubtful.

You could do some smart lookahead too and evaluate how long an instruction is going to take and force a read during the long ones.

However, why not do an experiment first and see whether a job that you can pre-load into memory actually is any faster.

You may want to post your code too.

7 characters per reference point.

What's the format, maybe it can be compressed.


Rob

Hello all,

first of all thx for your help... :slight_smile:

Yesterday I did some extensive research and measurements with an oscilloscope...

I found out, that the digital read operations take a insignificant amount of processing time…

Serial communication on the other hand take more time – I am sending one character to the Windows application after each reference point, to visualize the progress with a progress bar.

My oscilloscope is an old one and not very accurate, but sending one character with 57k baud takes about 100-200µS.

However I found another issue.
Basically I am having my “G-Code” on the SD-Card and when I start the execution of the project, the data on the SD-Card is iterated and the steppers are fed with the data…

Each Second or so, I heard a strange click, which I could not explain for a while… After some calculations and research, I realized that the click happens when each 512th Byte were read from the SD-Card…

With the oscilloscope I found out, that on those spots (each 512th Byte), there were a gap, where the steppers were not triggered. The gap was about 1mS big…

So I guess, that this gap is from the buffering / data loading of the SD-Card.

I don’t know if this has an big issue regarding the performance of the C&C application – in terms of perfection it is not beautiful…
Does anyone have an idea how to make a workaround?

By the way, I will prepare and post the code for the stepper driver here, maybe some of you have an idea how to improve things… (I still have to translate the comments from german to english...)

but sending one character with 57k baud takes about 100-200µS.

No, it takes roughly 1/5760th of a second, or about 174us.
But that is how long the character is in-flight, not how long the processor is concerned with the transaction, unless the processor is blocking always waiting for the transmit buffer to come empty.

What am I missing here? The data can be laid down on the SD card in any format you want. If all of the CNC data are positive and less than 255, byte values could be used. If not, store each each point as a signed or unsigned integer. You could define a structure that would hold one set of coordinate points, read it as one record, and store the records in an array of the structures. This would save you at least one byte per coordinate given what you said about using 3 digit characters per point. As AWOL pointed out, motors are relatively slow, so it would seem reasonable that you could buffer enough structure elements from the SD card to stay ahead of the CNC machine.