last day (15 days later) » 

19:21
0
Q: Problem with variables

MehrdadI have a simple Low pass filter in my program that stops working after some time (Let say 4 hours or more). 'CRate' is a double type variable between -20 and 100. uint8_t T_Sample=10; double FCR0=100.0, CRate=0, FCR=0; loop() { // CRate is calculated here double Tau = 0.001; double v = 1000...

Jot
Jot
Tested with arduino uno: the calculation in the loop takes almost no time, since the compiler calculates it, instead of runtime. For Tau = 500, FCR = 99.99799346. For Tau = 0.001, FCR = 9.09090909. The loop never stops.
How do you know it stops working? There is no visible output.
From Jot and Nick, I'll add you must add a display (a small Serial.println()) Even if it's slow down, you'll be able to see the result and also see it it really stop, and when.
There must be more than this in your code because, as @Jot already stated, the whole computation occurs at compile time, meaning there is no reason for the code to stop working. The whole code above, after compilation, will look like assigning a fixed value to a local variable and then wait for 5 seconds: that's it.
Thanks for the feedback. The whole code is 1260 lines of code. I just highlighted the part which makes a problem.
There is a Serial.print(\n"FCR: ");
Serial.print(FCR);
It works fine as it should be. However, the loop stops after a few hours of working. I have tested the code for several times and it stops exactly in the same place where it wants to print 'FCR'. This is why I cannot figure out the reason.
I have been using Arduino101 and have been careful about the SRAM usage and try to keep global and local variables under control to not exceed the limitation. One more thing is that CRate varies based on the measured value from analog input once in every loop time between -20 and 100.
My concern is that if there is a memory occopation while local variables are defined in every loop again and again. I mean double Tau and double v where there are many other variables in the code as global and local ones.
Jot
Jot
19:21
The Arduino 101 is known for having serious problems with everything, especially the i2c bus and the serial port. I have not heard yet that all the problems are fixed, the Arduino 101 is more or less abandoned. I think you are in serious trouble. About the code, we can have a look at the full code. When there is a stack or memory problem, then it is possible that the code stops at the same location even when that location is not the problem. The compiler optimizes a lot, so a problem might pop up somewhere else. I think you have to forget that calculation and look at the whole sketch.
Thanks a lot! Agree! Some time ago I used to receive wrong values for a variable randomly. After I changed the name of that variable, it turned to be ok! In my present case, it might be a memory or stack problem since that simple calculations look correct. Let me figure out how to monitor stack situation.
I noticed that you don't send a newline character after your Serial.print(FCR);. Serial output usually is buffered until a newline character is received, then the accumulated buffer gets printed. By not sending any terminating character you will provoke a buffer overflow. Even though I would expect this causing a problem on the receiving device it might be worth a try (are you actually sure that your slave stops working and not your master, which reads the serial output?). Maybe remove the delay so you don't have to wait for hours. It's just a guess as I don't know the entire code
Thanks Sim Son!. Today I worked around the issue and found out a clear view about the issue which might be interesting for others as well. Please try to divide the following: FCR = (5000095.0/50001.0); It makes a value which has a number of decimal points as FCR=99.9999... I cannot use Serial.print(FCR) since it has more than 2 decimal point in the right side of the point. This is what makes problem. In brief, I can print (99.99) however cannot print (99.999) or other numbers that have more decimal in the right side.
There is still one question. With a normal Serial.print(val) I could print (2.0/3.0) which gives 0.66 however I couldn't print ( (5000095.0/50001.0) which was 99.9999000019... it means that 0.6666666 is simply rounded to 0.66, however the other number fails to be normally rounded off!
Dear Sim Son, about your comment, In addition to my receint comments, I am sure that printing to the serial print makes problem. Because removing that serial print, it works fine. As soon as I use it to print, it stops. About terminating characetr, you might be right. I need to test it tomorrow.
Hi friends. Though I couldn't find a root cause for my printing issue, I found a solution here: forum.arduino.cc/index.php?topic=44216.msg320122#msg320122
I bet on "division by zero". test the values you use as divisor
It shouldn't be division by Zero. It is simply 5000095.0/50001.0 that cannot be represented in Serial.print(5000095.0/50001.0);

last day (15 days later) »