Control time of a function's execution time
Control time of a function's execution time
Hi, everyone!
I use STM32 to take photos by using an ARDUCAM mini. From time to time (for instance once a 100 times) it may stick to a piece of code including read/write registers functions and cannot come out of one of them.
I used a while-loop to limit the time that it takes to execute that piece of code. However, it didn't help at all. I know that a watchdog timer might be a solution to restart the code from scratch. However, I am looking to find a better solution to bypass that part because the next time in the loop, it might be able to simply execute it.
Many thanks for any help.
I use STM32 to take photos by using an ARDUCAM mini. From time to time (for instance once a 100 times) it may stick to a piece of code including read/write registers functions and cannot come out of one of them.
I used a while-loop to limit the time that it takes to execute that piece of code. However, it didn't help at all. I know that a watchdog timer might be a solution to restart the code from scratch. However, I am looking to find a better solution to bypass that part because the next time in the loop, it might be able to simply execute it.
Many thanks for any help.
Re: Control time of a function's execution time
It it goes into infinite loop then there is something wrong with the code.
Re: Control time of a function's execution time
tough to help without seeing what you are trying to do.
Re: Control time of a function's execution time
I just found out that the function that gets stuck is the following:
But as I mentioned, it works fine most of the time and may stop rarely. I cannot find neither the reason nor any solution to bypass it. Therefore, the only way is to use a Watchdog timer. Please let me know if you know a better solution.
Code: Select all
while (!myCAM.get_bit(ARDUCHIP_TRIG , CAP_DONE_MASK));
Re: Control time of a function's execution time
assuming that myCAM.get_bit() returns frequently.while (!myCAM.get_bit(ARDUCHIP_TRIG , CAP_DONE_MASK)) if (cnt++>TIMEOUT_CNT) break;
Re: Control time of a function's execution time
Thank you!
Does this differ from the following method for 1000 ms that I have already implemented.
If it is different, please let me know how to define cnt and TIMEOUT_CNT.
I think there is a problem with the function myCAM.get_bit. As I understand, it doesn't return a value for the while loop.
Does this differ from the following method for 1000 ms that I have already implemented.
Code: Select all
long cnt = millis();
while (!myCAM.get_bit(ARDUCHIP_TRIG , CAP_DONE_MASK)) if (millis()-cnt>1000) break;
I think there is a problem with the function myCAM.get_bit. As I understand, it doesn't return a value for the while loop.
Re: Control time of a function's execution time
unlikely - the program wouldn't compile if that's the case.it doesn't return a value for the while loop.
I think you will need to figure out if myCAM.get_bit() is returning the wrong value (0 in this case, assuming your code is correct), *or* its has a hung execution.
Re: Control time of a function's execution time
When I print the values of the following command under discussion, before and after the mentioned while loop in normal situation, they are 0 and 8, respectively.
Still looking to catch the case where the while loop stops, to present the value at least before the while loop. I will inform you as soon as I have a new achievement.
Still looking to catch the case where the while loop stops, to present the value at least before the while loop. I will inform you as soon as I have a new achievement.
Code: Select all
myCAM.get_bit(ARDUCHIP_TRIG , CAP_DONE_MASK)
Re: Control time of a function's execution time
No real difference, but your way of using an actual time limit may be better.mebab wrote: Sat Feb 18, 2023 9:01 pm Thank you!
Does this differ from the following method for 1000 ms that I have already implemented.If it is different, please let me know how to define cnt and TIMEOUT_CNT.Code: Select all
long cnt = millis(); while (!myCAM.get_bit(ARDUCHIP_TRIG , CAP_DONE_MASK)) if (millis()-cnt>1000) break;
If that does not work (as in, occasionally you still get "stuck" there even with you extra code in place), then it would seem that it is hanging somewhere within the myCAM.get_bit() processing. From a quick look at the ARDUCAM code, perhaps SPI.transfer() is not returning for some reason. To find out where, you would have to drill down into the ARDUCAM code and likely into the SPI processing too. That is something that would be quite easy to do if you are set up for "real" debugging using an STLINK, but it could also be done without that if you are prepared to spend some time on it.
As it stands myCAM.get_bit() has no way to return to you saying "I'm sorry Dave, I'm afraid I can't do that." I don't know how practical it would be to add some sort of timeout to ARDUCAM functions like that. So maybe that does mean you have to look at IWatchdog.
Edit:
I just noticed - you should really have defined cnt as unsigned (that is what millis() returns), but still lilely that myCAM.get_bit() is not returning to you.
Re: Control time of a function's execution time
that means that the routine returns execution to the main loop, just with the unexpected value (8). you will need to see 1) why it returns that value; and 2) how you would continue execution if that value is returned.before and after the mentioned while loop in normal situation, they are 0 and 8, respectively.
so the question now is much simpler.