Turntable Program Description |
This page contains the source code portion of the Basic Stamp 2 program that controls the turntable. Note that this program is written using the PBASIC 2.5 version. The complete version 2 code and documentation can be downloaded using this link: TurntableV2.zip The original code is available here: Turntable.zip
' ====================================================================== ' TurntableV2.bs2 5-03-2005 ' ' Note: This program is written using {$PBASIC 2.5} features. ' ' This program is used to control the engine terminal turntable on the ' D&B model railroad. This portion of the layout consists of two approach ' tracks and a number of engine storage tracks. A maximum of ten turntable ' track positions are supported. The rotating turntable bridge track is ' positioned using a stepper motor based upon user input via a keypad. ' Track numbers are entered using a 12 button telephone style keypad and ' cause the turntable bridge to rotate and align to the specified track ' number. All turntable track positions are user input via the keypad. This ' provides completely arbitrary approach and storage track positions. ' ' User input turntable bridge track positions are stored in the Basic Stamp ' NVRAM. In this way, the bridge track position programming is not lost when ' power is removed. The following memory map describes this storage area. ' All storage locations are a word (two bytes) in size. ' ' Address Description ' ------- ---------------------------------------------------- ' 0 Circle size - calculated by programming mode 0 key. ' 2 Head end position for key 0 - operate mode 0# keys. ' 4 Head end position for key 1 - operate mode 1# keys. ' ... Head end position for keys 2 through 8. ' 20 Head end position for key 9 - operate mode 9# keys. ' 22 Tail end position for key 0 - operate mode 0* keys. ' 24 Tail end position for key 1 - operate mode 1* keys. ' ... Tail end position for keys 2 through 8. ' 42 Tail end position for key 9 - operate mode 9* keys. ' ' When programming a bridge track position, the final rail alignment stepping ' should be done in a clockwise direction for proper gear backlash elimination. ' This program incorporates the program constant PosAdj. In operate mode, the ' value of this constant is used to overstep the specified track position when ' moving in a counter-clockwise direction. The turntable bridge is then im- ' mediately stepped the same PosAdj amount in the clockwise direction resulting ' in the final rail aligned position. Depending on the drive gear reduction ' used, this constant may need to be adjusted slightly. ' ' Mechanical considerations: ' ' The D&B model railroad uses a turntable bridge gear ratio of 12 to 1. This ' results in a step circle of 9,600 steps using a 3.6 degree stepper motor ' (100 steps) that is 8x micro-stepped (800 steps = 360 degrees). In use, ' this circle size results in a single step of about one eighth an HO scale ' rail width which has proven to be more than enough accuracy. ' ' Other combinations of gear ratios, stepper motors (e.g. 1.8 degree step), ' and micro-step settings can be used up to a maximum of 65,535 steps in the ' circle (16 bit word). Higher ratios may introduce more gear backlash that ' must be taken into account (PosAdj constant). Some planning and compromise ' that involves the desired rotation speed, position accuracy, and gear back- ' lash is necessary. No program code changes are required for other gear ' ratios or stepper motors other than the backlash PosAdj constant. The total ' steps in the circle is computed and stored by this program in response to ' the Programming mode '0' key. ' ' This design does not currently include any bridge track position feedback ' other than the home position sensor. All movements are based upon the home ' position that is located at power on time. The method used to gear the stepper ' motor and bridge track must be carefully considered to ensure accurate and ' repeatable positioning. Any bridge track rotational binding or rough spots ' must be eliminated. Gearing backlash should also be minimized. The prototype ' successfully uses the stock gears provided with the Walthers Cornerstone ' Series (R) turntable, part number 933-3171. Another method would be to use a ' miniature tooth/timing belt and pulley design. ' ' Program mode: ' ' The keypad is used to manually position the turntable bridge and assign ' the position to a keypad number button. This information is stored in the ' BS2 NVRAM for reference during operate mode. It is necessary to enter this ' data only when the turntable related track configuration is changed; ' normally following the laying of the track. ' ' Each turntable position has a head-end and tail-end which corresponds to ' the bridge track end. No specific keypad button to track mappings are ' enforced. The same bridge track position and head/tail alignment may be ' programmed for multiple keypad buttons if desired. ' ' The following summarizes the keypad buttons and corresponding functions ' that are used in program mode. ' ' Button Function ' ------ ---------------------------------------------------------- ' 0 Find home position and calculate circle size ' 1 Microstep turntable bridge counter-clockwise ' 2 Head-end of turntable bridge track aligned (default) ' 3 Microstep turntable bridge clockwise ' 4 Step turntable bridge counter-clockwise ' 5 Tail-end of turntable bridge track aligned ' 6 Step turntable bridge clockwise ' 7 Slew turntable bridge counter-clockwise ' 8 Remove current position data for track number/alignment ' 9 Slew turntable bridge clockwise ' ** Enter/exit program mode ' #x Associate current turntable bridge position and head/tail ' input with specified track number. ' ' Note that turntable motion keys 1, 3, 4, 6, 7, and 9 will auto-repeat when ' held down for more than 1/2 second. ' ' The following warning tones can occur in program mode: ' ' 1 tone - Circle size too large. Need less steps in circle. ' ' 2 tones - Unknown turntable bridge position or circle size. Do program ' mode key '0' first. ' ' 3 tones - Invalid keypad input. ' ' Programming example: ' ' The following example illustrates the steps used to input the information for ' the approach track and two storage track positions. The approach track is ' assigned to button 1 and the storage tracks to buttons 2 and 3. Storage track ' 2 is then removed. It is assumed that the controller circuit is connected to ' the turntable motor, power is applied, and the BS2 heartbeat indicator is ' flashing. ' ' It is recommended that a locomotive be placed on the bridge track during ' programming. The weight of the locomotive has a slight effect on the final ' position due to gear drive backlash. ' ' For reference in this programming example, the head-end of the turntable is ' the end where the operators shack is mounted. The keypad buttons '1', '3', ' '4', '6', '7', and '9' are collectively referred to below as the 'move' ' buttons. ' ' 1. Press the '*' key twice to enter programming mode. The heartbeat Led ' changes to solid on to show that programming mode is active. If three ' short tones are heard, an invalid key value was detected and is likely ' caused by a keypad wiring error. ' ' 2. Press the '0' key. This finds the turntable bridge home position. If not ' found, the turntable bridge will rotate continuously in a counter-clockwise ' direction indicating a wiring or sensor problem. The turntable bridge is ' then rotated once in a clockwise direction to determine the circle size. ' ' 3. Use the 'move' buttons to rotate the turntable bridge and accurately align ' the head-end bridge track with the approach track. The final alignment ' should be done in a clockwise direction to eliminate gear backlash. ' ' 4. Press the following buttons in order: '2', '#', '1'. ' ' 5. Use the 'move' buttons to rotate the turntable bridge and accurately align ' the tail-end bridge track with the approach track. The final alignment ' should be done in a clockwise direction to eliminate gear backlash. ' ' 6. Press the following buttons in order: '5', '#', '1'. ' ' 7. Use the 'move' buttons to rotate the turntable bridge and accurately align ' the head-end bridge track with storage track one. The final alignment ' should be done in a clockwise direction to eliminate gear backlash. ' ' 8. Press the following buttons in order: '2', '#', '2'. ' ' 9. Use the 'move' buttons to rotate the turntable bridge and accurately align ' the tail-end bridge track with storage track one. The final alignment ' should be done in a clockwise direction to eliminate gear backlash. ' ' 10. Press the following buttons in order: '5', '#', '2'. ' ' 11. Use the 'move' buttons to rotate the turntable bridge and accurately align ' the head-end turntable track with storage track two. The final alignment ' should be done in a clockwise direction to eliminate gear backlash. ' ' 12. Press the following buttons in order: '2', '#', '3'. ' ' 13. Use the 'move' buttons to rotate the turntable bridge and accurately align ' the tail-end bridge track with storage track two. The final alignment ' should be done in a clockwise direction to eliminate gear backlash. ' ' 14. Press the following buttons in order: '5', '#', '3'. ' ' 15. To remove the head-end aligned entry for storage track two, press the ' following buttons in order: '8', '2', '#', '2'. ' ' 16. To remove the tail-end aligned entry for storage track two, press the ' following buttons in order: '8', '5', '#', '2'. ' ' 17. Press the '*' key twice to exit programming mode. The heartbeat Led ' returns to operational flash rate; once per second. ' ' 18. Use operate mode turntable positioning commands to verify proper operation. ' Reprogram individual tracks if necessary. ' ' x# - Head-end of turntable should align to the specified track number. ' x* - Tail-end of turntable should align to the specified track number. ' ' Operate mode: ' ' Two button presses are entered via the keypad to rotate the turntable bridge ' track. The first button pressed is the desired track number. The second button ' pressed is the turntable bridge end to align to the specified track. The ' turntable bridge track is rotated following the second button input. The keypad ' entry indicator will flash during the turntable bridge move operation. ' ' A solid 'on' keypad entry indicator is used to show that a track number has ' been input and the program is waiting for a turntable bridge track end button to ' be pressed. If a turntable bridge track end button is not pressed within about ' 5 seconds, the entered track number button is ignored. ' ' Upon power up, the program initiates a search for the home position sensor. ' This involves stepping the turntable bridge in a counter-clockwise direction ' until the home position sensor returns an active state. This search operation ' can be aborted by pressing any key during the search operation. The next bridge ' movement, in program or operate mode, will redo the home position search. ' ' Two automatic turntable bridge movements can be enabled by the setting of program ' constants. ' ' The first optional movement, if enabled, is performed after initial power up. ' It permits automatic turntable bridge positioning to an initial track position. ' The constants InitPos1 and InitPos2, when both non-zero, identify a track and ' turntable bridge end respectively. The values specified should be the keypad ' number of a programmed track position (InitPos1 e.g. 1, 2, etc.) and the bridge ' end (InitPos2 e.g. 10 (*) tail end or 11(#) head end). ' ' The second optional movement, if enabled, results in random turntable bridge ' positioning. If the constant RandomMove is set to a non-zero value, the value ' represents a time delay. Each toggling of the heartbeat indicator (about 1 second) ' will cause a counter set to this value to be decremented. When the counter reaches ' zero, the turntable bridge will be positioned to a random track and bridge end. ' The time delay is then restarted. A user commanded move will also reset the time ' delay. ' ' RandomMove set to a value of 255 results in about a 4-5 minute delay between auto ' moves. The actual time between moves may be a longer multiple of this time since ' bridge positioning will only be performed if the random track/end position values ' are actually programmed. ' ' The following summarizes the keypad buttons and corresponding functions that ' are used in operate mode. ' ' Buttons Function ' ------- ------------------------------------------------------------- ' x# Position turntable bridge track head-end to track number 'x'. ' 'x' is a button 1 through 9. ' x* Position turntable bridge track tail-end to track number 'x'. ' 'x' is a button 1 through 9. ' 00 Re-index to home position sensor. Same as power on operation. ' 11 Toggle position of lead track turnout 1. ' 22 Toggle position of lead track turnout 2. ' ' The following warning tones can occur in operate mode: ' ' 1 tone - Unprogrammed track number specified. Program track number. ' 2 tones - Unknown turntable circle size. Redo program mode key '0'. ' 3 tones - Invalid keypad input. ' ' Turntable Lead Track Turnouts: ' ' The turnouts that provide access to the tracks associated with the turntable ' can be controlled by this program. The operational mode command 11 is used ' to change the position of turnout 1. The command 22 is used to change the ' position of turnout 2. Each entry of the 11 or 22 key sequence will toggle ' the position of the respective turnout; from closed to open or open to closed. ' The turnouts do not employ position sensors. The program assumes the turnouts ' are closed at power up. ' ' Turntable Bridge Track Power: ' ' The turntable bridge track must be powered by a polarity reversing circuit. An ' external circuit (MRC-AR auto reverser) is used to control the power polarity ' of the turntable bridge track. ' ' All storage tracks are wired to the same polarity as the lead track. These ' tracks are all connected to the "non-switched" power controller output. The ' turntable bridge track is connected to the power controller "switched" output. ' ' Hardware: ' ' The turntable control circuit uses the 74C922 keypad encoder to interface ' and debounce the push button key input. The capacitors associated with the ' 'osc' and 'msk' inputs determine the key scan rate and debounce time period; ' 600 hz and 10 msec respectively. ' ' The stepper motor is a 12 volt unit with a 3.6 degree step angle. The stepper ' motor is driven by an Allegro 3977 stepper motor controller which provide a ' simplified interface to the BS2 and the ability to microstep the motor. Micro ' stepping is used to provide the necessary accuracy for turntable bridge track ' rail alignment. The resistors used to set the stepper motor holding current ' are a compromise between overall power draw, stepper motor heat, and the ' weight of the largest locomotive to be turned. ' ' A 74LS38 quad open collector NAND gate is used to drive the switch machine ' coils for the approach track turnouts. Each turnout control bit is connected ' to the base circuit of a TIP127 5 amp darlington transistor. When a turnout is ' to be positioned, the program selects the appropriate NAND gate and pulses ' the common NAND gate inputs for a nominal 250 ms. This causes the TIP127 driver ' circuit to energize the turnout coil. ' ' An input pin of the Basic Stamp is connected to a position sensor that is ' used to identify the turntable bridge rotation reference point. If continuous ' 360 degree rotation of the turntable bridge occurs, a sensor circuit problem ' is the likely cause. ' ' An output pin of the Basic Stamp is connected to a Led and used to indicate ' the status of operator keypad input. ' ' An input pin of the Basic Stamp is connected to a switch and used to select ' normal or test mode program operation. When off (1), normal turntable func- ' tions as described herein are enabled. When on (0), test mode is enabled. ' In test mode, the turntable bridge will be stepped from its current position ' approximately 60 degrees clockwise. It is then stepped 60 degrees counter- ' clockwise. This sequence will be repeated as long as test mode is enabled. ' If the home sensor position is crossed during either motion, a short chirp ' tone will be sounded. ' ' Also during test mode, pressing a keypad button will result in key number ' of tones being sounded with 0 = 10, * = 11, and # = 12 tones respectively. ' ' The normal/test mode pin is also connected to a led that serves as a ' heartbeat indicator. ' ' An output pin of the Basic Stamp is connected to a speaker and used to ' sound warning or input error tones. ' ======================================================================
Navigation: Turntable D&B Home Buczynski.com Index
Copyright © 2006 Don Buczynski
San Diego, California