-
Notifications
You must be signed in to change notification settings - Fork 134
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Test Motor/Encoder Appears to Write to EEPROM 1000s of times #488
Comments
Very interesting, and excellent sleuthing. My memory about this are very vague, but I thought that if a motor is 'detached' it won't move. DirectWrite() may be overriding that however. |
The directWrite mechanism passes a force=true to the write routine and therefore it ignores whether the motor is attached or not. Is there harm in attaching the motor before doing the encoder test and detaching it when its done? If the motor was 'attached', then the eeprom wouldn't be written to. |
If this is truly writing to EEPROM, then other places that do maslowDelay with motors detached will also contribute to wearing out the EEPROM. I see it in the setSpindlePower code where there may be 6000 EEPROM writes done. It's also in the G4 dwell command... worrisome if true. |
Yes, we absolutely don't want to be writing to the eeprom that much. It should only write once two seconds after the last command. |
There's something I must be missing because no one's EEPROM should be working anymore. The .ino file's loop command continually executes execSystemRealtime() and that calls systemSaveAxesPosition() and that calls settingsSaveStepstoEEPROM() if the axes are detached. If the machine is idle for more than 2 seconds, the axes are supposed to detach.. So everytime loop runs when the machine is idle, it will be writing to EEPROM... When should steps be saved to EEPROM? I think it should save once, and only once, when all axes have been detached. Maybe we need a flag that gets set when the steps are written to EEPROM and gets cleared when an axis is attached and that flag is what's checked to determine whether or not to write to EEPROM? Perhaps add a bool to system_t structure? |
I put together a solution but have no idea how to make a PR for it since my fork's master has a bunch of other stuff in it that's custom. I'm no github expert. It's simple changes to four files (system.h, system.cpp, settings.cpp, and axis.cpp). Any suggestions on how to do a PR? I tried editing each file online off the Maslow/Firmware but it seemed to create "patches" for each file. Is that ok? Edit: Well, I took the first patch and added all the other changes to it. I created a PR for it for review: |
Is there any reason to not attach the axis during the motor/encoder test? I don't see any reason not to, but since it doesn't and uses a force override, I ask. |
I think that the issue was that when they are attached the regular PID controler is trying to control them and during the test we want them to spin no matter what someone has entered in their settings. |
Ok, make sense. Do we want to have encoder steps after the test? I think most of the time people are testing the motors/encoders they are doing so with the chains attached. We could easily set the flag at the end of the test function if saving is desired. |
I think that sounds like an excellent idea. For people testing without the chains attached (which is what I was picturing when I created the test), there is no harm in saving the correct position. |
I wonder if eeprom.h or even the chip itself has code that avoids eeprom writes when what is to be written is the same as what's already there.. would seem possible that's there to have that to minimize where. Edit: appears that the update function in eeprom.h will do that check, but the put function that's used to save the structure does not. |
Actually, put uses update (found it searching in a different manner) https://www.arduino.cc/en/Reference/EEPROMPut "Note That explains why the EEPROM isn't worn out.. whew. Still, if we can avoid the EEPROM.put calls, we should. I don't know if I can update the PR, but I could add the thing about saving steps after test in a new PR. |
Apparently editing the code in patch-4 branch (what the PR is based on) automatically updated the PR. |
Good sleuthing, that explains why it hasn't come up earlier, but I am still glad to have a fix. Isn't GitHub pretty sweet that way 😏 |
Sad thing is that I think this issue came up a while back because it seems so familiar. Nevertheless, it's good to call functions only when needed. What is interesting is that the eepeom.put command actually interferes with motor operations on a teensy (causes motor to stutter). Some conflict or something no one on teensy forum seems to know about. |
Hi,
I see no reason to repeat 1000 times the Did I understand well that each |
@madgrizzle did some sleuthing and found that maslowDelay uses EEPROM.update(0, which only writes to the EEPROM if the value has changed. This seems like the desired action, to keep a record of the values but only write when necessary. |
I don't know how the eeprom.update code works but I suspect it might do a read, then a comparison, and then write if there's a change (to avoid fatiguing the eeprom).. but that takes time to do so the modifications avoid it all since it's not necessary. |
I'm thinking of putting some pair of counters around settingsSaveStepstoEEprom(), just to check how often it is called with the bit When the eeprom isn't ready, one of two things could happen:
Just to keep it at hand, the call chain to the eeprom write is like this:
|
I would be interested in seeing the results of that |
Sure!
|
Meanwhile, I have found some good news reading the arduino reference file:
By chance that right function is used here in Setting.cpp (by design perhaps!). Likewise, it would be good to replace the last calls And I haven't yet seen a check of the EEPE bit in the arduino code. Still checking before implementing my debug code... |
And the result is ... surprise ... :
Tadaa! I mean, that happened each time I have typed "B04" on the Arduino Monitor console (to test the motors)... ie after having typed 21 times that command I got this (Look for the
I'm puzzled... So, maybe yeah, there were not so many writes after all, or I have made some huge mistake, but we are far from what I feared: two large growing numbers. No need for long integers ;-) And at the end, there is still no confirmed bug about the writes, which is promising after all. |
The plot thickens...but at least it keeps thickening in a good way |
Can you explain what the results mean? Is this based upon the current master of firmware? |
It's built from this branch: Then I flashed an arduino mega2560, and opened the monitor console. |
ok, I just wanted to make sure this was post-PR.. I'm not sure why it writes just before the test because the code doesn't set sys.writeStepsToEEPROM to true until all motor tests are completed. The only other time it gets set to true is when the axis is attached, but I could never find code that did that in response to a B04 command. |
You asked the right question! |
Digging deeper, here is what I have found, typing
Still going in a nice direction then. |
Sounds logical.. I think if you take out the mod I made with the addition of sys.writeStepsToEEPROM test then you'll get markedly different results.. but the amount of times the eeprom is written to may not actually change. |
OK, well thought!
Which makes me understand that the
From my point of view, your mod stays relevant, great! |
Firmware/cnc_ctrl_v1/Axis.cpp
Lines 259 to 264 in 2c4e420
I've been hunting down an issue in some custom firmware I'm working on and believe that their may be an issue with the stock firmware where it appears that when the test motor/encoder function is run, it writes encoder steps to eeprom at least 2000 times per axis.
The loop in the axis' test function executes maslowDelay(1) for each direction 1000 times. maslowDelay() calls execSystemRealtime() continually until the 1 ms delay is up. execSystemRealtime() does a number of things, including calling systemSaveAxesPosition(), where, if all axes are "detached", settingsSaveStepstoEEPROM() is executed. During the axis test function, I don't see anywhere an axis gets "attached" so I assume they are all still "detached". I've found that my custom firmware does actually call settinsSaveStepstoEEPROM during this time (so it appears the axes remain detached), and I don't think I changed anything from the stock firmware in this area that would make it behave differently. Obviously, if its truly writing to EEPROM so many times, that's a bad thing.
The text was updated successfully, but these errors were encountered: