anyone have experience using an encoder to control a motor's position? what algorithms used to deal with motor momentum? how would PID be applied?
greg - Philadelphia & Reading / Reading
If you look at the code for my turnout controller, you can see the functions that write the current position of each turnout.
The 'data' is 2 bytes, one is the counter for how many times that data location has been written, 0-255. The other byte is the actual data, 4 possible values for the 2 turnouts: 00, 0F, F0, or FF. Each time the position changes, the counter increments and is also written. When it rolls over past 255 and back to 0, the pointer is incremented by 2 and written. Then it repeats. 256 writes, then on to the next pair of locations, another 256 writes, etc.
And yes, Flash. The stuff built in to the micros is fairly low endurance at 10K cycles ( though that's the guaranteed level, not absolute maximum, as some have gotten WAY more in a test environment by doing continuous read/write/compare to see how long it would go until an error showed up). Some of the external serial chips are rated to 100k writes, plus are typically larger than the built in flash space, so not only can each cell take more writing, there are more of them for the pointer to range over. Suffice to say, you cna store the position millions of times before hotting the endurance limits, especially if you only write the position when you are sure the operation is complete - for example, in my turnout controller, if you start one servo moving to the reverse positon but then press the normal button before the movement completes, the servo will retuen to the normal position. It will never have written that it was set to reverse - it only updates the flash when movement has stopped AND it is at one position or the other. Also why the code has to be non-blocking - if turnout 1 is in the middle of a movement and you also need to operate turnout 2, it will respond immediately, not wait until turnout 1 finishes moving. This is the issue that makes the otherwise inexpensive Lenz LS150 turnout decoder unsuitable for any sort of slow motion motors - once one of the outputs has been commanded to change state, it ignores DCC commands to change any others until the operation is complete. Not a big deal for solenoids which change almost instantly, but for slow motion machines that take a few seconds, that's a few seconds the decoder just ignors commands. For a turntable, you would do similar - only write the position when motion stops. That way if you are halfway between tracks 1 and 8, and decode you actually wanted track 6, you hit 6, and only after the bridge stops at track 6 does it write track 6 as the current location. Versus writing the position as soon as the button is pressed.
--Randy
Modeling the Reading Railroad in the 1950's
Visit my web site at www.readingeastpenn.com for construction updates, DCC Info, and more.
rrinkerFor every 256 writes to the pointer locations (out of the 10K lifetime), you get 256x256 stores to each pair of storage locations, so 65536 saves of whatever data you are saving. To get to 10K writes to the pointer, that's 39 passes (at 256 writes per pass). Since each pass through all 256 pointer values is 65536 writes, you get 39x that total writes, over 2.5 million.
having a hard time following this, and there are other requirements for the EEPROM
may be less of an issue. The 1k EEPROM (not flash) is rated at 100,000 write/erase cycles
sounds like ... you have 3 memory locations: one is the position and 2 3 bytes the number of writes. You use these until the count reaches the limit, 100k. You then use the next 3 4 locations.
At some point (unlikely), there i no additional storage. If you reach this point, you could potentially increase the limit. Maybe a readback test after each write to mark the space unusable
One (or 2) locations store a pointer. The location that the pointer points to is a counter, and the locatioon after that is the actual data. So for every update to the pointer, you get 256 writes to the data, then the pointer updates, and you get 256 writes to the next location for data, and so on. Say you have 256 pairs of addresses available (so the micro has more than 512 bytes of EEPROM - and I'm using easy numbers for reference). For every 256 writes to the pointer locations (out of the 10K lifetime), you get 256x256 stores to each pair of storage locations, so 65536 saves of whatever data you are saving. To get to 10K writes to the pointer, that's 39 passes (at 256 writes per pass). Since each pass through all 256 pointer values is 65536 writes, you get 39x that total writes, over 2.5 million. With no location exceeding 10K writes. The pointer hits the limit before the actual storage locations do. So another layer could be added to get more. If you are using a micro with 1K of EEPROM, you can (jusr rounding) get 500x256 stores per pass, for the same 39 passes. which is almost 5 million stores. (1024 bytes, less 2 bytes for the pointer, less a couple of bytes for an initialization string so your code can determine if it needs to start with the pointer at the first block or read the existing pointer to retrieve data - can't rely on a freshly programmed chip having all 0's or anything - divided by 2, for the 0-255 counter byte and the actual data byte).
rrinkeryou get 10K writes spread out across 256 or 1024 locations.
how do you keep track of which location is current? and don't you need to keep track of the number of writes in each location
You could so something liek what I'm doing with my turnout controller to roll the storage location in EEPROM, so you get 10K writes spread out across 256 or 1024 locations. It will take a long time to accumulate 10 million moves of the turntable.
Or same technique but use an external serial EEPROM, most of them are rated for 100K writes instead of just 10K of the microcontroller. Combine techniques (micro holds the address of the external EEPROM being used) and use say a 4K EEPROM - that's over 400 million 'saves' before hitting the endurance rating. If you moved the turntable 5 times a minute, 24 hours a day, 7 days a week, that's over 2.5 years of continuous operation. I think it should be fine. And one byte is plenty, since you'd never be able to have 255 tracks on one turntable anyway.
i'm guessing that the position, geared step #, is saved in eeprom after every movement, otherwise it needs to be realigned whenever turned on. I'm guessing this would be a reasonable number of writes to EEPROM (10k write lifetime)?
would you think there is an automatic position reset whenever the turntable passes the alignment point (led in wall)?
wondering how complicated a controller would be after getting past the mechanical setup
Especially if you have some rather expensive brass locoos - I'd say there should be at least 2 safety mechanism. One can detect motor current and stoop the step signal if it is too great, and as a last resort, the mechanical coupling somewhere should allow for slip.
There definitely are stepper motors plenty powerful enough to be direct drive.
Another option is what in referred to as servos - not the ones like in model airplanes, but a high torque motor with a precision encoder wheel on the shaft, rather than have some absolute number of steps between tracks, you have a number of counts on the encoder wheel. These things are extremely precise, more accurate than a typical stepper. This is the mechanism used on precision CNC machine tools. The cheap DIY ones use steppers. Downside is, they are not nearly as cheap as a stepper. And probbaly a lot more accurate than is really needed to line a turntable bridge - the stepper is going to be close enough, as there is no need to line the rails to within the nearest tenth. Cut a piece of straight track and the ends won't be aligned to those tolerances anyway.
yesterday the turntable bridge I was operating caught on the coupler of a loco a little to close. This prevented the bridge from moving and doing any damage
it didn't knock the loco off the track, which i think suggests how little force is needed to stop the bridge, as well as move it
and that you wouldn't want the motor to be so powerful that it can do damage -- it simply slipped on the rod. (yes, it needed to be re-calibrated, re-aligned with a known position).
gregcis that a good thing?
I never dared try to stall it. When there is a locomotive weighing close to two pounds on the bridge you certainly need some torque there. I suppose a shear pin or slip clutch might make a "safety valve" but, in twenty-five years operation I've never had anything jam the bridge. Keep the pit clean and obstructions clear before operating the turntable.
Cheers, Ed
as far as i know, they are all geared, stepper or otherwise..
direct coupled motors would have to be relatively large to generate needed torque i think
thanks
gmpullmanvery powerful.
is that a good thing?
I use the system provided by New York Railway Supply. The stepper motor is definitely geared. Step angle is .025°. I could look later to see what make/model it is.
IMG_5885 by Edmund, on Flickr
I don't believe a direct drive stepper motor would have the torque needed to turn the bridge.
I don't know the ratio of the gearcase but the result is a nice slow movement and very powerful. 10:1 maybe?
IMG_5883 by Edmund, on Flickr
Good Luck, Ed
i see that the Nema stepper motors have a 1.8 deg step size.
for a 10" turntable, i calculate that this is ~0.2" arc at the edge of the bridge, which seems large to me for aligning rails within a rail thickness
are stepper motors w/ 1.8 deg step size typically directly coupled to turntable bridges or are they geared some how?
i see geared stepper motors on ebay (1:63, step size 18 deg, ~0.02")
seems that there are lots of articles on the use of stepper motors, but they are focused on the software.