Go Down

Topic: Problem with long programs (Read 525 times) previous topic - next topic

luxornet

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?

AWOL

#1
Sep 10, 2018, 11:14 am Last Edit: Sep 10, 2018, 11:15 am by AWOL
Quote
What is the explanation?
There's a problem with the code you didn't post in the wrong forum section.

Quote
Installation & Troubleshooting

For problems with Arduino itself, NOT your project
"Pete, it's a fool (who) looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.
I speak for myself, not Arduino.

sterretje

Memory problems come to mind. Use of excessive String concatenations or writing outside bounds of arrays are amongst possible causes.
If you understand an example, use it.
If you don't understand an example, don't use it.

Electronics engineer by trade, software engineer by profession. Trying to get back into electronics after 15 years absence.

nanar06

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....

AWOL

@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.
"Pete, it's a fool (who) looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.
I speak for myself, not Arduino.

DrAzzy

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?
ATtiny core for 841+1634+828 and x313/x4/x5/x61/x7/x8 series Board Manager:
http://drazzy.com/package_drazzy.com_index.json
ATtiny breakouts (some assembled), mosfets and awesome prototyping board in my store http://tindie.com/stores/DrAzzy

luxornet

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.

sterretje

@luxornet

You have boundary problems

e.g.
Code: [Select]
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
If you understand an example, use it.
If you don't understand an example, don't use it.

Electronics engineer by trade, software engineer by profession. Trying to get back into electronics after 15 years absence.

Robin2

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
Two or three hours spent thinking and reading documentation solves most programming problems.

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

sterretje

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.
If you understand an example, use it.
If you don't understand an example, don't use it.

Electronics engineer by trade, software engineer by profession. Trying to get back into electronics after 15 years absence.

luxornet

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

sterretje

Just curious, was what I pointed out new code or existing code and you were just lucky?
If you understand an example, use it.
If you don't understand an example, don't use it.

Electronics engineer by trade, software engineer by profession. Trying to get back into electronics after 15 years absence.

luxornet

"char v[16];"

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

Go Up