Hey All,
I'm designing a state machine and up to this point, I've been saving all of my variables globally. The code is getting pretty long and I've been thinking about having all my variables to be stored locally. Many of the functions that I've written use variables from other functions (Using a MEGA2560 as the master on my I2C BUS).
Does copying the variable contents from one function to the other take a substantial amount of time (I'm using a DAQ to store my data and I need close to 1ms accuracy)?
As a side note, I have used Scheduler and FreeRTOs libraries for multi-tasking in the past. Both of them have given me a hard time with their weird interrupt protocols (It's very important in my case not to lose any data points on my DAQ setup). Any suggestions would be hugely appreciated
Does copying the variable contents from one function to the other take a substantial amount of time
Only microseconds, as they are transferred to the function via the stack, and then the function code is called - and the stack released when the function ‘retrurns’.
If those few uS are too much, make the shared variables ‘global’. It will save moments, but use slightly more RAM at runtime.
Hey Paul,
I use a NI DAQ toolbox to collect my data. I've found synchronizing their (The BUS and the DAQ) times to be pretty difficult (I simply don't know a way to do it other than sending a synchronizing pulse to the DAQ every xms). I know accessing vars from the common memory is the shortest pathway for the microcontroller.
I cannot verify (eventX at timePointX) using any of the Arduino timer software that I know (Serial Monitor is also too slow to handle the data output). Even with OOP, the code is pretty large and handling vars locally could help a lot to clean it up. I just don't know if I would be taking a timing accuracy hit by doing it.
Just a wild guess as you didn't show the actual code: a lot of those variables may be bundled in a struct... another way of making your code less of a mess.
mousas02:
I use a NI DAQ toolbox to collect my data. I've found synchronizing their (The BUS and the DAQ) times to be pretty difficult
I don't know that toolbox and you have not posted a link to it nor have you posted the program you are having trouble with.
Although 1 millisec is a quite a long time for an Arduino it can only do one thing at a time and if any of the toolbox functions takes longer than 1 msec then you are not going to be able to get several things within the same msec.
As a side note, I have used Scheduler and FreeRTOs libraries for multi-tasking in the past.
Those libraries may make life easier for the person doing the programming but they do so by using up CPU cycles so the net effect is that they reduce the ability to do things close to the same time.