Problem with long programs

I have been working for a long time with an Arduino UNO R3 (I've also tried Arduino Mega 2560) and I'm facing the following problems:

  • I compiled the program correctly regardless of the compiler used (Window7 Professional)
    -Program runs correctly.

However, if I add a few rows of programs, say a subroutine, even if that subroutine does not run - the program does not execute it, the program behaves differently and incorrectly. Also, compiling this last variant with various compilers, the program also runs incorrectly and differently from one compiler to another.
What is the explanation?

What is the explanation?

There's a problem with the code you didn't post in the wrong forum section.

Installation & Troubleshooting

For problems with Arduino itself, NOT your project

Memory problems come to mind. Use of excessive String concatenations or writing outside bounds of arrays are amongst possible causes.

Hello,

I posted a subject with similar problem : Strange behaviour of Serial.print
du a declaration of a "large" string array....

I hope that these 2 known posts make the software team find the problem....

If you want, you can compare the 2 posts and problems....

For the moment, I can have a solution, but the solution limit the amount
of software and the behaviour is so strange that I am not able to know when
the data or the software where in "default" !!!

Hope a solution for us soon....

@nanar06 - your problem was misuse of the String class, when you would have been better off using PROGMEM.

No fault found.

Please don't hijack unrelated threads.

Code that does not run should have no effect on behavior (it won't be included in the binary by the linker)

But code with a syntax error of some sort can occasionally look like it does.

What do you mean "different compilers"? The arduino IDE only uses avr-gcc, and afaik can only have one version installed at any given time.

Does it compile successfully but behave differently, or fail to compile?

Have you ruled out a coincidental problem, say, in a hardware connection?

My sketch is an AD9833 frequency generator.
I use a I2C_LCD display, a 4x3 keypad (for frequency input) and two other buttons (start and pause).
The assembly has worked well for a long time, but now I would like to make certain additions to the code. Anything I'm trying to do, results in misinformation and misunderstanding of the assembly.
The sketch is compiled correctly with both Arduino 1.06, Arduino 1.5, Arduino 1.86 (on Windows 7 Pro) or Arduino Web Editor compilers.
I worked with Arduino Uno and Arduino Mega 2560.
Compilation is done successfully with all the mentioned compilers (I installed them on the computer - not all at once)
Operation is different depending on the compiler used!
It often happens that the keyboard is not read correctly, ie columns 2 and 3 of the keyboard return the characters on the first column (instead of "2" appears "1", instead of "#" appears "" etc.) after code is running a bit.
{'1', '2', '3'},
{'4', '5', '6'},
{'7', '8', '9'},
{'
', '0', '#'}
I've attached the code I used.
The part of the code that I've attached to Sketch now and that is causing my problems is between lines 825 and 951.
Thank you very much.

Generator.zip (41.7 KB)

@luxornet

You have boundary problems

e.g.

void updateDisplay() {
    char u[5];
    char v[16]; //pentru program
    
    //if (dispUnit == mHz) strcpy(u, " mHz");
    if (dispUnit == Hz) strcpy(u, " Hz");
    else if (dispUnit == KHz) strcpy(u, " KHz");
    //else if (dispUnit == MHz) strcpy(u, " MHz");
    
         if (prg == 1) strcpy(v,   "  1 minut       ");
...
...

You're writing outside the boundaries of arrays. You need to allocate one byte more to vto hold the terminating nul-character. If I counted correctly, " 1 minut " is 16 characters so no space for the terminating nul-character in variable v

luxornet:
I've attached the code I used.

You have attached a 41k ZIP file which implies that the code is considerably larger.

Nobody writes 41k of code without frequent testing as the project grows. Presumably you have an earlier version of the code that worked perfectly and then you added a small extra piece that has caused the problem. What is that small extra piece?

...R

Hi!
The part of the code that I've attached to Sketch now and that is causing my problems is between lines 825 and 951.
Thank you

luxornet:
Hi!
The part of the code that I've attached to Sketch now and that is causing my problems is between lines 825 and 951.
Thank you

No, the cause of your problem is not there. I've pointed out the first mistake that I found; check the boundaries of ALL your arrays.

Dear sterretje
Correct resizing has solved a lot of problems!
Thank you very much.

Just curious, was what I pointed out new code or existing code and you were just lucky?

"char v[16];"

I resized this to v[17], like you said, in existing (old) code. :cry: