DCC Output Transmit
This singleton class manages the serialisation of DCC command packets to the track.
The PIO has to be fed with words. If the top bit (bit 31) is clear the word contains pre-amble ('1's) or two framing bit/command byte combinations. 18 bits are output. If bit 31 is set and bit 30 is clear the word contains a single framing bit/command byte. 9 bits are output. If both bits 31 and 30 are set, the word contains the packet end bit, which will also trigger the RailCom cutout. The Packet End Bit is encoded as a final word with bit 8 set. Bit 7 must be set too if the cutout is to be generated. Normal command databytes are preceeded by a '0' start bit.
Both short (7 bit) and long (14 bit) Multifuntion (mobile) decoder addresses are catered for but note that an address in the range 1 to 127 will be interpreted as a short address and an address in the range 128 - 10239 will be interpreted as a long address. I.e a mobile decoder with a long address in the range 0 - 127 is not addressable.
A RailCom cutout is inserted following the transmission of a DCC command.
| Class Method | get |
Get the DCC Command tx instance. |
| Method | __init__ |
DCC serialisation constructor |
| Method | pio |
Stop PIO State Machine |
| Method | pio |
DCC Power On/Off |
| Method | pio |
Send Packet. |
| Constant | FWD |
Forward direction |
| Constant | OFF |
Power Off |
| Constant | ON |
Power On |
| Constant | REV |
Reverse direction |
| Method | _dcc |
PIO Serialise DCC Command |
| Class Variable | _this |
Undocumented |
| Instance Variable | _rc |
Undocumented |
| Instance Variable | _sleep |
Undocumented |
| Instance Variable | _sm |
Undocumented |
Get the DCC Command tx instance.
This returns the singleton instance of the DCC Generator.
| Parameters | |
| cls | |
| Returns | |
| The DCC generator instance |
DCC serialisation constructor
This initialises the DCC serialisation singleton. An attempt to create a 2nd instance will cause a runtime error. The PIO state machine is allocated and initialised.
Pins parameters are provided as Pin objects - not numbers!
If RailCom cutouts are required the cutout generator must use a PIO state machine in the same PIO block.
DCC Power On/Off
- On power on we
- de-assert the booster sleep pin (1 for False)
- start the DCC generator state machine
On power off we assert the booster sleep pin (0 for True)
The state machine will be stopped when the current command cycle is complete.
| Parameters | |
| p | 1 for power on, 0 for power off, None for get power status |
| Returns | |
| power status as held by the power pin |
Send Packet.
Write the DCC Command packet to the state machine's FIFO buffer.
| Parameters | |
| packet | The DCC command object. |
PIO Serialise DCC Command
This is the PIO DCC command transmitter. A GPIO pin is used for the DCC output. This pin is set or cleared with the 'set(pins, ...)' command using the set_base pin as allocated for the state machine.
A second GPIO pin, connected to the DRV8874 enable pin controls the RailCom cutout. The pin is normally high, and set low during for the cutout, setting both sides of the H-bridge to low impedance and thereby connecting the two track rails. This pin is allocated to the state machine as out_base and its state changed using the 'mov(pins, ...) command. Using separate bases allows the state of the two pins to be managed independently.
OSR is set to shift left so the Most Significant bits are shifted out first.
The RX FIFO is joined to the TX FIFO so doubling the TX FIFO length.
As this is output only we can use the Input Shift Register (ISR/isr) as an additional store.
TODO There needs to be an option to allow for generation of DCC without the RailCom cutout.