class documentation

class DCCCmdTx:

Constructor: DCCCmdTx()

View In Hierarchy

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_instance Get the DCC Command tx instance.
Method __init__ DCC serialisation constructor
Method pio_off Stop PIO State Machine
Method pio_pwr DCC Power On/Off
Method pio_send Send Packet.
Constant FWD Forward direction
Constant OFF Power Off
Constant ON Power On
Constant REV Reverse direction
Method _dcc_tx PIO Serialise DCC Command
Class Variable _this_dcc Undocumented
Instance Variable _rc_ch2 Undocumented
Instance Variable _sleep_pin Undocumented
Instance Variable _sm Undocumented
@classmethod
def get_instance(cls):

Get the DCC Command tx instance.

This returns the singleton instance of the DCC Generator.

Parameters
cls
Returns
The DCC generator instance
def __init__(self):

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.

def pio_off(self):

Stop PIO State Machine

def pio_pwr(self, p=None):

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
p1 for power on, 0 for power off, None for get power status
Returns
power status as held by the power pin
def pio_send(self, packet):

Send Packet.

Write the DCC Command packet to the state machine's FIFO buffer.

Parameters
packetThe DCC command object.
FWD =

Forward direction

Value
const(1)
OFF =

Power Off

Value
const(0)
ON =

Power On

Value
const(1)
REV =

Reverse direction

Value
const((-1))
@rp2.asm_pio(out_init=rp2.PIO.OUT_HIGH, set_init=rp2.PIO.OUT_HIGH, out_shiftdir=rp2.PIO.SHIFT_LEFT, fifo_join=rp2.PIO.JOIN_TX)
def _dcc_tx():

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.

_this_dcc =

Undocumented

_rc_ch2 =

Undocumented

_sleep_pin =

Undocumented

_sm =

Undocumented