Hi all,
Hundreds of 24BYJ-48 steppers driven by custom made boards with TPIC6B595's. To have a better understanding of the project please see:Creating The BMW Kinetic Sculpture
Wawa had an excellent solution and kindly provided the software also.
Wiring hundreds of end stops or using encoders were not an option. So, I thought of saving the stepper positions on EEPROM, micro SD or NVRam, etc. and reload them on start up.
But a problem rises. What if there's a power failure or the the setup is shut down while steppers are moving from A to B and have not reached their destination ?
All the solutions I have read suggest something (?) to test power loss and a large capacitor to feed the Arduino enough current to write to EEPROM.
I'm not sure if this solution will work. Writing hundreds of integers to EEPROM takes time ? Will the saved positions be accurate ?
I've thought of an interrupt button that would stop the steppers and save positions, and a red LED against intentional shut down but that would not save me in case of a power failure.
Appreciate your help and suggestions.
The "standard" way of doing this is to have end or home switches, but you indicate that this is not an option.
Writing to EEPROM is useless. Too slow and what if the load moves the motor when powered off?
I'd do a "dummy home." Move the motor to its "home" position, but without using a home sensor. If you know that the entire motor travel from end to end is 5,000 steps, then move it 5,000 steps in the home direction. You'll get a lot of unpleasant grinding noise when it hits the end stop (since you don't have a sensor to tell it to stop moving), but it's pretty much the only way without feedback.
Ideally if your motor controller has adjustable running current, you'd set the current to a low value before doing this to reduce the possibility of damaging the structure.
Why not save the value of B before starting the move ? That way, in the worst case the motors would be in a known position when the system was restarted and the last known positions were reloaded
+1
In detail with the sculpture the saving of stepper motor positions is of no use ![]()
The problem with this is that at startup, you're still not guaranteed that the motors are in a known position so they'll be out of sync with each other.
That's true, and the only way that you can know exactly where the steppers are is to have a position to which they home before repositioning to the desired position.
However, that is a requirement of the system when working normally as you cannot rely on the current position at start-up
If the system has no limit switches then how can it ever work ? Like you, I can imagine driving the motors so far in one direction that they must have reached an end stop even if there is no actual limit switch but that is a very undesirable way to have the system working
It is, but this is for a kinetic sculpture with low-performance steppers so I think we can cut OP a bit of slack.
Do you know exactly how many byte's you'd like to save?
Thanks for the feed back.
@UKHeliBob the problem is power shut down while stepper is moving. So saving the target position is of no use.
@cedarlakeinstruments Wawa uses your suggested approach in his sketch. Low torque at start up, homes the steppers with no end switches. I could use this method, i.e. instead of saving hundreds of positions on EEPROM, I could save just a flag that tells if there was a power failure, then run the steppers till they "grind". Howerver, it won't work for me. In my project I have the steppers moving small mirrored tiles that would hit the frame and break if I move beyond a certain point in any direction.
Can you add a physical stop on the shaft that the tile is on that would keep it from hitting the frame?
The only other alternative I can think of is that you'd need a UPS with a power shutdown signal. When that signal is tripped, you stop all motors and read back their current positions and save to SD card or EEPROM or something and then shut the system down. This assumes that nothing moves when power is off, though.
Then that is too much torque -- There should be a torque between zero and max that will move an unloaded system but not produce damage with excessive load.
What if a child puts a finger between the panels?
Slipping and skipped steps is a good failure mode.
Yes, exactly what I need. Can you pls elaborate more on this idea.
How would I tell Arduino that UPS has been tripped, so stop the steppers and save ?
Good question ![]()
My APC UPS has a feature where it sends an alert over the serial port when external power fails, but it is probably about 25 years old at this point and long since obsoleted by APC!
I know many others have a similar feature, but I can't suggest specific brands. If you have trouble finding one, it's pretty simple to add the feature. You can use a regular UPS with enough battery power to run your system for a few seconds and connect a 120VAC relay to the power line. When the power goes out, the relay switches off and the arduino can detect that and stop the motors and save their current positions.
[edit]
Here's a DC-input UPS that has a relay output to indicate when input power is lost and it's switched to battery mode.
The way my program works is that all steppers take one step every ~2ms, and can be stopped in 14ms, including deceleration. Then coil power is cut.
That process of stopping all motors is less than a sine wave of mains power (20ms@50Hz).
My guess is that 30Amp motor power supply should be able to bridge several mains power sine waves with the energy stored in the primary caps. If motors have stopped there could be enough power left to have the Arduino write to it's eprom.
Step one, to test this theory, is to make a mains power fail detector. I suggest an AC opto coupler (HA11A1), to detect both positive and negative half, and see how short you can set it before false triggers. I wrote some code to experiment with.
Leo..
// AC opto LED with two 100k resistors (one on each pin)connected to mains power
// opto transistor between pin (collector) and ground (emitter), no resistor
const byte optoPin = 3;
unsigned long previousMillis;
void setup() {
Serial.begin(115200);
pinMode (optoPin, INPUT_PULLUP);
}
void loop() {
if (!digitalRead(optoPin)) previousMillis = millis(); // keep updating while AC available
if (millis() - previousMillis > 10) { // no AC for 10ms
// stop motors
// write to Eeprom
Serial.println("Brownout detected");
delay(1000); // dirty delay
}
}
Edit: If you can't get an AC opto coupler, then use two normal ones.
Connect the LEDs back2back and the transistors in parallel.
How about this board ?
I'm also searching for an UPS with TTL signal to Arduino but have no knowledge
You don't need all those extra parts, or perfect zero crossings.
Just use an AC opto coupler with two 100k 1/4watt resistors, protected with some heatshrink.
Leo..
Pls bear in mind that I have no knowledge in electronics and don't feel safe playing around with 220v. I could ask help from a engineer I know but it will cost me more than the board I mentioned. So, if you think it will do the job, I'd rather spend € 50 for the board. Thanks.
That board is for a different purpose. Something like this board should work to detect presence/absence of 220VAC.
The bridge rectifier and cap on that board would make it too slow for the half-wave detection I had in mind. It could work for a UPS-based backup.
Leo..