Hi. I am implementing model train DCC s/w using Uno and an L298N H-bridge. At this stage getting the correct electrical signals onto the track so that the train moves is not working for me. My program appears to work in that if I extend the duration of "0" and "1" to 1 second and 0.58 seconds I can replace the track with diodes and they turn on and off OK. Unfortunately, my train does not move though. Any comments about the code below will be appreciated:
const int In3 = 7;
const int In4 = 6;
unsigned int header[13] = {0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0}; // 12 * "1" + "0"
unsigned int train_1_address[9] = {0, 0, 0, 0, 0, 0, 1, 1, 0}; // “3” + "0" at end
unsigned int train_1_command[9] = {0, 1, 1, 0, 1, 1, 1, 1, 0}; // + "0" at end
unsigned int train_1_XOR[9] = {0, 1, 1, 0, 1, 1, 0, 0, 1}; // + "1" at end. XOR precalculated. This will be changed when I get the program to work.
unsigned int train_1[3][9];
void setup()
{
pinMode(In3, OUTPUT);
pinMode(In4, OUTPUT);
for (int i = 0; i <= 8; ++i)
{
train_1[0] = train_1_address*; // Copy address of train_1 into train_1 array*
train_1[1] = train_1_command*; // command train to go forward at start*
train_1[2] = train_1_XOR; // Copy XOR data
* }*
}
void Zero() // define ‘0’ as an electrical signal
{
* digitalWrite(In3, LOW);*
* digitalWrite(In4, HIGH);*
* delayMicroseconds(100);*
* digitalWrite(In3, HIGH);*
* digitalWrite(In4, LOW);*
* delayMicroseconds(100);*
}
void One() // define ‘1’ as an electrical signal
{
* digitalWrite(In3, LOW);*
* digitalWrite(In4, HIGH);*
* delayMicroseconds(58);*
* digitalWrite(In3, HIGH);*
* digitalWrite(In4, LOW);*
* delayMicroseconds(58);*
}
void goStraight() //Output header then convert array data to electrical signals.
{
// Output header
* for (int i = 0; i <= 12; ++i)*
* {*
_ if (header == 0)
* {
Zero();
}
else*
* {
One();
}
}_
//Output train_1 address, command, and XOR*
for (int j = 0; j <= 2; ++j)
{
* for (int i = 0; i <= 8; ++i)*
{
if (train_1[j] == 0)
* {*
* Zero();*
* }*
* else*
* {*
* One();*
* }*
}
}
}
void loop()
* {*
* goStraight();*
* }*
Format of the packet can be found at:
*https://www.nmra.org/sites/default/files/s-92-2004-07.pdf*_
Thanks in advance_
train_v4.pdf (76.7 KB)


