This shows you the differences between two versions of the page.
Both sides previous revision Previous revision Next revision | Previous revision Next revision Both sides next revision | ||
traincontrol [2021/10/12 16:19] dpisuperadmin [Next Steps] |
traincontrol [2021/10/15 00:38] dpisuperadmin [Hardware and Wiring] |
||
---|---|---|---|
Line 12: | Line 12: | ||
open-drain driver. | open-drain driver. | ||
- | {{ wiki: | + | {{ wiki: |
* Hardware and Wiring | * Hardware and Wiring | ||
* Peripherals | * Peripherals | ||
Line 25: | Line 25: | ||
{{ trans1.v3.gif? | {{ trans1.v3.gif? | ||
==== Hardware and Wiring ==== | ==== Hardware and Wiring ==== | ||
- | {{ wiki: | + | {{ wiki: |
User interface hardware consists of a quad slide switch card and a quad slide potentiometer card. The leftmost two switches control the track switches. | User interface hardware consists of a quad slide switch card and a quad slide potentiometer card. The leftmost two switches control the track switches. | ||
- | {{ wiki: | + | {{ wiki: |
Engine and track switch control use a dual H-bridge card and a quad open-drain driver card. The dual DC motor controller peripheral (DC2) and the dual H-bridge card (D7HB) can easily control the engine speed and direction. | Engine and track switch control use a dual H-bridge card and a quad open-drain driver card. The dual DC motor controller peripheral (DC2) and the dual H-bridge card (D7HB) can easily control the engine speed and direction. | ||
- | The track switches are left and right hand three-wire switches from Atlas. | + | The track switches are left and right hand three-wire switches from Atlas. |
One problem with our chosen hardware is that at power up the open-drain driver outputs are at ground. | One problem with our chosen hardware is that at power up the open-drain driver outputs are at ground. | ||
Line 43: | Line 43: | ||
A wireviz generated wiring diagram for the system is shown below. | A wireviz generated wiring diagram for the system is shown below. | ||
{{ wiki: | {{ wiki: | ||
+ | /* Wiringviz source file for the above | ||
+ | connectors: | ||
+ | Switch-Left: | ||
+ | type: Soldered wires | ||
+ | pinlabels: [Coil-Left, Common, Coil-Straight] | ||
+ | show_name: false | ||
+ | notes: Track Switch Left | ||
+ | Switch-Right: | ||
+ | type: Soldered wires | ||
+ | pinlabels: [Coil-Right, | ||
+ | show_name: false | ||
+ | notes: Track Switch Right | ||
+ | DC-IN: | ||
+ | type: Barrel | ||
+ | subtype: female | ||
+ | pinlabels: [V+, GND] | ||
+ | show_name: false | ||
+ | notes: Power Adapter | ||
+ | SMR-5: | ||
+ | type: screw terminal | ||
+ | pinlabels: [V+, GND, V5.0, GND] | ||
+ | show_name: false | ||
+ | notes: SMR-5 regulator | ||
+ | DRV4: | ||
+ | type: screw terminal | ||
+ | pinlabels: [V+, GND, O1, O2, O3, O4] | ||
+ | show_name: false | ||
+ | notes: DRV4 Open-Drain Driver | ||
+ | D7HB: | ||
+ | type: screw terminal | ||
+ | pinlabels: [V+, GND, A1, A2, B1, B2] | ||
+ | show_name: false | ||
+ | notes: D7HB H-bridge | ||
+ | SBC: | ||
+ | type: Soldered wires | ||
+ | pinlabels: [V5.0, GND] | ||
+ | show_name: false | ||
+ | notes: Single Board Computer | ||
+ | Track: | ||
+ | type: screw terminal | ||
+ | pinlabels: [Rail-1, Rail-2] | ||
+ | show_name: false | ||
+ | notes: Track | ||
+ | |||
+ | cables: | ||
+ | W1: | ||
+ | colors: [RD,BK] | ||
+ | W2: | ||
+ | colors: [RD,BK] | ||
+ | W3: | ||
+ | colors: [RD,WH] | ||
+ | W4: | ||
+ | colors: [RD,WH] | ||
+ | W5: | ||
+ | colors: [GN,YE,RD] | ||
+ | W6: | ||
+ | colors: [GN,YE,RD] | ||
+ | W7: | ||
+ | colors: [RD,WH] | ||
+ | |||
+ | connections: | ||
+ | - | ||
+ | - DRV4: [4,1,3] | ||
+ | - W5: [1,2,3] | ||
+ | - Switch-Left: | ||
+ | - | ||
+ | - DRV4: [5,1,6] | ||
+ | - W6: [1,2,3] | ||
+ | - Switch-Right: | ||
+ | - | ||
+ | - DRV4: [1,2] | ||
+ | - W7: [1,2] | ||
+ | - D7HB: [5,2] | ||
+ | - | ||
+ | - DC-IN: [1-2] | ||
+ | - W1: [1-2] | ||
+ | - SMR-5: [1-2] | ||
+ | - | ||
+ | - D7HB: [1-2] | ||
+ | - W2: [1-2] | ||
+ | - SMR-5: [1-2] | ||
+ | - | ||
+ | - SMR-5: [3,4] | ||
+ | - W3: [1-2] | ||
+ | - SBC: [1-2] | ||
+ | - | ||
+ | - D7HB: [3,4] | ||
+ | - W4: [1,2] | ||
+ | - Track: [1,2] | ||
+ | */ | ||
==== Peripherals ==== | ==== Peripherals ==== | ||
- | The four daughter | + | The four //cards// in the system are the D7HB dual H-bridge, the DRV4 quad open-drain driver, the SW4 quad slide switch, and the SLIDE4 quad slide pot. The Linux (and FPGA) // |
- | We used the Demand Peripherals support page "Build your FPGA Image" to request the four peripherals we needed. | + | We used the Demand Peripherals support page "Build your FPGA Image" |
+ | ([[http:// | ||
+ | to request the four peripherals we needed. | ||
| Slot | Name | Description | | | Slot | Name | Description | | ||
Line 72: | Line 164: | ||
< | < | ||
Test one switch with the commands: \\ | Test one switch with the commands: \\ | ||
- | < | + | < |
Once the program starts we can read the state of the switches and the position of the slide pots using dpget commands. | Once the program starts we can read the state of the switches and the position of the slide pots using dpget commands. | ||
Line 95: | Line 187: | ||
\\ | \\ | ||
< | < | ||
+ | < | ||
=== Python === | === Python === | ||
Line 103: | Line 195: | ||
At program start time we want to force the speed of the engine to be zero until the slide pot is actually set to zero, at which time the pot can start to control the engine speed. | At program start time we want to force the speed of the engine to be zero until the slide pot is actually set to zero, at which time the pot can start to control the engine speed. | ||
+ | |||
+ | < | ||
+ | # | ||
+ | import socket | ||
+ | import sys | ||
+ | import time | ||
+ | |||
+ | # The purpose of this program is to control the speed | ||
+ | # and direction of model railroad. | ||
+ | # hardware is a Demand Peripherals Baseboard4 FPGA card | ||
+ | # along with a quad slide switch card, a quad slide pot, | ||
+ | # and dual H-bridge. | ||
+ | # FPGA based peripherals control this hardware through | ||
+ | # a daemon supplied by Demand Peripherals. | ||
+ | # visible peripherals are a in4 peripheral in slot 2, | ||
+ | # a slide4 peripheral in slot 3, and a dc2 peripheral | ||
+ | # in slot 4. Please see their respective pages at : | ||
+ | # http:// | ||
+ | # | ||
+ | # This program opens one socket to dpserver for commands | ||
+ | # to the FPGA card. Normally there is one socket per | ||
+ | # sensor and one for commands. | ||
+ | # we use polling to read the slide pot and direction | ||
+ | # switch. | ||
+ | # | ||
+ | # Switch 0x1 sets the direction. Slide pot 1 sets the | ||
+ | # speed. | ||
+ | # be set unless the speed is set to zero. | ||
+ | |||
+ | def send_cmd(socket , str ) : | ||
+ | "Send Command to FPGA deamon" | ||
+ | socket.send(str) | ||
+ | response = '' | ||
+ | while True : | ||
+ | c = sock_cmd.recv(1).decode() | ||
+ | if c ==' | ||
+ | break | ||
+ | response += c | ||
+ | if ((len(response) > 0) and (response[0] == ' | ||
+ | # Error if first character of response is an E | ||
+ | print(" | ||
+ | print(" | ||
+ | # | ||
+ | # | ||
+ | return response | ||
+ | |||
+ | try: | ||
+ | sock_cmd = socket.socket(socket.AF_INET, | ||
+ | sock_cmd.connect((' | ||
+ | | ||
+ | # Init H-bridge PWM frequency to 50 Hz and mode to brake. | ||
+ | # Set the H-bridge watchdog timer to 300 ms. | ||
+ | response = send_cmd(sock_cmd, | ||
+ | response = send_cmd(sock_cmd, | ||
+ | response = send_cmd(sock_cmd, | ||
+ | response = send_cmd(sock_cmd, | ||
+ | # init track swith states to unknown | ||
+ | switch_left = " | ||
+ | switch_right = " | ||
+ | |||
+ | # loop forever getting speed and direction | ||
+ | while True: | ||
+ | # Get speed and switch settings | ||
+ | positions = send_cmd(sock_cmd, | ||
+ | position1 = int(positions[: | ||
+ | speed = int(100 * (1024 - position1) / 1024) | ||
+ | switches = send_cmd(sock_cmd, | ||
+ | |||
+ | # Set track switches if controlling slide switches changed | ||
+ | if (int(switches[0], | ||
+ | switch_left = " | ||
+ | response = send_cmd(sock_cmd, | ||
+ | time.sleep(0.10) | ||
+ | response = send_cmd(sock_cmd, | ||
+ | elif (int(switches[0], | ||
+ | switch_left = " | ||
+ | response = send_cmd(sock_cmd, | ||
+ | time.sleep(0.10) | ||
+ | response = send_cmd(sock_cmd, | ||
+ | if (int(switches[0], | ||
+ | switch_right = " | ||
+ | response = send_cmd(sock_cmd, | ||
+ | time.sleep(0.10) | ||
+ | response = send_cmd(sock_cmd, | ||
+ | elif (int(switches[0], | ||
+ | switch_right = " | ||
+ | response = send_cmd(sock_cmd, | ||
+ | time.sleep(0.10) | ||
+ | response = send_cmd(sock_cmd, | ||
+ | # | ||
+ | |||
+ | # Set engine direction if speed is zero | ||
+ | if speed == 0: | ||
+ | if int(switches[0], | ||
+ | response = send_cmd(sock_cmd, | ||
+ | else : | ||
+ | response = send_cmd(sock_cmd, | ||
+ | # Always set engine speed to keep watchdog alive | ||
+ | response = send_cmd(sock_cmd, | ||
+ | time.sleep(0.05) | ||
+ | # | ||
+ | |||
+ | except KeyboardInterrupt: | ||
+ | # exit on Ctrl^C | ||
+ | sock_cmd.close() | ||
+ | sys.exit() | ||
+ | |||
+ | except socket.error: | ||
+ | print(" | ||
+ | sys.exit() | ||
+ | |||
+ | </ | ||
Line 116: | Line 320: | ||
=== DCC === | === DCC === | ||
- | Model train Digital Command and Control (DCC) is well explained at the DCC Wikipedia article: | + | Model train Digital Command and Control (DCC) is well explained at the DCC Wikipedia article: |
- | < | + | https:// |
The system described in the this article is well positioned to move to DCC. Right now there are two peripherals that use the D7HB dual H-bridge, the DC2 dual DC motor controller, and the STEPB bipolar stepper motor controller. | The system described in the this article is well positioned to move to DCC. Right now there are two peripherals that use the D7HB dual H-bridge, the DC2 dual DC motor controller, and the STEPB bipolar stepper motor controller. | ||
=== Low Cost Track Switch Control === | === Low Cost Track Switch Control === | ||
{{ http:// | {{ http:// | ||
- | Larger layouts tend to use servo motors mounted under the train table to control track switches. | + | Larger layouts tend to use servo motors mounted under the train table to control track switches. |
+ | ([[http:// | ||
+ | shows how the servo movement switches the track. | ||