overloading processor?

I’m not sure if there’s something wrong in my programming or if I am just overloading the processor on the Uno R3.
My sketch is about 8k with a while loop that searches through an array of about 300 numbers using a while loop. It then uses the numbers in a function to get a result. It has to do the same type search with another while loop on a second array of numbers & use the same function also. The first one works fine but the second one doesn’t. If I comment out the first search then the second one will work fine. Everything uploads fine to the Arduino & runs OK but the second result is not correct. I can take the same code in C++ with a few minor adjustments like cout instead of Serial.print & it works fine. I know without seeing the code there’s no way to know but I was wondering if it sounds like I’m overloading the processor or not.

There’s a problem with your code.

If you posted it (use code tags, the </> button in the upper left), we could tell you what it was.

Maybe, maybe not. Let's see the code. Could be SRAM issue, maybe it work on a Mega (8K SRAM) or '1284P (16K SRAM) but not an Uno (2K SRAM).

What would you imagine "overloading" the processor" would even mean?

If the code is functionally, and syntactically, correct it will do what it is supposed to do. Period. If adding functionality causes it to no longer run correctly, then it is, by definition, buggy. It could be a logical error, or it could be written such that it requires more memory than the processor physically has.

Bottom line, without the actual code, it's pretty much a waste of time to talk about it.

Regards, Ray L.

I was wondering if it sounds like I'm overloading the processor or not.

No, the processor can handle anything you throw at it.

Whatever that is.

Read this before posting a programming question

How to use this forum

The included file contains 3 arrays, one is for temperature & the other two are for pressures that correspond to those temperatures in numerical order. This is just a test to see if I can get the results I need so I’m using 355 as a random constant to see if it will work. If I comment out either one of the two codes in the if statement then the other one will work fine but I can’t get them both to work. I can compile this same code in C++ using cout , int main() & changing the delay to a cin that will let me exit the program & it works fine.

#include "ptchart.h"
// find temp from pressure 
float p1; // used for first pressure no.
float p2; // used for second pressure no.
float t1; // first temp no.
float t2; // second temp no.
float tf; // final temp calculation R22
float tf4; // final temp calculation R410A
int z=1; // for alternating odd & even numbers for if statement
// function to interpolate pressure & temp
float interper ( float lp, float lt, float hp, float ht, float ep)
{
// low pressure,temp, higher pressure, temp, entered pressure
float pd = hp-lp;  // difference in high & low pressure
float pde = hp-ep;  // difference in high & entered pressure
float pdm = (pd-pde)/pd; // pressure diff multiplier
float td = ht-lt; // difference in high & low temps
float ft1 = (pdm*td) + lt;  // new interpolated temp 
return ft1;

}

void setup ()
{
  Serial.begin(9600);
}
void loop()
{

const float pressure=355; // entered pressure number 
if (z%2==0)
{
int x= 0;  // index number of the array for R22
// This searches for the closest pressure without going over the entered pressure 
while (r22[x] < pressure)
{
x++;
}

p1 = r22[x-1];
p2 = r22[x];
t1 = temp[x-1];
t2 = temp[x];
tf4 = interper(p1,t1,p2,t2,pressure);
Serial.print("Temp for R22  ");
Serial.println(tf4);
}
else {
int y=0;  // index number of the array for 410A 

while (r410a[y] < pressure)
{
y++;
}
p1 = r410a[y-1];
p2 = r410a[y];
t1 = temp[y-1];
t2 = temp[y];
tf4 = interper(p1,t1,p2,t2,pressure);
Serial.print("Temp for R410A  ");
Serial.println(tf4);
///
}
delay(3000);
z++;
}

Another thing that makes me think I'm overloading the processor is that I can use the same code but make the included array smaller & it works fine too.

leftyg:
Another thing that makes me think I’m overloading the processor is that I can use the same code but make the included array smaller & it works fine too.

Which is a very strong clue that either you don’t have enough memory, or you’re running past the end if the array. I’m betting on the latter. You’re doing things like this in several places:

while (r22[x] < pressure)
{
    x++;
}

You’re not even checking to make sure you’re running off the end of the array, which is pretty much guaranteed to cause problems at some point.

Regards,
Ray L.

Regards,
Ray L.

RayLivingston:
Which is a very strong clue that either you don’t have enough memory, or you’re running past the end if the array. I’m betting on the latter. You’re doing things like this in several places:

while (r22[x] < pressure)

{
    x++;
}




You're not even checking to make sure you're running off the end of the array, which is pretty much guaranteed to cause problems at some point. While we're at it, what would be a good way to check for that? 

Regards,
Ray L.

Regards,
Ray L.

That’s a good point but I’m entering a constant number that I know is already covered in the arrays so I don’t see how I can run off the end of an array when i know there are larger numbers than I’ve entered in it.

What is in ptchart.h?

You can attach files to posts.

How to use this forum

It has to do the same type search with another while loop on a second array of numbers & use the same function also.

Big clue there. Nothing in your code looks like it would "overload" the processor.

I think RayLivingston is probably right.

I have tried entering the arrays in the code without using them in an include file & the results are still the same. if I shrink all the arrays down to 20 elements & use a constant number that is covered in the arrays then the code works.

I’m attaching the ptchart.h file, I hope:

ptchart.h (3.57 KB)

While we’re at it I may as well ask this question also.
I access this same chart in a mysql database using php and a similar function to interpolate whatever pressure number is entered to two decimals. Being new to the Arduino programming, the only way I could think to use the chart was to turn the database into arrays. Is there a better way?

Is there a better way?

No.

I suspect you are running out of SRAM and the arrays are wrapping around.

You have three arrays with 208 floats in each. They take 208*4*3 bytes = 2496 bytes.

On a point of style, x, y, and z are variables names that are more indicative of linear algebra, or 3d representations. It is not too hard to think of better ones.

SurferTim: I suspect you are running out of SRAM and the arrays are wrapping around.

After reading this link: https://www.arduino.cc/en/Tutorial/Memory , I think you're correct.

My title should have read just "overloading ?" because I suspected something was overloading but I used "processor" thinking it was all inclusive of the board which was a poor choice of words.

Thanks to all for the help,

I’m going to need to double the size of my arrays so I guess I’ll need to go to the Mega.

leftyg: Thanks to all for the help,

I'm going to need to double the size of my arrays so I guess I'll need to go to the Mega.

Are the contents of the arrays fixed where they could go into flash memory instead?