Author Topic: [arduino] can't subtract two time stamps  (Read 14568 times)

0 Members and 1 Guest are viewing this topic.

Online SimonTopic starter

  • Global Moderator
  • *****
  • Posts: 17728
  • Country: gb
  • Did that just blow up? No? might work after all !!
    • Simon's Electronics
Re: [arduino] can't subtract two time stamps
« Reply #25 on: October 22, 2021, 05:48:21 am »
Yea will do, I'll try putting it in the main loop. but this sort of flakyness will not do. The only thing is that the guy that designed this based it on a MKR Zero but took the 32.768 kHz crystal out. He had to do his own board file for it as it was looking for the clock to stabilize and would not start. I don't know if there is more in there that may be a problem. But then this works to control the main loop timing just fine but not the timing of the tacho signals so it's still very odd.
 

Offline semir-t

  • Regular Contributor
  • *
  • Posts: 56
  • Country: ba
Re: [arduino] can't subtract two time stamps
« Reply #26 on: October 22, 2021, 07:13:52 am »
Code: [Select]
if ((millis() - varLastLoopTime) > constLoopIntervalMs) { // check time since last loop counter update
  loopCount ++; // update loop count
  if (loopCount > 10) loopCount = 0; // if loop count has eceeded 10 reset
    varLastLoopTime = millis();
  }

  if (loopCount == 10){
    task2s();
  }

Suggestions:
1. Don't be lazy, improve the code readability . Use the brackets :)
2. You are not taking in the account the overflow when subtracting the varLastLoopTime from the millis(). millis() will overflow at one point and your program will not behave like expected
3. Try to print out the values for the tempvarTime and v_LastSpeedTime using the Serial output.
 

Online SimonTopic starter

  • Global Moderator
  • *****
  • Posts: 17728
  • Country: gb
  • Did that just blow up? No? might work after all !!
    • Simon's Electronics
Re: [arduino] can't subtract two time stamps
« Reply #27 on: October 22, 2021, 07:26:45 am »
Millis will overflow after some days, this will never run for days. It's a machine that is carried around and used for an hour at a time. I'll have another stab at it.
 

Offline semir-t

  • Regular Contributor
  • *
  • Posts: 56
  • Country: ba
Re: [arduino] can't subtract two time stamps
« Reply #28 on: October 22, 2021, 07:42:20 am »
Yes, I understand that the product won't work long enough for the overflow to occur and I saw that you mentioned this in this thread. I was just making a suggestion because you don't won't to reinvent the wheel each time. In my projects (rarely use Arduino platform) I use my custom library based on the millis() where I have a function that checks if the timeout happened, something similar as yours but I have included the overflow check. I wrote this library once and benefit is that I know that it is working and it is easy to use  ;) :D.

But, nevertheless there is something odd with the code or Arduino that you are using. I am interested to see what the Serial.print will tell you, and it would be great if you could get lot of debugging messages out just to see what is happening.
 

Online SimonTopic starter

  • Global Moderator
  • *****
  • Posts: 17728
  • Country: gb
  • Did that just blow up? No? might work after all !!
    • Simon's Electronics
Re: [arduino] can't subtract two time stamps
« Reply #29 on: October 22, 2021, 08:13:23 am »
Well I now have:
Code: [Select]
void lcdSpeedPrint() {
 
  uint32_t varCurrentSpeedTime = millis();
  int32_t vtSpeed = (vTachoSpeedCounts * tachoStep * 600) / (varCurrentSpeedTime - vLastSpeedTime);
  char text[6] = {0, 0, 0, 0, 0, 0};
  char counter = 0;
  char temp;

  lcd.setCursor(0, 2);
  lcd.print(varCurrentSpeedTime);
  lcd.setCursor(0, 3);
  lcd.print(vLastSpeedTime);

  vLastSpeedTime = millis();

}

the two time stamps are indeed just a few ms apart...... This is getting weirderso in I just put in my main loop in the what should happen every 2s

Code: [Select]
void loop() {

  if ((millis() - varLastLoopTime) > constLoopIntervalMs)
  { // check time since last loop counter update
     loopCount ++; // update loop count
     varLastLoopTime = millis();
     if (loopCount > 10) loopCount = 0; // if loop count has exceeded 10 reset
   
  }

  if (loopCount == 10){

    if (backlightstate == 1)
    {
      digitalWrite(lcdBackLightPin, LOW);
      backlightstate = 0;
    }
    else
{
   digitalWrite(lcdBackLightPin, HIGH);
   backlightstate = 1;
}
    //task2s();
  }
 
}

That turns the lcd backlight on and off for 2s each. but if I make the else and else if it does not work properly it flickers like that bit runs all the time, is this a C++ versus C thing? in C "else if" means that only if the first thing was not satisfied will I test the second, rather than do the second regardless.
 

Offline semir-t

  • Regular Contributor
  • *
  • Posts: 56
  • Country: ba
Re: [arduino] can't subtract two time stamps
« Reply #30 on: October 22, 2021, 08:29:53 am »
You should try to define varLastLoopTime as volatile.
Code: [Select]
volatile unsigned long varLastLoopTime;

Also, I would reset this variable in the part of the code where we check if current value is equal to 10. So
Code: [Select]
void loop() {

  if ((millis() - varLastLoopTime) > constLoopIntervalMs) { // check time since last loop counter update
  loopCount ++; // update loop count
  varLastLoopTime = millis();
  }

  if (loopCount == 10)
{
    loopCount = 0;
    task2s();
  }
 
}

There shouldn't be any difference between the C and C++ for the else if statement.
 

Offline retiredfeline

  • Frequent Contributor
  • **
  • Posts: 526
  • Country: au
Re: [arduino] can't subtract two time stamps
« Reply #31 on: October 22, 2021, 08:54:14 am »
Code: [Select]
void loop()
{
    if ((millis() - varLastLoopTime) > constLoopIntervalMs) {   // check time since last loop counter update
        loopCount++;            // update loop count
        varLastLoopTime = millis();
        if (loopCount > 10)
            loopCount = 0;      // if loop count has exceeded 10 reset
    }
    if (loopCount == 10) {
        if (backlightstate == 1) {
            digitalWrite(lcdBackLightPin, LOW);
            backlightstate = 0;
        } else {
            digitalWrite(lcdBackLightPin, HIGH);
            backlightstate = 1;
        }
        //task2s();
    }
}

I reformatted the code to be more readable.

Consider what happens when loopcount reaches 10, but ((millis() - varLastLoopTime) > constLoopIntervalMs) is not true. Then this section of the code will be executed as fast as loop() can be called repeatedly.

Code: [Select]
    if (loopCount == 10) {
        if (backlightstate == 1) {
            digitalWrite(lcdBackLightPin, LOW);
            backlightstate = 0;
        } else {
            digitalWrite(lcdBackLightPin, HIGH);
            backlightstate = 1;
        }
        //task2s();
    }

semir-t's suggestion of resetting loopcount in that part of the code would also fix it.
 

Online SimonTopic starter

  • Global Moderator
  • *****
  • Posts: 17728
  • Country: gb
  • Did that just blow up? No? might work after all !!
    • Simon's Electronics
Re: [arduino] can't subtract two time stamps
« Reply #32 on: October 22, 2021, 09:04:58 am »
The idea is that the loops will be counted up to 10 but other timed functions may run more often, so all I have to do is do a "loopcount % 'a number' " and run at any multiple of 200ms any event I want. I will probably be letting loopcount overflow in the end and check the modulus as if i want something to run every 4 counts on a 10 top out that will cause a delay every 2 cycles.
 

Online SimonTopic starter

  • Global Moderator
  • *****
  • Posts: 17728
  • Country: gb
  • Did that just blow up? No? might work after all !!
    • Simon's Electronics
Re: [arduino] can't subtract two time stamps
« Reply #33 on: October 22, 2021, 09:20:04 am »
So now i have:

Code: [Select]
#define lcd_rs_pin 6
#define lcd_enable_pin 10
#define lcd_d4_pin 9
#define lcd_d5_pin 8
#define lcd_d6_pin 19
#define lcd_d7_pin 15

#define lcdBackLightPin LED_BUILTIN
#define tachoSensor 5

#include <LiquidCrystal.h>
// configuring LCD data pins
LiquidCrystal lcd(lcd_rs_pin, lcd_enable_pin, lcd_d4_pin, lcd_d5_pin, lcd_d6_pin, lcd_d7_pin);


//#include "2s_tasks.h"
//#include "tacho.h"


const unsigned int constLoopIntervalMs = 200;

uint8_t backlightstate;

unsigned int loopCount = 0; // counts
unsigned long varLastLoopTime = 0;
uint32_t vLastSpeedTime;

void setup() {
  // set up the LCD's number of columns and rows:
  lcd.begin(20, 4);

  pinMode(lcdBackLightPin, OUTPUT);
  digitalWrite(lcdBackLightPin, HIGH);
  pinMode(tachoSensor, INPUT);
  //attachInterrupt(digitalPinToInterrupt(tachoSensor), tachoUpdate, FALLING);
  lcd.clear();
}

void loop() {

  if ((millis() - varLastLoopTime) > constLoopIntervalMs)
  { // check time since last loop counter update
     loopCount ++; // update loop count
     varLastLoopTime = millis(); 
  }

  if (loopCount % 10 == 0){
   uint32_t varCurrentSpeedTime = millis();
 // int32_t vtSpeed = (vTachoSpeedCounts * tachoStep * 600) / (varCurrentSpeedTime - vLastSpeedTime);
  char text[6] = {0, 0, 0, 0, 0, 0};
  char counter = 0;
  char temp;

  lcd.setCursor(0, 2);
  lcd.print(varCurrentSpeedTime);
  lcd.setCursor(0, 3);
  lcd.print(vLastSpeedTime);

  vLastSpeedTime = millis();
}
}

So now I just get identical numbers on the display.
« Last Edit: October 22, 2021, 09:33:38 am by Simon »
 

Offline semir-t

  • Regular Contributor
  • *
  • Posts: 56
  • Country: ba
Re: [arduino] can't subtract two time stamps
« Reply #34 on: October 22, 2021, 10:03:31 am »
Nice one retiredfeline. At first sight that part of the code cached my attention, but I didn't saw this bug. I just suggested what I always do and what made sense to make the code more understandable.

I can't understand now why would you use loopCount % 10 == 0 ? And please, use brackets. Don't let the compiler chose the operation order. So, if you really want this line of the code it should be like this (loopCount % 10) == 0

Even some compilers (depending on the flags you set) would warn you about this statement.
« Last Edit: October 22, 2021, 10:06:50 am by semir-t »
 

Online SimonTopic starter

  • Global Moderator
  • *****
  • Posts: 17728
  • Country: gb
  • Did that just blow up? No? might work after all !!
    • Simon's Electronics
Re: [arduino] can't subtract two time stamps
« Reply #35 on: October 22, 2021, 10:17:46 am »
Yea I did put those brackets in, but it made no difference. You are all looking at the wrong thing here. this code works:

Code: [Select]

void loop() {
  uint32_t timenow = millis();
  if ((timenow - varLastLoopTime) > constLoopIntervalMs)
  { // check time since last loop counter update
    loopCount++; // update loop count
    varLastLoopTime = millis();
 
    // int32_t vtSpeed = (vTachoSpeedCounts * tachoStep * 600) / (varCurrentSpeedTime - vLastSpeedTime);

      if (backlightstate == 1) {
        digitalWrite(lcdBackLightPin, LOW);
        backlightstate = 0;
      } else {
        digitalWrite(lcdBackLightPin, HIGH);
        backlightstate = 1;
      }


      lcd.setCursor(0, 2);
      lcd.print(timenow);
      lcd.setCursor(0, 3);
      lcd.print(vLastSpeedTime);

      vLastSpeedTime = millis();   
  }
}

The difference is that I took the statement out that gives me a multiple of the basic loop tic, so I can take the time stamps at the start and end of the main loop, but I can't in other code in a seperate block. So while I can make the lastup work, I am not prepared to do a production project like this. Basically i have to work all in one file? and in one function.
 

Offline Nusa

  • Super Contributor
  • ***
  • Posts: 2416
  • Country: us
Re: [arduino] can't subtract two time stamps
« Reply #36 on: October 22, 2021, 11:11:48 am »
You should try to define varLastLoopTime as volatile.
Code: [Select]
volatile unsigned long varLastLoopTime;

Also, I would reset this variable in the part of the code where we check if current value is equal to 10. So
Code: [Select]
void loop() {

  if ((millis() - varLastLoopTime) > constLoopIntervalMs) { // check time since last loop counter update
  loopCount ++; // update loop count
  varLastLoopTime = millis();
  }

  if (loopCount == 10)
{
    loopCount = 0;
    task2s();
  }
 
}

There shouldn't be any difference between the C and C++ for the else if statement.

Of course, when there are no "else if" statements in the code, it hardly matters.
 

Offline Psi

  • Super Contributor
  • ***
  • Posts: 9889
  • Country: nz
Re: [arduino] can't subtract two time stamps
« Reply #37 on: October 22, 2021, 11:51:56 am »
The difference is that I took the statement out that gives me a multiple of the basic loop tic, so I can take the time stamps at the start and end of the main loop, but I can't in other code in a seperate block. So while I can make the lastup work, I am not prepared to do a production project like this. Basically i have to work all in one file? and in one function.

Can you create two versions of your code. 
One that works and one that does not work using functions instead of all in void loop
Greek letter 'Psi' (not Pounds per Square Inch)
 

Online SimonTopic starter

  • Global Moderator
  • *****
  • Posts: 17728
  • Country: gb
  • Did that just blow up? No? might work after all !!
    • Simon's Electronics
Re: [arduino] can't subtract two time stamps
« Reply #38 on: October 23, 2021, 12:29:33 am »
yes, basically if you call millis() from a function that is too deeply nested things go wrong. I vaguely remember reading something about this a long time ago, naturally because arduino is perfect this information is no longer on their website under the milis() page. I think it was a maximum of 2 levels, even an if block stops it from working. I's a joke.
 

Offline Psi

  • Super Contributor
  • ***
  • Posts: 9889
  • Country: nz
Re: [arduino] can't subtract two time stamps
« Reply #39 on: October 23, 2021, 01:06:35 am »
hm. This is sounding like a bug in the setup of the compiler for the ARM core in the ATSAMD.
That is well outside my experience so I have no idea how to check that.
If you simplify it to two examples one that works and one that doesnt and post them to the arduino forum someone might be able to help debug that.

Oh, one minor thing you could try.
Change all your unsigned long variables to uint32_t variables.
It's probably not that, but worth a try.  I'm not sure what unsigned long is actually being converted to by your compiler.   uint32_t is more fixed,  an unsigned int of 32bits long.

It could also be a bug with the millis function itself.   
ARM cores do actually have a dedicated systick timer for getting millisecond ticks. I dunno if millis is trying to use that or doing the tick some other way, but you should be able to use the systick timer directly. Check for some examples of using systick on arduino with AT-SAMD

« Last Edit: October 23, 2021, 01:16:43 am by Psi »
Greek letter 'Psi' (not Pounds per Square Inch)
 

Offline brucehoult

  • Super Contributor
  • ***
  • Posts: 3996
  • Country: nz
Re: [arduino] can't subtract two time stamps
« Reply #40 on: October 23, 2021, 02:18:57 am »
yes, basically if you call millis() from a function that is too deeply nested things go wrong. I vaguely remember reading something about this a long time ago, naturally because arduino is perfect this information is no longer on their website under the milis() page. I think it was a maximum of 2 levels, even an if block stops it from working. I's a joke.

No. That is ridiculously unlikely to be true.
 

Offline semir-t

  • Regular Contributor
  • *
  • Posts: 56
  • Country: ba
Re: [arduino] can't subtract two time stamps
« Reply #41 on: October 23, 2021, 06:17:41 am »
And I agree fully with this. There is no way that nesting can affect the functionality of the code. Most likely, by adding the code you add some bugs that produce undesired behavior. This thread is the perfect example, because the problem was that the time between two calls was to small ( we didn't want this functionality but by writing our code we created this bug) but someone pointed out that there is a bug that when the counter is equal to 10 and the timeout didn't happen, function will be called as fast as possible.

So, if you want us to help you best way is to share the example that it doesn't work and one that is working. Basically, more info you give it will be easier to find the bug because most certainly bug is somewhere in your code. As bad as some Arduino libraries are, millis() is present for a long time and has been heavily tested and functions should be really stable.

 

Offline ledtester

  • Super Contributor
  • ***
  • Posts: 3032
  • Country: us
Re: [arduino] can't subtract two time stamps
« Reply #42 on: October 23, 2021, 06:55:11 am »
yes, basically if you call millis() from a function that is too deeply nested things go wrong. I vaguely remember reading something about this a long time ago, naturally because arduino is perfect this information is no longer on their website under the milis() page. I think it was a maximum of 2 levels, even an if block stops it from working. I's a joke.

I believe this is the code for millis() for AVR devices:

https://github.com/arduino/ArduinoCore-avr/blob/44dc454b9382298fa8be542c8c92e7944d9aa21e/cores/arduino/wiring.c#L65

and for the SAMD21:

https://github.com/arduino/ArduinoCore-samd/blob/39f483e901a6c7c10cbacc67df2048502913cf8b/cores/arduino/delay.c#L28
 

Online SimonTopic starter

  • Global Moderator
  • *****
  • Posts: 17728
  • Country: gb
  • Did that just blow up? No? might work after all !!
    • Simon's Electronics
Re: [arduino] can't subtract two time stamps
« Reply #43 on: October 23, 2021, 10:15:35 am »
And I agree fully with this. There is no way that nesting can affect the functionality of the code. Most likely, by adding the code you add some bugs that produce undesired behavior. This thread is the perfect example, because the problem was that the time between two calls was to small ( we didn't want this functionality but by writing our code we created this bug) but someone pointed out that there is a bug that when the counter is equal to 10 and the timeout didn't happen, function will be called as fast as possible.

So, if you want us to help you best way is to share the example that it doesn't work and one that is working. Basically, more info you give it will be easier to find the bug because most certainly bug is somewhere in your code. As bad as some Arduino libraries are, millis() is present for a long time and has been heavily tested and functions should be really stable.



Yes the arduino is of course perfect which is why someone that I beleive is a contributor had to put on his own forum not the arduino website haw to avoid issues caused by the arduino IDE itself: https://www.gammon.com.au/forum/?id=12625

i also do very well remember there once being a mention of not calling millis() from a function too deeply nested, but again the arduino is perfect so that information has been removed. maybe they thought they had it fixed. On monday I will have a look at taking a copy of my working code and hammer it back into what did not work.
« Last Edit: October 23, 2021, 10:17:45 am by Simon »
 

Offline semir-t

  • Regular Contributor
  • *
  • Posts: 56
  • Country: ba
Re: [arduino] can't subtract two time stamps
« Reply #44 on: October 23, 2021, 10:43:04 am »
And I agree fully with this. There is no way that nesting can affect the functionality of the code. Most likely, by adding the code you add some bugs that produce undesired behavior. This thread is the perfect example, because the problem was that the time between two calls was to small ( we didn't want this functionality but by writing our code we created this bug) but someone pointed out that there is a bug that when the counter is equal to 10 and the timeout didn't happen, function will be called as fast as possible.

So, if you want us to help you best way is to share the example that it doesn't work and one that is working. Basically, more info you give it will be easier to find the bug because most certainly bug is somewhere in your code. As bad as some Arduino libraries are, millis() is present for a long time and has been heavily tested and functions should be really stable.



Yes the arduino is of course perfect which is why someone that I beleive is a contributor had to put on his own forum not the arduino website haw to avoid issues caused by the arduino IDE itself: https://www.gammon.com.au/forum/?id=12625

i also do very well remember there once being a mention of not calling millis() from a function too deeply nested, but again the arduino is perfect so that information has been removed. maybe they thought they had it fixed. On monday I will have a look at taking a copy of my working code and hammer it back into what did not work.

I think you are missing a point here. I can see that you are frustrated with the Arduino and you should be, because when it comes to doing some serious stuff Arduino platform is pain in the a**. Most people are tempted with how easily you can program the board but whenever you start doing some serious stuff it fails, and it fails miserably.

That is way a had 2 suggestion, either you get familiar with the libraries or you write your own stuff. Either way, then you will know that is really happening.

That being said, by the code that you provided previously we can't say that the problem is in fact with the millis() function. I worked a lot with the millis() function (I had to because it was required to use Arduino) and I have to say that I didn't have this problem, and this function was in other .cpp files and not in the .ino file.

So, if you do have that problem. Create the example, share it with us and tell us which board you are using. Maybe someone will try to recreate that problem and will be able to help you. At this point it is just guessing game if the millis() is correct or not.
 

Online SimonTopic starter

  • Global Moderator
  • *****
  • Posts: 17728
  • Country: gb
  • Did that just blow up? No? might work after all !!
    • Simon's Electronics
Re: [arduino] can't subtract two time stamps
« Reply #45 on: October 23, 2021, 12:30:37 pm »
The first full sketch I uploaded in reply #5 does not work, I have posted here code that does work and code that does not. I can post more on Monday. The idea of the arduino is a good one but I have no idea what the arduino does to my code before it is compiled and it seems this can be an issue. When I first started in programming it was with the arduino but as I needed access to the hardware I converted my first commercial project from arduino to C, from there I was comfortable working with the hardware directly. But these days I do have the need for functionality that either I spend a long time learning for no reason other than to reinvent the wheel and write by own libraries or I use libraries. The arduino is again attractive in this sense but compared to a real no nonsense IDE feels like a toy that itself is playing too much with my code and does not give me any tools.
 

Offline brucehoult

  • Super Contributor
  • ***
  • Posts: 3996
  • Country: nz
Re: [arduino] can't subtract two time stamps
« Reply #46 on: October 24, 2021, 02:54:15 am »
Yes the arduino is of course perfect which is why someone that I beleive is a contributor had to put on his own forum not the arduino website haw to avoid issues caused by the arduino IDE itself: https://www.gammon.com.au/forum/?id=12625

"the Arduino". WTF even is that? There are several independent factors at play here

- the ATMega328 or other CPU
- the C compiler, usually gcc

Neither of those depends on it being "Arduino" instead of Atmel Studio in any way.

- the Arduino libraries, including millis()
- the Arduino IDE

What the above link is referring to is a custom preprocessor run by the Arduino IDE before running gcc. The aim is to simplify programming for beginners and to make the "Wiring" language compatible between C++ and Java by automatically adding prototypes for all declared functions at the start of the program, so that you can declare your functions in any order (like in Java).

Quote
i also do very well remember there once being a mention of not calling millis() from a function too deeply nested

Nothing unique to millis() there. That applies to calling ANY function on a tiny CPU with very limited RAM. The ATMega328 only has 2k of RAM so if you have a lot of global variables (or use malloc() carelessly) and have deeply nested functions then there is a risk of them colliding.

That is completely independent of using the Arduino IDE vs programming in any other language or environment.

I had a look at millis() and on avr gcc 5.4.0 and earlier the stack space used by millis() is ... precisely 2 bytes for the return address (3 bytes on Mega2560). I don't know about Arduino on ARM. The code does look more complex there, but nothing extreme. But you probably also have more RAM to play with.

Quote
On monday I will have a look at taking a copy of my working code and hammer it back into what did not work.

Do you seriously not use a code repository?
 
The following users thanked this post: xrunner

Offline Psi

  • Super Contributor
  • ***
  • Posts: 9889
  • Country: nz
Re: [arduino] can't subtract two time stamps
« Reply #47 on: October 24, 2021, 06:03:46 am »
"the Arduino". WTF even is that? There are several independent factors at play here
- the ATMega328 or other CPU
- the C compiler, usually gcc

He is using Arduino on a ATSamD21G18A  (ARM core)
Greek letter 'Psi' (not Pounds per Square Inch)
 

Offline westfw

  • Super Contributor
  • ***
  • Posts: 4196
  • Country: us
Re: [arduino] can't subtract two time stamps
« Reply #48 on: October 24, 2021, 08:52:57 am »
(paraphrasing)
Quote
Arduino doesn't allow direct access to the hardware.
Basic functions (millis(), subtraction, etc) in arduino don't work, perhaps because the ARM compiler is misconfigured.
The Arduino forums hide this by censoring their forums, forcing expert contributors off onto their own forums.
The Arduino code is full of clever and complex (and thus indecipherable) C++ code.

None of those are true.  You sound like a conspiracy theorist.


I ran your code from #5 through Arduino with all the warnings turned on, and took a general look through.  I don't have your hardware setup, so I can't duplicate all the testing.  I changed the LCD output to Serial, and it prints stuff about every 2 seconds.

These look like real problems (use of boolean "!" operator where there should be a bitwise "~"?  I'm not real clear on what it's trying to do.)
Code: [Select]
/Volumes/MacOS/HD-Downloads/Downloads/lashup/button_inputs.ino: In function 'void buttonRead(unsigned char)':
/Volumes/MacOS/HD-Downloads/Downloads/lashup/button_inputs.ino:11:46: warning: '<<' in boolean context, did you mean '<' ? [-Wint-in-bool-context]
   11 |     varButtonState = (varButtonState & !(0x1 << button)) | (0x1 << button);
      |                                         ~~~~~^~~~~~~~~~
/Volumes/MacOS/HD-Downloads/Downloads/lashup/button_inputs.ino:15:50: warning: '<<' in boolean context, did you mean '<' ? [-Wint-in-bool-context]
   15 |     varButtonPressed = (varButtonPressed & !(0x1 << button)) | (0x1 << button);
      |                                             ~~~~~^~~~~~~~~~


And here, it bothers me that tempstring[] can apparently be up to 14 characters, while the text[] string that it's being copied to can only have 5.  (whether that actually happens is a separate question, I guess.)

Code: [Select]
void asciiDistance(long vartoconvert, char *string) {
  unsigned char tempstring[15];
    :
  while (tempcounter != 0) {
    string[stringcounter] = tempstring[tempcounter];
    tempcounter--;
    stringcounter++;
  }
}

void lcdDistancePrint() {
  noInterrupts();
  long distance =  tachoDistanceCounts * tachoStep / 100;
  char text[6] = {0, 0, 0, 0, 0, 0};
 
  asciiDistance(distance, text);
    :

There is a bunch of use of "uint8_t" and "uint16_t" and similar that would be a good idea on an AVR, but is un-useful to harmful on an ARM.

The stack pointer for a SAMD21 image is initialized to 0x20008000 (the end of the 32k of RAM), so stack-overflow - the only reason I could imagine that "millis() fails if call from "too deeply nested", seems extremely unlikely.  (And I've never heard of any such thing.)

-----

There are annoying things about "Arduino", but in the end it's a very shallow framework on top of standard well-trusted tools, and it has a LOT of users.   If you're going to make extraordinary claims about serious and should-be-obvious bugs and misbehaviors, we (well, I) will need extraordinary proof.  That means code and instructions for a (hopefully very minimal; ie no LCD, no actual tach hardware) hardware setup that demonstrates the problem.

Nick Gammon was never an official Arduino employee, though he was a significant contributor to the forums for quite a while.   His personal forums and web pages pre-date the Arduino by a long time, so it makes sense that he'd post info of long-term interest there.  He hasn't been around the Arduino forums for a while, and I don't recall him posting a reason for leaving.  I suspect he got tired of rude users, rather than of the administration.)  I've never seen the forums censor people for technical info critical of Arduino code/etc; only for ... rudeness to other people.  (And I would have, having been a main player in the "Freeduino" project, back when it looked like the HW might go "closed source.")
 

Online SimonTopic starter

  • Global Moderator
  • *****
  • Posts: 17728
  • Country: gb
  • Did that just blow up? No? might work after all !!
    • Simon's Electronics
Re: [arduino] can't subtract two time stamps
« Reply #49 on: October 24, 2021, 08:53:41 am »


"the Arduino". WTF even is that? There are several independent factors at play here


Yes but this is a dumbed down system for beginners meant to work on several different processors with no regard for the hardware detail. What wiring program? I here this mentioned a lot is relation to the arduino but then I am told it's C/C++.

A code repository, um yea, how do I get that to work with the arduino, at what point do I decide "this code won't work and never has but hey I should keep a copy for posterity, oh hang on over 2 days I have like 100 mods to this and the result of all 100 mods is the same - so how do I evaluate what to keep".
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf