Baseline PacketsThere are many types of packets used in a DCC system but for the moment we will only look at what are called the Baseline Packets. Compliance with these packets is mandatory in a DCC system which means that all Command Stations and Decoders must use or recognise them. There are many other optional packets and these are described in the Extended Packet and the Service Mode Recommended Practices. The optional packets will be discussed in future articles. In the packet examples given below the bit values 1 and 0 are mandatory for that type of packet whilst bit values such as A, D, E etc are alterable values for that packet which are defined in the text.Speed & Direction Packet for Mobile Receivers1111111111 0 0AAAAAAA 0 01DUSSSS 0 EEEEEEEE 1Preamble Address Byte Data Byte Error ByteThe address byte contains the binary address that can be from 0 to 127depending on the value of "AAAAAAA". It is permissible for command stations to address a reduced range of addresses, some have as little as eight addresses but more commonly ninety-nine. The zero at the start of the byte allows address space for other non compulsory packets such as those for accessory control.The data byte starts with the bits "01" again to allow space for non compulsory packets such as function control (lights, bells, couplers etc). The next bit (bit 5 labelled D) provides for direction, "1" indicates move forward, "0" reverse. Bit 4, called the "U bit", is undefined in the baseline standard and was originally used by Lenz for headlights but is now used as the least significant bit for 28 speed control.The speed control, bits 0 - 4 and labelled SSSS, allow for sixteen values. The first, "0000", is a Stop command. Emergency stop has the value "0001" while the rest of the values from "0010" to "1111" are the speed steps 1 to 14. Hence the fourteen speeds of the baseline DCC system.A Stop command utilises any programmed inertia whereas the Emergency Stop brings the loco to an immediate undignified halt
void emergencyStop(){// int xxx = 0; for (int xyz = 0; xyz <= maxLocos - 1; xyz++) { // do this to make sure every loco keeps stationary after restarting the layout LocoAddress[xyz] = EEPROM.read(xyz * 2) * 256; LocoAddress[xyz] = LocoAddress[xyz] + EEPROM.read(xyz * 2 + 1); Serial.print("<t1 "); Serial.print(LocoAddress[xyz] ); // locoID); Serial.print(" "); Serial.print(LocoSpeed[LocoAddress[xyz]] = -1 ); Serial.print(" "); Serial.print(LocoDirection[LocoAddress[xyz]] ); Serial.write(">"); } LocoSpeed[ActiveAddress] = 0; rotaryHalfSteps = 0; actualRotaryTicks = 0; doMainLCD(); delay(50); // give some time to write the DCC command to the base station before shutting off the power //Serial.print("<0>"); }
switchValue = analogRead(switchPin); if (switchValue > 512) { Serial.print("<t1 "); Serial.print(LocoAddress[ActiveAddress] ); // locoID); Serial.print(" "); Serial.print(LocoSpeed[ActiveAddress] = -1 ); Serial.print(" "); Serial.print(LocoDirection[ActiveAddress] ); Serial.write(">"); LocoSpeed[ActiveAddress] = 0; rotaryHalfSteps = 0; actualRotaryTicks = 0; doMainLCD(); delay(50); // give some time to write the DCC command to the base station before doing something else
Als je alle locs wilt aansturen was het geloof ik ook mogelijk om dcc adres 0 te gebruiken. Dit werkt enkel voor snelheid commando's.
wordt de polariteit (blijft wel tussen 0 en +18v, dus niet -18V zoals bij M*) gewisseld.
Ik wil nog een functie inbouwen dat als ik rangeer ik een knop kan induwen om de loc direct stil te zetten (niet de noodstop maar meer een "rangeerstop").
Als ik via de Throttle de wissels ga aansturen, dan heb ik denk ik per wissel een decoder nodig die net zoals een loc zijn signaal en energie van de rails haalt.
voor servo's via een PWM output
Nee hoor Servo's kunnen aan elke pin. Hardnekkig misverstand maar voor servo's wordt alleen Timer1 gebruikt waardoor de PWM van pin 9 en 10 niet meer werkt. Maar heeft verder niets met de hardware PWM te maken.
Servo myServo;myServo.attach(A2);